Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. public class Player
  2. {
  3. private int red=0;
  4. private int green=0;
  5. private int blue=0;
  6.  
  7. public Player()
  8. {
  9. int num;
  10. for(int i=0 ; i<5 ; i++)
  11. {
  12. num=1+(int)(Math.random()*3);
  13. if(num==1)
  14. red++;
  15. if(num==2)
  16. green++;
  17. if(num==3)
  18. blue++;
  19. }
  20. }
  21. public void addCard (String color)
  22. {
  23. if(color.equals("red"))
  24. red++;
  25. if(color.equals("green"))
  26. green++;
  27. if(color.equals("blue"))
  28. blue++;
  29. }
  30. public String throwCard ()
  31. {
  32. String color="error";
  33. int tempRed=this.red;
  34. int tempBlue=this.blue;
  35. int tempGreen=this.green;
  36. if(tempRed==0)
  37. tempRed=6;
  38. if(tempBlue==0)
  39. tempBlue=6;
  40. if(tempGreen==0)
  41. tempGreen=6;
  42.  
  43. if((tempRed<=tempGreen)&&(tempRed<=tempBlue))
  44. {
  45. red--;
  46. color="red";
  47. return color;
  48. }
  49.  
  50. if((tempGreen<=tempRed)&&(tempGreen<=tempBlue))
  51. {
  52. green--;
  53. color="green";
  54. return color;
  55.  
  56. }
  57.  
  58. if((tempBlue<=tempRed)&&(tempBlue<=tempGreen))
  59. {
  60. blue--;
  61. color="blue";
  62. return color;
  63. }
  64.  
  65.  
  66.  
  67. return color;
  68.  
  69. }
  70. public String toString()
  71. {
  72. String hand;
  73. hand=("Your hand is: "+'\n'+"red: "+red+'\n'+"green: "+green+'\n'+"blue: "+blue);
  74. return hand;
  75. }
  76. public boolean win ()
  77. {
  78. boolean win=false;
  79. if (red==5)
  80. win=true;
  81. if(blue==5)
  82. win=true;
  83. if(green==5)
  84. win=true;
  85. return win;
  86. }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement