Exemplo n.º 1
0
        //Process user inputs
        public void UserInput(string input)
        {
            string commands = input.Trim().ToUpper();

            Regex place  = new Regex(@"^PLACE ");
            Regex move   = new Regex(@"^MOVE$");
            Regex left   = new Regex(@"^LEFT$");
            Regex right  = new Regex(@"^RIGHT$");
            Regex report = new Regex(@"^REPORT$");

            if (place.IsMatch(commands))
            {
                ProcessPlace(commands);
            }
            else if (move.IsMatch(commands))
            {
                _pacman.Move();
            }
            else if (left.IsMatch(commands))
            {
                _pacman.Left();
            }
            else if (right.IsMatch(commands))
            {
                _pacman.Right();
            }
            else if (report.IsMatch(commands))
            {
                Console.WriteLine(_pacman.Report());
            }
            else
            {
                throw new InvalidInputException("Invalid command");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// press space to start or pause, Escape to switch in game over mode
        /// </summary>
        /// <param name="key"></param>
        public void KeyPressed(PacmanKey key)
        {
            // Gestion des flèches pour le déplacement du pacman

            if (key == PacmanKey.Pause)
            {
                // touche Pause ou P
                Paused = !Paused;
            }

            if (_Pacman != null)
            {
                switch (key)
                {
                case PacmanKey.Left:
                    _Pacman.Left();
                    break;

                case PacmanKey.Right:
                    _Pacman.Right();
                    break;

                case PacmanKey.Down:
                    _Pacman.Down();
                    break;

                case PacmanKey.Up:
                    _Pacman.Up();
                    break;
                }
            }

            if (key == PacmanKey.Space && GameMode.GAME_OVER == Status)
            {
                // passe en mode de jeu READY
                numLaby = 0;
                Level   = 1;
                SetLabyrinth(numLaby);
                // initialisation du score, des vies, ...
                Lives     = 3;
                LifeScore = 5000;
                Score     = 0;
                SetMode(GameMode.READY);
                if (Audio != null)
                {
                    Audio.PlayIntro();
                }
            }
            else if (key == PacmanKey.Escape)
            {
                SetMode(GameMode.GAME_OVER);
            }
            else if (key == PacmanKey.NextLevel)
            {
                Labyrinth.getCurrent().RemainingPills = 0;
            }
        }
Exemplo n.º 3
0
        public void Test_Left()
        {
            FACE   expected = FACE.WEST;
            Pacman p        = new Pacman();

            p.PlacePacman("4", "4", "NORTH");
            p.Left();
            Assert.AreEqual(expected, p.CurrentFace);
        }
Exemplo n.º 4
0
        public void Place_WhenNotPlaced_ShouldIgnoreCommands()
        {
            var pacman = new Pacman();

            pacman.Move();
            pacman.Left();
            var result = pacman.Report();

            Assert.IsEmpty(result);
        }
Exemplo n.º 5
0
        public void PacmanCanReportThePositionAfterPlacingandTurning()
        {
            var pacman = new Pacman();
            var result = pacman.Place(0, 0, Facing.North);

            pacman.Left();
            var report = pacman.Report();

            Assert.IsTrue(result);
            Assert.AreEqual("", pacman.Error);
            Assert.AreEqual("Output: 0,0,WEST", report);
        }
Exemplo n.º 6
0
        public void PacmanCanReportThePositionAfterPlacingTurningAndMoving()
        {
            var pacman = new Pacman();
            var result = pacman.Place(1, 2, Facing.East);

            pacman.Move();
            pacman.Move();
            pacman.Left();
            pacman.Move();
            var report = pacman.Report();

            Assert.IsTrue(result);
            Assert.AreEqual("", pacman.Error);
            Assert.AreEqual("Output: 3,3,NORTH", report);
        }
Exemplo n.º 7
0
        // Le jeu est dans l'état PLAY
        private void AnimatePlay()
        {
            GameRecord record;

            while (_cfg.play.Count > 0)
            {
                record = _cfg.play[0];
                if (record.tim > oturn)
                {
                    break;
                }
                _cfg.play.RemoveAt(0);
                _cfg.playerCfg.record.Add(record);
                if (record.tim == oturn)
                {
                    if (record.isKey)
                    {
                        switch (record.key)
                        {
                        case PacmanKey.Back:
                        {
                            TXYList xyList = _Pacman.xyList;
                            if (!xyList.empty)
                            {
                                xyList.deAdd();
                            }
                        }
                        break;

                        case PacmanKey.Left:
                            _Pacman.Left();
                            break;

                        case PacmanKey.Right:
                            _Pacman.Right();
                            break;

                        case PacmanKey.Down:
                            _Pacman.Down();
                            break;

                        case PacmanKey.Up:
                            _Pacman.Up();
                            break;
                        }
                    }
                    else
                    {
                        intProcessKey(record.tsk);
                    }
                }
            }

            if (Labyrinth.getCurrent().RemainingPills <= 0)
            {
                // toutes les pastilles ont été mangées, changement de niveau
                // accélère un peu le jeu
                Level++;
                SleepTime -= 1;
                numLaby    = (numLaby + 1) % 4;
                SetLabyrinth(numLaby);
                SetMode(GameMode.READY);
            }
            else
            {
                int        i;
                int        xp, yp;
                GhostState state;

                EraseSprites();
                ErasePoints();

                // testes de collisions
                xp = _Pacman.X;
                yp = _Pacman.Y;
                // collisions avec les fantomes
                foreach (Ghost ghost in _Ghosts)
                {
                    state = ghost.State;
                    // teste si le Pacman est en collision avec le Fantome i
                    if (_Pacman.HasCollision(ghost))
                    {
                        if (state.isHunt() || state.isRandom())
                        {
                            // Perdu une vie
                            SetMode(GameMode.DEATH);
                            return;
                        }
                        else if (state.isFlee())
                        {
                            // le fantome est mangé
                            ghost.setState(GhostState.EYE);
                            AddScore(_GhostScore);
                            FantScore *= 2;
                            AddPoints(_GhostScore);
                            if (Audio != null)
                            {
                                Audio.PlayEatGhost();
                            }
                        }
                    }
                }
                // collisions avec le bonus
                if (CurrentBonus != null)
                {
                    // le bonus existe
                    if (_Pacman.HasCollision(CurrentBonus))
                    {
                        int points = Math.Min(1600, Level * 100);
                        AddScore(points);
                        AddPoints(points);
                        CurrentBonus = null;
                        if (Audio != null)
                        {
                            Audio.PlayBonus();
                        }
                    }
                    if (CurrentBonus != null && CurrentBonus.animate() <= 0)
                    {
                        // le bonus est en fin de vie
                        CurrentBonus = null;
                    }
                }
                else
                {
                    // pas de bonus
                    if (Game.GetRandom(1000) < 5)
                    {
                        CurrentBonus = new Bonus(Level - 1);
                    }
                }

                // animate pacman
                if (speedCheck(Config.SpeedPacman))
                {
                    i = _Pacman.animate();
                    if (i == 1)
                    {
                        // une pastille est mangée
                        AddScore(10);
                        Audio.PlayPill();
                    }
                    else if (i == 2)
                    {
                        FantScore = 100;
                        // Les fantomes qui chasse deviennent fuyards
                        AddScore(50);
                        Audio.PlayBigPill();
                        setGhostsState(GhostState.FLEE);
                    }
                }
                // animate fantomes
                //      bool siren = false;

                foreach (Ghost ghost in _Ghosts)
                {
                    switch (ghost.State.ToEnum())
                    {
                    case GhostStateEnum.FLEE:
                        ghost.speedDevider = Config.GhostSpeedFlee;
                        break;

                    case GhostStateEnum.EYE:
                        ghost.speedDevider = Config.GhostSpeedEye;
                        break;

                    default:
                        if (Math.Sqrt((_Pacman.xLaby - ghost.xLaby) ^ 2 + (_Pacman.yLaby - ghost.yLaby) ^ 2) < Config.SafeRadius)
                        {
                            if (ghost.State.isHunt())
                            {
                                if (GetRandom(Config.GhostSpeedSwitchTime) == 2)
                                {
                                    if (GetRandom(1) == 1)
                                    {
                                        ghost.speedDevider = Config.GhostSpeedHunt;
                                    }
                                    else
                                    {
                                        ghost.speedDevider = Config.GhostSpeedHuntPulse;
                                    }
                                }
                            }
                            else
                            {
                                ghost.speedDevider = Config.GhostSpeed;
                            }
                        }
                        else
                        {
                            ghost.speedDevider = Config.GhostSpeedOutSafe;
                        }
                        break;
                    }

                    if (!speedCheck(ghost.speedDevider))
                    {
                        ghost.timers();
                        continue;
                    }
                    ghost.setPacmanCoor(xp, yp);
                    ghost.animate();
                    //        if (!siren && ghosts[i].getState().isHunt()) {
                    //          siren = true;
                    //          Audio.playSiren();
                    //        }
                }

                // animate points
                foreach (FlyingScore pt in _FlyingScores)
                {
                    pt.animate();
                }

                DrawSprites();
                DrawPoints();
                DrawScore();
                DrawLives();
                //if (DEBUG)
                //{
                //    foreach(Ghost ghost in _Ghosts)
                //    {
                //        //draw.drawDebugString(4, 12 + i * 12, 12, ghosts[i].toString());
                //    }
                //}
            }
        }
Exemplo n.º 8
0
 public void Left_WhenTurn_ShouldTurnNinetyDegreesLeft()
 {
     _pacman.Place(_grid, _pacman.X, _pacman.Y, _pacman.Face);
     _pacman.Left();
     Assert.That(_pacman.Face, Is.EqualTo(Directions.Face.WEST));
 }