Skip to content

Instantly share code, notes, and snippets.

@ChrisOwen101
Last active July 11, 2024 12:50
Show Gist options
  • Save ChrisOwen101/f105faedcd75dcd4699265fbe0cb0050 to your computer and use it in GitHub Desktop.
Save ChrisOwen101/f105faedcd75dcd4699265fbe0cb0050 to your computer and use it in GitHub Desktop.

Fruit machine

fruit machine

1. Build the Machine

We are going to create a virtual fruit machine. To make things easier instead of symbols we are going to use colours: black, white, green, yellow.

Each time a player plays our fruit machine we display four 'slots' each with a randomly selected colour in each slot.

If the colours in each slot are the same then the player wins the jackpot which is all of the money that is currently in the machine.

Implement a basic machine, along with the concept of a player who has a fixed amount of money to play the machine.

2. Floats and Prizes

We are now going to add a "float" to our fruit machine, this is an initial sum of money that the machine has. In addition we are going to implement a prize system.

If each slot has a different colour then the machine should pay out half the current money in the machine.

If a given play results in two or more adjacent slots containing the same colour then the machine should pay out a prize of 5 times the cost of a single play.

If the machine does not have enough money to pay a prize it should credit the player with a number of free plays equal to the difference between the full prize and the amount of money available. This does not affect a jackpot win.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment