Advertisement
Guest User

Untitled

a guest
Feb 15th, 2014
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class RussianRoulette{
  4. public static void main (String[]args){
  5. Scanner console = new Scanner(System.in);
  6. introduction(console);
  7. ArrayList players=players(console);
  8. ArrayList winner=game(players,console);
  9. Winner(winner);
  10. }
  11.  
  12. /* Introduction to the game*/
  13. public static void introduction(Scanner console){
  14. System.out.println("This is a game of russian roulette where 2 or more people test there luck against each other.");
  15. System.out.println("A revolver is loaded with a single bullet and the chamber is spun.");
  16. System.out.println("Each player takes turns of putting the gun to their head and pulling the trigger.");
  17. System.out.println("If a player survives, he can choose to pass the gun or press the trigger one more time.");
  18. System.out.println("If a player is not so lucky, the gun is reloaded and continues with the remaining players.");
  19. System.out.println("The winner is the last player left alive.");
  20. System.out.println("Type anything to continue");
  21. String Continue=console.next();
  22. System.out.println();
  23. }
  24.  
  25. /*Creates an arraylist for the players*/
  26. public static ArrayList players(Scanner console){
  27. ArrayList<Integer> list = new ArrayList<Integer>();
  28. System.out.println("How many players will be playing today? 2-4 people only ");
  29. int players=console.nextInt();
  30. if(players<=1||players>4)throw new IllegalArgumentException("Please type a valid number");
  31. for(int i=1;i<=players;i++){
  32. list.add(i);
  33. }
  34. return list;
  35. }
  36. /*Starts the game where each player takes a turn pulling the trigger. Those
  37. who are eliminated are removed from the arraylist and cease to play*/
  38. public static ArrayList game(ArrayList players,Scanner console){
  39. String Continue="";
  40. int trigger=1;
  41. int wheel=spinWheel();
  42. while(players.size()!=1){
  43. for (int i=0;i<players.size();i++){
  44. System.out.println("Player "+players.get(i)+" picks up the gun and aims at his head.");
  45. System.out.println("He pulls the trigger\n");
  46. if(trigger==wheel){
  47. System.out.println("Player "+players.get(i)+" shot himself! He has been eliminated.\n");
  48. players.remove(i);
  49. System.out.println("The guns is reloaded and the wheel is spun.\n");
  50. wheel=spinWheel();
  51. trigger=0;
  52. i--;
  53. System.out.println("Type anything to continue");
  54. Continue=console.next();
  55. if(players.size()==1){
  56. return players;
  57. }
  58. }else{
  59. trigger++;
  60. System.out.println("Player "+players.get(i)+" survives, will he test his luck again?\n");
  61. System.out.println("(1) Press the trigger (2) Pass the gun");
  62. int again=console.nextInt();
  63. if(again==1){
  64. System.out.println("Player "+players.get(i)+" pulls the trigger again.");
  65. if(trigger==wheel){
  66. System.out.println("Player "+players.get(i)+" shot himself! He has been eliminated.\n");
  67. players.remove(i);
  68. trigger=0;
  69. System.out.println("The guns is reloaded and the wheel is spun.\n");
  70. wheel=spinWheel();
  71. i--;
  72. System.out.println("Type anything to continue");
  73. Continue=console.next();
  74. if(players.size()==1){
  75. return players;
  76. }
  77. }else{
  78. trigger++;
  79. System.out.println("Player "+players.get(i)+" survives! He must pass the gun.\n");
  80. System.out.println("Type anything to continue");
  81. Continue=console.next();
  82. }
  83. }else{
  84. System.out.println("Player "+players.get(i)+" puts down the gun.\n");
  85. }
  86. }
  87. }
  88. }
  89. return players;
  90. }
  91. /*Spins the wheel, randomizing the chances of a player getting shot*/
  92. public static int spinWheel(){
  93. Random rand = new Random();
  94. int bullet=rand.nextInt(6)+1;
  95. return bullet;
  96. }
  97. /*Prints the winner when the arraylist Players reach .size()==1*/
  98. public static void Winner(ArrayList winner){
  99. System.out.println("The winnner is: Player "+winner);
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement