Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication25
- {
- class Program
- {
- class snake
- {
- public List<Point> points;
- public int lenght;
- Point head;
- public void move(Point point)
- {
- points.Insert(0, point);
- points.RemoveAt(points.Count - 1);
- Point haed;
- }
- public void Rost(Point point)
- {
- points.Insert(0, point);
- Point haed;
- }
- public snake(Point point)
- {
- points.Add(point);
- }
- }
- class Point
- {
- public int x;
- public int y;
- public Point()
- {
- x = 11;
- y = 11;
- }
- public Point(int x, int y)
- {
- this.x = x;
- this.y = y;
- }
- public static bool operator == (Point p1,Point p2)
- {
- return (p1.x == p2.x) && (p1.y == p2.y);
- }
- public static bool operator !=(Point p1, Point p2)
- {
- return (p1.x != p2.x) || (p1.y != p2.y);
- }
- }
- static void pole(int size)
- {
- for (int i = 0; i < size + 2; i++)
- {
- Console.SetCursorPosition(2 * i, 0); //вг
- Console.Write("#");
- Console.SetCursorPosition((size + 1) * 2, i);//пв
- Console.Write("#");
- Console.SetCursorPosition(2 * i, size + 1);//нг
- Console.Write("#");
- Console.SetCursorPosition(0, i);//лв
- Console.Write("#");
- }
- }
- static bool CharacterControl(ref Point point, int size, ref bool isEat, Point apple)
- {
- ConsoleKeyInfo button;
- button = Console.ReadKey(true);
- if (button.Key == ConsoleKey.Escape)
- {
- return true;
- }
- Console.SetCursorPosition(point.x, point.y);
- Console.Write(" ");
- switch (button.Key)
- {
- case ConsoleKey.W:
- point.y = (point.y - 1 == 0) ? size : point.y - 1;
- break;
- case ConsoleKey.A:
- point.x = (point.x - 2 < 0) ? size * 2 + 1 : point.x - 2;
- break;
- case ConsoleKey.S:
- point.y = (point.y + 1 == size + 1) ? 1 : point.y + 1;
- break;
- case ConsoleKey.D:
- point.x = (point.x + 2 > size * 2 + 1) ? 1 : point.x + 2;
- break;
- }
- if (point == apple)
- {
- isEat = true;
- }
- Console.SetCursorPosition(point.x, point.y);
- Console.Write("0");
- return false;
- }
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- snake snake = new snake(new Point());
- Point apple= new Point();
- Random r = new Random();
- Point point = new Point();
- Console.SetCursorPosition(point.x, point.y);
- Console.Write("0");
- int size = 20;
- bool isEat = true;
- pole(size);
- bool exit;
- do
- {
- exit = CharacterControl( ref point, size , ref isEat, apple);
- if (isEat)
- {
- do
- {
- apple.x = r.Next(0, size + 1) * 2 + 1;
- apple.y = r.Next(1, size + 1);
- } while (point == apple);
- Console.SetCursorPosition(apple.x, apple.y);
- Console.Write("@");
- isEat = false;
- }
- } while (!exit);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement