Example #1
0
        public void TestMethod1()
        {
            BoggleServer.BoggleServer bServ = new BoggleServer.BoggleServer(60, new HashSet<string>(System.IO.File.ReadAllLines(@"..\..\..\Resources\Dictionary.txt")), "horstoaeaggdpple");
            
            BoggleClientModel model1 = new BoggleClientModel();
            BoggleClientModel model2 = new BoggleClientModel();
            model1.Connect("localhost", 2000);
            model2.Connect("localhost", 2000);

            Assert.IsFalse(model1._client == null);
            Assert.IsFalse(model1._stringSocket == null);

            model1.SendCommand("PLAY Frodo");
            model2.SendCommand("PLAY Sam");

            model2.IncomingLineEvent += messageReceived;

            Assert.AreEqual(" ", BoggleClientTest.received);

            model1.Disconnect();
            model2.Disconnect();

            Assert.IsTrue(model1._stringSocket == null);
            Assert.IsTrue(model2._stringSocket == null);

        }
Example #2
0
 public void Initialize()
 {
     model = new BoggleClientModel();
         model2 = new BoggleClientModel();
         server = new BoggleServer.BoggleServer(2000, 2, "..\\..\\..\\dictionary", null);
         model.Connect(2000, "localhost");
         model2.Connect(2000, "localhost");
         //Assert.IsTrue(model.IsConnected);
 }
Example #3
0
        /// <summary>
        /// Event handler for the connect click
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">exception</param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //Check to make sure user put in a username
            if (!String.IsNullOrEmpty(userNameTextbox.Text) && !String.IsNullOrEmpty(ServerAddress.Text))
            {
                //Check to see if connection works
                if (!clientModel.Connect(ServerAddress.Text, 2000, userNameTextbox.Text))
                {
                    MessageBox.Show("Failed connection.");
                    return;
                }

                //Save client model in properties so that the other pages may access it
                Application.Current.Properties["clientModel"] = clientModel;
                Switcher.Switch(new WaitingForResponse());
            }
        }
        /// <summary>
        /// Connects the game to the given server, else disconnects
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void connectionButton_Click(object sender, EventArgs e)
        {
            if (!isConnected) // connects game to server
            {
                string server = serverTextBox.Text;
                string player = nameTextBox.Text;

                // REMOVED FOR BUTTON TESTING ONLY ********************************************************
                model.Connect(server, player);
                // REMOVED FOR BUTTON TESTING ONLY ********************************************************

                // We need to test that it is connected

                // update connection button
                connectionButton.Invoke(new Action(() => connectionButton.Text = "Disconnect"));
                isConnected = true;

                // hide unnecessary fields
                serverLabel.Invoke(new Action(() => serverLabel.Visible     = false));
                serverTextBox.Invoke(new Action(() => serverTextBox.Visible = false));

                // update name label
                nameLabel.Invoke(new Action(() => nameLabel.Text        = player));
                nameTextBox.Invoke(new Action(() => nameTextBox.Visible = false));

                // clear score, time, and wordbox
                wordTextBox.Invoke(new Action(() => wordTextBox.Text = ""));
                scoreLabel.Invoke(new Action(() => scoreLabel.Text   = "Score: 0"));
                opponentScoreLabel.Invoke(new Action(() => opponentScoreLabel.Text = "Score: 0"));


                // TESTING PURPOSE ONLY *******************************************************************
                //setupGame("    ABCDEFGHJKLMNOPQ    60    Player 2   ");
                //updateScore("    5   7   ");
                //terminate(null);
                //summary("3 cat dog bird 3 mouse frog horse 2 common words 2 aaa bbb 2 ccc ddd");
                // TESTING PURPOSE ONLY *******************************************************************
            }
            else  // disconnects game from the server
            {
                disconnect();
                model.Disconnect();
            }
        }
Example #5
0
        public void TestSimpleGame()
        {
            // Create two clients.
            BoggleClientModel client1 = new BoggleClientModel();
            BoggleClientModel client2 = new BoggleClientModel();

            // Connect the clients.
            client1.Connect("localhost", 2000, "Harry");
            client2.Connect("localhost", 2000, "Hermione");

            // Check start messages.
            Thread.Sleep(100);
            Assert.AreEqual("START TESRRDELEAOBSINM 5 HERMIONE", client1.msgString);
            Assert.AreEqual("START TESRRDELEAOBSINM 5 HARRY", client2.msgString);

            // Send words, and check the score messages:

            client1.SendGoMessage("read");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 1 0", client1.msgString);
            Assert.AreEqual("SCORE 0 1", client2.msgString);

            client2.SendGoMessage("reads");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 1 2", client1.msgString);
            Assert.AreEqual("SCORE 2 1", client2.msgString);

            // Send a word already played by other player
            client2.SendGoMessage("read");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 0 2", client1.msgString);
            Assert.AreEqual("SCORE 2 0", client2.msgString);

            // Send an invalid word
            client2.SendGoMessage("asdfjkl");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 0 1", client1.msgString);
            Assert.AreEqual("SCORE 1 0", client2.msgString);

            // Make time run out, then check game summary messages.
            Thread.Sleep(6000);
            Assert.AreEqual("STOP 0 1 READS 1 READ 0 1 ASDFJKL", client1.msgString); 
            Assert.AreEqual("STOP 1 READS 0 1 READ 1 ASDFJKL 0", client2.msgString);
        }
