コード例 #1
0
            // ============== ICommand ================

            void ICommand.Exec(IContextWritable context)
            {
                IGhostBWritable ghostB = context.CharactardsContainer.Get <IGhostBWritable>();

                if (_isScared)
                {
                    IPacManWritable pacman = context.CharactardsContainer.Get <IPacManWritable>();

                    ePacmanPosition   pacmanPosition = Direction.getPacmanPosition(pacman.X, pacman.Y, ghostB.X, ghostB.Y);
                    List <eDirection> directions     = Direction.RunFromPacman(pacmanPosition);

                    foreach (eDirection direction in directions)
                    {
                        if (context.Field.IsCanMove(ghostB.X, ghostB.Y, direction))
                        {
                            _direction = direction;
                            break;
                        }
                    }
                }
                else
                {
                    bool isCanMove = context.Field.IsCanMove(ghostB.X, ghostB.Y, _direction);
                    while (!isCanMove)
                    {
                        ChangeDirection();
                        isCanMove = context.Field.IsCanMove(ghostB.X, ghostB.Y, _direction);
                    }
                }

                (int x, int y)nextPositon = Direction.GetNextPosition(ghostB.X, ghostB.Y, _direction);
                ghostB.UpdatePositionB(nextPositon.x, nextPositon.y);
                context.EventManager.Get <IPacManEventsWritable>().UpdateGhostBPosition(nextPositon.x, nextPositon.y);
            }
コード例 #2
0
            // ======= ITurnInternal =======

            void ITurnInternal.Exec(IContextWritable context)
            {
                foreach (ICommand curCommand in _commands)
                {
                    curCommand.Exec(context);
                }
            }
コード例 #3
0
            public eDirection getDirection(eDirection direction, IContextWritable context)
            {
                IGhostBWritable ghostB    = context.CharactardsContainer.Get <IGhostBWritable>();
                bool            isCanMove = context.Field.IsCanMove(ghostB.X, ghostB.Y, direction);

                while (!isCanMove)
                {
                    ChangeDirection();
                    isCanMove = context.Field.IsCanMove(ghostB.X, ghostB.Y, _direction);
                }
                return(_direction);
            }
コード例 #4
0
            // ============== ICommand ================

            void ICommand.Exec(IContextWritable context)
            {
                IPacManWritable pacMan    = context.CharactardsContainer.Get <IPacManWritable>();
                bool            isCanMove = context.Field.IsCanMove(pacMan.X, pacMan.Y, _direction);

                if (isCanMove)
                {
                    (int x, int y)nextPositon = Direction.GetNextPosition(pacMan.X, pacMan.Y, _direction);
                    pacMan.UpdatePosition(nextPositon.x, nextPositon.y);
                    context.EventManager.Get <IPacManEventsWritable>().UpdatePacManPosition(nextPositon.x, nextPositon.y);
                }
            }
コード例 #5
0
            // ============== ICommand ================

            void ICommand.Exec(IContextWritable context)
            {
                IGhostBWritable ghostB    = context.CharactardsContainer.Get <IGhostBWritable>();
                bool            isCanMove = context.Field.IsCanMove(ghostB.X, ghostB.Y, _direction);

                while (!isCanMove)
                {
                    ChangeDirection();
                    isCanMove = context.Field.IsCanMove(ghostB.X, ghostB.Y, _direction);
                }

                (int x, int y)nextPositon = Direction.GetNextPosition(ghostB.X, ghostB.Y, _direction);
                ghostB.UpdatePositionB(nextPositon.x, nextPositon.y);
                context.EventManager.Get <IPacManEventsWritable>().UpdateGhostBPosition(nextPositon.x, nextPositon.y);
            }
コード例 #6
0
            public void Exec(IContextWritable context)
            {
                IGhostWritableRandom ghost = context.CharactardsContainer.Get <IGhostWritableRandom>();

                ghost.Direction = (eDirection)Direction.GetRandomDirection();
                ghost.CanMove   = context.Field.IsCanMove(ghost.X, ghost.Y, ghost.Direction);

                if (ghost.CanMove)
                {
                    (int x, int y)nextPositon = Direction.GetNextPosition(ghost.X, ghost.Y, ghost.Direction);
                    if (nextPositon.x == ghost.X && nextPositon.y == ghost.Y)
                    {
                        _pacModel.StopGame(); return;
                    }
                    ghost.UpdatePositionRandom(nextPositon.x, nextPositon.y);
                    context.EventManager.Get <IGhostEventsWritable>().UpdateRandomPosition(nextPositon.x, nextPositon.y);
                }
            }
