示例#1
0
        /// <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;
        }
示例#2
0
            private void gameStarted(BoggleConnection conn)
            {
                p1Op = conn.oppName;

                p1Letters = conn.BoardLetters;
                conn.SendWord("aaa");
            }
示例#3
0
            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();
            }
示例#4
0
            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();
            }
示例#5
0
 private void scoreChanged1(BoggleConnection conn)
 {
     if (!p1ScoreSet)
     {
         p1score1   = conn.Score;
         p1ScoreSet = true;
     }
 }
示例#6
0
 private void scoreChanged2(BoggleConnection conn)
 {
     if (!p2ScoreSet)
     {
         p2score1   = conn.Score;
         p2ScoreSet = true;
     }
 }
示例#7
0
        /// <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();
        }
示例#8
0
 private void timechanged1(BoggleConnection conn)
 {
     if (!timeSet)
     {
         time1   = conn.TimeLeft;
         timeSet = true;
     }
 }
示例#9
0
        /// <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);
        }
示例#10
0
 /// <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];
     }
 }
示例#11
0
        /// <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;
        }
示例#12
0
 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();
     }
 }
示例#13
0
        /// <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();
            }
        }
示例#14
0
            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();
            }
示例#15
0
 private void p2LostServer(BoggleConnection conn)
 {
     p2Lost = true;
 }
示例#16
0
 /// <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) { }
 }
示例#17
0
 private void p2terminated(BoggleConnection conn)
 {
     p2ReceivedTERMINATED = conn.gameTerminated;
 }
示例#18
0
 public void run()
 {
     BoggleConnection invalid = new BoggleConnection("badIP", "player1");
     // don't have to disconnect because connection not made
 }
示例#19
0
 private void gameStarted2(BoggleConnection conn2)
 {
     p2Op      = conn2.oppName;
     p2Letters = conn2.BoardLetters;
 }
示例#20
0
 /// <summary>
 /// helper method to terminate game
 /// </summary>
 /// <param name="conn"></param>
 private void HandleLostServer(BoggleConnection conn)
 {
     TerminateTheGame(conn, "The Server");
 }
示例#21
0
 /// <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) { }
 }
示例#22
0
 /// <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) { }
 }
示例#23
0
 private void gameEnded2(BoggleConnection conn)
 {
     p2Summary = conn.Summary;
 }
示例#24
0
 /// <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) { }
 }