Bag Of Cows

Basic JS Game - Part 1

  1. Create a new folder for the game and open it in Visual Studio Code
  2. Make four files, initially empty
  3. copy all of this code into the utilities.js file
  4. In the index.html page, put in the code necessary to make it look like this:
  5. At the bottom of the HTML, just before the</BODY>, paste in this code to bring in the Javascript files
  6.         <script src="utilities.js" type="text/Javascript"></script>
            <script src="buttons.js" type="text/Javascript"></script>
            <<script src="game.js" type="text/Javascript"></script>
            

    The reason this is going at the end is that the Javascript files will run some code as soon as they load, and that code tries to access the CANVAS. By putting the Javascript at the end of the file, we make sure that the CANVAS actually exists before we try to use it.

  7. In the buttons.js file, make two functions,
    startGame()
    and
    endGame()
  8. Initially these functions just need to enable and disable the start and end buttons appropriately.

  9. Connect the onClick events of the buttons to these functions

At this stage the project looks like this.

Part 2