Advertisement
Guest User

kolkooo

a guest
Oct 17th, 2019
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. public static int rozmiar = 3;
  12. public static int[,] tab = new int[rozmiar, rozmiar];
  13. public static void CheckWin(int deployment)
  14. {
  15. int suma = 0;
  16. for (int i = 0; i < rozmiar; i++)
  17. {
  18. suma = 0;
  19. for (int j = 0; j < rozmiar; j++)
  20. suma += tab[i, j];
  21.  
  22. }
  23. if (suma == 3 * deployment)
  24. {
  25. Console.WriteLine("Wygrana!"); // 1 opcja
  26.  
  27. }
  28.  
  29. for (int j = 0; j < rozmiar; j++)
  30. {
  31. suma = 0;
  32. for (int i = 0; i < rozmiar; i++)
  33. suma += tab[i, j];
  34. }
  35. if (suma == 3 * deployment)
  36. {
  37. Console.WriteLine("Wygrana!"); // 2 opcja
  38.  
  39. }
  40. suma = 0;
  41. suma = tab[0, 0] + tab[1, 1] + tab[2, 2];
  42. if (suma == 3 * deployment)
  43. {
  44. Console.WriteLine("Wygrana!"); //3 opcja
  45. }
  46. suma = 0;
  47. suma = tab[2, 0] + tab[1, 1] + tab[0, 2];
  48. if (suma == 3 * deployment)
  49. {
  50. Console.WriteLine("Wygrana!"); //4 opcja
  51. }
  52. }
  53.  
  54. static void DrawMatrix()
  55. {
  56. for (int i = 0; i < 3; i++)
  57. {
  58. tab[i, i] = 0;
  59.  
  60. for (int j = 0; j < 3; j++)
  61. {
  62. tab[j, j] = 0;
  63. }
  64. }
  65. for (int i = 0; i < rozmiar; i++)
  66. {
  67. for (int j = 0; j < rozmiar; j++)
  68. {
  69. Console.Write(tab[i, j] + " ");
  70. }
  71. Console.WriteLine();
  72. }
  73.  
  74. }
  75. static void ShowMatrix()
  76. {
  77. Console.Clear();
  78. for (int i = 0; i < rozmiar; i++)
  79. {
  80. for (int j = 0; j < rozmiar; j++)
  81. {
  82. Console.Write(tab[i, j] + " ");
  83. }
  84.  
  85. Console.WriteLine();
  86. }
  87. }
  88. static void Main(string[] args)
  89. {
  90. while (true)
  91. {
  92. DrawMatrix();
  93.  
  94. for (int x = 9; x > 0; x--)
  95. {
  96. if (x % 2 == 0)
  97. {
  98. try
  99. {
  100. Console.WriteLine("Gracz 1 : znak ,,1'' ");
  101. Console.WriteLine("Wpisz Wiersz ");
  102. int wiersz = int.Parse(Console.ReadLine());
  103. Console.WriteLine("Wpisz kolumne: ");
  104. int kolumna = int.Parse(Console.ReadLine());
  105.  
  106. if (wiersz < 0 || wiersz > 2 && kolumna < 0 || kolumna > 2)
  107. {
  108. throw new Exception();
  109. }
  110. for (int i = 0; i < rozmiar; i++)
  111. {
  112. for (int j = 0; j < rozmiar; j++)
  113. {
  114. tab[wiersz, kolumna] = 1;
  115. }
  116. }
  117. ShowMatrix();
  118. CheckWin(1);
  119. }
  120. catch (Exception e)
  121. {
  122. Console.WriteLine(e.Message);
  123. }
  124.  
  125. }
  126.  
  127. else
  128. {
  129. Console.WriteLine("Gracz 2: znak ,, -1 ''");
  130. Console.WriteLine("Wpisz Wiersz ");
  131. try
  132. {
  133. int wiersz = int.Parse(Console.ReadLine());
  134. Console.WriteLine("Wpisz kolumne: ");
  135. int kolumna = int.Parse(Console.ReadLine());
  136. if (wiersz < 0 || wiersz > 2)
  137. {
  138. throw new Exception();
  139.  
  140. }
  141. if (kolumna < 0 || kolumna > 2)
  142. {
  143. throw new Exception();
  144. }
  145.  
  146.  
  147. for (int i = 0; i < rozmiar; i++)
  148. {
  149. for (int j = 0; j < rozmiar; j++)
  150. {
  151. tab[wiersz, kolumna] = -1;
  152. }
  153. }
  154. ShowMatrix();
  155. CheckWin(-1);
  156. }
  157.  
  158. catch (Exception e)
  159. {
  160. Console.WriteLine(e.Message);
  161.  
  162. }
  163. }
  164.  
  165. Console.ReadKey();
  166. }
  167. }
  168.  
  169. }
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement