Git Product home page Git Product logo

lab-javascript-ping-pong's Introduction

Ironhack Logo

JS | Ping Pong Game

Learning Goals

After this learning unit, you will be able to:

  • Build your own Ping Pong game, using HTML, CSS and JavaScript
  • Create the logic of the game using JavaScript classes
  • Separate the logic of the game from the JavaScript DOM operations
  • Structure JavaScript files according to the game classes

Requirements

Submission

Upon completion, run the following commands

$ git add .
$ git commit -m "done"
$ git push origin master

Navigate to your repo and create a Pull Request -from your master branch to the original repository master branch.

In the Pull request name, add your name and last names separated by a dash "-" Ironhack Logo

JS | Ping Pong Game

Learning Goals

After this learning unit, you will be able to:

  • Build your own Ping Pong game, using HTML, CSS and JavaScript
  • Create the logic of the game using JavaScript classes
  • Separate the logic of the game from the JavaScript DOM operations
  • Structure JavaScript files according to the game classes

Requirements

Submission

Upon completion, run the following commands

$ git add .
$ git commit -m "done"
$ git push origin master

Navigate to your repo and create a Pull Request -from your master branch to the original repository master branch.

In the Pull request name, add your name and last names separated by a dash "-"

Deliverables

Remember to add every file needed to make your game work. Don't forget external libraries (lib/) and other resources.

Introduction

![Ping Pong Pic](https://i.imgur.com/XOUlFqu.png =300)

In this Learning Unit, we are going to build one of the first games ever created: the Ping Pong.

We have a ball and two paddles at each side of a table.

  • The left paddle belongs to the user, and is going to be controlled with the keyboard arrows
  • The right paddle belongs to the computer, and is going to be automatically controlled by the application
  • The ball is going to move in a random direction at the beginning. It will rebound when reaches the top or bottom side of the board or is hit by a paddle

The goal is to score 7 points against the computer. A point is won if the ball reaches the right or left side of the board. Each player has to avoid the ball to reach his side of the board returning the ball with the paddle.

The Board

  • In the board.js file, let's code the functions we will need to handle the game. The Board will hold three elements: the user paddle, the computer's paddle and the ball
  • In this file we will create the function to start, restart and stop the game and a function to check the game status. This function will be executed recurrently to render the updated elements

The Ball

  • In the ball.js file we will hold the functions to make the ball move and recognize the edges. If this happens, rebound in the opposite direction.
  • These functions are:
    • Set a random direction to start the movement
    • Keep moving the ball in the same direction until it reaches an obstable, or the right and left sides of the board
    • Score a point to a paddle when needed
    • Restart the ball position when a point is scored

The Paddle

  • In the paddle.js file we will create the functions to relocate the paddles in their initial positions if a point is scored
  • It will also detect when a paddle is hit by the ball

User interactions

The user has only two input possibilities: Arrow up or Arrow down. This will move his paddle in the desired position.

In the index.js file we will create the methods to receive user's input.

The computer has to play

Also, in the index.js we will create the method to make the computer play. The computer's paddle position should follow the ball at anytime to emulate intelligence.

Summary

In this learning unit we created a Ping Pong game by separating at first the logic from the rendering. We also implemented a recurrent function with an interval to update and render the elements in the screen.

Extra Resources

lab-javascript-ping-pong's People

Contributors

adifox avatar fontcuberta avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.