コード例 #1
0
ファイル: Apple.cs プロジェクト: Racksay/SnakeRefactored
 public Apple(Renderer renderer, PlayField playField)
 {
     _renderer = renderer;
     AppleCoordinate = new Coord();
     _playFieldHeight = playField.Height;
     _playFieldWidth = playField.Width;
 }
コード例 #2
0
        private void UpdatePlayField()
        {
            while (GameIsPlaying)
            {
                OnKeyDown();                 // Input logic

                if (!Paused)                 // Game logic
                {
                    if (Tick.ElapsedMilliseconds < 100)
                    {
                        continue;                                                     // Tick ensures that each update will happen in constant time.
                    }
                    Tick.Restart();

                    Player.GetNextPosition(TailCoordsList);
                    Player.SwitchDirection(Direction.NewDirection);

                    GameIsPlaying = Player.BorderCollisionCheck(PlayField.Width, PlayField.Height);
                    if (!GameIsPlaying)
                    {
                        continue;
                    }

                    AppleEaten = PlayField.AppleCollisionCheck(TailCoordsList, Player.NewHeadCoord);

                    GameIsPlaying = Player.SelfCollisionTest(TailCoordsList, AppleEaten);
                    if (!GameIsPlaying)
                    {
                        continue;
                    }

                    Renderer.Render(Player.HeadCoord, '0');

                    if (!AppleEaten)
                    {
                        Renderer.Render(Player.TailEndCoord, ' ');
                    }
                    else
                    {
                        AppleEaten = true;
                    }

                    Player.ExtendSnakeTail(TailCoordsList);
                    Renderer.Render(Player.NewHeadCoord, '@');
                    Direction.LastDirection = Direction.NewDirection;
                }
            }
        }
コード例 #3
0
        private void Initiliaze()
        {
            GameIsPlaying = true;
            Paused        = false;
            AppleEaten    = false;

            TailCoordsList = new List <Coord>();

            PlayField = new PlayField(TailCoordsList);

            Tick     = new Stopwatch();
            Renderer = new SnakeRenderer();

            Player    = new Snake(TailCoordsList);
            Direction = new Direction();

            Tick.Start();
            UpdatePlayField();
        }
コード例 #4
0
ファイル: SnakeGame.cs プロジェクト: Racksay/SnakeRefactored
        private void Initiliaze()
        {
            GameIsPlaying = true;
            Paused = false;
            AppleEaten = false;

            TailCoordsList = new List<Coord>();

            PlayField = new PlayField(TailCoordsList);

            Tick  = new Stopwatch();
            Renderer = new SnakeRenderer();

            Player = new Snake(TailCoordsList);
            Direction = new Direction();

            Tick.Start();
            UpdatePlayField();
        }