예제 #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
            // ============== 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);
            }