Пример #1
0
 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
        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();
        }