.
3 в ряд
Сообщений 1 страница 5 из 5
Поделиться22025-12-18 16:05:12
[html]<div id="match3">
<div id="board"></div>
<div id="score">Очки: 0</div>
</div>
<style>
#match3 {
margin: 20px auto;
width: max-content;
text-align: center;
font-family: Arial;
}
#board {
display: grid;
grid-template-columns: repeat(6, 64px);
gap: 4px;
}
.cell {
width: 64px;
height: 64px;
border-radius: 10px;
cursor: pointer;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
transition: transform 0.35s ease, opacity 0.25s;
}
.cell.empty { opacity: 0; }
.cell.selected { outline: 3px solid #fff; }
</style>
<script>
const SIZE = 6;
const TILE = 68;
const COLORS = [
{ id:'red', img:'https://upforme.ru/uploads/001c/84/76/2/401102.png' },
{ id:'blue', img:'https://upforme.ru/uploads/001c/84/76/2/700139.png' },
{ id:'green', img:'https://upforme.ru/uploads/001c/84/76/2/128242.png' },
{ id:'yellow', img:'https://upforme.ru/uploads/001c/84/76/2/330476.png' }
];
const ICONS = {
'line-h': 'https://upforme.ru/uploads/001c/0f/f1/3/544551.png',
'line-v': 'https://upforme.ru/uploads/001c/0f/f1/3/675860.png',
'color' : 'https://upforme.ru/uploads/001c/0f/f1/3/753893.png',
'area' : 'https://upforme.ru/uploads/001c/0f/f1/77/689325.webp'
};
let board = [];
let selected = null;
let score = 0;
const boardEl = document.getElementById('board');
const scoreEl = document.getElementById('score');
const idx = (x,y) => y*SIZE+x;
function randGem(){
const c = COLORS[Math.floor(Math.random()*COLORS.length)];
return { colorId:c.id, img:c.img, type:'normal', protected:false };
}
function draw(){
boardEl.innerHTML='';
board.forEach((c,i)=>{
const d=document.createElement('div');
d.className='cell';
if(!c){
d.classList.add('empty');
} else {
d.style.backgroundImage =
c.type==='normal'
? `url(${c.img})`
: `url(${ICONS[c.type]})`;
}
if(i===selected) d.classList.add('selected');
d.onclick=()=>click(i);
boardEl.appendChild(d);
});
}
function click(i){
if(selected===null){ selected=i; draw(); return; }
if(!neighbor(selected,i)){ selected=null; draw(); return; }
swap(selected,i);
if(!processMatches()) swap(selected,i);
selected=null;
draw();
}
function neighbor(a,b){
const ax=a%SIZE, ay=~~(a/SIZE);
const bx=b%SIZE, by=~~(b/SIZE);
return Math.abs(ax-bx)+Math.abs(ay-by)===1;
}
function swap(a,b){ [board[a],board[b]]=[board[b],board[a]]; }
function findMatches(){
let res=[];
for(let y=0;y<SIZE;y++){
for(let x=0;x<SIZE-2;x++){
let i=idx(x,y), c=board[i];
if(c && board[i+1] && board[i+2] &&
c.colorId===board[i+1].colorId &&
c.colorId===board[i+2].colorId){
let len=3;
while(x+len<SIZE && board[idx(x+len,y)] &&
board[idx(x+len,y)].colorId===c.colorId) len++;
res.push({cells:Array.from({length:len},(_,k)=>idx(x+k,y)),dir:'h'});
}
}
}
for(let x=0;x<SIZE;x++){
for(let y=0;y<SIZE-2;y++){
let i=idx(x,y), c=board[i];
if(c && board[i+SIZE] && board[i+SIZE*2] &&
c.colorId===board[i+SIZE].colorId &&
c.colorId===board[i+SIZE*2].colorId){
let len=3;
while(y+len<SIZE && board[idx(x,y+len)] &&
board[idx(x,y+len)].colorId===c.colorId) len++;
res.push({cells:Array.from({length:len},(_,k)=>idx(x,y+k)),dir:'v'});
}
}
}
return res;
}
function processMatches(){
const matches = findMatches();
if(!matches.length){
board.forEach(c=>c && (c.protected=false));
return false;
}
let remove = new Set();
matches.forEach(m=>{
let center = m.cells[Math.floor(m.cells.length/2)];
if(m.cells.length===5){
board[center]={...board[center],type:'color',protected:true};
}
else if(m.cells.length===4){
board[center]={...board[center],
type:m.dir==='h'?'line-h':'line-v',
protected:true
};
}
else center=null;
m.cells.forEach(i=>{
if(i!==center && !board[i]?.protected)
remove.add(i);
});
});
remove.forEach(i=>board[i]=null);
score+=remove.size*10;
scoreEl.textContent='Очки: '+score;
setTimeout(()=>{
drop();
draw();
processMatches();
},300);
return true;
}
function drop(){
for(let x=0;x<SIZE;x++){
let col=[];
for(let y=SIZE-1;y>=0;y--){
const i=idx(x,y);
if(board[i]) col.push(board[i]);
}
for(let y=SIZE-1;y>=0;y--){
const i=idx(x,y);
board[i]=col.shift()||randGem();
}
}
}
function init(){
board=[];
for(let i=0;i<SIZE*SIZE;i++) board.push(randGem());
draw();
processMatches();
}
init();
</script>
[/html]
Поделиться32025-12-18 17:00:25
[html]<div id="game"></div>
<style>
#game {
width: 360px;
display: grid;
grid-template-columns: repeat(8, 1fr);
gap: 4px;
user-select: none;
}
.cell {
width: 42px;
height: 42px;
background-size: cover;
cursor: pointer;
transition: transform 0.3s ease;
}
.cell.selected {
outline: 3px solid #fff;
}
.cell.highlight {
box-shadow: 0 0 15px 5px rgba(255,255,255,0.9);
transform: scale(1.15);
}
</style>
<script>
/* ====== НАСТРОЙКИ ====== */
const SIZE = 8;
const COLORS = [
{ id:'red', img:'https://upforme.ru/uploads/001c/84/76/2/401102.png' },
{ id:'blue', img:'https://upforme.ru/uploads/001c/84/76/2/700139.png' },
{ id:'green', img:'https://upforme.ru/uploads/001c/84/76/2/128242.png' },
{ id:'yellow', img:'https://upforme.ru/uploads/001c/84/76/2/330476.png' }
];
const ICONS = {
'line-h': 'https://upforme.ru/uploads/001c/0f/f1/3/544551.png',
'line-v': 'https://upforme.ru/uploads/001c/0f/f1/3/675860.png',
'color' : 'https://upforme.ru/uploads/001c/0f/f1/3/753893.png',
'area' : 'https://upforme.ru/uploads/001c/0f/f1/77/689325.webp'
};
/* ====== СОСТОЯНИЕ ====== */
const game = document.getElementById('game');
let board = [];
let selected = null;
/* ====== ВСПОМОГАТЕЛЬНЫЕ ====== */
const idx = (x,y)=>y*SIZE+x;
const xy = i=>[i%SIZE,Math.floor(i/SIZE)];
const neighbor=(a,b)=>{
const [ax,ay]=xy(a),[bx,by]=xy(b);
return Math.abs(ax-bx)+Math.abs(ay-by)===1;
};
const randColor=()=>COLORS[Math.floor(Math.random()*COLORS.length)];
/* ====== ИНИЦИАЛИЗАЦИЯ ====== */
function init(){
board=[];
for(let i=0;i<SIZE*SIZE;i++){
const c=randColor();
board.push({type:'normal',color:c.id,img:c.img});
}
draw();
processMatches();
}
/* ====== ОТРИСОВКА ====== */
function draw(){
game.innerHTML='';
board.forEach((c,i)=>{
const d=document.createElement('div');
d.className='cell';
if(i===selected) d.classList.add('selected');
if(c){
d.style.backgroundImage=`url(${c.img})`;
}
d.onclick=()=>click(i);
game.appendChild(d);
});
}
/* ====== КЛИК ====== */
function click(i){
if(selected===null){ selected=i; draw(); return; }
if(!neighbor(selected,i)){ selected=null; draw(); return; }
swap(selected,i);
if(activateSpecial(i,selected)||activateSpecial(selected,i)){
selected=null;
return;
}
if(!processMatches()) swap(selected,i);
selected=null;
draw();
}
/* ====== SWAP ====== */
function swap(a,b){
[board[a],board[b]]=[board[b],board[a]];
}
/* ====== ПОИСК КОМБИНАЦИЙ ====== */
function findMatches(){
let res=[];
let specials={};
// горизонталь
for(let y=0;y<SIZE;y++){
let run=[];
for(let x=0;x<SIZE;x++){
const i=idx(x,y),c=board[i];
if(c&&run.length&&board[run[0]].color===c.color) run.push(i);
else { if(run.length>=3) res.push(run); run=[i]; }
}
if(run.length>=3) res.push(run);
}
// вертикаль
for(let x=0;x<SIZE;x++){
let run=[];
for(let y=0;y<SIZE;y++){
const i=idx(x,y),c=board[i];
if(c&&run.length&&board[run[0]].color===c.color) run.push(i);
else { if(run.length>=3) res.push(run); run=[i]; }
}
if(run.length>=3) res.push(run);
}
return res;
}
/* ====== ОБРАБОТКА КОМБО ====== */
function processMatches(){
const matches=findMatches();
if(!matches.length) return false;
let toRemove=new Set();
matches.forEach(group=>{
if(group.length===4){
const i=group[1];
board[i]={type:'line-h',img:ICONS['line-h']};
group.forEach(j=>j!==i&&toRemove.add(j));
}
else if(group.length>=5){
const i=group[2];
board[i]={type:'color',img:ICONS['color']};
group.forEach(j=>j!==i&&toRemove.add(j));
}
else{
group.forEach(j=>toRemove.add(j));
}
});
toRemove.forEach(i=>board[i]=null);
setTimeout(()=>{
drop();
draw();
setTimeout(processMatches,200);
},200);
return true;
}
/* ====== ПАДЕНИЕ ====== */
function drop(){
for(let x=0;x<SIZE;x++){
for(let y=SIZE-1;y>=0;y--){
const i=idx(x,y);
if(board[i]===null){
for(let k=y-1;k>=0;k--){
const j=idx(x,k);
if(board[j]){
board[i]=board[j];
board[j]=null;
break;
}
}
if(board[i]===null){
const c=randColor();
board[i]={type:'normal',color:c.id,img:c.img};
}
}
}
}
}
/* ====== СПЕЦ-ФИШКИ ====== */
function activateSpecial(i,target){
const c=board[i];
if(!c||c.type==='normal') return false;
let affected=new Set();
const [x,y]=xy(i);
if(c.type==='line-h')
for(let xx=0;xx<SIZE;xx++) affected.add(idx(xx,y));
if(c.type==='line-v')
for(let yy=0;yy<SIZE;yy++) affected.add(idx(x,yy));
if(c.type==='color'&&board[target])
board.forEach((b,j)=>b&&b.color===board[target].color&&affected.add(j));
highlightDestroy(affected,i);
return true;
}
/* ====== ПОДСВЕТКА → УДАЛЕНИЕ ====== */
function highlightDestroy(cells,source){
[...cells].forEach(i=>game.children[i]?.classList.add('highlight'));
setTimeout(()=>{
cells.forEach(i=>board[i]=null);
board[source]=null;
draw();
setTimeout(()=>{
drop();
draw();
processMatches();
},200);
},1000);
}
init();
</script>
[/html]
Поделиться52026-01-18 19:00:01
[html]<div style="max-width:980px;margin:18px auto;">
<iframe id="m3frame"
src="https://test006.rusff.me/pages/3_v_ryad_2_skripta"
style="width:100%;height:780px;border:0;border-radius:16px;overflow:hidden;"></iframe>
</div>
<script>
(function(){
var frame = document.getElementById("m3frame");
// ================== УРОВЕНЬ (МЕНЯЕШЬ ТОЛЬКО ЭТО) ==================
var LEVEL = {
moves: 25,
tiles: [
{ name:"Аптечка", img:"https://upforme.ru/uploads/001c/84/76/5/767427.png" }, // 0
{ name:"Канистра", img:"https://upforme.ru/uploads/001c/84/76/5/38086.png" }, // 1
{ name:"Консерва", img:"https://upforme.ru/uploads/001c/84/76/5/866531.png" }, // 2
{ name:"Мозг", img:"https://upforme.ru/uploads/001c/84/76/5/96590.png" }, // 3
{ name:"Кофе", img:"https://upforme.ru/uploads/001c/84/76/5/717095.png" }, // 4
{ name:"Сигареты", img:"https://upforme.ru/uploads/001c/84/76/5/254615.png" } // 5
],
// веса выпадения по индексам tiles
weights: [1, 3, 2, 8, 2, 2],
// цели: очень просто менять
goals: [
{ type:"tile", tileIndex: 2, need: 20 }, // 20 консерв
{ type:"crate", need: 5 } // 5 ящиков (убери эту строку если не нужно)
],
// ящики фиксированные координаты (0..7)
crates: [
{r:2,c:2},
{r:2,c:5},
{r:4,c:3},
{r:5,c:1},
{r:5,c:6}
],
// картинки бустеров
boosters: {
rocketV: "https://upforme.ru/uploads/001c/84/76/5/341609.png",
rocketH: "https://upforme.ru/uploads/001c/84/76/5/886780.png",
bomb: "https://upforme.ru/uploads/001c/84/76/5/364334.png",
rainbow: "https://upforme.ru/uploads/001c/84/76/5/104536.png",
plane: "https://upforme.ru/uploads/001c/84/76/5/77568.png"
},
// ящик (целый/битый)
crateImg: "https://upforme.ru/uploads/001c/84/76/5/43738.png",
crateDmg: "https://upforme.ru/uploads/001c/84/76/5/727026.png"
};
// ================================================================
function send(type, payload){
try{
frame.contentWindow.postMessage({ channel:"M3", type:type, payload: payload || {} }, "*");
}catch(e){}
}
frame.addEventListener("load", function(){
send("LOAD_LEVEL", LEVEL);
});
// (не обязательно) слушаем события от движка
window.addEventListener("message", function(ev){
var msg = ev.data;
if(!msg || msg.channel !== "M3") return;
if(msg.type === "STATE"){
// тут можно выводить прогресс куда угодно в посте
// console.log("STATE", msg.payload);
}
if(msg.type === "WIN"){
// console.log("WIN");
}
if(msg.type === "LOSE"){
// console.log("LOSE");
}
});
})();
</script>[/html]
