Exemplo n.º 1
0
        public Block MakeFood()
        {
            if (Eaten)
            {
                //防止相同

                Position.X = r.Next((int)GameConfig.MapSize);
                Position.Y = r.Next((int)GameConfig.MapSize);

                while (Snake.InBody(Position))
                {
                    Console.WriteLine("food in body");
                    Position.X = r.Next((int)GameConfig.MapSize);
                    Position.Y = r.Next((int)GameConfig.MapSize);
                }

                block = new Block(Color.Green, GameConfig.BlockSize, Position);
                Eaten = false;
            }

            return(block);
        }