Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. package MasterMind;
  2.  
  3. import java.util.*;
  4.  
  5. public class MainMastermind
  6. {
  7. public static void main(String[] args)
  8. {
  9. Scanner in = new Scanner(System.in);
  10. Random rnd = new Random();
  11.  
  12. String[] kolory = new String[] {"niebieski","zielony","czerwony","zolty","fioletowy","pomaranczowy"};
  13. int czarne, biale;
  14. String input;
  15. boolean ok=true;
  16. int[] wylosowane = new int[4];
  17. int[] wybrane = new int[] {-1,-1,-1,-1};
  18.  
  19. for (int i=0; i<4; i++)
  20. {
  21. wylosowane[i]=(Math.abs(rnd.nextInt())%6);
  22. //dwie poniższe linijki do usunięcia po zakodzeniu :)
  23. System.out.println(wylosowane[i]);
  24. System.out.println(kolory[wylosowane[i]]);
  25. }
  26.  
  27. System.out.println("Podaj cztery kolory z następujących: niebieski, zielony, czerwony, zolty, fioletowy, pomaranczowy.");
  28. do{
  29. czarne=0;
  30. biale=0;
  31. for (int i=0; i<4; i++)
  32. {
  33. do{
  34. ok=true;
  35. input = in.nextLine().toLowerCase();
  36. for(int j=0; j<6; j++)
  37. {
  38. if(input.equals(kolory[j]))
  39. {
  40. wybrane[i]=j;
  41. }
  42.  
  43. }
  44. if(wybrane[i]==-1)
  45. {
  46. ok=false;
  47. System.out.println("Nie ma takiego koloru, spróbuj jeszcze raz!");
  48. }
  49. }while(!ok);
  50. }
  51. /*for(int i=0; i<4; i++)
  52. {
  53. System.out.println(wylosowane[i]+ " " + wybrane[i]);
  54. }*/
  55. for(int i=0; i<4; i++)
  56. {
  57. if(wybrane[i]==wylosowane[i])
  58. {
  59. czarne++;
  60. }
  61. else
  62. {
  63. for(int j=0; j<4; j++)
  64. {
  65. if(wybrane[i]==wylosowane[j])
  66. {
  67. biale++;
  68. break;
  69. }
  70. }
  71. }
  72.  
  73. }
  74. System.out.println(czarne + " czarnych i " + biale + " bialych.");
  75. }while(czarne!=4);
  76. in.close();
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement