Example #1
0
 private void Start()
 {
     _state = new State();
     _idle  = new idle();
     _eat   = new eat();
     _run   = new run();
 }
Example #2
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(80, 25);
            Console.SetBufferSize(80, 25);
            Snake snake = new Snake();
            eat   eat   = new eat();

            Direction direction = Direction.Right;
            Walls     new_walls = new Walls(25, 80);

            new_walls.Draw();

            Foodcreator fc = new Foodcreator(25, 80, '$');

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo Key = Console.ReadKey();
                    if (Key.Key == ConsoleKey.LeftArrow)
                    {
                        direction = Direction.Left;
                    }
                    if (Key.Key == ConsoleKey.UpArrow)
                    {
                        direction = Direction.Up;
                    }
                    if (Key.Key == ConsoleKey.DownArrow)
                    {
                        direction = Direction.Down;
                    }
                    if (Key.Key == ConsoleKey.RightArrow)
                    {
                        direction = Direction.Right;
                    }
                }
                try
                {
                    snake.Move(direction, eat, 80, 25);
                    if (snake.Zmeya[0].x == fc.Korm.x && snake.Zmeya[0].y == fc.Korm.y)
                    {
                        eat = eat.yes;
                        fc  = new Foodcreator(25, 80, '$');
                    }
                    else
                    {
                        eat = eat.no;
                    }
                }
                catch (System.ArgumentOutOfRangeException)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.SetCursorPosition(25, 8);
                    Console.WriteLine("============================");
                    Console.SetCursorPosition(26, 9);
                    Console.WriteLine("И Г Р А    О К О Н Ч Е Н А");
                    Console.SetCursorPosition(30, 10);
                    Console.WriteLine("Автор: DANISSIMO");
                    Console.SetCursorPosition(29, 11);
                    Console.WriteLine("KAK ZGE YA EBASHU!!!");
                    Console.SetCursorPosition(25, 12);
                    Console.WriteLine("============================");
                    while (true)
                    {
                        if (Console.KeyAvailable)
                        {
                            ConsoleKeyInfo Key = Console.ReadKey();
                            if (Key.Key == ConsoleKey.LeftArrow)
                            {
                                direction = Direction.Left;
                            }
                            if (Key.Key == ConsoleKey.UpArrow)
                            {
                                direction = Direction.Up;
                            }
                            if (Key.Key == ConsoleKey.DownArrow)
                            {
                                direction = Direction.Down;
                            }
                            if (Key.Key == ConsoleKey.RightArrow)
                            {
                                direction = Direction.Right;
                            }
                        }
                        try
                        {
                            snake.Move_(direction);
                        }
                        catch (System.ArgumentOutOfRangeException)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.SetCursorPosition(25, 8);
                            Console.WriteLine("============================");
                            Console.SetCursorPosition(26, 9);
                            Console.WriteLine("И Г Р А    О К О Н Ч Е Н А");
                            Console.SetCursorPosition(30, 10);
                            Console.WriteLine("Автор: DANISSIMO");
                            Console.SetCursorPosition(29, 11);
                            Console.WriteLine("KAK ZGE YA EBASHU!!!");
                            Console.SetCursorPosition(25, 12);
                            Console.WriteLine("============================");
                        }
                        Thread.Sleep(200);
                    }
                }

                Thread.Sleep(100);
            }
        }
Example #3
0
        public void Move(Direction temp_direction, eat eat, int shirina, int visota)
        {
            Point temp_Last = new Point(Zmeya[Zmeya.Count - 1].x, Zmeya[Zmeya.Count - 1].y, '@');

            this.direction = temp_direction;
            for (int i = Zmeya.Count - 1; i > 0; i--)
            {
                if (((Zmeya[i].x == Zmeya[0].x) && (Zmeya[i].y == Zmeya[0].y)) || (Zmeya[0].x <= 1 || Zmeya[0].x >= shirina - 1 || Zmeya[0].y <= 1 || Zmeya[0].y >= visota - 1))
                {
                    Point p = new Point(100, 100, '!');
                    p.Draw();
                }
            }
            try
            {
                switch (direction)
                {
                case Direction.Right:

                    Zmeya[Zmeya.Count - 1].Clear();

                    for (int i = Zmeya.Count - 1; i > 0; i--)
                    {
                        Zmeya[i].Priravnyat(Zmeya[i - 1]);
                        Zmeya[i].Draw();
                    }

                    Zmeya[0].x = Zmeya[0].x + 1;
                    Zmeya[0].Draw();

                    break;

                case Direction.Left:
                    Zmeya[Zmeya.Count - 1].Clear();

                    for (int i = Zmeya.Count - 1; i > 0; i--)
                    {
                        Zmeya[i].Priravnyat(Zmeya[i - 1]);
                        Zmeya[i].Draw();
                    }

                    Zmeya[0].x = Zmeya[0].x - 1;
                    Zmeya[0].Draw();

                    break;

                case Direction.Up:
                    Zmeya[Zmeya.Count - 1].Clear();

                    for (int i = Zmeya.Count - 1; i > 0; i--)
                    {
                        Zmeya[i].Priravnyat(Zmeya[i - 1]);
                        Zmeya[i].Draw();
                    }

                    Zmeya[0].y = Zmeya[0].y - 1;
                    Zmeya[0].Draw();

                    break;

                case Direction.Down:
                    Zmeya[Zmeya.Count - 1].Clear();

                    for (int i = Zmeya.Count - 1; i > 0; i--)
                    {
                        Zmeya[i].Priravnyat(Zmeya[i - 1]);
                        Zmeya[i].Draw();
                    }

                    Zmeya[0].y = Zmeya[0].y + 1;
                    Zmeya[0].Draw();
                    break;
                }
            }
            catch (System.ArgumentOutOfRangeException)
            {
                throw;
            }
            if (eat == eat.yes)
            {
                Zmeya.Add(temp_Last);
            }
        }