HTMLs Tutorial

HTML Tutorial HTML Tags HTML Basic Tags HTML Attributes HTML Elements HTML Formatting HTML Text Format HTML body tag HTML samp tag HTML script Tag HTML section tag HTML select tag HTML source tag HTML span tag HTML strike tag HTML strong tag HTML style tag HTML sub tag HTML summary tag HTML sup Tag HTML svg tag HTML table tag HTML u tag HTML Headings HTML Paragraphs HTML wbr tag HTML Anchor HTML Image HTML Lists HTML Ordered List HTML Unordered List HTML Form HTML Form input HTML with CSS HTML Layouts HTML References HTML Frames HTML Links Fieldset Tag in HTML Basic HTML Tags Br Tag in HTML Free HTML Templates How to Create a Table in HTML HTML Calendar HTML Card HTML Cellspacing HTML Center Image HTML Checkbox Read-only HTML Cleaner HTML Code for a Tab HTML Comment HTML Compiler HTML Nested Forms HTML Overlay Text on the Image HTML Select Option Default HTML Snake Game HTML Subheader HTML Tab Character dd Tag in HTML How Many HTML Tags are There HTML Align Tag HTML Responsive HTML Tab Code HTML Table Alternate Row Color HTML Table Fix Column Width Contact HTML DL Tag in HTML How to Insert Image in HTML HTML Background Color HTML Dark Mode How to Convert HTML to PNG HTML Data Toggle HTML Email Template HTML Font Color HTML Font Family ID and Class in HTML HTML Tab Space HTML Tab Tag HTML Itemprop HTML Itemscope HTML Form Design HTML Input Only Numbers HTML Textarea HTML to JPG HTML to Markdown Python li Tag in HTML MDN HTML What is the Correct HTML for Making a Hyperlink? What is the Root Element of an HTML Document How to Make a Box in HTML How to Save HTML Files in Notepad How to Align Text in HTML How to Change Font Color in HTML? How to Change Font Size in HTML How to Change Image Size in HTML How to Create a HTML Page How to Create a Link in HTML File? How to Create an HTML File? HR Tag in HTML HTML Base Tag HTML Default Attribute HTML Hyperlink HTML Indent HTML Injection Payloads HTML Input Numbers Only HTML Roadmap HTML Row Height HTML Schedule HTML Space HTML Tab HTML vs HTTP HTML5 API HTML5 Video HTML Collection to Array Text Area in HTML

HTML5 Advance

HTML5 Tutorial HTML5 Tags HTML Button Tag HTML canvas Tag HTML caption Tag HTML City tag HTML Tag HTML5 SVG HTML Event Attribute HTML5 Audio HTML5 Youtube HTML5 Button Tag HTML5 Tags

Misc

How to add JavaScript to HTML How to change font in HTML How to change text color in HTML HTML Date HTML Hide Element HTML Nested Table HTML Reset Button What does HTML stand for? HTML Background Image HTML Tag Div Tag in HTML How to insert Image in HTML How to create a link with no underline in HTML How to insert spacestabs in text using HTMLCSS HTML tag HTML Code HTML Tag HTML Canvas Design a tribute page using HTML and CSS What is a Container tag Font tag in HTML Difference between HTML and DHTML Empty Tag in HTML HTML Button Link Html Line Break Img src HTML Nested List in HTML Placeholder in HTML TD in HTML HTML Space Code HTML Target Attribute HTML Tag Markup Meaning in HTML Border-Collapse in HTML HTML Onclick Online HTML Compiler Convert HTML to PDF HTML Formatter HTML5 - Web Storage HTTP – Responses Container Tag in HTML DL Tag in HTML Horizontal Rule HTML HTML Tab Text Html Table Cell Background Color HTML Table Cell Color HTML Col Width How Many HTML Tags are There Convert String to Unicode Characters in Python HTML Runner HTML Style Attribute HTML Superscript Attribute HTML tabindex Marquee Tag in HTML HTML Dynamic Form HTML side Tag HTML Pattern Attribute HTML q Tag HTML Readonly Base 64 Encoding in HTML Documents Enhancing Data Portability and Security Evo Cam Web Cam HTML Free code camp HTML CSS How to Add a JS File in HTML? How to Add Picture in HTML How to Add the Logo in HTML? How to Add Video in HTML HTML Class Attribute HTML Entities HTML Form Elements HTML Form Templates HTML Marquee Tag HTML Radio Buttons HTML Text box HTML to JSX HTML Tooltip Basic HTML Codes How to Align Image Center in HTML HTML Header Tag HTML Image Tag HTML Next Line

HTML Snake Game

Introduction

Making Snake is enjoyable since it doesn't need a lot of code less than 100 lines when all comments are removed. That is a simple version of the snake game; certain elements are purposefully left out for the reader to discover.

A basic game called "Snake Game" involves a snake moving around a box in an attempt to eat an apple. Once it has consumed the apple, the snake grows longer and moves more quickly. The game is finished when the Snake runs into itself or any of the box's four walls.

Additional Research

Score

  • The Snake should get one point for eating an apple. Apply context. Use fill Text() to show the score on the screen.

Support for touchscreens and mobile

  • Let the game resize to the size of a phone. Look at

/straker/pen/VazMaL on codepen.io

  • to accommodate touch controls

And Improve the spawning of apples

  • Even if the Snake is already there, the apple appears on any random grid in the game. Please make it so that it appears only in vacant grid spaces.
