예제 #1
0
        public void GenerateNewApple()
        {
            bool check = true;

            while (check)
            {
                apple = new Apple(new Vector2i(Map[0].Length, Map.Length));

                check = false;
                foreach (Vector2i part in snake.Parts)
                {
                    if (part == apple.Position)
                    {
                        check = true;
                    }
                }
            }
        }
예제 #2
0
        public GameLogic(Vector2i mapSize, int snakeSize)
        {
            snake = new Snake(snakeSize);
            snake.MoveTo(mapSize / 2);

            SnakeDirection = new Vector2i(1, 0);

            apple = new Apple(mapSize);

            Map = new CellType[mapSize.Y][];

            for (int y = 0; y < Map.Length; y++)
            {
                Map[y] = new CellType[mapSize.X];

                for (int i = 0; i < Map[y].Length; i++)
                {
                    Map[y][i] = CellType.Empty;
                }
            }

            DrawSnake();
            Map[apple.Position.Y][apple.Position.X] = CellType.Apple;
        }