// --- done MoveQueue --- public IEnumerator Run() { //TODO: logic to wait a max of X seconds (2?) before a round is played and the robots move InPlay = true; while (InPlay) { MoveType?playerMove = null; while (!Quit && (playerMove = RemoveNextMoveFromQueue()) == null) { yield return(new WaitForSeconds(.1f)); } if (Quit) { InPlay = false; continue; } DesiredMove playerDesiredMove = new DesiredMove { PrimaryMove = new Move(playerMove.Value), SecondaryMove = null }; //?Change this to GetCharacterIds() or GetThingIds(ThingType.Character)? foreach (var player in theBoard.GetThings <Player>()) { DoSingleTurn(player, playerDesiredMove); yield return(new WaitForSeconds(.1f)); // ?change to a regular yield return } foreach (var robot in theBoard.GetThings <Robot>()) { DoSingleTurn(robot); yield return(new WaitForSeconds(.1f)); // ?change to a regular yield return } //?WaitForSeconds here? CompletedRounds++; OnRoundCompleted(); CheckSpecialSquares(); } //Not InPlay anymore ClearMoveQueue(); OnGameEnded(); }
private void DoSingleTurn(Character character, DesiredMove desiredMove) { if (desiredMove.PrimaryMove != null) { IEnumerable <PositionedThing> posThingsThatMoved; bool success = theBoard.TryMove(character.IdOnBoard, desiredMove.PrimaryMove, out posThingsThatMoved); if (!success && desiredMove.SecondaryMove != null) { success = theBoard.TryMove(character.IdOnBoard, desiredMove.SecondaryMove, out posThingsThatMoved); } if (success) { foreach (var posThing in posThingsThatMoved) { OnThingMoved(posThing); } } } }