Monday, August 12, 2013

Javascript Game pt. 1 - Defining the Variables

I have learned that the best way to learn something is to do it. Therefore in my quest to learn Javascript I set myself the task of programming a game. I based this game off of an ancient Asian dice game used to gamble, known here in America as Chinchirorin. The basic rules for this game can be found here. This really taught me a lot, especially in terms of planning out how to program something. Previous to this the program effects I was trying to accomplish through Javascript were relatively simplistic.

It turns out that the keys to successfully defining a larger Javascript project is to successfully map the functions that you'll need as well as the variables. In this particular blogpost I'm going to only review the variables that I ended up defining for this game, a list whose length surprised me. All these variables I defined in a list at the beginning of my embedded script.

var housemoney=500; (This variable is what I used to track the money held by the bank that the player could gamble against and potentially win. Though you could create the game without this variable, the game would be endless without it. I used it in the programming to track when the player has 'broke the bank' and provide a win condition to the game.)

var h0us3m0n3y=document.getElementById("housemoney"); (This variable was created to interact with the HTML of the page so that the current amount of house money could be displayed and updated.)

var yourmoney=50; (This is the variable that I used to set how much money the player had available to bet. If a player runs out of this they could lose.)

var y0urm0n3y=document.getElementById("yourmoney"); (This variable was created to interact with the HTML of the page so that the current amount of player money could be displayed and updated.)

var housescore=0; (The internal variable to define what the house scored on a given turn barring a auto-win/loss.)

var h0us3sc0r3=document.getElementById("housescore"); (This variable was created to interact with the HTML of the page so that what the house scored could be displayed and updated.)

var yourscore=0; (The internal variable to define what the player scored on a given turn barring a auto-win/loss.)

var y0ursc0r3=document.getElementById("yourscore"); (This variable was created to interact with the HTML of the page so that what the player scored could be displayed and updated.)

var score=0; (The internal variable designed to keep track of a score on a given roll. This was then reassigned to the yourscore or housescore variable as appropriate. Resets every roll.)

var yourbet=0; (The internal variable designed to keep track of what the player chose to bet on a given turn.)

var y0urb3t=document.getElementById("yourbet"); (This variable was created to interact with the HTML of the page so that what the player chose to bet could be displayed and updated.)

var housebet=0; (The internal variable designed to track the house's bet on a given turn.)

var h0us3b3t=document.getElementById("housebet"); (This variable was created to interact with the HTML of the page so that the player knew that the house always matched their bet, and the the house's bet could be displayed and updated.)

var die1=0; (The internal variable designed to keep track of the result of die rolls on the first die.)

var dieroll1=document.getElementById("die1"); (A variable designed to interact with the HTML of the page so that the results of the die rolls of the first die could be displayed and updated.)

var die2=0; (The internal variable designed to keep track of the result of die rolls on the second die.)

var dieroll2=document.getElementById("die2"); (A variable designed to interact with the HTML of the page so that the results of the die rolls of the second die could be displayed and updated.)

var die3=0; (The internal variable designed to keep track of the result of die rolls on the third die.)

var dieroll3=document.getElementById("die3"); (A variable designed to interact with the HTML of the page so that the results of the die rolls of the third die could be displayed and updated.)

var winlose="undecided"; (An internal variable designed to keep track of whether a given roll matched a automatic win or loss condition.)

var triples="undecided"; (An internal variable designed to keep track of whether the roll result was a triple.)

var doubles="undecided"; (An internal variable designed to keep track of whether the roll result was a double.)

var stage=0; (An internal variable designed to keep track of what stage the game is currently at so that the programming can implement the appropriate next functions, or wait for player input.)

var zelda=document.getElementById("zelda"); (This variable was arbitrarily named after my cat. It was created to interact with the bottom text bar of the page, and display announcements about game play as they were triggered.)


No comments:

Post a Comment