Hey,
I'm nearly done.Thanks for all your help...
Now I have only 2 small problems. I need my counters to count separately for each of the different winnings
(tie++,computerWins++ and playerWins++) .
The other thing I need help is for the game application to stay open for the player to play and closes only when they enter an invalid statement--so that's loop too right? I have done the most part, it's just a few lines I guess I am missing that I can't seem to figure out. I have pasted the appropriate class and the driver. Please help...I am nearly done! Are there things I need to change?
My driver:
My class:Code:import java.io.*; import rps.*; public class RockPaperScissorsDr { public static void main(String []args) throws IOException { Player player; Decider decider; String playerEntry; int playerWins=0,computerWins=0,ties=0; System.out.println("An invalid entry will close the game!"); System.out.println("Please choose from the menu, the letter you would like to play"); BufferedReader in; in=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter r for rock,p for paper,s for scissors:"); playerEntry=in.readLine().toLowerCase(); System.out.println("Player played is "+playerEntry); while(playerEntry!=null){ int computerChoice=(int)(Math.random()*2+1); System.out.println("The computer played "+computerChoice); if(!(!playerEntry.equals("r"))&&(!playerEntry.equals("s"))&&(!playerEntry.equals("p"))){ System.out.println("The winner is: " +Decider.decideWinner(computerChoice,playerEntry));} else { System.out.println("Player's choice is invalid.The game will close!");} //System.out.println("To play again,please enter letter from menu: "); //playerEntry=in.readLine().toLowerCase(); System.out.println("The computer won "+computerWins); System.out.println("The player won "+playerWins); System.out.println("There were "+ties+" ties. Thank you for playing"); } }}
[ArchAngel added CODE tags]Code:package rps; public class Decider { public static String decideWinner(int computerChoice,String playerEntry) { String winner; int rock=1; int paper=2; int scissors=3; if(computerChoice==1&&playerEntry.equals("r")&&computerChoice==2&&playerEntry.equals("p")&& computerChoice==3&&playerEntry.equals("s")){ winner = "draw"; } else if(computerChoice==1&& playerEntry.equals("r"))//rock breaks scissors { winner="computer"; } else if(computerChoice==3&&playerEntry.equals("p"))//scissors cut paper { winner ="computer"; } else if(computerChoice==2&&playerEntry.equals("r"))//paper covers rock { winner = "computer"; } else{winner="You"; } return winner; } public static String update(String winner,int computerWins,int playerWins,int tie){ if (winner.equals("computer")) { computerWins++; } else if (winner.equals("you")) { playerWins++; } else{tie++;} return "draw"; } }


Reply With Quote


Bookmarks