private void GameBoard_BoardFinished(object sender, TTTBoard.BoardFinishedEventArgs e) { var board = e.Board; if (e.CrossWin) { f1.Add(totalgamenumber + 2, $"Crosses ({CPlayer.Name}) wins!"); f1.Add(0, $"Round {roundnumber} Game {roundgamenumber}: {CPlayer.Name} beat {NPlayer.Name}"); tournamentin.SpectatorMessage($"Round {roundnumber} Game {roundgamenumber}: {CPlayer.Name} beat {NPlayer.Name}"); CPlayer.Send("You win"); NPlayer.Send("You lose"); won = CPlayer; if (Program.AllPlayers.Contains(NPlayer)) { Program.AllPlayers.Remove(NPlayer); } f1.RemovePlayer(NPlayer.Name, roundgamenumber.ToString(), roundnumber.ToString()); f1.FinishedGame(totalgamenumber + 2); SpectatorUpdate(); BT.Start(); } else if (e.Draw) { f1.Add(totalgamenumber + 2, "Draw!"); GameBoard = new TTTBoard(); GameBoard.BoardFinished += GameBoard_BoardFinished; GameBoard.gamenumber = totalgamenumber; GameBoard.f1 = f1; GameBoard.Game = this; if (Program.Quick == true) { drawcount++; if (drawcount == drawsallowed) { TieBreaker = true; f1.Add(totalgamenumber + 2, $"{CPlayer.Name} and {NPlayer.Name} go into tie breaker"); CPlayer.Send("Tie"); NPlayer.Send("Tie"); SpectatorUpdate(); dt.Start(); } else { CPlayer.Send("draw"); NPlayer.Send("draw"); DrawnGame(); // this determines who's go it is. CheckLastDraw(); SpectatorUpdate(); } } else { CPlayer.Send("draw"); NPlayer.Send("draw"); DrawnGame(); // this determines who's go it is. CheckLastDraw(); SpectatorUpdate(); } } else if (e.NoughtWin) { f1.Add(totalgamenumber + 2, $"Nought ({NPlayer.Name}) win!"); f1.Add(0, $"Round {roundnumber} Game {roundgamenumber}: {NPlayer.Name} beat {CPlayer.Name}"); tournamentin.SpectatorMessage($"Round {roundnumber} Game {roundgamenumber}: {NPlayer.Name} beat {CPlayer.Name}"); NPlayer.Send("You win"); CPlayer.Send("You lose"); won = NPlayer; if (Program.AllPlayers.Contains(CPlayer)) { Program.AllPlayers.Remove(CPlayer); } f1.RemovePlayer(CPlayer.Name, roundgamenumber.ToString(), roundnumber.ToString()); f1.FinishedGame(totalgamenumber + 2); SpectatorUpdate(); BT.Start(); } }
public void DisconnectPlayer(bool kicked) { try { if (!Connected || spectator != null) // prevents spam on player leave. { return; } if (GameIn == null) { f1.Add(0, Name + " has left"); if (Program.AllPlayers.Contains(this)) { Program.AllPlayers.Remove(this); } if (Tournamentin != null) { if (Tournamentin.Winners.Contains(this)) { Tournamentin.Winners.Remove(this); } } Program.f1.Invoke((MethodInvoker) delegate { Program.AllPlayersnames.Remove(Name); Program.f1.numberplay.Text = (Program.AllPlayers.Count.ToString()); }); f1.RemovePlayer(Name, "", ""); } else { if (kicked == false) { if (GameIn.gamefinshed == false && GameIn.won == null) { f1.Add(0, Name + " has left"); if (Program.AllPlayers.Contains(this)) { Program.AllPlayers.Remove(this); } Program.AllPlayersnames.Remove(Name); GameIn.gamefinshed = true; Connected = false; oppopent.Send("Opponent left"); f1.Add(GameIn.totalgamenumber + 2, $"{Name} quit, {oppopent.Name} wins"); f1.Add(0, $"Round {GameIn.totalgamenumber} Game {GameIn.roundgamenumber}: {oppopent.Name} beat {Name}"); Tournamentin.SpectatorMessage($"Round {GameIn.roundnumber} Game {GameIn.roundgamenumber}: {oppopent.Name} beat {Name}"); GameIn.won = oppopent; f1.RemovePlayer(Name, GameIn.roundgamenumber.ToString(), GameIn.roundnumber.ToString()); f1.FinishedGame(GameIn.totalgamenumber + 2); try { recicivedataThread.Abort(); } catch (Exception) { } } else { if (Tournamentin.Winners.Contains(this)) { Tournamentin.Winners.Remove(this); } if (Program.AllPlayers.Contains(this)) { Program.AllPlayers.Remove(this); } Program.AllPlayersnames.Remove(Name); f1.RemovePlayer(Name, GameIn.roundgamenumber.ToString(), GameIn.roundnumber.ToString()); } } else { f1.Add(0, Name + " has been kicked for inactivity"); if (Program.AllPlayers.Contains(this)) { Program.AllPlayers.Remove(this); } Program.AllPlayersnames.Remove(Name); GameIn.gamefinshed = true; Connected = false; oppopent.Send("Opponent left"); f1.Add(GameIn.totalgamenumber + 2, $"{Name} was kicked for inactivity, {oppopent.Name} wins"); f1.Add(0, $"Round {GameIn.totalgamenumber} Game {GameIn.roundgamenumber}: {oppopent.Name} beat {Name}"); Tournamentin.SpectatorMessage($"Round {GameIn.roundnumber} Game {GameIn.roundgamenumber}: {oppopent.Name} beat {Name}"); GameIn.won = oppopent; f1.RemovePlayer(Name, GameIn.roundgamenumber.ToString(), GameIn.roundnumber.ToString()); f1.FinishedGame(GameIn.totalgamenumber + 2); try { recicivedataThread.Abort(); } catch (Exception) { } } } } catch (Exception) { } try { if (Program.MASTERLIST?.Enabled ?? false) { Program.MASTERLIST.Update(Program.Server_Name, Program.AllPlayers.Count, false); } } catch (Exception) { //Console.WriteLine("ML error: " + ex.ToString()); } }