Exemplo n.º 1
0
        static void GameStart()
        {
            AutoSetting();
            Direction      dir  = Direction.Right;
            ConsoleKeyInfo cki  = new ConsoleKeyInfo();
            Worm           worm = new Worm(WormLen, (byte)((Conf.FieldWidth - WormLen) / 2), (byte)(Conf.FieldHeight / 2));
            Food           food = new Food(Conf.FieldHeight, Conf.FieldWidth);

            food.GenerateNewPos(ref worm);
            PrintWorm(worm);
            PrintFood(food.Element);
            while (true)
            {
                if (Console.KeyAvailable == true)
                {
                    cki = Console.ReadKey(true);
                    KeyToDir(cki.Key, ref dir);
                }
                if (!worm.Go(dir, ref food))
                {
                    Console.Clear();
                    Console.WriteLine("The end");
                    Console.ReadLine();
                    return;
                }
                if ((worm[0].X == food.Element.X) && (worm[0].Y == food.Element.Y))
                {
                    if (!food.GenerateNewPos(ref worm))
                    {
                        Console.Clear();
                        Console.WriteLine("You win");
                        Console.ReadLine();
                        return;
                    }
                    PrintFood(food.Element);
                }
                PrintAction(worm[0], worm.DeletedElement);
                Thread.Sleep(200);
            }
        }