<repo_name>AnnikaChauhan/flappy-game-part-two<file_sep>/Obstacle.js
export default class Obstacle {
    constructor(obstacleID){
        this.obstacleID = obstacleID;
        this.height = this.setObstacleHeight;
        this.width = 100;
        this.obstacleRight = -80;
    }

    setObstacleHeight = () => {
        let randomIndex = Math.ceil(Math.random() * 4)
        return 100 * randomIndex;
    }

    randomColourGenerator = () => {
        let red = Math.floor(Math.random() * 255);
        let green = Math.floor(Math.random() * 255);
        let blue = Math.floor(Math.random() * 255);
        return `${red},${green},${blue}`;
    }

    generateObstacle = () => {
        return `<div class="obstacle" id="obstacle-${this.obstacleID}"></div>`;
    }

    buildObstacle = () => {
        let obstacle = document.getElementById(`obstacle-${this.obstacleID}`);
        obstacle.style.height = this.height();
        obstacle.style.width = this.width;
        obstacle.style.backgroundColor = `rgb(${this.randomColourGenerator()})`;
    }

    moveObstaclemove = () => {
        const intervals = setInterval(() => {
            if (this.obstacleRight < 750) {
                this.obstacleRight += 25;
                document.getElementById(`obstacle-${this.obstacleID}`).style.right = this.obstacleRight;
            }
        }, 200);
        return intervals;
    }
}<file_sep>/Object.js
export default class Object {
    constructor(objectID) {
        this.objectID = objectID;
        this.objectTop = 100;
        this.objectHeight = 100;
        this.objectWidth = 100;
    }

    generateObject = () => {
        return '<div id="ball"></div>';
    }

    fallObjectfall = () => {
        const intervals = setInterval(() => {
            if (this.objectTop < 400) {
                this.objectTop += 5;
                document.getElementById('ball').style.top = this.objectTop;
                document.getElementById('ball').style.height = this.objectHeight;
                document.getElementById('ball').style.width = this.objectWidth;
            }
        }, 100);
        return intervals;
    }

    jumpObjectJump = () => {
        if (event.which === 32) {
            this.objectTop -= 40;
            document.getElementById('ball').style.top = this.objectTop;
        }
    }
}<file_sep>/app.js
import Game from "./Game.js";

const myGame = new Game('game');

myGame.buildTheGamePage();
document.onkeypress = () => {
    if(event.which === 13){
        myGame.play();
    }
}<file_sep>/README.md
# flappy-game-part-two
A game built after finishing the _nology course, in an attempt to improve the original 'flappy game' produced in game week (week 5) at _nology. It is an attempt to recreate flappy bird.

Original game can be found [here](https://github.com/AnnikaChauhan/flappy-game).

The game was built using HTML, CSS and JavaScript and does not need any additional packages to be run locally.

Access to the live game is available [here](https://annikachauhan.github.io/flappy-game-part-two/).<file_sep>/Game.js
import Object from "./Object.js";
import Obstacle from "./Obstacle.js";

export default class Game {
    constructor(id) {
        this.id = id;
    }

    buildTheGamePage = () => {
        document.getElementById(this.id).innerHTML = '<div id="gameBox"></div>';
    }

    play = () => {
        let gameBoxHTML = document.getElementById('gameBox');
        let myObject = new Object('flappyThing');
        gameBoxHTML.innerHTML += myObject.generateObject();
        myObject.fallObjectfall();
        document.onkeydown = () => {
            if (event.which === 32) {
                myObject.jumpObjectJump();
            }
        }
        let number = 0;
        const interval = () => {
            setInterval(() => {
                //this if statement is just whilst I test, maybe you can up this to 20 for the actual game???
                if (number < 5) {
                    number += 1;
                    let myObstacle = new Obstacle(`${number}`);
                    gameBoxHTML.innerHTML += myObstacle.generateObstacle();
                    myObstacle.buildObstacle();
                    myObstacle.moveObstaclemove();
                    // console.log(myObstacle.height());
                    // console.log(myObstacle.obstacleRight);
                    this.hasCollided(myObject);
                } else {
                    clearInterval(interval);
                }
            }, 1000);
        }
        interval();
        this.hasCollided(myObject);
        //call the collision detection here, to stop intervals on true
    }

    hasCollided = (obj) => {
        let objectBottom = obj.objectTop + obj.objectHeight;
        console.log(obj.objectTop);
        console.log(objectBottom);
    }

}