Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class RussianRoulette{
- public static void main (String[]args){
- Scanner console = new Scanner(System.in);
- introduction(console);
- ArrayList players=players(console);
- ArrayList winner=game(players,console);
- Winner(winner);
- }
- /* Introduction to the game*/
- public static void introduction(Scanner console){
- System.out.println("This is a game of russian roulette where 2 or more people test there luck against each other.");
- System.out.println("A revolver is loaded with a single bullet and the chamber is spun.");
- System.out.println("Each player takes turns of putting the gun to their head and pulling the trigger.");
- System.out.println("If a player survives, he can choose to pass the gun or press the trigger one more time.");
- System.out.println("If a player is not so lucky, the gun is reloaded and continues with the remaining players.");
- System.out.println("The winner is the last player left alive.");
- System.out.println("Type anything to continue");
- String Continue=console.next();
- System.out.println();
- }
- /*Creates an arraylist for the players*/
- public static ArrayList players(Scanner console){
- ArrayList<Integer> list = new ArrayList<Integer>();
- System.out.println("How many players will be playing today? 2-4 people only ");
- int players=console.nextInt();
- if(players<=1||players>4)throw new IllegalArgumentException("Please type a valid number");
- for(int i=1;i<=players;i++){
- list.add(i);
- }
- return list;
- }
- /*Starts the game where each player takes a turn pulling the trigger. Those
- who are eliminated are removed from the arraylist and cease to play*/
- public static ArrayList game(ArrayList players,Scanner console){
- String Continue="";
- int trigger=1;
- int wheel=spinWheel();
- while(players.size()!=1){
- for (int i=0;i<players.size();i++){
- System.out.println("Player "+players.get(i)+" picks up the gun and aims at his head.");
- System.out.println("He pulls the trigger\n");
- if(trigger==wheel){
- System.out.println("Player "+players.get(i)+" shot himself! He has been eliminated.\n");
- players.remove(i);
- System.out.println("The guns is reloaded and the wheel is spun.\n");
- wheel=spinWheel();
- trigger=0;
- i--;
- System.out.println("Type anything to continue");
- Continue=console.next();
- if(players.size()==1){
- return players;
- }
- }else{
- trigger++;
- System.out.println("Player "+players.get(i)+" survives, will he test his luck again?\n");
- System.out.println("(1) Press the trigger (2) Pass the gun");
- int again=console.nextInt();
- if(again==1){
- System.out.println("Player "+players.get(i)+" pulls the trigger again.");
- if(trigger==wheel){
- System.out.println("Player "+players.get(i)+" shot himself! He has been eliminated.\n");
- players.remove(i);
- trigger=0;
- System.out.println("The guns is reloaded and the wheel is spun.\n");
- wheel=spinWheel();
- i--;
- System.out.println("Type anything to continue");
- Continue=console.next();
- if(players.size()==1){
- return players;
- }
- }else{
- trigger++;
- System.out.println("Player "+players.get(i)+" survives! He must pass the gun.\n");
- System.out.println("Type anything to continue");
- Continue=console.next();
- }
- }else{
- System.out.println("Player "+players.get(i)+" puts down the gun.\n");
- }
- }
- }
- }
- return players;
- }
- /*Spins the wheel, randomizing the chances of a player getting shot*/
- public static int spinWheel(){
- Random rand = new Random();
- int bullet=rand.nextInt(6)+1;
- return bullet;
- }
- /*Prints the winner when the arraylist Players reach .size()==1*/
- public static void Winner(ArrayList winner){
- System.out.println("The winnner is: Player "+winner);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement