/// <summary> /// Removes a player from the table /// </summary> /// <param name="c">the player instance to remove</param> public void nowLeaving(GameClient c) { if (black != null && black.Equals(c)) { black = null; if (red != null) { red.sendMessage(Message.OPP_LEFT_TABLE.ToString()); } seatsOpen++; } else if (red != null && red.Equals(c)) { red = null; if (black != null) { black.sendMessage(Message.OPP_LEFT_TABLE.ToString()); } seatsOpen++; } if (curGame != null) { //if a game was instanciated, tell the game a player quit. //This will make the game close properly. curGame.tsPlayerLeft(c); } }
/// <summary> /// The table says this client has left the table. /// </summary> /// <param name="c">The client quitting the game.</param> public void tsPlayerLeft(GameClient c) { //we just have to check if the game started. If so, send winning messages. if (gameStarted()) { if (c.Equals(red)) { setWinner(black); } else if (c.Equals(black)) { setWinner(red); } else { throw new Exception("Client " + c.getUserName() + " is not playing game " + gid + "!"); } } table.alertGameEnd(); }
/// <summary> /// Tells the game a client is ready. If both are ready, this /// method also starts the game and tells black to move. /// </summary> /// <param name="c">The GameClient instance that is ready</param> public void tsAlertReady(GameClient c) { if (red.Equals(c)) { redRdy = true; } if (black.Equals(c)) { blackRdy = true; } if (redRdy && blackRdy) { resetBoard(); //reset the board red.sendMessage(Message.COLOR_RED); red.sendMessage(Message.GAME_START.ToString()); black.sendMessage(Message.COLOR_BLACK); black.sendMessage(Message.GAME_START.ToString()); black.sendMessage(Message.YOUR_TURN.ToString()); } }
public void alertLeaveLobby(GameClient c) { //we have to be locked from an above method foreach (object o in clients.Values) { GameClient gc = (GameClient)o; if (!gc.Equals(c)) { if (gc.isConnected()) { gc.sendMessage(Message.NOW_LEFT_LOBBY + " " + c.getUserName()); } else { dcList.Add(gc); } } } clearClosedClients(); }
private void setWinner(GameClient c) { if (c.Equals(black)) { black.sendMessage(Message.GAME_WIN); red.sendMessage(Message.GAME_LOSE); if (Program.CUR_PHASE == Program.Phase.FULL) { DBConnection.updateWin(black.getUserName()); DBConnection.updateLoss(red.getUserName()); } } else { red.sendMessage(Message.GAME_WIN); black.sendMessage(Message.GAME_LOSE); if (Program.CUR_PHASE == Program.Phase.FULL) { DBConnection.updateWin(red.getUserName()); DBConnection.updateLoss(black.getUserName()); } } }