Example #6
0
        public void TestIllegalWords()
        {
            // Create two clients.
            BoggleClientModel client1 = new BoggleClientModel();
            BoggleClientModel client2 = new BoggleClientModel();

            // Connect the clients.
            client1.Connect("localhost", 2000, "Harry");
            client2.Connect("localhost", 2000, "Hermione");
            Thread.Sleep(100);

            // Send words, and check the score messages:

            client1.SendGoMessage("asdfjkl");
            client1.SendGoMessage("re");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE -1 0", client1.msgString);
            Assert.AreEqual("SCORE 0 -1", client2.msgString);
        }
Example #7
0
        /// <summary>
        /// Tries to connect the client to the server.
        /// If an error occurs, a message box appears.
        /// </summary>
        private void Connect()
        {
            if (Name_Text_Box.Text.Trim().Length == 0)
            {
                MessageBox.Show("Invalid Name. Please enter one or more characters.", "Invalid Input");
                return;
            }

            try
            {
                model.Connect(IPAddress_Text_Box.Text, 2000, Name_Text_Box.Text);
            }
            catch
            {
                MessageBox.Show("Invalid IP Address. Please try again.", "Invalid Input");
                return;
            }

            // Close this window and open the game window.

            new GameWindow(model).Show();
            this.Close();
        }
            public void run()
            {
                try
                {
                    //setup server
                    server = new BoggleServer(10, "dictionary.txt");

                    //setup clients
                    BoggleClientModel target = new BoggleClientModel();
                    string IPAddress = "127.0.0.1";
                    string name = "test";

                    BoggleClientModel target2 = new BoggleClientModel();
                    string name2 = "test2";

                    target.IncomingTimeEvent += delegate(string line)
                    {
                        MRE.Set();
                    };

                    target2.IncomingTimeEvent += delegate(string line)
                    {
                        MRE1.Set();
                    };

                    //connect the clients
                    target.Connect(IPAddress, name);
                    target2.Connect(IPAddress, name2);

                    //trigger event
                    Thread.Sleep(1000);

                    Assert.AreEqual(true, MRE.WaitOne(timeout), "Timed out waiting 1");
                    Assert.AreEqual(true, MRE1.WaitOne(timeout), "Timed out waiting 2");
                }
                finally
                {
                    server.close();
                }
            }
            public void run()
            {
                try{
                //setup server
                server  = new BoggleServer(80, "dictionary.txt");

                //setup client
                BoggleClientModel target = new BoggleClientModel();
                string IPAddress = "garbageAddress";
                string name = "test";

                target.noSuchHostEvent += delegate(string line)
                {
                    MRE.Set();
                };

                //trigger event
                target.Connect(IPAddress, name);

                Assert.AreEqual(true, MRE.WaitOne(timeout), "Timed out waiting 1");
                }
                finally
                {server.close();}
            }
Example #10
0
        /// <summary>
        /// on clicking the submit button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SubmitClick(object sender, RoutedEventArgs e)
        {
            if (Input.Text == "" && model.state != State.wait)
            {
                return;
            }
            Input.Text = Input.Text.ToUpper();
            switch (model.state)
            {
            case State.iP:
                try
                {
                    model.Connect(2000, Input.Text);
                    Status.Dispatcher.Invoke(() => { Status.Text = "Connected. Please input your name."; saveIP = Input.Text;  Input.Text = ""; Input.Focus(); });
                }
                catch (Exception ee)
                {
                    Status.Dispatcher.Invoke(() => { Status.Text = "Not able to connect. Please enter an IP address for an active Boggle server."; Input.Text = saveIP; Input.Focus(); });
                    model.state = State.iP;
                    //throw ee;
                }

                break;

            case State.name:
                //sends whatever is in input
                Input.Text = Input.Text.Replace(" ", "");
                hermes.RunWorkerAsync(Input.Text);
                name1.Text = Input.Text;
                Status.Dispatcher.Invoke(() => { Status.Text = "Please wait for another player."; SubmitButton.Content = "Cancel"; Input.Text = ""; Input.IsEnabled = false; });
                break;

            case State.wait:
                Status.Dispatcher.Invoke(() =>
                {
                    TimeLeft.Text = "0";
                    name1.Text    = "name1";
                    name2.Text    = "name2";
                    Score1.Text   = "score1";
                    Score2.Text   = "score2";
                    Input.Text    = saveIP;
                    wordset.Clear();
                    Status.Text   = "Welcome to Boggle. Please input the IP address for a Boggle server.";
                    Wordlist.Text = "";
                    foreach (TextBlock tile in BoardView.Children)
                    {
                        tile.Text = "";
                    }
                    model.state          = State.iP;
                    SubmitButton.Content = "Submit";
                    Input.IsEnabled      = true;
                    model.closeSocket();
                });
                break;

            case State.game:
                // Use to add a word to the Wordlist displayed, it adds e and a new line
                hermes.RunWorkerAsync(Input.Text);
                break;

            default:

                break;
            }
        }
