예제 #1
0
        public MZMaze()
        {
            int    cuurent_mod = (Application.Current as App).UserGameData.current_module;
            string path        = (Application.Current as App).UserGameData.GameSettings.what_module(cuurent_mod);

            path = string.Concat(path, ".mzp");
            //string path = "kal.mzp";
            Uri uri = new Uri(path, UriKind.Relative);

            StreamResourceInfo sri = Application.GetResourceStream(uri);

            byte[] data = new byte[sri.Stream.Length];
            sri.Stream.Read(data, 0, data.Length);

            //int level = 1;
            int level = (Application.Current as App).UserGameData.levelnumber;

            int n          = data[0];
            int baseOffset = 1 + n * 2 + data[1 + (level - 1) * 2] * 256 + data[2 + (level - 1) * 2];

            _width  = data[baseOffset];
            _height = data[baseOffset + 1];
            _minimalStepsRequired = data[baseOffset + 2] * 256 + data[baseOffset + 3];
            _cellMatrix           = new MZCellMatrix(_width, _height);

            for (int i = 0; i < _width; i++)
            {
                for (int j = 0; j < _height; j++)
                {
                    MZPosition thisPosition = new MZPosition(i, j);
                    MZCell     thisCell     = _cellMatrix.cellAtPosition(thisPosition);
                    MZByte     thisCellData = new MZByte(data[baseOffset + i * _height + j + 4]);
                    MZByte     walls        = new MZByte((byte)(thisCellData.value() & MZMacro.LOW4BIT));
                    bool       isWin        = (thisCellData.value() & MZMacro.BIT5) != 0;
                    bool       isStart      = (thisCellData.value() & MZMacro.BIT6) != 0;
                    bool       isEmpty      = (thisCellData.value() & MZMacro.BIT7) != 0;
                    thisCell.isEmpty = isEmpty;
                    thisCell.setWallsValue(walls);
                    if (isWin)
                    {
                        _winningPosition = thisPosition;
                    }
                    if (isStart)
                    {
                        _startingPosition = thisPosition;
                    }
                }
            }
            _flowList = new List <MZFlow>();

            /*
             * if(userGameData currentModuleName] isEqualToString: @"Reciever"] && level == 2)
             * {
             * [_flowList addObject:[[MZFlow alloc] initWithPosition: [[MZPosition alloc] initWithX:4 andY:8] direction: RIGHT length:6 andSpeed: 1.0/15.0]];
             * }*/
            //cuurent_mod == 4 - Reciever
            if ((cuurent_mod == 4) && (level == 2))
            {
                MZPosition pos  = new MZPosition(4, 8);
                MZFlow     flow = new MZFlow(pos, MZDirection.RIGHT, 6, 1.0 / 15.0);
                _flowList.Add(flow);
            }
        }
예제 #2
0
파일: MZGame.cs 프로젝트: GA239/robolabwp
        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);
                }
            }
        }