Sherman  Zemlak

Sherman Zemlak

1627135920

PART II: Coding JavaScript Snake Game (Plain Vanilla JavaScript & HTML Canvas)

Learn how to build a the iconic Snake game using JavaScript in the browser! We will be using plain vanilla JS to code this fun game. This is the second part in a two part series of how to make a snake game in the browser using vanilla JavaScript.

We use an object orientated approach to build the snake game using javascript. Follow along as we create this iconic game.

PART 1: https://www.youtube.com/watch?v=21eSpMtJwrc

Code on GitHub: https://github.com/kriscfoster/Snake-Game

Don’t forget to Subscribe here: https://www.youtube.com/channel/UCWkzkhQ3syxBjjAYwqCbzYg?sub_confirmation=1

#javascript #html #canvas

What is GEEK

Buddha Community

PART II: Coding JavaScript Snake Game (Plain Vanilla JavaScript & HTML Canvas)
Sherman  Zemlak

Sherman Zemlak

1627135920

PART II: Coding JavaScript Snake Game (Plain Vanilla JavaScript & HTML Canvas)

Learn how to build a the iconic Snake game using JavaScript in the browser! We will be using plain vanilla JS to code this fun game. This is the second part in a two part series of how to make a snake game in the browser using vanilla JavaScript.

We use an object orientated approach to build the snake game using javascript. Follow along as we create this iconic game.

PART 1: https://www.youtube.com/watch?v=21eSpMtJwrc

Code on GitHub: https://github.com/kriscfoster/Snake-Game

Don’t forget to Subscribe here: https://www.youtube.com/channel/UCWkzkhQ3syxBjjAYwqCbzYg?sub_confirmation=1

#javascript #html #canvas

JavaScript Snake Game Tutorial - Develop a Simple Snake Game

Work on real-time JavaScript Snake game project and become a pro

Snake game is an interesting JavaScript project for beginners. Snake game is a single-player game, which we’ve been playing for a very long time. The game mainly consists of two components – snake and fruit. And we just need to take our snake to the food so that it can eat and grow faster and as the number of fruits eaten increases, the length of snake increases which makes the game more interesting. While moving if the snake eats its own body, then the snake dies and the game ends. Now let’s see how we can create this.

JavaScript Project Prerequisites

To implement the snake game in JavaScript you should have basic knowledge of:

1. Basic concepts of JavaScript

2. HTML

3. CSS

Download Project Code

Before proceeding ahead please download source code of Snake Game: Snake Game in JavaScript

Steps to Build the Project – JavaScript Snake game

1. Create Html file

HTML builds the basic structure. This file contains some basic HTML tags like div, h1, title, etc. also we’ve used bootstrap (CDN is already included).

index.html:

Code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>DataFlair Snake game</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <link rel="stylesheet" href="static/style.css">
</head>
<body>
    <div class="container">
        <div class ="Jumbotron">
        <h1>DataFlair Snake game using vanilla JavaScript</h1>

            <h2 class="btn btn-info"> 
                Score:   0 
            </h2>

            <div class="containerCanvas">
                <canvas id="canvas" width="500" height="500" class="canvasmain"> </canvas>
            </div>
        </div>
    </div>
    <script src="static/fruit.js"></script>
    <script src="static/snake.js"></script>
    <script src="static/draw.js"></script>
</body>
</html>

We have used simple HTML tags except tag. This new tag was introduced in HTML5, which is used to draw graphics, via JavaScript. It is nothing without JavaScript so we will use it in our JavaScript file to actually draw the board and the objects required. We’ll see its implementation in JS files.

#javascript tutorial #javascript project #javascript snake game #simple snake game #javascript

Sherman  Zemlak

Sherman Zemlak

1627096260

Coding JavaScript Snake Game (Plain Vanilla JavaScript & HTML Canvas)

Learn how to build a the iconic Snake game using JavaScript in the browser! We will be using plain vanilla JS to code this fun game.

We use a html5 canvas to create this snake game. We draw on the canvas using drawrect and other methods provided by the canvas. We will be tracking our score based on how many fruit the snake eats. We us an object orientated approach to build this game.

Code on GitHub: https://github.com/kriscfoster/Snake-Game

Don’t forget to Subscribe here: https://www.youtube.com/channel/UCWkzkhQ3syxBjjAYwqCbzYg?sub_confirmation=1

#vanilla #javascript #html #html5

Houston  Sipes

Houston Sipes

1604088000

How to Find the Stinky Parts of Your Code (Part II)

There are more code smells. Let’s keep changing the aromas. We see several symptoms and situations that make us doubt the quality of our development. Let’s look at some possible solutions.

Most of these smells are just hints of something that might be wrong. They are not rigid rules.

This is part II. Part I can be found here.

Code Smell 06 - Too Clever Programmer

The code is difficult to read, there are tricky with names without semantics. Sometimes using language’s accidental complexity.

_Image Source: NeONBRAND on _Unsplash

Problems

  • Readability
  • Maintainability
  • Code Quality
  • Premature Optimization

Solutions

  1. Refactor the code
  2. Use better names

Examples

  • Optimized loops

Exceptions

  • Optimized code for low-level operations.

Sample Code

Wrong

function primeFactors(n){
	  var f = [],  i = 0, d = 2;  

	  for (i = 0; n >= 2; ) {
	     if(n % d == 0){
	       f[i++]=(d); 
	       n /= d;
	    }
	    else{
	      d++;
	    }     
	  }
	  return f;
	}

Right

function primeFactors(numberToFactor){
	  var factors = [], 
	      divisor = 2,
	      remainder = numberToFactor;

	  while(remainder>=2){
	    if(remainder % divisor === 0){
	       factors.push(divisor); 
	       remainder = remainder/ divisor;
	    }
	    else{
	      divisor++;
	    }     
	  }
	  return factors;
	}

Detection

Automatic detection is possible in some languages. Watch some warnings related to complexity, bad names, post increment variables, etc.

#pixel-face #code-smells #clean-code #stinky-code-parts #refactor-legacy-code #refactoring #stinky-code #common-code-smells

Lyda  White

Lyda White

1628189100

How to Image Uploader with Preview || Html CSS JavaScript

Image Uploader with Preview || Html CSS JavaScript || #html #css #javascript #coding

#html #css #javascript