Code Monkey home page Code Monkey logo

game-time's Introduction

Game Time

Synopsis

We were tasked with creating a working game utilizing TDD with object oriented programming principles in mind. A mid project refactor to ES6 was also implemented.

Code Example

class Paddle {
  constructor (board) {
    this.canvas = board.canvas;
    this.context = board.context;
    this.width = 80;
    this.height = 10;
    this.x = board.canvas.width/2 - this.width/2;
    this.y = board.canvas.height - this.height;
    this.moveRight = false;
    this.moveLeft = false;
  }

  draw () {
    this.context.fillStyle = '#2E2E3A';
    this.context.fillRect(this.x, this.y, this.width, this.height);
  }

  move () {
    if (this.moveRight && this.x < this.canvas.width-this.width) {
      this.x += 7;
    } if (this.moveLeft && this.x > 0) {
      this.x -= 7;
    }
  }
}

Motivation

This project is part of the Turing School of Software and Designs Front-end Engineering program for module 2.

Tests

The game.js file houses the bulk of the game's functionality and game play. We tested to see if collision detection and boundaries were working properly. As such the ball would continue moving and collision detection would score points.

examples:

it('should be able to detect the right boundary', () => {
  game.ball.x = 519;
  game.ball.dx = 2;
  game.detectRightBoundry();
  assert.equal(game.ball.dx, -2)
});

it('should be able to detect collisions', () => {
  game.ball.x = 30;
  game.ball.y = 80;
  game.bricks.brick[0][0].x = 20;
  game.bricks.brick[0][0].y = 60;
  assert.equal(game.bricks.brick[0][0].status, 1)
  game.collisionDetection();
  assert.equal(game.bricks.brick[0][0].status, 0)
  assert.equal(game.score, 1)
});

Contributors

Jack Bevis and Jenn Peavler

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.