/// <summary> /// Builds a new Boggle Game form - the main component of the BoggleClient GUI /// </summary> /// <param name="_conn"> The player's Boggle Connection</param> /// <param name="_name">The player's name</param> public GameForm(BoggleConnection _conn, String _name) { InitializeComponent(); conn = _conn; //register the event handlers conn.GameStarted += StartReceived; conn.GameEnded += StopReceived; conn.GameTerminated += TerminateReceived; conn.ScoreChanged += ScoreReceived; conn.TimeChanged += TimeReceived; conn.ServerLost += LostServer; //normalize player name for nice display _name = _name.ToLower(); name = _name[0].ToString().ToUpper() + _name.Substring(1); //update labels, initialize board, set up buttons P1ScoreLabel.Text = name; P2ScoreLabel.Text = "Waiting..."; this.FormClosing += ExitApplication; BoardButtons = new Dictionary <int, Button>(); FillBoardButtons(); ButtonsUsed = false; GameStarted = false; WordBox.Focus(); this.AcceptButton = PlayButton; }
private void gameStarted(BoggleConnection conn) { p1Op = conn.oppName; p1Letters = conn.BoardLetters; conn.SendWord("aaa"); }
public void run() { BoggleServer.BoggleServer server = new BoggleServer.BoggleServer(3, "..\\..\\customDic.txt", BoardLetters); BoggleConnection conn1 = new BoggleConnection("localhost", "P1"); BoggleConnection conn2 = new BoggleConnection("localhost", "P2"); conn1.ServerLost += p1LostServer; conn2.ServerLost += p2LostServer; conn1.Connect(); conn2.Connect(); Thread.Sleep(1000); server.Close(); while (!p1Lost && !p2Lost) { Thread.Sleep(10); } Assert.AreEqual(true, p1Lost); Assert.AreEqual(true, p2Lost); server.Close(); }
public void run() { BoggleServer.BoggleServer server = new BoggleServer.BoggleServer(1, "..\\..\\customDic.txt", sixteenAs); BoggleConnection conn = new BoggleConnection("localhost", "p1"); conn.GameStarted += gameStarted; conn.ScoreChanged += scoreChanged1; conn.TimeChanged += timechanged1; conn.GameEnded += gameEnded1; conn.Connect(); BoggleConnection conn2 = new BoggleConnection("localhost", "p2"); conn2.GameStarted += gameStarted2; conn2.ScoreChanged += scoreChanged2; conn2.GameEnded += gameEnded2; conn2.Connect(); Thread.Sleep(1200); Assert.AreEqual("P2", p1Op); Assert.AreEqual("P1", p2Op); Assert.AreEqual(sixteenAs, p1Letters); Assert.AreEqual(sixteenAs, p2Letters); Assert.AreEqual("1 0", p1score1); Assert.AreEqual("0 1", p2score1); Thread.Sleep(1000); Assert.AreEqual("1 AAA 0 0 0 0", p1Summary); Assert.AreEqual("0 1 AAA 0 0 0", p2Summary); server.Close(); }
private void scoreChanged1(BoggleConnection conn) { if (!p1ScoreSet) { p1score1 = conn.Score; p1ScoreSet = true; } }
private void scoreChanged2(BoggleConnection conn) { if (!p2ScoreSet) { p2score1 = conn.Score; p2ScoreSet = true; } }
/// <summary> /// Does as the name implies. Disconnects the BoggleConnection, hides the current window, shows the summary. /// </summary> /// <param name="conn"></param> private void EndTheGame(BoggleConnection conn) { Summary summary = new Summary(conn.Summary, name, oppName, P1ScoreBox.Text, P2ScoreBox.Text, conn.Ip); conn.Disconnect(); this.Hide(); summary.ShowDialog(); }
private void timechanged1(BoggleConnection conn) { if (!timeSet) { time1 = conn.TimeLeft; timeSet = true; } }
/// <summary> /// Helper method to update time remaining after an event handler is notified to do so. /// </summary> /// <param name="conn"></param> private void UpdateTime(BoggleConnection conn) { int sec; Int32.TryParse(conn.TimeLeft, out sec); TimeSpan timeLeft = new TimeSpan(0, 0, sec); TimeLabel.Text = String.Format("{0:D2}:{1:D2}", timeLeft.Minutes, timeLeft.Seconds); }
/// <summary> /// Helper method to update scores after an event handler is notified to do so. /// </summary> /// <param name="conn"></param> private void UpdateScore(BoggleConnection conn) { String[] scores = conn.Score.Split(' '); lock (scoreLock) { P1ScoreBox.Text = scores[0]; P2ScoreBox.Text = scores[1]; } }
/// <summary> /// Does as the name implies. Populates the board with letters, displays opponent name, prepares word box for word sending. /// </summary> /// <param name="conn"></param> private void startTheGame(BoggleConnection conn) { GameStarted = true; TimeLabel.Text = conn.TimeLeft; populateBoard(conn.BoardLetters); string opponentName = conn.oppName.ToLower(); oppName = opponentName[0].ToString().ToUpper() + opponentName.Substring(1); P2ScoreLabel.Text = oppName; WordBox.Enabled = true; }
private void PlayButton_Click(object sender, EventArgs e) { try { conn = new BoggleConnection(IPAddrBox.Text, NameBox.Text); GameForm game = new GameForm(conn, NameBox.Text); this.Hide(); game.ShowDialog(); } catch (BoggleConnectionException) { MessageBox.Show("Could not connect to a Boggle Server at the specified IP Address", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); IPAddrBox.Text = ""; updatePlayButton(); } }
/// <summary> /// Called when one of the players terminates or becomes disconnected in the middle of the game /// </summary> /// <param name="conn"></param> private void TerminateTheGame(BoggleConnection conn, String reason) { DialogResult result = MessageBox.Show(reason + " disconnected. Play again?", "Game Terminated", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.Yes) { this.Dispose(); this.Hide(); Prompt replay = new Prompt(name, conn.Ip); replay.ShowDialog(); conn.Disconnect(); } else { conn.Disconnect(); this.Close(); } }
public void run() { BoggleServer.BoggleServer server = new BoggleServer.BoggleServer(1, "..\\..\\customDic.txt", BoardLetters); BoggleConnection P1conn = new BoggleConnection("localhost", "p1"); P1conn.GameTerminated += p1terminated; P1conn.Connect(); BoggleConnection P2conn = new BoggleConnection("localhost", "p2"); P2conn.GameTerminated += p2terminated; P2conn.Connect(); Thread.Sleep(100); P1conn.Disconnect(); Thread.Sleep(1000); Assert.AreEqual(false, p1ReceivedTERMINATED); Assert.AreEqual(true, p2ReceivedTERMINATED); server.Close(); }
private void p2LostServer(BoggleConnection conn) { p2Lost = true; }
/// <summary> /// Event handler for when the server is lost or unavailable /// </summary> /// <param name="conn"></param> private void LostServer(BoggleConnection conn) { try { Invoke((Action)(() => { HandleLostServer(conn); })); } catch (ObjectDisposedException) { } }
private void p2terminated(BoggleConnection conn) { p2ReceivedTERMINATED = conn.gameTerminated; }
public void run() { BoggleConnection invalid = new BoggleConnection("badIP", "player1"); // don't have to disconnect because connection not made }
private void gameStarted2(BoggleConnection conn2) { p2Op = conn2.oppName; p2Letters = conn2.BoardLetters; }
/// <summary> /// helper method to terminate game /// </summary> /// <param name="conn"></param> private void HandleLostServer(BoggleConnection conn) { TerminateTheGame(conn, "The Server"); }
/// <summary> /// Event handler for when the 'STOP' message is received /// </summary> /// <param name="conn"></param> private void StopReceived(BoggleConnection conn) { try { Invoke((Action)(() => { EndTheGame(conn); })); } catch (ObjectDisposedException) { } }
/// <summary> /// Event handler for when the time changes via 'TIME' message /// </summary> /// <param name="conn"></param> private void TimeReceived(BoggleConnection conn) { try { Invoke((Action)(() => { UpdateTime(conn); })); } catch (ObjectDisposedException) { } }
private void gameEnded2(BoggleConnection conn) { p2Summary = conn.Summary; }
/// <summary> /// Event handler for when the 'TERMINATE' message is recieved /// </summary> /// <param name="conn"></param> private void TerminateReceived(BoggleConnection conn) { try { Invoke((Action)(() => { TerminateTheGame(conn, oppName); })); } catch (ObjectDisposedException) { } }