public void RunSimulation() { while (GameInProgress(_players)) { _activePlayer.RollAndUpdatePosition(); var currentPosition = _positions[_activePlayer.PositionIndex]; switch (currentPosition.type) { case PositionType.property: case PositionType.railroad: case PositionType.utility: SimulateLandOnPropertyRailOrUtility(_activePlayer, currentPosition); break; case PositionType.communitychest: SimulateCommunityChest(_activePlayer, _players); break; case PositionType.tax: SimulateLandOnTax(_activePlayer, currentPosition); break; case PositionType.chance: SimulateLandOnChance(_activePlayer); break; case PositionType.gotojail: SimulateLandOnGoToJail(_activePlayer); break; case PositionType.freeparking: case PositionType.jail: case PositionType.go: break; default: throw new ArgumentOutOfRangeException(); } SimulatePlayerRealEstateDecision(_activePlayer); if (true) { Console.WriteLine("Id:{0}\tBalance:{1}\tRolls:{2}\tPositions:{3}\tAlive:{4}\tHouses{5}", _activePlayer.Id, _activePlayer.Balance, _activePlayer.Rolls.Count, _activePlayer.PositionsAcquired.Count, _activePlayer.PlayerIsAlive, _activePlayer.PositionsAcquired.Sum(pos => pos.BuildingCount)); if (++stepCount % _players.Count(player => player.PlayerIsAlive) == 0) { Console.WriteLine(); Console.WriteLine(stepCount); Thread.Sleep(50); } } _activePlayer = _players[GetNextPlayer(_activePlayer)]; } Console.WriteLine(); Console.WriteLine("Finished Game"); _players.ForEach(p => { Console.WriteLine("Id:{0}\tBalance:{1}\tRolls:{2}\tPositions:{3}\tAlive:{4}\tHouses{5}", p.Id, p.Balance, p.Rolls.Count, p.PositionsAcquired.Count, p.PlayerIsAlive, p.PositionsAcquired.Sum(pos => pos.BuildingCount)); }); }
private void SimulateLandOnGoToJail(Player activePlayer) { activePlayer.Imprison(); }