Example #11
0
        public void TwoGames()
        {
            // Create four clients.
            BoggleClientModel client1 = new BoggleClientModel();
            BoggleClientModel client2 = new BoggleClientModel();
            BoggleClientModel client3 = new BoggleClientModel();
            BoggleClientModel client4 = new BoggleClientModel();

            // Connect the clients.
            client1.Connect("localhost", 2000, "Harry");
            client2.Connect("localhost", 2000, "Hermione");
            client3.Connect("localhost", 2000, "Ron");
            client4.Connect("localhost", 2000, "Crookshanks");
            Thread.Sleep(1000);

            // Send words.
            client2.SendGoMessage("load");
            client3.SendGoMessage("reads");
            client1.SendGoMessage("invalid");
            client4.SendGoMessage("read");
            client1.SendGoMessage("loads");
            client3.SendGoMessage("xxx");
            client4.SendGoMessage("reads");

            // Check scores.
            Thread.Sleep(200);
            Assert.AreEqual("SCORE 1 1", client1.msgString);
            Assert.AreEqual("SCORE 1 1", client2.msgString);
            Assert.AreEqual("SCORE -1 1", client3.msgString);
            Assert.AreEqual("SCORE 1 -1", client4.msgString);

            // Make time run out, then check game summary messages.
            Thread.Sleep(6000);
            Assert.AreEqual("STOP 1 LOADS 1 LOAD 0 1 INVALID 0", client1.msgString);
            //Assert.AreEqual("STOP 1 LOAD 1 LOADS 0 0 1 INVALID", client2.msgString);
            Assert.AreEqual("STOP 0 1 READ 1 READS 1 XXX 0", client3.msgString);
            //Assert.AreEqual("STOP 1 READ 0 1 READS 0 1 XXX", client4.msgString);
        }
Example #12
0
        public void TestTerminated()
        {
            // Create two clients.
            BoggleClientModel client1 = new BoggleClientModel();
            BoggleClientModel client2 = new BoggleClientModel();

            // Connect the clients.
            client1.Connect("localhost", 2000, "Harry");
            client2.Connect("localhost", 2000, "Hermione");
            Thread.Sleep(100);

            client1.disconnect();
            Thread.Sleep(100);

            Assert.AreEqual("TERMINATED", client2.msgString);
        }
Example #13
0
        public void TestLargePointWords()
        {
            // Create two clients.
            BoggleClientModel client1 = new BoggleClientModel();
            BoggleClientModel client2 = new BoggleClientModel();

            // Connect the clients.
            client1.Connect("localhost", 2000, "Harry");
            client2.Connect("localhost", 2000, "Hermione");
            Thread.Sleep(100);

            // Send words and check scores.

            client1.SendGoMessage("reloader");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 11 0", client1.msgString);
            Assert.AreEqual("SCORE 0 11", client2.msgString);

            client1.SendGoMessage("RELOAD");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 14 0", client1.msgString);
            Assert.AreEqual("SCORE 0 14", client2.msgString);

            client2.SendGoMessage("reload");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 11 0", client1.msgString);
            Assert.AreEqual("SCORE 0 11", client2.msgString);

            client2.SendGoMessage("ReLoaDS");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 11 5", client1.msgString);
            Assert.AreEqual("SCORE 5 11", client2.msgString);

            // Make time run out, then check game summary messages.
            Thread.Sleep(6000);
            Assert.AreEqual("STOP 1 RELOADER 1 RELOADS 1 RELOAD 0 0", client1.msgString);
            Assert.AreEqual("STOP 1 RELOADS 1 RELOADER 1 RELOAD 0 0", client2.msgString);
        }
Example #14
0
        public void TestIgnoringWord()
        {
            // Create two clients.
            BoggleClientModel client1 = new BoggleClientModel();
            BoggleClientModel client2 = new BoggleClientModel();

            // Connect the clients.
            client1.Connect("localhost", 2000, "Harry");
            client2.Connect("localhost", 2000, "Hermione");

            // Check start messages.
            Thread.Sleep(50);
            Assert.AreEqual("START TESRRDELEAOBSINM 5 HERMIONE", client1.msgString);
            Assert.AreEqual("START TESRRDELEAOBSINM 5 HARRY", client2.msgString);

            // Send words, and check IGNORING messages:

            client1.SendGoMessage("");
            Thread.Sleep(100);
            Assert.AreEqual("IGNORING WORD ", client1.msgString);

            client1.SendGoMessage(" ");
            Thread.Sleep(100);
            Assert.AreEqual("IGNORING WORD  ", client1.msgString);
        }