Beispiel #1
0
        public PacmanGame()
        {
            CurrentGameEvent = new List <KeyValuePair <EventType, string> >();
            Board            = new PacmanBoard();
            CurrentGameEvent.Add(new KeyValuePair <EventType, string>(EventType.BoardReset, GetBoardString()));
            Pacman = new PacmanPacman();
            CurrentGameEvent.Add(new KeyValuePair <EventType, string>(EventType.PacmanLives, $"{Pacman.Lives}"));
            Ghosts = new PacmanGhost[4]
            {
                new PacmanGhost(1),
                new PacmanGhost(2),
                new PacmanGhost(3),
                new PacmanGhost(4)
            };
            Random random = new Random();

            for (var i = 0; i < Ghosts.Length; i++)
            {
                Ghosts[i].Facing = (PacmanPacman.Direction)random.Next(1, 5);
                CurrentGameEvent.Add(new KeyValuePair <EventType, string>(EventType.GhostUpdate, $"{i} {Ghosts[i].GetPosition().ToString()} {Ghosts[i].IsDead} {Ghosts[i].IsVulnerable}"));
            }
            Score = 0;
            CurrentGameEvent.Add(new KeyValuePair <EventType, string>(EventType.Score, $"{Score}"));
            GhostScoreMultiplier = 1;
            PoweredUpCounter     = 0;
            FruitSpawnCounter    = 0;
            TimeStarted          = DateTime.Now;
            GameRunning          = true;
        }
Beispiel #2
0
 /// <summary>
 /// Call after all dots and powerUp are consumed
 /// </summary>
 private void ResetBoard()
 {
     Board  = new PacmanBoard();
     Pacman = new PacmanPacman();
     Ghosts = new PacmanGhost[]
     {
         new PacmanGhost(1),
         new PacmanGhost(2),
         new PacmanGhost(3),
         new PacmanGhost(4)
     };
     CurrentGameEvent.Add(new KeyValuePair <EventType, string>(EventType.BoardReset, GetBoardString()));
 }
Beispiel #3
0
 /// <summary>
 /// Checks whether a ghost has collided with pacman and handles resetting positions after death
 /// </summary>
 private bool PacmanGhostCollide()
 {
     for (int i = 0; i < Ghosts.Length; i++)
     {
         if (Ghosts[i].GetPosition().Collide(Pacman.GetPosition()))
         {
             if (Ghosts[i].IsVulnerable)
             {
                 Ghosts[i].IsDead       = true;
                 Ghosts[i].IsVulnerable = false;
                 Ghosts[i].StartDeathCounter();
                 Ghosts[i].Location.Xpos = 13;
                 Ghosts[i].Location.Ypos = 12;
                 Score += 200 * GhostScoreMultiplier;
                 CurrentGameEvent.Add(new KeyValuePair <EventType, string>(EventType.GhostDie, i + $" 1 {200 * GhostScoreMultiplier}"));
             }
             else if (!Ghosts[i].IsDead)
             {
                 Pacman.Location.Xpos = 13;
                 Pacman.Location.Ypos = 17;
                 Pacman.Facing        = PacmanPacman.Direction.right;
                 Pacman.Lives--;
                 CurrentGameEvent.Add(new KeyValuePair <EventType, string>(EventType.PacmanLives, $"{Pacman.Lives}"));
                 Ghosts = new PacmanGhost[4]
                 {
                     new PacmanGhost(1),
                     new PacmanGhost(2),
                     new PacmanGhost(3),
                     new PacmanGhost(4)
                 };
                 if (Pacman.Lives <= 0)
                 {
                     Pacman.Lives = 0;
                     GameRunning  = false;
                     TimeEnded    = DateTime.Now;
                     return(true);
                 }
             }
         }
     }
     return(false);
 }