Play this article
Jackpot Machine
- Total 3 slots
- Each slot have 0 -> 9 digits
- You get 10 chance
- Winner declaration
4.1 All three same 4.2 Times two same (449 994 885)
Features
- Start the game
- Trigger slot run - Pull the lever
- Keep track of outcomes -
- End game or declare winner whichever comes first
Rough Solution (LLD-Machine Coding)
Basic Entity
Player, Score, Slot , Random Number, JackPot Machine
Important Points
- There can be more than 3 slots also in a machine in future
- There can be multiple players who are using the same machine (may be turn by turn)
- Slots range may also change in future (so we should not hardcode them)
Final Code
Class JackpotMachine {
Private:
Int chance;
Int totalSlots ;
vector<Player> players ;
vector<int> slotsRange ;
map<player, winner>
Public
JackpotMachine(int chance, int totalSlots, vector<int> slotRange) {
}
AddPlayer(Player p) {
}
pullTheLevel(player p) {
}
}
Class RandomNumber {
Private:
Int start;
Int end ;
public :
RandomNumber(int start, int end) {
}
getRandomNumber() {
}
}
Class Slot : public RandomNumber {
Public:
Slot(int range) {
RandomNumber(range) ;
}
getSlotValue() {
}
}
Class Player {
Private:
Int playerId ;
Int chances_left ;
vector<Scores> playerScores ;
Public :
Player(int id, int chances) {
}
pullTheLever() {
if(chances_left == 0) return “You LOSE” ;
Chances_lef– ;
}
getScore() {
Return playerScores ;
}
}
Class Scores {
Private:
vector<int> score;
Public:
Scores(int totalSlots) {
score.reszie(totalSlots) ;
}
}