Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Player
- {
- private int red=0;
- private int green=0;
- private int blue=0;
- public Player()
- {
- int num;
- for(int i=0 ; i<5 ; i++)
- {
- num=1+(int)(Math.random()*3);
- if(num==1)
- red++;
- if(num==2)
- green++;
- if(num==3)
- blue++;
- }
- }
- public void addCard (String color)
- {
- if(color.equals("red"))
- red++;
- if(color.equals("green"))
- green++;
- if(color.equals("blue"))
- blue++;
- }
- public String throwCard ()
- {
- String color="error";
- int tempRed=this.red;
- int tempBlue=this.blue;
- int tempGreen=this.green;
- if(tempRed==0)
- tempRed=6;
- if(tempBlue==0)
- tempBlue=6;
- if(tempGreen==0)
- tempGreen=6;
- if((tempRed<=tempGreen)&&(tempRed<=tempBlue))
- {
- red--;
- color="red";
- return color;
- }
- if((tempGreen<=tempRed)&&(tempGreen<=tempBlue))
- {
- green--;
- color="green";
- return color;
- }
- if((tempBlue<=tempRed)&&(tempBlue<=tempGreen))
- {
- blue--;
- color="blue";
- return color;
- }
- return color;
- }
- public String toString()
- {
- String hand;
- hand=("Your hand is: "+'\n'+"red: "+red+'\n'+"green: "+green+'\n'+"blue: "+blue);
- return hand;
- }
- public boolean win ()
- {
- boolean win=false;
- if (red==5)
- win=true;
- if(blue==5)
- win=true;
- if(green==5)
- win=true;
- return win;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement