Как запустить игру в браузере
Чтобы запустить игру на своём компьютере, не нужно устанавливать дополнительные программы. Достаточно сохранить HTML-код в файл и открыть его в браузере.
- Скопируйте HTML-код. Раскройте блок с исходным кодом игры, выделите весь код и скопируйте его в буфер обмена.
- Откройте Блокнот. Запустите стандартное приложение «Блокнот» в Windows и вставьте скопированный код.
- Сохраните файл в формате HTML.
В меню «Файл» выберите «Сохранить как». Укажите имя
kot_zvezdy.html, в поле «Тип файла» выберите «Все файлы», а в качестве кодировки укажите UTF-8. Сохраните файл, например, на рабочем столе. - Запустите игру.
Найдите сохранённый файл
kot_zvezdy.htmlи дважды щёлкните по нему. Игра откроется в браузере по умолчанию, например Google Chrome, Microsoft Edge или Firefox. - Начните играть. Управляйте котом с помощью стрелок на клавиатуре, собирайте звёзды и постарайтесь набрать пять очков.
Обратите внимание.
Файл должен иметь расширение .html, а не .txt. Если Windows сохранила файл под именем kot_zvezdy.html.txt, включите отображение расширений файлов в Проводнике и удалите окончание .txt.
После сохранения игру можно запускать в любое время без подключения к интернету, если весь код игры и необходимые изображения содержатся в самом HTML-файле.
Показать полный HTML-код игры
Нажмите на заголовок ещё раз, чтобы свернуть исходник.
<!-- Игра «Кот собирает звёзды» прямо внутри статьи. Без Base64 и iframe. -->
<style>
#scratch-stars-game, #scratch-stars-game *{box-sizing:border-box}
#scratch-stars-game{margin:0;padding:0;background:#fff;color:#225e6c;font:16px/1.4 Arial,sans-serif}
#scratch-stars-game{width:100%;max-width:800px;margin:0 auto;padding:8px 8px 16px}
#scratch-stars-game .header{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:6px 0 10px}
#scratch-stars-game h2{font-size:clamp(18px,3.4vw,24px);margin:0;color:#238394}
#scratch-stars-game button{appearance:none;border:0;cursor:pointer;border-radius:10px;padding:10px 13px;font:700 15px Arial,sans-serif;background:#8759d8;color:#fff;touch-action:none}
#scratch-stars-game button:hover{background:#7447c5}
#scratch-stars-game .stage{position:relative;width:100%;aspect-ratio:4/3;overflow:hidden;background:#daf5fa;border-radius:12px;outline:none;user-select:none}
#scratch-stars-game .backdrop{position:absolute;width:100%;height:100%;inset:0}
#scratch-stars-game .sprite{position:absolute;display:block;transform:translate(-50%,-50%);pointer-events:none;will-change:left,top}
#scratch-stars-game .sprite svg{width:100%;height:auto;display:block}
#scratch-stars-game .cat{width:19%;height:auto;z-index:3}
#scratch-stars-game .star{width:14%;height:auto;z-index:2}
#scratch-stars-game .score{position:absolute;top:10px;left:10px;z-index:5;background:#fff;border:1px solid #d7e7ed;border-radius:8px;padding:4px 10px;font-weight:700;color:#3b565f}
#scratch-stars-game .score b{display:inline-block;background:#ff9e26;color:#fff;border-radius:5px;padding:1px 13px;margin-left:8px}
#scratch-stars-game .hint{position:absolute;bottom:10px;text-align:center;left:0;right:0;pointer-events:none;color:#3b7c8a;font-size:clamp(11px,2vw,14px)}
#scratch-stars-game .won{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(30,93,112,.28);z-index:6}
#scratch-stars-game .won[hidden]{display:none}
#scratch-stars-game .won-inner{background:#fff;border-radius:18px;text-align:center;box-shadow:0 12px 36px #0003;padding:26px 32px;max-width:92%}
#scratch-stars-game .won-inner h3{font-size:clamp(27px,5vw,39px);margin:0;color:#19869b}
#scratch-stars-game .won-inner p{margin:9px 0 16px}
#scratch-stars-game .footer{display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:10px;margin-top:12px}
#scratch-stars-game .controls{display:flex;justify-content:center;gap:8px}
#scratch-stars-game .controls button{background:#d9eff5;color:#22667b;font-size:22px;min-width:48px;min-height:43px}
#scratch-stars-game .controls button:active{background:#abdce7}
@media(max-width:480px){#scratch-stars-game{padding:5px}
#scratch-stars-game .header button{font-size:13px;padding:8px}
#scratch-stars-game .footer{justify-content:center}
#scratch-stars-game .controls{width:100%}}
</style>
<div class="game" id="scratch-stars-game">
<div class="header"><h2>Собери 5 звёзд!</h2><button id="restart" type="button">Начать заново</button></div>
<div class="stage" tabindex="0" aria-label="Игровое поле. Управляй котом стрелками и собирай звёзды">
<svg class="backdrop" viewBox="0 0 480 360" preserveAspectRatio="none" aria-hidden="true" xmlns="http://www.w3.org/2000/svg">
<defs><linearGradient id="star-game-sky" x1="0" y1="0" x2="0" y2="1"><stop stop-color="#D7F4FB"/><stop offset="1" stop-color="#E4F9FD"/></linearGradient></defs>
<rect width="480" height="360" fill="url(#star-game-sky)"/>
<circle cx="60" cy="70" r="36" fill="#fff" opacity=".25"/><circle cx="395" cy="79" r="22" fill="#fff" opacity=".35"/>
<circle cx="447" cy="207" r="50" fill="#fff" opacity=".21"/><circle cx="318" cy="148" r="4" fill="#fff" opacity=".64"/>
<circle cx="180" cy="105" r="3" fill="#fff" opacity=".6"/><circle cx="110" cy="230" r="4" fill="#fff" opacity=".56"/>
<path d="M0 300 Q95 277 170 300 T340 299 T480 297 V360 H0Z" fill="#C3EDE6"/>
<path d="M0 321 Q100 300 190 325 T370 319 T480 320 V360 H0Z" fill="#A3DBD7"/>
</svg>
<div class="score">Счёт <b id="score-value">0</b></div>
<div class="sprite cat" id="stars-cat"><svg xmlns="http://www.w3.org/2000/svg" width="150" height="170" viewBox="0 0 150 170">
<g stroke="#A95519" stroke-linejoin="round" stroke-linecap="round">
<!-- tail -->
<path d="M105 119 C138 121 145 102 132 89 C124 81 133 76 139 80 C153 90 149 114 134 129 C122 142 112 142 105 139" fill="#F19A2A" stroke-width="3.5"/>
<!-- legs and feet -->
<path d="M45 129 C43 142 37 153 32 157 C28 163 34 167 45 163 L63 153 L73 146 L78 160 C79 166 91 166 91 160 L96 141" fill="#F7A32E" stroke-width="3.5"/>
<path d="M99 132 L107 157 C110 165 124 164 122 155 L116 127" fill="#F7A32E" stroke-width="3.5"/>
<path d="M49 103 C34 111 37 140 46 145 C60 155 98 156 111 138 C121 122 111 99 100 95" fill="#F7A32E" stroke-width="4"/>
<path d="M68 132 C75 137 87 137 94 131" fill="none" stroke="#D8781D" stroke-width="2"/>
<!-- ears -->
<path d="M27 50 L28 13 L59 28 Z" fill="#FFAD39" stroke-width="4"/>
<path d="M92 27 L124 8 L119 55 Z" fill="#FFAD39" stroke-width="4"/>
<path d="M35 24 L36 44 L53 34 Z" fill="#F8A4AA" stroke="none"/>
<path d="M116 19 L98 32 L114 44 Z" fill="#F8A4AA" stroke="none"/>
<!-- head -->
<path d="M25 48 C31 33 52 27 76 28 C98 28 118 37 121 60 C127 83 111 108 86 112 C56 116 29 104 23 81 C20 67 21 57 25 48 Z" fill="#F9A12E" stroke-width="4"/>
<!-- eyes -->
<ellipse cx="57" cy="66" rx="12" ry="19" fill="#FFFDF6" stroke="none"/>
<ellipse cx="95" cy="63" rx="11" ry="18" fill="#FFFDF6" stroke="none"/>
<ellipse cx="59" cy="69" rx="5" ry="8" fill="#273747" stroke="none"/>
<ellipse cx="93" cy="66" rx="5" ry="8" fill="#273747" stroke="none"/>
<ellipse cx="58" cy="65" rx="2" ry="2.7" fill="white" stroke="none"/>
<ellipse cx="92" cy="63" rx="2" ry="2.7" fill="white" stroke="none"/>
<!-- muzzle -->
<path d="M63 84 C69 80 76 82 80 88 C87 82 96 85 99 94 C101 106 84 110 78 101 C70 111 58 104 60 95 Z" fill="#FFBB58" stroke="none"/>
<path d="M73 86 Q79 82 85 86 L80 92 Z" fill="#C45D58" stroke="#A95519" stroke-width="1.2"/>
<path d="M80 92 L80 98 M80 98 C73 106 67 101 66 96 M80 98 C85 105 94 103 95 96" fill="none" stroke="#8C4A2A" stroke-width="2.2"/>
<!-- whiskers -->
<path d="M62 90 L16 86 M60 96 L14 100 M62 101 L25 113 M98 89 L140 82 M99 96 L147 97 M99 101 L136 113" fill="none" stroke="#925127" stroke-width="2.1"/>
<!-- stripes -->
<path d="M52 36 L49 43 M75 30 L74 39 M98 34 L100 42" fill="none" stroke="#DB7C21" stroke-width="3"/>
</g>
</svg></div>
<div class="sprite star" id="stars-star"><svg xmlns="http://www.w3.org/2000/svg" width="126" height="126" viewBox="0 0 126 126">
<polygon points="63.00,8.00 79.46,40.35 115.31,46.00 89.63,71.65 95.33,107.50 63.00,91.00 30.67,107.50 36.37,71.65 10.69,46.00 46.54,40.35" fill="#FFCA3C" stroke="#C97916" stroke-width="5" stroke-linejoin="round"/>
<polygon points="63.00,18.00 76.52,44.39 105.80,49.09 84.87,70.11 89.45,99.41 63.00,86.00 36.55,99.41 41.13,70.11 20.20,49.09 49.48,44.39" fill="#FFDE69" stroke="none"/>
<path d="M49 38 Q61 23 73 37" fill="none" stroke="#FFEBA0" stroke-width="4" stroke-linecap="round"/>
<ellipse cx="49" cy="60" rx="5.5" ry="8" fill="#81531D"/>
<ellipse cx="77" cy="60" rx="5.5" ry="8" fill="#81531D"/>
<circle cx="47" cy="57" r="2" fill="#FFFFFF"/>
<circle cx="75" cy="57" r="2" fill="#FFFFFF"/>
<path d="M49 77 Q63 93 77 77" fill="none" stroke="#9C5B19" stroke-width="4" stroke-linecap="round"/>
<circle cx="43" cy="73" r="5" fill="#FFAD76" opacity="0.7"/>
<circle cx="83" cy="73" r="5" fill="#FFAD76" opacity="0.7"/>
</svg></div>
<div class="hint">Управляй котом стрелками на клавиатуре</div>
<div class="won" hidden><div class="won-inner"><h3>Победа!</h3><p>Все 5 звёзд собраны!</p><button id="again" type="button">Сыграть ещё раз</button></div></div>
</div>
<div class="footer"><span id="game-status" role="status" aria-live="polite">Собрано 0 из 5 звёзд</span>
<div class="controls" aria-label="Управление с телефона">
<button type="button" data-arrow="ArrowLeft" aria-label="Влево">←</button>
<button type="button" data-arrow="ArrowUp" aria-label="Вверх">↑</button>
<button type="button" data-arrow="ArrowDown" aria-label="Вниз">↓</button>
<button type="button" data-arrow="ArrowRight" aria-label="Вправо">→</button>
</div>
</div>
</div>
<script>
(function(){
const game=document.getElementById('scratch-stars-game');
if(!game||game.dataset.ready)return;
game.dataset.ready='1';
const field=game.querySelector('.stage');
const catEl=game.querySelector('#stars-cat');
const starEl=game.querySelector('#stars-star');
const scoreEl=game.querySelector('#score-value');
const statusEl=game.querySelector('#game-status');
const wonEl=game.querySelector('.won');
const restart=game.querySelector('#restart');
const again=game.querySelector('#again');
const keys=new Set();
const arrows=['ArrowLeft','ArrowRight','ArrowUp','ArrowDown'];
const STAGE_W=480,STAGE_H=360,SPEED=6,TARGET=5;
let cat,star,score,won,last=0,elapsed=0;
function distance(a,b){return Math.hypot(a.x-b.x,a.y-b.y)}
function reposition(){
for(let i=0;i<120;i++){
star={x:45+Math.random()*390,y:60+Math.random()*240};
if(distance(cat,star)>100)break;
}
}
function render(){
catEl.style.left=(cat.x/STAGE_W*100)+'%';
catEl.style.top=(cat.y/STAGE_H*100)+'%';
starEl.style.left=(star.x/STAGE_W*100)+'%';
starEl.style.top=(star.y/STAGE_H*100)+'%';
}
function reset(){
cat={x:75,y:180};star={x:370,y:250};score=0;won=false;
keys.clear();reposition();render();
scoreEl.textContent='0';
statusEl.textContent='Собрано 0 из 5 звёзд';
wonEl.hidden=true;starEl.hidden=false;starEl.style.display='block';
}
function update(){
if(won)return;
if(keys.has('ArrowRight'))cat.x+=SPEED;
if(keys.has('ArrowLeft'))cat.x-=SPEED;
if(keys.has('ArrowUp'))cat.y-=SPEED;
if(keys.has('ArrowDown'))cat.y+=SPEED;
cat.x=Math.max(48,Math.min(432,cat.x));
cat.y=Math.max(52,Math.min(310,cat.y));
if(distance(cat,star)<58){
score++;scoreEl.textContent=String(score);
statusEl.textContent='Собрано '+score+' из '+TARGET+' звёзд';
if(score>=TARGET){
won=true;keys.clear();wonEl.hidden=false;
starEl.style.display='none';
statusEl.textContent='Победа! Собраны все 5 звёзд';
}else reposition();
}
render();
}
function frame(now){
elapsed+=Math.min(100,now-(last||now));last=now;
while(elapsed>=1000/30){update();elapsed-=1000/30}
requestAnimationFrame(frame);
}
game.addEventListener('keydown',function(e){
if(arrows.includes(e.key)){e.preventDefault();keys.add(e.key)}
if(won&&(e.key==='Enter'||e.key===' ')){reset()}
});
window.addEventListener('keyup',function(e){keys.delete(e.key)});
window.addEventListener('blur',function(){keys.clear()});
document.addEventListener('pointerdown',function(e){if(!game.contains(e.target))keys.clear()});
field.addEventListener('pointerdown',function(){field.focus()});
game.querySelectorAll('[data-arrow]').forEach(function(b){
const key=b.getAttribute('data-arrow');
b.addEventListener('pointerdown',function(e){
e.preventDefault();keys.add(key);b.setPointerCapture(e.pointerId)
});
['pointerup','pointercancel','lostpointercapture'].forEach(function(name){
b.addEventListener(name,function(){keys.delete(key)})
});
});
restart.addEventListener('click',function(){reset();field.focus()});
again.addEventListener('click',function(){reset();field.focus()});
reset();requestAnimationFrame(frame);
})();
</script>