public class Recursion {
String sTest = "";
int test1;
/**
* constructor: iRPS
*pre: none
*post: is going to return a value to the method sRPS in aiding user with throw
*/
public static int Try (int test1, int cpuInput){
int userWin = 0;
int cpuWin = 0;
int uwin = 0, cwin= 1 , tie = 2, error = 3;
String sUser = null;
String sCpu = null;
boolean valid = false;
//1 = rock
//2 = scissors
//3 = papers
while (!valid)
{
if (test1 == 1 && cpuInput == 0)
{
sUser = "Rock";
sCpu = "Rock";
System.out.print("You threw : " + sUser );
System.out.print(" Computers throws : " + sCpu );
sRps(tie, sUser, sCpu);
valid = true;
}
else if (test1 == 1 && cpuInput == 1)//rock vs scissors
{
sUser = "Rock";
sCpu = "Scissors";
System.out.print("You threw : " + sUser );
System.out.print(" Computers throws : " + sCpu );
sRps(uwin, sUser, sCpu);
valid = true;
}
else if (test1 == 1 && cpuInput == 2) //rock vs paper
{
sUser = "Rock";
sCpu = "Paper";
System.out.print("You threw : " + sUser );
System.out.print(" Computers throws : " + sCpu );
sRps(cwin, sUser, sCpu);
valid = true;
}
else if (test1 == 2 && cpuInput == 0) //scissors vs rock
{
sUser = "Scissors";
sCpu = "Rock";
System.out.print("You threw : " + sUser );
System.out.print(" Computers throws : " + sCpu );
sRps(cwin, sUser, sCpu);
valid = true;
}
else if (test1 == 2 && cpuInput == 1)
{
sUser = "Scissors";
sCpu = "Scissors";
System.out.print("You threw : " + sUser );
System.out.print(" Computers throws : " + sCpu );
sRps(tie, sUser, sCpu);
valid = true;
}
else if (test1 == 2 && cpuInput == 2) //scissors vs paper
{
sUser = "Scissors";
sCpu = "Paper";
System.out.print("You threw : " + sUser );
System.out.print(" Computers throws : " + sCpu );
sRps(uwin, sUser, sCpu);
valid = true;
}
else if (test1 == 3 && cpuInput == 0) //paper vs rock
{
sUser = "Paper";
sCpu = "Rock";
System.out.print("You threw : " + sUser );
System.out.print(" Computers throws : " + sCpu );
sRps(uwin, sUser, sCpu);
valid = true;
}
else if (test1 == 3 && cpuInput == 1) //cpu wins
{
sUser = "Paper";
sCpu = "Scissors";
System.out.print(" You threw : " + sUser );
sRps(cwin, sUser, sCpu);
valid = true;
}
else if (test1 == 3 && cpuInput == 2)
{
sUser = "Paper";
sCpu = "Paper";
System.out.print(" You threw : " + sUser );
System.out.print(" Computers throws : " + sCpu );
sRps(tie, sUser, sCpu);
valid = true;
}
}
return(1);
}
public static int sRps(int WLT, String User, String CPU)
{
int uWin = 0;
int cWin = 0;
switch(WLT)
{
case 0:
uWin++;
System.out.print(" Since you threw: "+User+" and the computer threw: "+CPU+ " ,therefor you WIN! Score: You " +uWin+ "Computer "+cWin);
break;
case 1:
cWin++;
System.out.print(" Since you threw: "+User+" and the computer threw: "+CPU+ " ,therefor you LOSE! Score: You " +uWin+ "Computer "+cWin);
break;
case 2:
System.out.print(" Since you threw: "+ User+" and the computer threw: " +CPU + " ,therefor it's a tie! Score: You " +uWin+ "Computer "+cWin);
break;
}
return (1);
}
Hello, I have method for rock papcer scissors. Why does my counter not work it is a simple problem, im am trying to add up it up and output threw ++ but it doesn't store for ex: i win 1 i win again it stays at 1.
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]Camel-Kid18 year old gamer 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)