Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 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 Laba1CSharp
  8. {
  9. class Program
  10. {
  11. static void Main()
  12. {
  13. Console.OutputEncoding = Encoding.Unicode;
  14. int inputFigure;
  15. int vert, horizon; //Координаты фигуры
  16. int xCoord, yCoord;
  17. char[,] arrZero = new char[8, 8];
  18.  
  19. Console.WriteLine("Добро пожаловать\nВас привутствует программа, располагающая шахматные фигуры на доске в произвольном месте\nНа данный момент разработаны комбинации лишь для 2 фигур: Ферзя(0) и Коня(1)\nПожалуйста, сделайте Ваш выбор : ");
  20. inputFigure = Convert.ToInt32(Console.ReadLine());
  21.  
  22. if (inputFigure == 0) //Ferz
  23. {
  24. Console.WriteLine("Хороший выбор! Вы выбрали самую комбинаторную и опасную фигуру - Ферзь.");
  25. }
  26. else
  27. {
  28. Console.WriteLine("Horse");
  29. }
  30.  
  31. Console.WriteLine("Пожалуйста, введите координаты фигуры на шахмотной доске: ");
  32. vert = Convert.ToInt32(Console.ReadLine());
  33. horizon = Convert.ToInt32(Console.ReadLine());
  34. xCoord = vert - 1;
  35. yCoord = horizon - 1;
  36.  
  37. ArrConsist(xCoord, yCoord, arrZero, inputFigure);
  38. Console.ReadLine();
  39. }
  40.  
  41. public static void ArrConsist(int y_Coord, int x_Coord, char[,] arr_Zero, int inputFigure)
  42. {
  43. for (int i = 0; i < 8; i++)
  44. {
  45. for (int j = 0; j < 8; j++)
  46. {
  47. arr_Zero[i, j] = ' ';
  48. }
  49. }
  50. if (inputFigure == 0)
  51. {
  52. Ferz(y_Coord, x_Coord, arr_Zero);
  53. }
  54. else Horse(y_Coord, x_Coord, arr_Zero);
  55.  
  56. for (int i = 0; i < 8; i++)
  57. {
  58. for (int j = 0; j < 8; j++)
  59. {
  60. Console.BackgroundColor = ((i + j) % 2 == 0) ? ConsoleColor.White : ConsoleColor.DarkGray;
  61. Console.ForegroundColor = ConsoleColor.Blue;
  62. Console.Write(arr_Zero[i, j] + " ");
  63. }
  64. Console.WriteLine();
  65. }
  66.  
  67. }
  68.  
  69. public static void Horse(int y_Coord, int x_Coord, char[,] arr_Zero)
  70. {
  71.  
  72. for (int x = -2; x < 3; x++)
  73. {
  74. if (x_Coord + x >= 0 && x_Coord + x < 8)
  75. {
  76. if (Math.Abs(x) == 2)
  77. {
  78. if (y_Coord + 1 < 8) arr_Zero[y_Coord + 1, x + x_Coord] = '*';
  79. if (y_Coord - 1 >= 0) arr_Zero[y_Coord - 1, x + x_Coord] = '*';
  80. }
  81. else if (Math.Abs(x) == 1)
  82. {
  83. if (y_Coord + 2 < 8) arr_Zero[y_Coord + 2, x + x_Coord] = '*';
  84. if (y_Coord - 2 >= 0) arr_Zero[y_Coord - 2, x + x_Coord] = '*';
  85. }
  86. }
  87. }
  88. arr_Zero[y_Coord,x_Coord] = 'H';
  89. }
  90. public static void Ferz(int y_Coord, int x_Coord, char[,] arr_Zero)
  91. {
  92.  
  93. for (int X_bias = -1; X_bias < 2 ; X_bias++)
  94. {
  95. for (int Y_bias = -1; Y_bias < 2; Y_bias++)
  96. {
  97. if (X_bias == 0 && Y_bias == 0) continue;
  98. for (int x = x_Coord, y = y_Coord; x < 8 && y >= 0 && y<8 && x>= 0; x+=X_bias, y+=Y_bias)
  99. arr_Zero[y, x] = '*';
  100. }
  101. }
  102. arr_Zero[y_Coord,x_Coord] = 'F';
  103. }
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement