SLiGerr

Код игры 2

Oct 7th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.97 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Game
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int[,] Field = new int[25, 25];
  10. Random random = new Random();
  11.  
  12. for (int i = 0; i < 25; i++)
  13. {
  14. for (int j = 0; j < 25; j++)
  15. {
  16. Field[i, j] = 0;
  17. }
  18. }
  19. string player1Str = "OOO";
  20. string player2Str = "XXX";
  21. string fieldStr = "###";
  22.  
  23. FieldOut(Field, player1Str, player2Str, fieldStr);
  24.  
  25. int round = 2;
  26. do
  27. {
  28. if (round == 1)
  29. round++;
  30. else round = 1;
  31.  
  32. int x = random.Next(1, 7), y = random.Next(1, 7);
  33. InterfaceMove(round, x, y, Field, player1Str, player2Str, fieldStr);
  34. Console.ReadKey();
  35.  
  36. } while (true);
  37. }
  38.  
  39. static void WhoWin(int[,] FieldTemp)
  40. {
  41. int player1=0, player2=0, empt = 0;
  42. for (int i = 0; i < 25; i++)
  43. {
  44. for (int j = 0; j < 25; j++)
  45. {
  46. if(FieldTemp[i, j] == 1)
  47. player1++;
  48. else if(FieldTemp[i, j] == 2)
  49. player2++;
  50. else empt++;
  51. }
  52. }
  53. if(player1 > player2)
  54. Console.WriteLine("Player 1 Win!! with "+(player1-player2)+" cells ahead");
  55. else if(player1 < player2)
  56. Console.WriteLine("Player 2 Win!! with "+(player2-player1)+" cells ahead");
  57. else
  58. Console.WriteLine("Draw! blue and red got " +player1+" cells marked, and field has " +empt+" empty cells");
  59.  
  60. Console.ReadKey();
  61. Environment.Exit(0);
  62. }
  63.  
  64. static void InterfaceMove(int move, int x, int y, int[,] FieldTemp, string player1, string player2, string emptFieldSymb)
  65. {
  66. int x1, y1;
  67.  
  68. bool rot= false;
  69. do
  70. {
  71. Console.Clear();
  72. FieldOut(FieldTemp, player1, player2, emptFieldSymb);
  73.  
  74. Console.WriteLine("Write 'e' to Exit or nothing to continue;");
  75. string exit = Console.ReadLine();
  76. if(exit == "e")
  77. WhoWin(FieldTemp);
  78.  
  79. if(move == 1)
  80. Console.WriteLine("Red Turn!");
  81. else Console.WriteLine("Blue Turn!");
  82. Console.WriteLine("Dice drop: " + x + ", and " + y);
  83. Console.WriteLine("Rotate? (n/y):");
  84.  
  85. string ch = Console.ReadLine();
  86. if (ch == "y")
  87. {
  88. int temp = x;
  89. x = y;
  90. y = temp;
  91. rot = true;
  92. }
  93. else rot = false;
  94. }
  95. while(rot == true);
  96.  
  97. Console.Write("Place at: \nx(vertical): ");
  98. x1 = Convert.ToInt32(Console.ReadLine());
  99. Console.Write("y(horizontal): ");
  100. y1 = Convert.ToInt32(Console.ReadLine());
  101.  
  102. Console.WriteLine();
  103. if (move == 1)
  104. for (int i = x1; i < x1 + x; i++)
  105. {
  106. for (int j = y1; j < y1 + y; j++)
  107. {
  108. FieldTemp[i, j] = move;
  109. }
  110. }
  111. else if (move == 2)
  112. for (int i = x1; i < x1 + x; i++)
  113. {
  114. for (int j = y1; j < y1 + y; j++)
  115. {
  116. FieldTemp[24 - i, 24 - j] = move;
  117. }
  118. }
  119. }
  120.  
  121. static void FieldOut(int[,] FieldTemp, string player1, string player2, string emptFieldSymb)
  122. {
  123. for(int i = 0; i < 27; i++)
  124. {
  125. if (i == 0 || i == 26)
  126. {
  127. Console.Write(" ");
  128. for (int j = 0; j < 25; j++)
  129. {
  130. if(i == 0)
  131. {
  132. if(j<10)
  133. Console.Write(j+" ");
  134. else Console.Write(j + " ");
  135. }
  136. else
  137. {
  138. if(25-j<11)
  139. Console.Write(" "+(24-j));
  140. else Console.Write(" "+ (24-j));
  141. }
  142. }
  143. Console.Write(" ");
  144. }
  145. else
  146. {
  147. if (i < 10)
  148. Console.Write(" " + (i - 1)+" ");
  149. else Console.Write(i+" ");
  150. for (int j = 0; j < 25; j++)
  151. {
  152. if (FieldTemp[i - 1, j] == 0)
  153. {
  154. Console.ForegroundColor = ConsoleColor.White;
  155. Console.Write(emptFieldSymb);
  156. Console.ResetColor();
  157. }
  158. else if (FieldTemp[i - 1, j] == 1)
  159. {
  160. Console.ForegroundColor = ConsoleColor.Red;
  161. Console.Write(player1);
  162. Console.ResetColor();
  163. }
  164. else if (FieldTemp[i - 1, j] == 2)
  165. {
  166. Console.ForegroundColor = ConsoleColor.Blue;
  167. Console.Write(player2);
  168. Console.ResetColor();
  169. }
  170. }
  171. Console.Write(" "+ (25 - i));
  172. }
  173. Console.WriteLine();
  174. }
  175. }
  176. }
  177. }
Add Comment
Please, Sign In to add comment