static void PrintPhrases(TelephoneGameRepository repository) { foreach (GamePhrase p in GameService.GetPhraseList(repository)) { Console.WriteLine(string.Format("{0} {1}", p.id, p.text)); } }
public void Game_PlayerOneTurn() { using (var repository = new TelephoneGameRepository()) { Assert.That(GameService.IsPlayersTurn(_player1, _newGame, repository), "Should be player one's turn"); } }
public void Transition_to_PickPhrase() { using (var repository = new TelephoneGameRepository()) { EdgeConditional edge = _newGame.Edges.First<EdgeConditional>(e => e.nextNode.GetType().Name.Equals("PickPhrase")); Assert.That(GameService.TransitionGameState(_newGame, edge, repository), "Transition failed"); } }
public void Player_FindByString() { using (var repository = new TelephoneGameRepository()) { Player p = GameService.FindPlayer("15022967010", repository); Assert.That(null != p, "Player not found"); } }
public void Player_FindByPhoneNumber() { using (var repository = new TelephoneGameRepository()) { PhoneNumber phone = new PhoneNumber() { Number = "15022967010" }; Player p = GameService.FindPlayer(phone, repository); Assert.That(null != p, "Player not found"); } }
protected virtual void ChangeState(Game game, TelephoneGameRepository repository) { if (!game.currentNode.edgeConditionals.Contains(this)) { throw new Exception("EdgeConditional is not in the GameStateNode"); } game._currentNodeNumber = nextNode.id; }
public void Game_CantAddMorePlayers() { using (var repository = new TelephoneGameRepository()) { Assert.That(_newGame.maxNumberOfPlayers == _newGame.numberOfPlayers); Player additionalPlayer = GameService.FindPlayer("15027625695", repository); GameService.AddPlayerToGame(_player2, _newGame, repository); } }
public void CheckNoCondition() { using (var repository = new TelephoneGameRepository()) { Game game = _game1; Assert.That(game.Edges[0].GetType() == typeof(NoCondition), "This edge is not a NoConditional"); bool success = GameService.TransitionGameState(game, game.Edges[0], repository); Assert.That(success, "Couldn't transition along NoConditional edge"); } }
public void SetupTests() { using (var repository = new TelephoneGameRepository()) { _player1 = GameService.FindPlayer("15022967010", repository); _newGame = GameService.CreateNewGame<TwoPlayersOriginal>(_player1, repository); Assert.That(null != _newGame, "Game not created"); _player2 = GameService.FindPlayer("15022967466", repository); GameService.AddPlayerToGame(_player2, _newGame, repository); } }
public void CheckNumberOfPlayers_Failure() { using (var repository = new TelephoneGameRepository()) { Game game = _game3; bool success = GameService.TransitionGameState(game, game.Edges[0], repository); Assert.That(success, "Couldn't transition"); Assert.That(game.Edges[0].GetType() == typeof(CheckNumberOfPlayers), "This edge is not a CheckNumberOfPlayers"); success = GameService.TransitionGameState(game, game.Edges[0], repository); Assert.That(!success, "Should not have transitioned along CheckNumberOfPlayers edge"); } }
public void CheckNumberOfPlayers_Success() { using (var repository = new TelephoneGameRepository()) { Game game = _game2; bool success = GameService.TransitionGameState(game, game.Edges[0], repository); Assert.That(success, "Couldn't transition"); Assert.That(game.Edges[0].GetType() == typeof(CheckNumberOfPlayers), "This edge is not a CheckNumberOfPlayers"); GameService.AddPlayerToGame(_player2, game, repository); success = GameService.TransitionGameState(game, game.Edges[0], repository); Assert.That(success, "Couldn't transition along CheckNumberOfPlayers edge"); } }
public void SetupTests() { using (var repository = new TelephoneGameRepository()) { _player1 = GameService.FindPlayer("15022967010", repository); _newGame = GameService.CreateNewGame<TwoPlayersOriginal>(_player1, repository); Assert.That(null != _newGame, "Game not created"); EdgeConditional edge = _newGame.Edges.First<EdgeConditional>(e => e.nextNode.GetType().Name.Equals("PickPlayer")); Assert.That(GameService.TransitionGameState(_newGame, edge, repository), "Transition failed"); _player2 = GameService.FindPlayer("15022967466", repository); GameService.AddPlayerToGame(_player2, _newGame, repository); } }
static void Main(string[] args) { using (var repository = new TelephoneGameRepository()) { // New Game Player player1 = GameService.FindPlayer("15022967010", repository); Game newGame = GameService.CreateNewGame<TwoPlayersOriginal>(player1, repository); Console.WriteLine(string.Format("{0} is starting the game", player1.Name)); // Pick Player EdgeConditional edge = newGame.Edges.First<EdgeConditional>(e => e.nextNode.GetType().Name.Equals("PickPlayer")); GameService.TransitionGameState(newGame, edge, repository); Player player2 = null; while (null == player2) { PrintPlayers(repository); Console.WriteLine("Pick a player by entering a phone number:"); string phonenumber = Console.ReadLine(); player2 = GameService.FindPlayer(phonenumber, repository); } GameService.AddPlayerToGame(player2, newGame, repository); Choices(newGame, repository); GamePhrase phrase = null; while (null == phrase) { PrintPhrases(repository); Console.WriteLine("Pick a phrase by choosing the number:"); string number = Console.ReadLine(); phrase = GameService.GetPhraseList(repository).FirstOrDefault<GamePhrase>(p => p.id.Equals(int.Parse(number))); } GameService.PickPhraseForGame(phrase, newGame, repository); while (true) { Choices(newGame, repository); } } }
static void Choices(Game game, TelephoneGameRepository repository) { bool success = false; while (!success) { int choice = -1; while (-1 == choice) { foreach (EdgeConditional edge in game.Edges) { Console.WriteLine(string.Format("{0}: {1}", edge.id, edge.text)); } Console.WriteLine("Choose: "); int.TryParse(Console.ReadLine(), out choice); } EdgeConditional chosenEdge = game.Edges.First<EdgeConditional>(e => e.id.Equals(choice)); success = GameService.TransitionGameState(game, chosenEdge, repository); if (!success) Console.WriteLine("Could not transition state"); } }
public void SetupTests() { using (var repository = new TelephoneGameRepository()) { bool success; _player1 = GameService.FindPlayer("15022967010", repository); _newGame = GameService.CreateNewGame<TwoPlayersOriginal>(_player1, repository); Assert.That(null != _newGame, "Game not created"); success = GameService.TransitionGameState(_newGame, _newGame.Edges[0], repository); Assert.That(success, string.Format("Couldn't transition to {0}", _newGame.Edges[0].nextNode.routeName)); _player2 = GameService.FindPlayer("15022967466", repository); GameService.AddPlayerToGame(_player2, _newGame, repository); Assert.That(_newGame.enoughPlayers, "not enough players added"); success = GameService.TransitionGameState(_newGame, _newGame.Edges[0], repository); Assert.That(success, string.Format("Couldn't transition to {0}", _newGame.Edges[0].nextNode.routeName)); } }
public void CheckPhraseChosen_Success() { using (var repository = new TelephoneGameRepository()) { Game game = _game4; bool success = GameService.TransitionGameState(game, game.Edges[1], repository); Assert.That(success, "Couldn't transition"); Assert.That(game.Edges[0].GetType() == typeof(CheckPhraseChosen), "This edge is not a CheckPhraseChosen"); var phrase = new GamePhrase(); GameService.PickPhraseForGame(phrase, game, repository); success = GameService.TransitionGameState(game, game.Edges[0], repository); Assert.That(success, "Couldn't transition along CheckPhraseChosen edge"); } }
internal void PickPhrase(GamePhrase phrase, TelephoneGameRepository repository) { _gamePhrase = phrase; }
internal void AddPlayer(Player player, TelephoneGameRepository repository) { if (_players.Count >= gameType.maxNumberOfPlayers) { throw new Exception(string.Format("Cannot add more than the maximum number of players for this game type: {0}", gameType.maxNumberOfPlayers)); } if (null != _players.Values.FirstOrDefault<Player>(p => p.ID == player.ID)) { throw new Exception("Player is already added to this game!"); } _players[_nextPlayerNumber++] = player; }
public abstract bool Transition(Game game, TelephoneGameRepository repository);
public void SetupTests() { using (var repository = new TelephoneGameRepository()) { _player1 = GameService.FindPlayer("15022967010", repository); _player2 = GameService.FindPlayer("15022967466", repository); _game1 = GameService.CreateNewGame<TestingGameType>(_player1, repository); _game2 = GameService.CreateNewGame<TestingGameType>(_player1, repository); _game3 = GameService.CreateNewGame<TestingGameType>(_player1, repository); _game4 = GameService.CreateNewGame<TestingGameType>(_player1, repository); _game5 = GameService.CreateNewGame<TestingGameType>(_player1, repository); _game6 = GameService.CreateNewGame<TestingGameType>(_player1, repository); Assert.That(null != _game1, "Game1 not created"); Assert.That(null != _game2, "Game2 not created"); Assert.That(null != _game3, "Game3 not created"); Assert.That(null != _game4, "Game4 not created"); Assert.That(null != _game5, "Game4 not created"); Assert.That(null != _game6, "Game4 not created"); } }
static void PrintPlayers(TelephoneGameRepository repository) { foreach(Player p in GameService.GetRecentPlayers(repository)) { Console.WriteLine(string.Format("{0} {1}", p.Name, p.TelephoneNumber.Number)); } }