Пример #1
0
 public MZMotion moveInFlowWithPositionandFrame(MZPosition position, int frame)
 {
     if (!isInFlow(position))
     {
         _isInUse = false;
         _shift   = 0;
         return(null);
     }
     if (!_isInUse)
     {
         _isInUse      = false;
         _frameUpdated = frame;
         position.move(_direction);
         _shift = 0;
         return(new  MZMotion(_speed, _direction));
     }
     else
     {
         if (frame - _frameUpdated >= 1.0 / _speed)
         {
             _frameUpdated = frame;
             position.move(_direction);
             return(new MZMotion(_speed, _direction));
         }
         _shift = (double)(frame - _frameUpdated) * _speed;
     }
     return(null);
 }
Пример #2
0
        public MZMoveResultCode makeStepTo(MZDirection direction)
        {
            if (_isPaused)
            {
                return(MZMoveResultCode.GAME_PAUSED);
            }

            /*
             * List<MZFlow> flowList = _maze.flowList();
             * for (int i = 0; i < flowList.Count(); i++)
             * {
             *  if (flowList[i].isInFlow(_currentPosition))
             *  {
             *      if ((direction == flowList[i].direction()) || (direction == (flowList[i].direction() + 2) % 2))
             *      {
             *          return MZMoveResultCode.MOTION_IMPOSSIBLE;
             *      }
             *  }
             * }*/

            if (!_maze.cells().cellAtPosition(_currentPosition).hasWallAtDirection(direction))
            {
                _currentPosition.move(direction);
                _stepsCount++;
                visitPosition(_currentPosition);
                if ((_maze.winningPosition().x() == _currentPosition.x()) && (_maze.winningPosition().y() == _currentPosition.y()))
                {
                    _isEnded = true;
                    return(MZMoveResultCode.GAME_ENDED);
                }
                else
                {
                    return(MZMoveResultCode.MOTION_PERFORMED);
                }
            }
            return(MZMoveResultCode.MOTION_IMPOSSIBLE);
        }
Пример #3
0
        public void visitPosition(MZPosition position)
        {
            _visitsMatrix.setLastVisit(_stepsCount, position);
            MZCellMatrix cellMatrix       = _maze.cells();
            MZPosition   iteratorPosition = new MZPosition(position.x(), position.y());

            while (iteratorPosition.x() > 0)
            {
                if (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.LEFT))
                {
                    break;
                }
                iteratorPosition.move(MZDirection.LEFT);
                _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
            }

            iteratorPosition = new MZPosition(position.x(), position.y());

            while (iteratorPosition.y() > 0)
            {
                if (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.DOWN))
                {
                    break;
                }
                iteratorPosition.move(MZDirection.DOWN);
                _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
            }

            iteratorPosition = new MZPosition(position.x(), position.y());

            while (iteratorPosition.x() < _maze.width() - 1)
            {
                if (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.RIGHT))
                {
                    break;
                }
                iteratorPosition.move(MZDirection.RIGHT);
                _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
            }
            iteratorPosition = new MZPosition(position.x(), position.y());

            while (iteratorPosition.y() < _maze.height() - 1)
            {
                if (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.UP))
                {
                    break;
                }
                iteratorPosition.move(MZDirection.UP);
                _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
            }

            if ((!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.LEFT)) && (!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.DOWN)))
            {
                iteratorPosition = new MZPosition(position.x(), position.y());
                iteratorPosition.move(MZDirection.LEFT);
                iteratorPosition.move(MZDirection.DOWN);

                while (iteratorPosition.x() >= 0)
                {
                    if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.RIGHT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.UP)))
                    {
                        break;
                    }
                    MZPosition tempPosition = iteratorPosition;
                    while (iteratorPosition.y() >= 0)
                    {
                        if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.RIGHT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.UP)))
                        {
                            break;
                        }
                        _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
                        iteratorPosition.move(MZDirection.DOWN);
                    }
                    iteratorPosition = tempPosition;
                    iteratorPosition.move(MZDirection.LEFT);
                }
            }

            if ((!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.LEFT)) && (!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.UP)))
            {
                iteratorPosition = new MZPosition(position.x(), position.y());
                iteratorPosition.move(MZDirection.LEFT);
                iteratorPosition.move(MZDirection.UP);

                while (iteratorPosition.x() >= 0)
                {
                    if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.RIGHT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.DOWN)))
                    {
                        break;
                    }
                    MZPosition tempPosition = iteratorPosition;
                    while (iteratorPosition.y() < _maze.height())
                    {
                        if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.RIGHT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.DOWN)))
                        {
                            break;
                        }
                        _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
                        iteratorPosition.move(MZDirection.UP);
                    }
                    iteratorPosition = tempPosition;
                    iteratorPosition.move(MZDirection.LEFT);
                }
            }

            if ((!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.RIGHT)) && (!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.DOWN)))
            {
                iteratorPosition = new MZPosition(position.x(), position.y());
                iteratorPosition.move(MZDirection.RIGHT);
                iteratorPosition.move(MZDirection.DOWN);

                while (iteratorPosition.x() < _maze.width())
                {
                    if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.LEFT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.UP)))
                    {
                        break;
                    }
                    MZPosition tempPosition = iteratorPosition;
                    while (iteratorPosition.y() >= 0)
                    {
                        if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.LEFT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.UP)))
                        {
                            break;
                        }
                        _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
                        iteratorPosition.move(MZDirection.DOWN);
                    }
                    iteratorPosition = tempPosition;
                    iteratorPosition.move(MZDirection.RIGHT);
                }
            }

            if ((!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.RIGHT)) && (!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.UP)))
            {
                iteratorPosition = new MZPosition(position.x(), position.y());
                iteratorPosition.move(MZDirection.RIGHT);
                iteratorPosition.move(MZDirection.UP);

                while (iteratorPosition.x() < _maze.width())
                {
                    if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.LEFT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.DOWN)))
                    {
                        break;
                    }
                    MZPosition tempPosition = iteratorPosition;
                    while (iteratorPosition.y() < _maze.height())
                    {
                        if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.LEFT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.DOWN)))
                        {
                            break;
                        }
                        _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
                        iteratorPosition.move(MZDirection.UP);
                    }
                    iteratorPosition = tempPosition;
                    iteratorPosition.move(MZDirection.RIGHT);
                }
            }
        }