//if the player disconnects midgame, the other player should be declared the winner public void surrenderByDisconnect(Server.Client disconnectedClient) { if (!isAI_Game) { Server.Client winner = (disconnectedClient == player1.playerClient) ? player2.playerClient : player1.playerClient; winner.sw.WriteLine("victory"); gameOver = true; player1.playerClient.inGame = false; player2.playerClient.inGame = false; } }
public Player(Server.Client playerClient) { mana = 2; maxMana = 2; this.playerClient = playerClient; }
public Game(Server.Client client1, Server.Client client2, DataManager dm, bool isAI_Game) { this.dm = dm; this.isAI_Game = isAI_Game; player1 = new Player(client1); player1.playerAllegiance = Unit.Allegiance.PLAYER_1; player2 = new Player(client2); player2.playerAllegiance = Unit.Allegiance.PLAYER_2; players = new Player[2]; players[0] = player1; players[1] = player2; gameOver = false; gameThread = new Thread(new ThreadStart(this.gameLoop)); String setupString = "spawnPieces"; board = new GameBoard(this); setupString += board.SetBoard(player1.playerClient.clientName, player1.playerClient.boardSetup , player2.playerClient.clientName, player2.playerClient.boardSetup , dm); player1.isMyTurn = true; if (!isAI_Game) { client1.sw.WriteLine("startGame\\1"); client2.sw.WriteLine("startGame\\2"); } else { client1.sw.WriteLine("startAI"); } string treeString = board.spawnTrees(); string rockString = board.SpawnRocks(); client1.sw.WriteLine("spawnTrees{0}", treeString); client1.sw.WriteLine("spawnRocks{0}", rockString); if (!isAI_Game) { client2.sw.WriteLine("spawnTrees{0}", treeString); client2.sw.WriteLine("spawnRocks{0}", rockString); } client1.sw.WriteLine(setupString); if (!isAI_Game) { client2.sw.WriteLine(setupString); } //We need to send each player the position of each unit on the board //player2's setups //send the tooltips SQLiteDataReader reader = dm.getTooltips(client1.clientName, 3); string tooltip = "showTip\\" + reader["tooltipID"]; string showTip = "" + reader["showTip"]; if (showTip.Equals("True")) { client1.sw.WriteLine(tooltip); } reader = dm.getTooltips(client2.clientName, 3); tooltip = "showTip\\" + reader["tooltipID"]; showTip = "" + reader["showTip"]; if (showTip.Equals("True")) { client2.sw.WriteLine(tooltip); } Console.WriteLine("Game between " + player1.playerClient.clientName + " and " + player2.playerClient.clientName + " has started."); //Console.WriteLine(" It is {0} 's turn", client1.clientName); }