private void CurrentTurn_LoadOpponentPositionEvent(OpponentCell opponentCell) { Cell lastPosition = OpponentCell.LastTurnPosition; OpponentCell = opponentCell; OpponentCell.LastTurnPosition = lastPosition; OpponentCell.DetermineFacing(); }
/// <summary> /// Default Constructor /// </summary> public Sensor() { CurrentTurn = new World(); CurrentTurn.LoadOpponentPositionEvent += new LoadOpponentPositionEventHandler(CurrentTurn_LoadOpponentPositionEvent); CurrentTurn.LoadPlayerPositionEvent += new LoadPlayerPositionEventHandler(CurrentTurn_LoadPlayerPositionEvent); LastTurn = new World(); LastTurn.LoadOpponentPositionEvent += new LoadOpponentPositionEventHandler(LastTurn_LoadOpponentPositionEvent); LastTurn.LoadPlayerPositionEvent += new LoadPlayerPositionEventHandler(LastTurn_LoadPlayerPositionEvent); PlayerCell = new PlayerCell(); OpponentCell = new OpponentCell(); }
/// <summary> /// Builds the world from the input given as a string /// </summary> /// <param name="newWorld"></param> /// <returns></returns> public bool BuildWorld(string[] newWorld) { bool builtWorld = false; if (newWorld.Length > 0) { OpponentCell opponent = null; PlayerCell player = null; for (var i = 0; i < newWorld.Length; i++) { string[] line = newWorld[i].Split(' '); int x = int.Parse(line[0]); int y = int.Parse(line[1]); if (!Cells.ContainsKey(x)) { Cells.Add(x, new Dictionary<int, Cell>()); } if (!Cells[x].ContainsKey(y)) { CellContent content = Cell.GetWorldState(line[2]); switch (content) { case CellContent.Opponent: opponent = new OpponentCell() { X = x, Y = y, Content = content, Value = 0 }; Cells[x].Add(y, opponent); break; case CellContent.You: player = new PlayerCell() { X = x, Y = y, Content = content, Value = 0 }; Cells[x].Add(y, player); break; case CellContent.OpponentWall: Cells[x].Add(y, new Cell() { X = x, Y = y, Content = content, Value = 0 }); break; case CellContent.YourWall: Cells[x].Add(y, new Cell() { X = x, Y = y, Content = content, Value = 0 }); break; case CellContent.Clear: Cells[x].Add(y, new Cell() { X = x, Y = y, Content = content, Value = 1 }); break; } } builtWorld = true; } if (LoadOpponentPositionEvent != null) { LoadPositions(opponent); LoadOpponentPositionEvent(opponent); } if (LoadOpponentPositionEvent != null) { LoadPositions(player); LoadPlayerPositionEvent(player); } } return builtWorld; }
/// <summary> /// Event which is fired when the opponents last position is loaded /// </summary> /// <param name="opponentCell">Opponent last turn position</param> private void LastTurn_LoadOpponentPositionEvent(OpponentCell opponentCell) { OpponentCell.LastTurnPosition = opponentCell; }