Ask questions which are clear, concise and easy to understand.

Ask Question
  • 0 answers
  • 0 answers
  • 0 answers
  • 0 answers
<html lang="en"> <head> <meta charset="utf-8" /> <title>Play Snake Game</title> <style type="text/css"> body {text-align:center;} canvas { border:5px dotted #ccc; } h1 { font-size:50px; text-align: center; margin: 0; padding-bottom: 25px;} </style> <script type="text/javascript"> function play_game() { var level = 160; // Game level, by decreasing will speed up var rect_w = 45; // Width var rect_h = 30; // Height var inc_score = 50; // Score var snake_color = "#006699"; // Snake Color var ctx; // Canvas attributes var tn = []; // temp directions storage var x_dir = [-1, 0, 1, 0]; // position adjusments var y_dir = [0, -1, 0, 1]; // position adjusments var queue = []; var frog = 1; // defalut food var map = []; var MR = Math.random; var X = 5 + (MR() * (rect_w - 10))|0; // Calculate positions var Y = 5 + (MR() * (rect_h - 10))|0; // Calculate positions var direction = MR() * 3 | 0; var interval = 0; var score = 0; var sum = 0, easy = 0; var i, dir; // getting play area  var c = document.getElementById('playArea'); ctx = c.getContext('2d'); // Map positions for (i = 0; i < rect_w; i++) { map[i] = []; } // random placement of snake food function rand_frog() { var x, y; do { x = MR() * rect_w|0; y = MR() * rect_h|0; } while (map[x][y]); map[x][y] = 1; ctx.fillStyle = snake_color; ctx.strokeRect(x * 10+1, y * 10+1, 8, 8); } // Default somewhere placement rand_frog(); function set_game_speed() { if (easy) { X = (X+rect_w)%rect_w; Y = (Y+rect_h)%rect_h; } --inc_score; if (tn.length) { dir = tn.pop(); if ((dir % 2) !== (direction % 2)) { direction = dir; } } if ((easy || (0 <= X && 0 <= Y && X < rect_w && Y < rect_h)) && 2 !== map[X][Y]) { if (1 === map[X][Y]) { score+= Math.max(5, inc_score); inc_score = 50; rand_frog(); frog++; } //ctx.fillStyle("#ffffff"); ctx.fillRect(X * 10, Y * 10, 9, 9); map[X][Y] = 2; queue.unshift([X, Y]); X+= x_dir[direction]; Y+= y_dir[direction]; if (frog < queue.length) { dir = queue.pop() map[dir[0]][dir[1]] = 0; ctx.clearRect(dir[0] * 10, dir[1] * 10, 10, 10); } } else if (!tn.length) { var msg_score = document.getElementById("msg"); msg_score.innerHTML = "Thank you for playing game.
Your Score : "+score+"

<input type='button' value='Play Again' onclick='window.location.reload();' />"; document.getElementById("playArea").style.display = 'none'; window.clearInterval(interval); } } interval = window.setInterval(set_game_speed, level); document.onkeydown = function(e) { var code = e.keyCode - 37; if (0 <= code && code < 4 && code !== tn[0]) { tn.unshift(code); } else if (-5 == code) { if (interval) { window.clearInterval(interval); interval = 0; } else { interval = window.setInterval(set_game_speed, 60); } } else { dir = sum + code; if (dir == 44||dir==94||dir==126||dir==171) { sum+= code } else if (dir === 218) easy = 1; } } } </script> </head> <body onload="play_game()">

Play Snake Game

<div id="msg"></div> <canvas id="playArea" width="450" height="300">Sorry your browser does not support HTML5</canvas> </body> </html>
  • 0 answers
  • 1 answers

Archana Bhandari 4 days, 2 hours ago

Let cost each kg of apples = Rs x Cost of each kg of grapes = Rs y Given that the cost of 2 kg of apples and 1kg of grapes on a day was found to be Rs 160 So that 2 x + y = 160 … (i) 2x = 160 - y x = (160 – y)/2 Let y = 0 , 80 and 160, we get x = (160 – ( 0 )/2 = 80 x = (160- 80 )/2 = 40 x = (160 – 2 × 80)/2 = 0 x 80 40 0 y 0 80 160 Given that the cost of 4 kg of apples and 2 kg of grapes is Rs 300 So we get 4x + 2y = 300 … (ii) Dividing by 2 we get 2x + y = 150 Subtracting 2x both side, we get y = 150 – 2x Putting x = 0 , 50 , 100 we get y = 150 – 2 × 0 = 150 y = 150 – 2 × 50 = 50 y = 150 – 2 × (100) = -50 x 0 50 100 y 150 50 -50 Algebraic representation, 2x + y = 160 … (i) 4x + 2y = 300 … (ii) Graphical representation, Graph 3
  • 1 answers
<html> <head><title>Simple Game</title></head> <style> #score{ background-color: white; height:50px; width:140px; top:10px; left:540px; font-size:30px; } #board{ position:absolute; width:5000px; height:300px; } #background{ position:absolute; width:700px; height:500px; } #ball{ position:absolute; width:70px; height:70px; top: 410px; left: 300px; } #goalie{ position:absolute; width:100px; top:200px; left:300px; } #rules{ position:absolute; top:0px; left:730px; } </style> <body> <div id="board"> <div id="score" style="position:absolute;" >Score</div> </div> <div id="rules" style="position:absolute;" >

Simple Shooter Game

On building this simple game I learnt more about how the programming languages HTML5, CSS and JavaScript worked. The rules are stated below

  • jkdsgjs
  • hfdja
  • `jeatngdadv

Have fun!!

<button onclick="shootLeft()" style="top:400px; left:100px;" type="leftButton">Shoot left</button> <button onclick="shootRight()" style="top:400px; left:200px;" type="rightButton">Shoot right</button> <div>

</div> </div> <script> var ball = null; var x = 1; var score = 0; document.getElementById('score').innerHTML = '0'; var animate; ball = document.getElementById('ball'); function shootLeft(){ var ran = Math.random(); while(parseInt(ball.style.top) != 300){ ball.style.left = parseInt(ball.style.left) - 1 + 'px'; ball.style.top = parseInt(ball.style.top) - 1 + 'px'; animate = setTimeout(shootLeft,20); } if(ran<0.3){ score = score + 1; document.getElementById('score').innerHTML = score; } else{ document.getElementById('score').innerHTML = score; } x++; if(x==10){ document.getElementById('gameover').innerHTML = "Game over! You got a score of " + score; } ball.style.left = '300px'; ball.style.top = '410px'; } function shootRight(){ van ran = Math.random(); while(parseInt(ball.style.top != 300){ ball.style.left = parseInt(ball.style.left) + 1 + 'px'; ball.style.top = parseInt(ball.style.top) - 1 + 'px'; animate = setTimeout(shootRight,20); } if(ran>0.7){ score = score + 1; document.getElementById('score').innerHTML = score; } else{ document.getElementById('score').innerHTML = score; } x++; if(x==10){ document.getElementById('gameover').innerHTML = "Game over! You got a score of " + score; } ball.style.left = '300px'; ball.style.top = '410px'; } } </script> </body> </html>
  • 1 answers

Sharanya Ashish 4 days, 5 hours ago

I don't know
  • 0 answers
  • 4 answers

Vinod Sharma 29 minutes ago

Hi sir

Vinod Sharma 47 minutes ago

Hi
विजय विश्व गान क्या है

Anil Kumar 4 days, 22 hours ago

Ans neeaatat
Dhf
  • 0 answers
  • 1 answers

Mahima Thakur 2 days, 13 hours ago

6
  • 1 answers
Yha pe bhi... 🤦‍♂🤷‍♂

myCBSEguide App

myCBSEguide

Trusted by 1 Crore+ Students

CBSE Test Generator

Create papers in minutes

Print with your name & Logo

Download as PDF

3 Lakhs+ Questions

Solutions Included

Based on CBSE Blueprint

Best fit for Schools & Tutors

Work from Home

  • Work from home with us
  • Create questions or review them from home

No software required, no contract to sign. Simply apply as teacher, take eligibility test and start working with us. Required desktop or laptop with internet connection