<h1>snake game </h1>

<div class="scoreDisplay"></div>

<div class="grid"></div>

<div class="button">

  <button class="top">top</button>

  <button class="bottom">bottom</button>

  <button class="left">left</button>

  <button class="right">right</button>

</div>

<div class="popup">

  <button class="playAgain">play Again</button>

</div>

This HTML is really simple.

  • Our scores will be shown as a division of the class score. Display.
  • The game will be in a class grid division, measuring 10 by 10.
  • For customers playing the game on the phone, the class button essentially includes a button (we will automate it with the keyboard for desktop users).
  • We'll save our replay button in the popup class as well.

CSS

body {

  background: rgb(212, 211, 211);

}

.grid {

  width: 200px;

  height: 200px;

  border: 1px solid red;

  margin: 0 auto;

  display: flex;

  flex-wrap: wrap;

}

.grid div {

  width: 20px;

  height: 20px;

  /*border:1px black solid;

box-sizing:border-box*/

}

.snake {

  background: blue;

}

.apple {

  background: yellow;

  border-radius: 20px;

}

.popup {

  background: rgb(32, 31, 31);

  width: 100px;

  height: 100px;

  position: fixed;

  top: 100px;

  left: 100px;

  display: flex;

  justify-content: center;

  align-items: center;

}

The CSS grid, or gameboard, displays flex and a fixed size. This allows the grid's contents (div) to align horizontally, much like inline components, rather than the typical block display they now have.

The flex-wrap feature prevents the divs from expanding over the grid's predefined dimension by moving them to the next line.

The components of the game board will be created dynamically by JS; however, in this case, we may specify the width and height (using the grid div). Over time, we will remove the comments from the code since I put them here to make the divs easier to read.

Whereas the replay div is housed in a fixed div called the popup class, the Snake and Apple classes indicate where the Snake and bonus are in the game.

HTML Online Code Editor

Take advantage of OneCompiler's HTML online code editor to write, run, and share HTML code online without cost. Utilizing the most recent version of HTML5, it's one of the most feature-rich and reliable online code editors for the HTML language. With OneCompiler, you can quickly and easily begin using the HTML compiler. Upon selecting HTML as the language, the editor displays boilerplate code examples. Beginning with the scripts.js tab, you may provide information about the scripts and stylesheets, and you can code.

About HTML

In 1991, Berners-Lee developed HTML, or Hyper Text Markup Language, now the industry standard markup language for Web sites. HTML is used on almost every webpage on the internet.

Syntax assistance

  • A document declaration of <!DOCTYPE html> must precede any HTML document.
  • starting with <html> HTML pages terminate with </html>.
  • With <h1> to <h6> as the heading definitions, <h1> is the most significant.
  • Head and the least significant subheading is <h6>.
  • The <p>..</p> element defines paragraphs here.
  • It is the <a> element that defines links.
  • Example

<a href="https://onecompiler.com/html"> Internet HTML compiler

  • <img> tags define images, with the image name serving as the src property.
  • Clickable elements are denoted by <button>.The tag </button>
  • Unordered/bullet lists are defined in <ul>, whereas ordered/number lists are defined in <ol>. <li> defines the list of components.

Features and elements of HTML

  • Everything is an HTML element From the start to the end tag.
  • The HTML element
  •  content is the text between an element's start and finish tags.
  • While anything may be a tag name, choosing the relevant term corresponding to the material used is best.
  • Keep the final tag in mind.
  • We refer to items that are devoid of content as such.
  • Attributes are a way for an element to have more details about itself.
  • The following example uses an as the tag name and href as an attribute.
  • Example:

<a href="https://onecompiler.com/html">HTML online compiler</a>

HTML Tables

  • Tables in HTML are specified inside the <table> element.
  • In the <tr> element, the table row should be specified.
  • The <th> element should specify the table heading.
  • In the <td> tag, table data should be specified.
  • In the <caption> element, the table caption has to be specified.

Javascript - HTML

  • To enhance interactivity, JavaScript is included in HTML sites.
  • The HTML scripting element, <script>, is used for writing code.
  • Script code may be written in this tag, or you can reference an external script.
  • Example :

<script src="script.js"> </script>

JavaScript, which manages the logic of the Snake and its presentation to the canvas, will go here after the canvas adds the script tag. First, let's specify what ought to happen if the window is. On load is triggered. We want the canvas to periodically repaint itself with the Snake and Apple's updated locations and an event listener for player key presses.

You now have a basic understanding of operating with an HTML canvas element. The `draw` function, which will be called regularly to update the canvas, should now be defined. An elementary illustration of how the `draw` function may seem is as follows:

function draw() {

// Clear the canvas

  ctx.clearRect(0, 0, canvas.width, canvas.height);

  // Draw something on the canvas

  ctx.fillStyle = "blue";

  ctx.fillRect(50, 50, 100, 100);

}

After clearing the canvas using the `draw` function, a blue rectangle of 100 pixels in width and height will be drawn at (50, 50). The `keyDownEvent` function, which will manage keyboard input, should now be defined:

function keyDownEvent(e) {

  // Log the keycode of the pressed key

  console.log("Key pressed: " + e.keyCode);

}

The pressed key's keycode will be recorded in the console by this {keyDownEvent} function. You are welcome to modify these features to meet your requirements!