Professional Documents
Culture Documents
DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<script>
// تعريف المتغيرات
let player = {
x: 250,
y: 250,
width: 50,
height: 50
};
let score = 0;
// بدء اللعبة
function startGame() {
trains = [
x: 0,
y: 0,
width: 100,
height: 100,
dx: 5
},
{
x: 500,
y: 0,
width: 100,
height: 100,
dx: -5
];
render();
// تحديث اللعبة
function update() {
player.x += player.dx;
if (player.x + player.width > trains[i].x && player.x < trains[i].x + trains[i].width &&
gameOver();
gameOver();
gameOver();
render();
}
// رسم اللعبة
function render() {
// رسم الالعب
ctx.fillStyle = "black";
// رسم القطارات
ctx.fillStyle = "red";
// عرض النتيجة
ctx.fillStyle = "white";
// التعامل مع األحداث
window.addEventListener("keydown", function(event) {
player.dx = -5;
player.dx = 5;
});
// بدء اللعبة
startGame();
// معالجة انتهاء اللعبة
function gameOver() {
ctx.fillStyle = "red";
</script>
</body>
</html>