public void testMakeUnique() { List<Player> players = new List<Player>(); Player p; p = new HumanPlayer("A"); players.Add(p); p = new HumanPlayer("A"); players.Add(p); p = new HumanPlayer("B"); players.Add(p); p = new HumanPlayer("A"); players.Add(p); PlayerList pl = new PlayerList(); pl.Players = players; pl.makeNamesUnique(); Assert.AreEqual("A", pl.Players[0].Name); Assert.AreEqual("A2", pl.Players[1].Name); Assert.AreEqual("B", pl.Players[2].Name); Assert.AreEqual("A3", pl.Players[3].Name); }
public void testRemovePlayer() { List<Player> players = new List<Player>(); Player p; p = new HumanPlayer("A"); players.Add(p); p = new HumanPlayer("B"); players.Add(p); p = new HumanPlayer("C"); players.Add(p); PlayerList pl = new PlayerList(); pl.Players = players; Assert.AreEqual(3, pl.Players.Count); Assert.AreEqual("A", pl.Players[0].Name); Assert.AreEqual("B", pl.Players[1].Name); Assert.AreEqual("C", pl.Players[2].Name); pl.removePlayer("B"); Assert.AreEqual(2, pl.Players.Count); Assert.AreEqual("A", pl.Players[0].Name); Assert.AreEqual("C", pl.Players[1].Name); }
public void CheckSerialization() { PlayerList playerList = new PlayerList(); Turn turn = new Turn(); DieSet dieSet = new DieSet(); HumanPlayer hp = new HumanPlayer("Test Player Name"); ComputerPlayer cp = new ComputerPlayer("Test Computer Player", new GreedyAIStrategy()); playerList.Players.Add(hp); playerList.Players.Add(cp); dieSet.Roll(); GameState gameState = new GameState(); gameState.Players = playerList; gameState.Turn = turn; XmlSerializer serializer = new XmlSerializer(typeof(GameState)); using (TextWriter writer = new StreamWriter(@"C:\GameStateTest.xml")) { serializer.Serialize(writer, gameState); } }
private void btnStartGame_Click(object sender, EventArgs e) { // Going to send out a GameState object here??? // What is needed by the clients at this point to begin a new game? List<string> connected = YahtzeeNetworking.NetworkUtility.GetConnectedPlayerNames(); GameState game = new GameState(); PlayerList players = new PlayerList(); foreach (string name in YahtzeeNetworking.NetworkUtility.GetConnectedPlayerNames()) { players.Players.Add(new NetworkPlayer(name)); } /* TEST CODE TO SIMULATE NETWORK players.Players.Add(new NetworkPlayer("Test"));*/ players.makeNamesUnique(); game.Players = players; YahtzeeNetworking.NetworkUtility.SendGameState(game); // TEMPORARY -- remove the echoed state //System.Threading.Thread.Sleep(500); //YahtzeeNetworking.NetworkUtility.RemoveGameState(); // END TEMPORARY startGame(game); }
private void startGame(GameState game) { PlayerList myPlayerList = new PlayerList(); foreach (Player player in game.Players.Players) { if (myLocalPlayers.Contains(player.Name)) { myPlayerList.Players.Add(new HumanPlayer(player.Name)); } else if (myAIPlayers.Contains(player.Name)) { //myPlayerList.Players.Add(new ComputerPlayer(player.Name)); // NEED TO GET AI TYPE } else { myPlayerList.Players.Add(new NetworkPlayer(player.Name)); } } foreach (Player player in myPlayerList.Players) { player.ScoreSheet.setupGame("Yahtzee"); } MainForm gameForm = new MainForm(); gameForm.PlayerList.Players = myPlayerList.Players; gameForm.PlayerList.makeNamesUnique(); gameForm.createScoreSheet(); gameForm.isNetworkGame = true; gameForm.Show(); Close(); }