// ============== 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); }
// ======= ITurnInternal ======= void ITurnInternal.Exec(IContextWritable context) { foreach (ICommand curCommand in _commands) { curCommand.Exec(context); } }
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); }
// ============== 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); } }
// ============== 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); }
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); } }
// ============== 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); } }
// ============== 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); }
// ========================================== public ModelBase() { _context = new Context(new CharactersContainer(), new Field(), new EventManager()); RegisterEvents(_context.EventManager); }
// ============== ICommand ================ void ICommand.Exec(IContextWritable context) { context.CharactardsContainer.Add <IPacManWritable>(new PacMan(_x, _y)); context.EventManager.Get <IPacManEventsWritable>().CreatePacMan(_x, _y); }
// ============== ICommand ================ void ICommand.Exec(IContextWritable context) { context.EventManager.Get <IPacManEventsWritable>().StopGame(); }
public void Exec(IContextWritable context) { context.CharactardsContainer.Add <IGhostWritableRandom>(new GhostRandom(_x, _y)); context.EventManager.Get <IGhostEventsWritable>().CreateGhost(_x, _y); }