public static void Build() { GameBuilder.ParseSnakesFromInput(); GameBuilder.ParseLaddersFromInput(); var players = GameBuilder.ParsePlayersFromInput(); var dice = GameBuilder.CreateDice(); GameSimulator.Play(players, dice); }
private static bool CheckGameStatus(Player player) { GameSimulator.UpdateGameStatus(player); return(GameSimulator.gameOver); }
public static void Play(Player[] players, Random dice) { GameSimulator.numberOfPlayers = players.Length; while (!GameSimulator.gameOver) { int currentPlayerIterator = 0; while (currentPlayerIterator < numberOfPlayers) { var currentDicePosition = dice.Next(1, 7); var previousCellPosition = players[currentPlayerIterator].GetCurrentCellPosition(); if (players[currentPlayerIterator].GetCurrentCellPosition() == 0 && currentDicePosition == 6) { players[currentPlayerIterator].IncrementCurrentCellPosition(currentDicePosition); if (GameSimulator.CheckGameStatus(players[currentPlayerIterator])) { DisplayWinningMessage(players[currentPlayerIterator]); break; } GameSimulator.CheckIfCurrentCellPositionIsSnakeHead(players[currentPlayerIterator]); GameSimulator.CheckIfCurrentCellPositionIsLadderStart(players[currentPlayerIterator]); if (GameSimulator.CheckGameStatus(players[currentPlayerIterator])) { DisplayWinningMessage(players[currentPlayerIterator]); break; } DisplayMoveMessage(players[currentPlayerIterator].GetName(), currentDicePosition, previousCellPosition, players[currentPlayerIterator].GetCurrentCellPosition()); } else if (players[currentPlayerIterator].GetCurrentCellPosition() != 0) { if (previousCellPosition + currentDicePosition > 100) { continue; } players[currentPlayerIterator].IncrementCurrentCellPosition(currentDicePosition); if (GameSimulator.CheckGameStatus(players[currentPlayerIterator])) { DisplayWinningMessage(players[currentPlayerIterator]); break; } GameSimulator.CheckIfCurrentCellPositionIsSnakeHead(players[currentPlayerIterator]); GameSimulator.CheckIfCurrentCellPositionIsLadderStart(players[currentPlayerIterator]); if (GameSimulator.CheckGameStatus(players[currentPlayerIterator])) { DisplayWinningMessage(players[currentPlayerIterator]); break; } DisplayMoveMessage(players[currentPlayerIterator].GetName(), currentDicePosition, previousCellPosition, players[currentPlayerIterator].GetCurrentCellPosition()); } GameSimulator.IncrementCurrentPlayerIterator(ref currentPlayerIterator); } } }