<!DOCTYPE html> <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"> <img id="background" src="img/background.jpg" /> <img id="ball" src="img/ball.jpg"/> <img id="goalie" src="img/goalie.jpg"/> <div id="score" style="position:absolute;" >Score</div> </div> <div id="rules" style="position:absolute;" > <h1>Simple Shooter Game</h1> <h3>Game Developer</h3> <p>This is my very first game! I made it using HTML5 and Javascript, with a little of CSS. I made this game, at the age of 14 years old. The rules to play the game are listed below. <ul> <li>Shoot down the smaller circles using the buttons below.</li> <li>Don't get touched by the little circles, or else you lose the game.</li> <li>Everytime you shoot down, your score on the top right increases. </li> </ul> <p>Have fun!! -Jeyasurya Subash</p> <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> <p id="gameover"></p> </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>
Write, Run & Share HTML code online using OneCompiler's HTML online Code editor for free. It's one of the robust, feature-rich online Code editor for HTML language, running on the latest version HTML5. Getting started with the OneCompiler's HTML compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as HTML
. You can also specify the stylesheet information in styles.css
tab and scripts information in scripts.js
tab and start coding.
HTML(Hyper Text Markup language) is the standard markup language for Web pages, was created by Berners-Lee in the year 1991. Almost every web page over internet might be using HTML.
<!DOCTYPE html>
<html>
and ends with </html>
<h1>
to <h6>
where <h1>
is the highest important heading and <h6>
is the least important sub-heading.<p>..</p>
tag.<a>
tag.
<a href="https://onecompiler.com/html">HTML online compiler</a>
<img>
tag, where src
attribute consists of image name.<button>..</button>
tag<ul>
for unordered/bullet list and <ol>
for ordered/number list, and the list items are defined in <li>
.<a href="https://onecompiler.com/html">HTML online compiler</a>
CSS(cascading style sheets) describes how HTML elements will look on the web page like color, font-style, font-size, background color etc.
Below is a sample style sheet which displays heading in green and in Candara font with padding space of 25px.
body{
padding: 25px;
}
.title {
color: #228B22;
font-family: Candara;
}
<table>
tag.<tr>
tag<th>
tag<td>
tag<caption>
tag<script>
is the tag used to write scripts in HTML<script src="script.js"></script>