Skip to content

Commit

Permalink
Add game "Roulette"
Browse files Browse the repository at this point in the history
  • Loading branch information
bkis committed Jan 24, 2022
1 parent 9894d5c commit 9b253cb
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ At this point, the following games are included in *Hot Seat Games* (in order of
- **[One Plus One](https://github.com/bkis/HotSeatGames/tree/main/src/idh/hotseatgames/games/oneplusone)** (by [chrkell](https://github.com/chrkell))
- **[Hangry Llama](https://github.com/bkis/HotSeatGames/tree/main/src/idh/hotseatgames/games/hangryllama)** (by [MarcHorvath2001](https://github.com/MarcHorvath2001))
- **[Where Is The Letter?](https://github.com/bkis/HotSeatGames/tree/main/src/idh/hotseatgames/games/whereistheletter)** (by [MilchStrassenBoi](https://github.com/MilchStrassenBoi))
- **[Roulette](https://github.com/bkis/HotSeatGames/tree/main/src/idh/hotseatgames/games/roulette)** (by L. Markic)


## How to add new games
Expand Down
1 change: 1 addition & 0 deletions src/idh/hotseatgames/GamesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class GamesManager {
"oneplusone.OnePlusOne",
"hangryllama.HangryLlama",
"whereistheletter.WhereIsTheLetter",
"roulette.Roulette",
};

private List<Class<?>> randomGames;
Expand Down
2 changes: 1 addition & 1 deletion src/idh/hotseatgames/HotSeatGames.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void startGames() {
// start game for each player in succession, add won points
for (Player player : players) {
input.prompt("> " + player.getName()
+ ", press [ENTER] when you're ready!");
+ ", press [ENTER] when you're ready!\n");
int points = game.startRound(player.getName());
Delay.now(500);
StringUtils.printLineBreaks(1);
Expand Down
133 changes: 133 additions & 0 deletions src/idh/hotseatgames/games/roulette/Roulette.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package idh.hotseatgames.games.roulette;

import java.util.Random;

import idh.hotseatgames.IGame;
import idh.hotseatgames.utils.Delay;
import idh.hotseatgames.utils.ResourceReader;
import idh.hotseatgames.utils.StringUtils;
import idh.hotseatgames.utils.UserInput;


public class Roulette implements IGame {

private static final NumberGroup[] NUMBER_GROUPS = {
new NumberGroup("Black",
2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35),
new NumberGroup("Red",
1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36),
new NumberGroup("Evens",
2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36),
new NumberGroup("Odds",
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35),
new NumberGroup("Manque",
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18),
new NumberGroup("Passe",
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36),
};

private Random rnd;
private String betsOverview;


@Override
public int startRound(String playerName) {
this.rnd = new Random();
this.betsOverview = getBetsOverview();
int[] input = getBet();
return evaluateBets(input);
}


private int[] getBet() {
UserInput input = UserInput.instance();
StringUtils.printLineBreaks(1);
StringUtils.slideInText(betsOverview, 100, 4);
StringUtils.printLineBreaks(1);
System.out.println("You can now bet up to five tokens.");
StringUtils.printLineBreaks(1);

int[] bet = new int[5];

for (int i = 0; i < bet.length; i++) {
bet[i] = input.prompt("Token " + (i+1) + " (0..42): ", 0, 42);
}

return bet;
}


private NumberGroup getWinConditions(int betNumber) {
if (betNumber <= 36) {
return new NumberGroup(String.valueOf(betNumber), betNumber);
} else {
return NUMBER_GROUPS[betNumber - 36 - 1];
}
}


private int evaluateBets(int[] bets) {
int totalPoints = 0;
int rolledNumber = rnd.nextInt(37);

System.out.println(String.format("\nNumber rolled: %d\n", rolledNumber));

for (int betNumber : bets) {
Delay.now(1000);
NumberGroup winConditions = getWinConditions(betNumber);
boolean win = false;
int points = 0;

for (int condition : winConditions.numbers) {
if (rolledNumber == condition) {
win = true;
break;
}
}

if (win) {
points = 36 / winConditions.numbers.length;
}

System.out.println(String.format(
"%s%s%s %d points",
winConditions.name,
StringUtils.padString(12 - winConditions.name.length()),
win ? "HIT!" : " ",
win ? points : 0));

totalPoints += points;
}

return totalPoints;
}


public String getBetsOverview() {
return ResourceReader.readResource("bets.txt", getClass());
}


@Override
public String getInstructions() {
return ResourceReader.readResource("instructions.txt", getClass());
}


@Override
public String getIntroBanner() {
return ResourceReader.readResource("intro_banner.ascii", getClass());
}


private static class NumberGroup {
String name;
int[] numbers;

public NumberGroup(String name, int... numbers) {
this.name = name;
this.numbers = numbers;
}
}

}
11 changes: 11 additions & 0 deletions src/idh/hotseatgames/games/roulette/bets.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
+----------+--------------------------+--------+--------+
| Number | What you bet on | Chance | Points |
+----------+--------------------------+--------+--------|
| 1 ... 36 | Single numbers 1 to 36 | 2,78 % | 36 |
| 37 | Black numbers | 50,0 % | 2 |
| 38 | Red numbers | 50,0 % | 2 |
| 39 | Pair (even numbers) | 50,0 % | 2 |
| 40 | Impair (odd numbers) | 50,0 % | 2 |
| 41 | Manque (numbers 1 to 18) | 50,0 % | 2 |
| 42 | Passe (numbers 19-36) | 50,0 % | 2 |
+----------+--------------------------+--------+--------+
1 change: 1 addition & 0 deletions src/idh/hotseatgames/games/roulette/instructions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The player bets five tokens on either individual numbers or number groups!
39 changes: 39 additions & 0 deletions src/idh/hotseatgames/games/roulette/intro_banner.ascii
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
0000000%0=%#####@0?@#@@#@%%&&&&&&&? ?&? 0&&&&&&&%%%0 =%% %? =0%%%&@@@@@@@@@
0000000?=@#####&=%#@@@@&0%&&&&&&&&0 %&? 0&&&&&&&%%% ?? =%%%%%&@@@@@@@@@@@#
000%00=0#####@0?@#@@@@%%@&&&&&&&&&&= =&&? %&&&&&&&%%0= =0%%%&@@@@@@@@@@####
00%00=%#####@?%#@@@@&0@###&&&&&&&&&% =&&? %&&&&&&%%%%%%%%&@@@@@@@@@&#####@@
000?=@#####&?&#@&@@%%@##@##&&&&&&&&&% ?&&= %&&%%%%%%%%%&@@@@@@@@##@@#@@&&&&
00??######%?@#@@#@0&########@&&&&&&&&% ?&&= =&&&&&&&%%&@@@@@@@@####@&@&%%%%%
0=0#####@0%##@#@&%###########@&&&&&&&&% ?&% %&&&&&&&@@@@@@@######@@&&@%%%%%
==&@###@?&##@#@&&#####%?0@####@&&&&&&&&0 ?%= %&&&&&@@@@@@@###@&&@#@&&@@&%%%%
%%&&@@&0@#@@#@%@####@= = &####@&&&&&&&&% 0&&%&@@@@@@@##@&&&%%&@#@&&&@%%%%
@@#@&%?@#@@#@%@#####0 ?#% %######&&&&&&&&&0%&&%&@@@@@@&@@@&&%%%%%%&##&&@@@%%%
@@#@%?&@@@@&&#######& ?##&??%####&&&&&&&&&&%%@@@@@@@@%@@&%%%%%%%%%&#@&&@@&%%
#@@0?0&@@@&&#####@@##% =% &###&&&&&&&&%&@@@@@@##&&0@@%%%%%%%%%%&#@&@@&%%
%@0%@@&@@&@####&= 0@& @@? 0###@&&&&%%@@@@@%???000&%@&%%%%%%%%%%&#@&@@0%
@00&%%&@&@####@ 0? &@? ?@#& ?###@&&%&@@@@%= 0&&@&%%%%%%%%%&&#&@@%%
0&@&&%&&@#####% @#&= &#% &#@ %###&%&@@@&0= ?@@@&%%%%%%%%%&@@&@@0
&##@@&%@######@= =&#@= @#@= ?&= &##%%&@@@&&?= %@@@&%%%%%%%%&&@@@@&
##@#@0%%&######@= 0@@= 0###% =&@&0&&&&&&#&0== %@@@@&%%%%%%%%%&@@@@
###@0%%%%%@######0 =@#& @####&&##&%@@@&&&&#@0?=== =@#&@@@%%%%%%%%%&&@@@
##@%%%%%%%%%@##########= %#@?0###%&@@@@@@@&%@&00?=======0@##&@@@%%%%%%%%%%&@@
#@%%%%%%%%%%%%@########% ?& 0##%&@@@&@##@@&%@@%%00???0%%%&##@@@&%%%%%%%%%&&@
@%%%%%%%%%%%%%%&@######@ &#@%@@@@&@####@@@&@##@@@@&%%%%%&@#@@@%%%%%%%%%%%&
%%%%%%%%%%%%%%%%%&######? =@#@%@@@@&&@######@@&@####&%%%%%%%%@#@@@%%%%%%%%%%&
%%%%%%%%%%%%%%%%%%%&####@%@#&%@@@@&&&&&@@####@@@@@&&%%%%%%%%%%&#@@@%%%%%%%&@#
%%%%0= =0%%%%%%%%%%%@#####&%@@@@&&&%%%%&@####@@@@&%%%%%%%%%%%%&@@@@%%%%&@###
%%%0 =0%%%%%%%%%%%@##&&@@@&&%%%%%%%&%&@####@@@@%%%%%%%%%%%%%@@@%%&@#####
%%%= =%0? ??0%%%%%%%%%%%&@@@&&%%%%%%%%%%&&&@###@@@@&%%%%%%%%%%%%&&0&#######
%%%0 =?%0 ?0%%%%%%0&@@@&%%%%%%%%%%%%%%%&&@###@@@&%%%%%%%%%%%0%@###@####
%%%%0= =%= =?? ?%%%%0&@@@&%&&%%%%%%%%%%%%%%&&&@##@@@@%%%%%%%%0?@@#########
%%%%%%%%%?=0????= 0%%%&&&@@@@@@&%%%%%%%%%%%%%%&%%&@#@@@&%%%%0%?%@@@#########
%%%%%%%%%%%? ==? 0%%&@@@@###@@@@&&%%%%%%%%%%%%%&%&&##@@&%0%0?&@@@@@########
%%%%%%%%%%%0 ?%%0@&@@@######@@@@&%%%%%%%%%%%%%%%&&#@&&%?0&@@@@@#########
%%%%%%%%%%%%0?= =?%%0%&&@&@#######@@@@@&%%%%%&%%%%%%%%%&&&%=0&&&@@@##########

██████╗ ██████╗ ██╗ ██╗██╗ ███████╗████████╗████████╗███████╗
██╔══██╗██╔═══██╗██║ ██║██║ ██╔════╝╚══██╔══╝╚══██╔══╝██╔════╝
██████╔╝██║ ██║██║ ██║██║ █████╗ ██║ ██║ █████╗
██╔══██╗██║ ██║██║ ██║██║ ██╔══╝ ██║ ██║ ██╔══╝
██║ ██║╚██████╔╝╚██████╔╝███████╗███████╗ ██║ ██║ ███████╗
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚══════╝

0 comments on commit 9b253cb

Please sign in to comment.