Skip to content

Instantly share code, notes, and snippets.

@rekursed
Created January 5, 2024 14:11
Show Gist options
  • Save rekursed/d7e89c93ed4e8bed47b4ef9e668c29f4 to your computer and use it in GitHub Desktop.
Save rekursed/d7e89c93ed4e8bed47b4ef9e668c29f4 to your computer and use it in GitHub Desktop.
Fruit Machine

Fruit 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.

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