コード例 #7
0
            // ============== ICommand ================

            void ICommand.Exec(IContextWritable context)
            {
                if (Constant.IsTwoPlayers)
                {
                    IGhostAWritable ghostA    = context.CharactardsContainer.Get <IGhostAWritable>();
                    bool            isCanMove = context.Field.IsCanMove(ghostA.X, ghostA.Y, _direction);

                    if (isCanMove)
                    {
                        (int x, int y)nextPositon = Direction.GetNextPosition(ghostA.X, ghostA.Y, _direction);
                        ghostA.UpdatePositionA(nextPositon.x, nextPositon.y);
                        context.EventManager.Get <IPacManEventsWritable>().UpdateGhostAPosition(nextPositon.x, nextPositon.y);
                    }
                }
                else
                {
                    IGhostAWritable ghostA = context.CharactardsContainer.Get <IGhostAWritable>();
                    IPacManWritable pacman = context.CharactardsContainer.Get <IPacManWritable>();

                    ePacmanPosition   pacmanPosition = Direction.getPacmanPosition(pacman.X, pacman.Y, ghostA.X, ghostA.Y);
                    List <eDirection> directions     = new List <eDirection>();

                    if (_isScared)
                    {
                        directions = Direction.RunFromPacman(pacmanPosition);
                    }
                    else
                    {
                        directions = Direction.FindPacman(pacmanPosition);
                    }
                    foreach (eDirection direction in directions)
                    {
                        if (context.Field.IsCanMove(ghostA.X, ghostA.Y, direction))
                        {
                            _direction = direction;
                            break;
                        }
                    }

                    (int x, int y)nextPositon = Direction.GetNextPosition(ghostA.X, ghostA.Y, _direction);
                    ghostA.UpdatePositionA(nextPositon.x, nextPositon.y);
                    context.EventManager.Get <IPacManEventsWritable>().UpdateGhostAPosition(nextPositon.x, nextPositon.y);
                }
            }
コード例 #8
0
ファイル: CmdMoveGhostA.cs プロジェクト: NnX/PakPak
            // ============== ICommand ================

            void ICommand.Exec(IContextWritable context)
            {
                IGhostAWritable ghostA = context.CharactardsContainer.Get <IGhostAWritable>();
                IPacManWritable pacman = context.CharactardsContainer.Get <IPacManWritable>();

                ePacmanPosition   pacmanPosition = Direction.getPacmanPosition(pacman.X, pacman.Y, ghostA.X, ghostA.Y);
                List <eDirection> directions     = Direction.FindPacman(pacmanPosition);

                foreach (eDirection direction in directions)
                {
                    if (context.Field.IsCanMove(ghostA.X, ghostA.Y, direction))
                    {
                        _direction = direction;
                        break;
                    }
                }

                (int x, int y)nextPositon = Direction.GetNextPosition(ghostA.X, ghostA.Y, _direction);
                ghostA.UpdatePositionA(nextPositon.x, nextPositon.y);
                context.EventManager.Get <IPacManEventsWritable>().UpdateGhostAPosition(nextPositon.x, nextPositon.y);
            }
コード例 #9
0
ファイル: ModelBase.cs プロジェクト: NnX/EatSomethingMan
        // ==========================================

        public ModelBase()
        {
            _context = new Context(new CharactersContainer(), new Field(), new EventManager());
            RegisterEvents(_context.EventManager);
        }
コード例 #10
0
            // ============== ICommand ================

            void ICommand.Exec(IContextWritable context)
            {
                context.CharactardsContainer.Add <IPacManWritable>(new PacMan(_x, _y));
                context.EventManager.Get <IPacManEventsWritable>().CreatePacMan(_x, _y);
            }
コード例 #11
0
            // ============== ICommand ================

            void ICommand.Exec(IContextWritable context)
            {
                context.EventManager.Get <IPacManEventsWritable>().StopGame();
            }
コード例 #12
0
 public void Exec(IContextWritable context)
 {
     context.CharactardsContainer.Add <IGhostWritableRandom>(new GhostRandom(_x, _y));
     context.EventManager.Get <IGhostEventsWritable>().CreateGhost(_x, _y);
 }