diff --git a/README.md b/README.md index c0bd851..591d5b4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/idh/hotseatgames/GamesManager.java b/src/idh/hotseatgames/GamesManager.java index aefd33a..cfdd19a 100644 --- a/src/idh/hotseatgames/GamesManager.java +++ b/src/idh/hotseatgames/GamesManager.java @@ -29,6 +29,7 @@ public class GamesManager { "oneplusone.OnePlusOne", "hangryllama.HangryLlama", "whereistheletter.WhereIsTheLetter", + "roulette.Roulette", }; private List> randomGames; diff --git a/src/idh/hotseatgames/HotSeatGames.java b/src/idh/hotseatgames/HotSeatGames.java index 1170526..6e79df6 100644 --- a/src/idh/hotseatgames/HotSeatGames.java +++ b/src/idh/hotseatgames/HotSeatGames.java @@ -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); diff --git a/src/idh/hotseatgames/games/roulette/Roulette.java b/src/idh/hotseatgames/games/roulette/Roulette.java new file mode 100644 index 0000000..52b35b9 --- /dev/null +++ b/src/idh/hotseatgames/games/roulette/Roulette.java @@ -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; + } + } + +} diff --git a/src/idh/hotseatgames/games/roulette/bets.txt b/src/idh/hotseatgames/games/roulette/bets.txt new file mode 100644 index 0000000..25805dc --- /dev/null +++ b/src/idh/hotseatgames/games/roulette/bets.txt @@ -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 | ++----------+--------------------------+--------+--------+ \ No newline at end of file diff --git a/src/idh/hotseatgames/games/roulette/instructions.txt b/src/idh/hotseatgames/games/roulette/instructions.txt new file mode 100644 index 0000000..a8a135c --- /dev/null +++ b/src/idh/hotseatgames/games/roulette/instructions.txt @@ -0,0 +1 @@ +The player bets five tokens on either individual numbers or number groups! \ No newline at end of file diff --git a/src/idh/hotseatgames/games/roulette/intro_banner.ascii b/src/idh/hotseatgames/games/roulette/intro_banner.ascii new file mode 100644 index 0000000..40fddaa --- /dev/null +++ b/src/idh/hotseatgames/games/roulette/intro_banner.ascii @@ -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&&&@@@########## + + ██████╗ ██████╗ ██╗ ██╗██╗ ███████╗████████╗████████╗███████╗ + ██╔══██╗██╔═══██╗██║ ██║██║ ██╔════╝╚══██╔══╝╚══██╔══╝██╔════╝ + ██████╔╝██║ ██║██║ ██║██║ █████╗ ██║ ██║ █████╗ + ██╔══██╗██║ ██║██║ ██║██║ ██╔══╝ ██║ ██║ ██╔══╝ + ██║ ██║╚██████╔╝╚██████╔╝███████╗███████╗ ██║ ██║ ███████╗ + ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚══════╝ \ No newline at end of file