public MoveResult AttemptMove(int playerId) { var moveAmount = _dice.RollDice(); var currentPosition = _gameBoard.GetPlayerPosition(playerId); if (currentPosition == -1) { return(new MoveResult(playerId, 0, "Invalid playerId")); } var potentialPosition = currentPosition + moveAmount; var finalPosition = _gameBoard.MakeMove(playerId, potentialPosition); string flavourText; if (finalPosition == -1) { flavourText = potentialPosition > _maxBoardSpace ? $"Player {playerId} went too far and was returned to their position." //shouldn't actually be able to happen : "Invalid move"; return(new MoveResult(playerId, currentPosition, flavourText)); } flavourText = finalPosition == _maxBoardSpace ? $"Player {playerId} wins!" : $"Player {playerId} moved from square {currentPosition + 1} to square {potentialPosition + 1}"; return(new MoveResult(playerId, finalPosition, flavourText)); }
public PlayerStatus RollDice(string playerName) { var score = _dice.RollDice(); MovePlayer(playerName, score); return(GetPlayerStatus(playerName)); }
public void RollDice_ReturnsValueBetween1And6() { _dice = new D6(); var results = new List <int>(); for (var i = 0; i < 100; i++) { results.Add(_dice.RollDice()); } Assert.IsTrue(results.All(r => r > 0 && r < 7)); }
public int RollDice() { if (dice == null) { throw new NullReferenceException("Dice is not set to an instance"); } if (gameState != GameState.Started) { throw new Exception($"Unable roll dice since the game is not started, it's current state is: {gameState}"); } return(dice.RollDice()); }
public void RollDice_ReturnsDifferentValues() { _dice = new D6(); var results = new List <int>(); for (var i = 0; i < 100; i++) { results.Add(_dice.RollDice()); } var distinct = results.Distinct(); Assert.IsTrue(distinct.Count() > 1); }
public int GetRoll() { return(_dice.RollDice()); }