Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.22 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp2
  4. {
  5. class Program
  6. {
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. static void sirka2(int pozice)//vypis jedne sirky
  17. {
  18.  
  19. Console.SetCursorPosition(pozice, 0);//nulty sloupce
  20. Console.WriteLine("*");
  21. Console.SetCursorPosition(pozice, 1);//nulty sloupce
  22. Console.WriteLine("|");
  23. Console.SetCursorPosition(pozice, 2);//nulty sloupce
  24. Console.WriteLine("|");
  25. Console.SetCursorPosition(pozice, 3);//nulty sloupce
  26. Console.WriteLine("|");
  27.  
  28.  
  29.  
  30. }
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. static void Main(string[] args)
  39.  
  40. {
  41. int pozice = 0;
  42.  
  43. int sirky = 13;
  44. while (true) //dělá furt
  45. {
  46. Console.WriteLine("Jsi na tahu");
  47. sirky = hrac(sirky3);
  48. if (sirky3 == 0)
  49. {
  50. Console.WriteLine("prohrál jsi");
  51. break;
  52. }
  53. Console.WriteLine("Na tahu je protihráč");
  54. sirky3 = AI(sirky3);
  55. if (pocetSirek == 0)
  56. {
  57. Console.WriteLine("vyhrál jsi");
  58. break;
  59. }
  60. Console.ReadKey();
  61. }
  62. static void sirky(int sirky3);
  63. {
  64. Console.Clear();
  65. for (int i = 0; i < sirky3; i++)
  66. {
  67. Console.ForegroundColor = ConsoleColor.Red;
  68. Console.Write("O\t");
  69. }
  70. Console.WriteLine("");
  71. for (int i = 0; i < sirky3; i++)
  72. {
  73. Console.ForegroundColor = ConsoleColor.DarkYellow;
  74. Console.Write("|\t");
  75. }
  76. Console.ForegroundColor = ConsoleColor.White;
  77. Console.WriteLine("");
  78. }
  79. static int AI(int sirky3)
  80. {
  81. sirka2(pozice);
  82. if (sirky3 > 8)
  83. {
  84. {
  85. random(out odectiTo);
  86. return sirky3 - odectiTo;
  87. }
  88. else if (sirky3 > 5 & sirky3 < 9)
  89. {
  90. odectiTo = sirky3 - 5;
  91. return sirky3 - odectiTo;
  92. }
  93. else
  94. {
  95. switch (sirky3)
  96. {
  97. case 5:
  98. random(out odectiTo);
  99. return sirky3 - odectiTo;
  100. break;
  101. case 4:
  102. return sirky3 - 3;
  103. break;
  104. case 3:
  105. return sirky3 - 2;
  106. break;
  107. case 2:
  108. return sirky3 - 1;
  109. break;
  110. default:
  111. return sirky3 - 1;
  112. break;
  113. }
  114. }
  115. }
  116. static int hrac(int sirky3)
  117. {
  118. while (true)
  119. {
  120. short odeberTo;
  121. sirky(sirky3);
  122. Console.WriteLine("zbývající sirky: {0}", sirky3);
  123. Console.Write("odeber 1-3 sirky: ");
  124. string s = Console.ReadLine();
  125. if ((Int16.TryParse(s, out odeberTo)) & odeberTo > 0 & odeberTo < 4 & odeberTo <= sirky3)
  126. {
  127. sirky(sirky3 - odeberTo);
  128. Console.WriteLine("zbývající sirky: {0}", sirky3 - odeberTo);
  129. return sirky3 - odeberTo;
  130. break;
  131. }
  132. else
  133. {
  134. Console.WriteLine("Neplatný počet sirek! Nezadal jsi 1-3 sirky nebo jsi odebral víc sirek, nez je k dispozici.");
  135. }
  136. }
  137. }
  138. static void random(out int rnd)
  139. {
  140. int a = 1;
  141. int b = 3;
  142. Random rn = new Random();
  143. rnd = rn.Next(a, b);
  144. }
  145. }
  146. }
  147.  
  148. }
  149.  
  150. Console.WriteLine("Zadej číslo");
  151. string s = Console.ReadLine();
  152. sirky = int.Parse(s);
  153. Console.WriteLine("Zadej číslo");
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160. while (!int.TryParse(Console.ReadLine(), out x))
  161. sirky3 = sirky - x;
  162.  
  163. if (sirky3 == 0)
  164. Console.WriteLine("Konec hry");
  165.  
  166.  
  167.  
  168.  
  169.  
  170. }
  171.  
  172.  
  173. }
  174. }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement