public void move(PlayerMemento playerMemento, DIRECTIONS direction) { if (direction == DIRECTIONS.RIGHT) { playerMemento.XIndex += 1; } if (direction == DIRECTIONS.UP) { playerMemento.YIndex -= 1; } if (direction == DIRECTIONS.LEFT) { playerMemento.XIndex -= 1; } if (direction == DIRECTIONS.DOWN) { playerMemento.YIndex += 1; } if (playerMemento.XIndex < 0 || playerMemento.XIndex > 5 || playerMemento.YIndex < 0 || playerMemento.YIndex > 5) { PlayerMemento p = LoadPrev(playerMemento); if (p.XIndex < 0 || p.XIndex > 5 || p.YIndex < 0 || p.YIndex > 5) { exitSimulation(); } else { playerMemento.value = p.value; playerMemento.XIndex = p.XIndex; playerMemento.YIndex = p.YIndex; } } }
static void PrintBoard(PlayerMemento player) { Console.WriteLine(); Console.WriteLine(); Console.WriteLine("-------------------"); int boardSize = 5; for (int i = 0; i < boardSize; i++) { Console.WriteLine(); for (int j = 0; j < boardSize; j++) { if (i == player.YIndex && j == player.XIndex) { Console.Write('P'); } else { Console.Write('.'); } } } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("-------------------"); }
public PlayerMemento LoadPrev(PlayerMemento playerMemento) { if (careTake.GetLast(false) != null) { playerMemento = careTake.GetLast(true); } return(playerMemento); }
public void AddMemento(PlayerMemento memento) { if (allMementos.Count - 1 > index) { allMementos.RemoveRange(index, allMementos.Count - index); } allMementos.Add(memento); index = allMementos.Count; }
public PlayerMemento getNext(bool changeIndex) { if (index < allMementos.Count - 1) { PlayerMemento playerMemento = allMementos[index + 1]; if (changeIndex) { index += 1; } return(playerMemento); } return(null); }
public PlayerMemento GetLast(bool changeIndex) { if (index > 0) { PlayerMemento playerMemento = allMementos[index - 1]; if (changeIndex) { index -= 1; } return(playerMemento); } return(null); }
static void Main() { Context context = new Context(); PlayerMemento playerMemento = new PlayerMemento(1, 1, 1); // Context ctx = new Context(); // ctx.Save() PrintBoard(playerMemento); // context.Save(playerMemento.value, playerMemento.XIndex, playerMemento.YIndex); context.move(playerMemento, Context.DIRECTIONS.UP); context.move(playerMemento, Context.DIRECTIONS.UP); PrintBoard(playerMemento); playerMemento = context.LoadPrev(playerMemento); playerMemento = context.LoadPrev(playerMemento); playerMemento = context.LoadPrev(playerMemento); PrintBoard(playerMemento); }
public void Load(PlayerMemento memento) { Coord = memento.Coord; HP = memento.HP; Stamnia = memento.Stamnia; }
public void decreaseNumber(PlayerMemento playerMemento) { playerMemento.value -= 1; }
public void increaseNumber(PlayerMemento playerMemento) { playerMemento.value += 1; }
public void Load(PlayerMemento memento) { HP = memento.HP; Stamina = memento.Stamina; Location = memento.Location; }