Project 1 (Browser-Based Game)
A slot machine is a gambling machine which relies on chance to determine a win or loss. The machine takes credits or coins as input and outputs a scaled amount of coins if a certain "win" condition is met. There are usually three or more reels, which depict fruits or other popular symbols. In the simplest form, a win takes place when the same symbol (as depicted on the pay table) appears across a row. In this application, a player can keep playing until the credits run out (loss condition).
You can access the game by clicking here: Slot Machine
The game can be played by selecting the lines to bet, the credits per line, and hitting the GAMBLE! button. The credits will be automatically updated based on a win or loss. A reset button is available to restart the game. NOTE: The game has sound which will be played upon initial load, after each gamble, and upon a reset.
- Define required constants
- Define a SYMBOLS object that defines the symbols that will be on each reel
- Define which three symbols will scale the value of a bet and store as an object property
- Define required variables used to track the state of the game
- Define an array to represent each of the three active symbols on the reels
- Define a variable to keep track of a user’s credits (money)
- Define variables to store the player's betting options (1 CR per line, 5 CR per line, one bet line, three bet lines)
- Store elements on the page that will be accessed in code more than once in variables to make code more concise, readable and performant
- Store each of the buttons used to play the game
- Store the elements used to display the remaining credits and any user message
- Upon loading the app should:
- Initialize the state variables
- Initialize each of the three arrays to a starting value representing the initial symbols on the reel
- Initialize the user’s credits to 500
- Default the button values to false
- Render those values to the page
- Render the slot machine:
- Display a symbol to each of the 9 elements that will be displayed on the page
- Update the CREDITS REMAINING to the current credits value
- Render any messages:
- Display messages to indicate start of game and win/loss
- Render the slot machine:
- Wait for the user to click GAMBLE! to start game
- Initialize the state variables
- Handle a player clicking the GAMBLE! button to start the slot machine:
- Check that the user’s total credits inserted are > 0
- Check that the appropriate bet option selections are made
- Check that the user has enough credits to make a bet
- Trigger a random generation function three times
- Randomly select an array index to determine which relative symbols are “active” on each of the reels
- Trigger an update credits function
- Calculate the reward based on the “pay table” for each of line of the reels
- Trigger an equality check function (for each selected row) that checks if all the elements in a given row are equal
- Scale the value of the input credits based on the “pay table”
- Update the total credits of the user
- Calculate the reward based on the “pay table” for each of line of the reels
- Render the slot machine after all states have been updated
- Handle a player clicking on any of the bet option buttons:
- Set the appropriate variables based on the lines selected and credits per line allocated
- Render the active buttons with appropriate styling
- Handle a player clicking the reset button:
- Initialize the state variables again and render the slot machine
- As a player, I want to be able to select the lines & bet amounts and start a game.
- As a player, I want to be able to play multiple games to increase my winnings.
- As a player, I want to be able to see the resulting symbols/numbers displayed to confirm a win/loss.
- As a player, I want to be able to know when I can no longer play (do not have sufficient credits).
- HTML5
- CSS3
- JavaScript
- Make the game page responsive across other browsers and mobile devices
- Add scrolling animation to the reels
- Add functionality to bet on cross lines