Advertisement
Nikitaantiov

Змейка

Jan 22nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 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 ConsoleApp1
  8. {
  9. class Program
  10. {
  11. public class Point
  12. {
  13. public int x, y;
  14. public Point()
  15. {
  16. y = size / 2;
  17. x = size;
  18. }
  19. public Point(int x, int y)
  20. {
  21. this.x = x;
  22. this.y = y;
  23. }
  24. }
  25. static void Walls(int size)
  26. {
  27.  
  28. for (int i = 0; i <= size + 1; i++)
  29. {
  30. Console.SetCursorPosition(i * 2, 0);// Вг
  31. Console.Write("X");
  32. Console.SetCursorPosition(0, i);// ЛВ
  33. Console.Write("X");
  34. Console.SetCursorPosition(i * 2, size + 1); //Нг
  35. Console.Write("X");
  36. Console.SetCursorPosition((size + 1) * 2, i); //Пв
  37. Console.Write("X ");
  38. }
  39.  
  40.  
  41. }
  42. static void GameOver()
  43. {
  44. Console.Clear();
  45. Console.ForegroundColor = ConsoleColor.Red;
  46. Console.WriteLine("GAME OVER");
  47. }
  48. static int size = 50;
  49. static void Main(string[] args)
  50. {
  51. Console.CursorVisible = false;
  52. Walls(size);
  53. Random R = new Random();
  54. Point player = new Point(R.Next(1, size + 1) * 2 - 1, R.Next(1, size + 1));
  55. Console.SetCursorPosition(player.x, player.y);
  56. Console.Write("#");
  57. ConsoleKeyInfo button;
  58. button = Console.ReadKey(true);
  59. switch (button.Key)
  60. {
  61. case ConsoleKey.W:
  62. if (player.y == 1)
  63. {
  64. GameOver();
  65. }
  66. else
  67. {
  68. player.y--;
  69. }
  70. break;
  71. case ConsoleKey.A:
  72. if (player.x == 1)
  73. {
  74. GameOver();
  75. }
  76. else
  77. {
  78. player.y-=2;
  79. }
  80. break;
  81. case ConsoleKey.S:
  82. if (player.y == size)
  83. {
  84. GameOver();
  85. }
  86. else
  87. {
  88. player.y ++;
  89. }
  90. break;
  91. case ConsoleKey.D:
  92. if (player.x == size * 2 - 1)
  93. {
  94. GameOver();
  95. }
  96. else
  97. {
  98. player.y +=2;
  99. }
  100. break;
  101. }
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement