This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Лицензия CC0 1.0 Universal--> | |
<!-- оригинал — https://gist.github.com/straker/98a2aed6a7686d26c04810f08bfaf66b --> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Arkanoid</title> | |
<style> | |
/* стили для всей страницы */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// перезагружаем шарик, если он улетел вниз, за край игрового поля | |
if (ball.y > canvas.height) { | |
// уменьшаем количество жизней | |
lives -= 1; | |
// обнуляем набранные очки | |
score = 0; | |
score_paddle = 25; | |
score_lives = 100; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Цвет текста — серый | |
context.fillStyle = "#777777"; | |
// Задаём размер и шрифт | |
context.font = "20pt monospace"; | |
// Сначала выводим рекорд | |
context.fillText('Очки: ' + score, 50, 490); | |
// Затем — набранные очки | |
context.fillText('Жизни:'+ lives, 250, 490); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// в эту функцию мы поместим всё, что связано с касанием кирпичей | |
function touchdown(t_brick) { | |
// начисляем очки в зависимости от цвета кирпича | |
switch(t_brick.color) { | |
case "yellow" : score += 1; break; | |
case "green" : score += 2; break; | |
case "orange" : score += 3; break; | |
case "red" : score += 4; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// количество набранных очков за одну попытку | |
score = 0; | |
// количество жизней на старте | |
lives = 3; | |
// сколько очков нужно набрать до очередного увеличения платформы | |
score_paddle = 25; | |
// сколько очков нужно набрать до получения дополнительной жизни | |
score_lives = 100; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Лицензия CC0 1.0 Universal--> | |
<!-- оригинал — https://gist.github.com/straker/98a2aed6a7686d26c04810f08bfaf66b --> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Арканоид</title> | |
<style> | |
/* стили для всей страницы */ | |
html, body { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// генератор случайных чисел в заданном диапазоне | |
function getRandomInt(min, max) { | |
return Math.floor(Math.random() * (max - min)) + min; | |
} | |
// переменные для исходного сообщения, зашифрованного и ключа шифрования | |
var input, output,key; | |
// служебные переменные для шифра | |
var inp, k; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// шифруем сообщение | |
output = ""; | |
for (i = 0; i < input.length; i++) { | |
// берём цифровое значение очередного символа в сообщении и ключе | |
inp = input.charCodeAt(i); | |
k = key.charCodeAt(i); | |
// и применяем к ним исключающее или — XOR | |
output += String.fromCharCode(inp ^ k); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// если длина ключа меньше длины сообщения — говорим пользователю и генерируем свой ключ | |
if ((key.length) < (input.length)) { | |
alert("Ключ короче сообщения, это небезопасно. Скопируйте новый сгенерированный ключ из консоли браузера."); | |
// в самом начале ключ будет пустой | |
key = ""; | |
// генерируем новый ключ такой же длины, как и сообщение | |
for (var i = 0; i < input.length; i++) { | |
key += String.fromCharCode(getRandomInt(0,66535)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// запрашиваем текст, который будем шифровать | |
input = prompt("Введите исходный текст"); | |
// запрашиваем ключ шифрования | |
key = prompt("Введите ключ"); |