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); }
public void setLastVisit(int step, MZPosition position) { if (position.x() >= 0 && position.y() >= 0 && position.x() < _visits.Count() && position.y() < _visits[0].Count()) { _visits[(int)position.x()][(int)position.y()] = step; } }
// вызврат клетки через позицию public MZCell cellAtPosition(MZPosition position) { if (position.x() >= 0 && position.y() >= 0 && position.x() < _cells.Count() && position.y() < _cells[0].Count()) { return(_cells[(int)position.x()][(int)position.y()]); } return(new MZCell()); }
public MZFlow(MZPosition pos, MZDirection dir, int length, double speed) { _position = pos; _direction = dir; _length = length; _speed = speed; _isInUse = false; }
public int lastVisitAtPoisiton(MZPosition position) { if (position.x() >= 0 && position.y() >= 0 && position.x() < _visits.Count() && position.y() < _visits[0].Count()) { return(_visits[(int)position.x()][(int)position.y()]); } return(-MZMacro.LAST_STEPS_VISIBLE); }
private MZGame() { _maze = new MZMaze(); _stepsCount = 0; _minimalSteps = _maze.minimalSteps(); _currentPosition = _maze.startingPosition(); _visitsMatrix = new MZVisitsMatrix(_maze.width(), _maze.height()); visitPosition(_currentPosition); _isEnded = false; _isPaused = false; }
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); } }
public bool isInFlow(MZPosition position) { switch (_direction) { case MZDirection.UP: if (_position.x() != position.x()) { return(false); } else { if (_position.y() <= position.y() && position.y() < _position.y() + _length - 1) { return(true); } else { return(false); } } case MZDirection.RIGHT: if (_position.y() != position.y()) { return(false); } else { if (_position.x() <= position.x() && position.x() < _position.x() + _length - 1) { return(true); } else { return(false); } } case MZDirection.DOWN: if (_position.x() != position.x()) { return(false); } else { if (_position.y() >= position.y() && position.y() > _position.y() - _length + 1) { return(true); } else { return(false); } } case MZDirection.LEFT: if (_position.y() != position.y()) { return(false); } else { if (_position.x() >= position.x() && position.x() > _position.x() - _length + 1) { return(true); } else { return(false); } } default: return(false); } }
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); } } }