PennyGame

/** * * @Charlie Barton (your name) * @version 1 */ import java.util.*; public class PennyGame { ArrayList<Integer> playertwo = new ArrayList<Integer>(); ArrayList<Integer> coinflips = new ArrayList<Integer>(); ArrayList<Integer> playerone = new ArrayList<Integer>(); int playeronescore = 0; int playertwoscore = 0; public PennyGame(){ playerOne(); coinflips(); } public void playerOne(){ int max = 2;//tails int min = 1;//heads for(int i = 0; i < 3; i++){ int randomNum = (int)(Math.random() * ((max - min) + 1)) + min; playerone.add(randomNum); } System.out.println("Player one : " + playerone); if(playerone.get(1) == 1){ playertwo.add(2); }else{ playertwo.add(1); } if(playerone.get(0) == 1){ playertwo.add(1,1); }else{ playertwo.add(1,2); } if(playerone.get(2) == 1){ playertwo.add(2,1); }else{ playertwo.add(2,2); } System.out.println("Player Two : " + playertwo); } public void coinflips(){ int counter = 0; int max = 2;//tails int min = 1;//heads while(playeronescore+ playertwoscore < 20){ int randomNum1 = (int)(Math.random() * ((max - min) + 1)) + min; int randomNum2 = (int)(Math.random() * ((max - min) + 1)) + min; int randomNum3 = (int)(Math.random() * ((max - min) + 1)) + min; coinflips.add(randomNum1); coinflips.add(1,randomNum2); coinflips.add(2,randomNum3); if(coinflips.get(0) == playerone.get(0) && coinflips.get(1) == playerone.get(1) && coinflips.get(2) == playerone.get(2)){ playeronescore++; }else if(coinflips.get(0) == playertwo.get(0) && coinflips.get(1) == playertwo.get(1) && coinflips.get(2) == playertwo.get(2)){ playertwoscore++; } //System.out.println(coinflips); coinflips.clear(); } System.out.println("Player One Wins: " + playeronescore); System.out.println("Player Two wins: " + playertwoscore); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.