コード例 #1
0
ファイル: Game.cs プロジェクト: AdrianGajewskiDev/Snake
        public void Update()
        {
            while (_gameOver == false)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo input = Console.ReadKey();
                    switch (input.Key)
                    {
                    case ConsoleKey.UpArrow:
                        snakeDirection = Direction.Up;
                        break;

                    case ConsoleKey.DownArrow:
                        snakeDirection = Direction.Down;
                        break;

                    case ConsoleKey.LeftArrow:
                        snakeDirection = Direction.Left;
                        break;

                    case ConsoleKey.RightArrow:
                        snakeDirection = Direction.Right;
                        break;
                    }
                }

                if ((DateTime.Now - _lastDate).TotalMilliseconds >= _frameRate)
                {
                    snake.Draw();
                    snake.Move(snakeDirection);

                    target.Draw();

                    if (snake.IsOverlapping(target))
                    {
                        snake.Eat();
                        target.SetNewPosition();
                    }

                    if (snake.GameOver() || snake.HitBorder())
                    {
                        _gameOver = true;
                    }


                    _lastDate = DateTime.Now;
                }
            }

            if (_gameOver == true)
            {
                Console.Clear();
                Console.WriteLine($"Game Over, Score: {snake.GetLength()}");
            }
        }
コード例 #2
0
 private void ProcessCommand(string direction, ILevel curentLevel, IList <IObstacle> obstacles)
 {
     snake.Move(direction, curentLevel, obstacles);
 }
コード例 #3
0
 /// <summary>
 /// Active by timer.
 /// snakeMove
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void timerOfSnakeMove_Tick(object sender, EventArgs e)
 {
     snake.Move();
     //Invalidate();
 }