Example #1
0
        /// <summary>
        /// Opens a game window and adds events to the model
        /// </summary>
        public GameWindow(BoggleClientModel model)
        {
           
            this.model = model;
            this.model.IncomingStartEvent += StartReceived;
            this.model.IncomingStopEvent += StopReceived;
            this.model.IncomingTimeEvent += TimeReceived;
            this.model.IncomingScoreEvent += ScoreReceived;
            this.model.IncomingTerminatedEvent += TerminatedReceived;
            this.model.IncomingTurnEvent += TurnReceived;
            this.model.IncomingErrorEvent += ErrorReceived;
            
            InitializeComponent();
            
            word_text_box.IsEnabled = false;
            send_word_button.IsEnabled = false;

            // Assign RenderTransform property for each letter image.
            letter_image1.RenderTransform = rt;
            letter_image2.RenderTransform = rt1;
            letter_image3.RenderTransform = rt2;
            letter_image4.RenderTransform = rt3;
            letter_image5.RenderTransform = rt;
            letter_image6.RenderTransform = rt1;
            letter_image7.RenderTransform = rt2;
            letter_image8.RenderTransform = rt3;
            letter_image9.RenderTransform = rt;
            letter_image10.RenderTransform = rt1;
            letter_image11.RenderTransform = rt2;
            letter_image12.RenderTransform = rt3;
            letter_image13.RenderTransform = rt;
            letter_image14.RenderTransform = rt1;
            letter_image15.RenderTransform = rt2;
            letter_image16.RenderTransform = rt3;
        }
Example #2
0
        /// <summary>
        /// Opens a game window and adds events to the model
        /// </summary>
        public GameWindow(BoggleClientModel model)
        {
            this.model = model;
            this.model.IncomingStartEvent      += StartReceived;
            this.model.IncomingStopEvent       += StopReceived;
            this.model.IncomingTimeEvent       += TimeReceived;
            this.model.IncomingScoreEvent      += ScoreReceived;
            this.model.IncomingTerminatedEvent += TerminatedReceived;
            this.model.IncomingTurnEvent       += TurnReceived;
            this.model.IncomingErrorEvent      += ErrorReceived;

            InitializeComponent();

            word_text_box.IsEnabled    = false;
            send_word_button.IsEnabled = false;

            // Assign RenderTransform property for each letter image.
            letter_image1.RenderTransform  = rt;
            letter_image2.RenderTransform  = rt1;
            letter_image3.RenderTransform  = rt2;
            letter_image4.RenderTransform  = rt3;
            letter_image5.RenderTransform  = rt;
            letter_image6.RenderTransform  = rt1;
            letter_image7.RenderTransform  = rt2;
            letter_image8.RenderTransform  = rt3;
            letter_image9.RenderTransform  = rt;
            letter_image10.RenderTransform = rt1;
            letter_image11.RenderTransform = rt2;
            letter_image12.RenderTransform = rt3;
            letter_image13.RenderTransform = rt;
            letter_image14.RenderTransform = rt1;
            letter_image15.RenderTransform = rt2;
            letter_image16.RenderTransform = rt3;
        }
Example #3
0
 /// <summary>
 /// This is the beginning window for the client view.
 /// </summary>
 public MainWindow()
 {
     InitializeComponent();
     IPAddress_Text_Box.Focus();
     
     model = new BoggleClientModel();
 }
Example #4
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 #5
0
        /// <summary>
        /// This is the beginning window for the client view.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            IPAddress_Text_Box.Focus();

            model = new BoggleClientModel();
        }
        /// <summary>
        /// Loads in the client model and sets up a incomingWordEvent handler
        /// </summary>
        public WaitingForResponse()
        {
            InitializeComponent();

            clientModel = (BoggleClientModel)Application.Current.Properties["clientModel"];
            clientModel.incomingWordEvent += HandleGameRequest;
        }
 private void Window_Closed(object sender, EventArgs e)
 {
     if (Application.Current.Properties["clientModel"] != null)
     {
         BoggleClientModel model = (BoggleClientModel)Application.Current.Properties["clientModel"];
         model.CloseClient();
     }
 }
Example #8
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 #9
0
        /// <summary>
        /// Opens a new MainWindow with the last hostname and name that the client used.
        /// </summary>
        public MainWindow(string hostname, string name)
        {
            InitializeComponent();
            Play_Button.Focus();

            IPAddress_Text_Box.Text = hostname;
            Name_Text_Box.Text      = name;

            model = new BoggleClientModel();
        }
Example #10
0
        /// <summary>
        /// Opens a new MainWindow with the last hostname and name that the client used.
        /// </summary>
        public MainWindow(string hostname, string name)
        {
            InitializeComponent();
            Play_Button.Focus();

            IPAddress_Text_Box.Text = hostname;
            Name_Text_Box.Text = name;

            model = new BoggleClientModel();
        }
        private BoggleClientModel model; // model for this client

        #endregion Fields

        #region Constructors

        // false otherwise.
        /// <summary>
        /// constructs the client
        /// </summary>
        public BoggleClientView()
        {
            InitializeComponent();
            model = new BoggleClientModel();
            //register event handlers
            model.IncomingStartEvent += setupGame;
            model.IncomingScoreEvent += updateScore;
            model.IncomingTimeEvent += updateTime;
            model.IncomingStopEvent += summary;
            model.IncomingTerminatedEvent += terminate;
            model.noSuchHostEvent += badHost;
        }
        private bool isConnected;           // true is the result of the client being connected to a server
                                            // false otherwise.

        /// <summary>
        /// constructs the client
        /// </summary>
        public BoggleClientView()
        {
            InitializeComponent();
            model = new BoggleClientModel();
            //register event handlers
            model.IncomingStartEvent      += setupGame;
            model.IncomingScoreEvent      += updateScore;
            model.IncomingTimeEvent       += updateTime;
            model.IncomingStopEvent       += summary;
            model.IncomingTerminatedEvent += terminate;
            model.noSuchHostEvent         += badHost;
        }
Example #13
0
 public MainWindow()
 {
     InitializeComponent();
     model = new BoggleClientModel();
     model.LineComplete        += MessageReceived;
     wordset                    = new HashSet <string>();
     Status.Text                = "Welcome to Boggle. Please input the IP address for a Boggle server.";
     hermes.DoWork             += sender_DoWork;
     hermes.RunWorkerCompleted += sender_RunWorkerCompleted;
     saveIP = "localhost";
     Input.Focus();
 }
 /// <summary>
 /// Sends the page back to the connect page with the name and address the client is using
 /// </summary>
 /// <param name="sender">sender</param>
 /// <param name="e">Exception</param>
 private void Play_Click(object sender, RoutedEventArgs e)
 {
     //If the user already entered information, send it back to the connection page
     if (Application.Current.Properties["clientModel"] != null)
     {
         BoggleClientModel clientModel = (BoggleClientModel)Application.Current.Properties["clientModel"];
         Switcher.Switch(new ConnectPage(clientModel.clientName, clientModel.address));
     }
     else
     {
         Switcher.Switch(new ConnectPage());
     }
 }
 /// <summary>
 /// Starts the game if the command sent in is START
 /// </summary>
 /// <param name="line">Command sent in</param>
 /// <param name="model">The client model</param>
 private void GameStart(string line, BoggleClientModel model)
 {
     //If start, start a new game
     if (line != null && Regex.IsMatch(line, @"^START"))
     {
         Switcher.Switch(new GameBoard(line));
     }
     // In case of early termination
     else if (line != null && Regex.IsMatch(line, @"^Terminated"))
     {
         Switcher.Switch(new ConnectPage());
     }
 }
Example #16
0
        /// <summary>
        /// Creates a new game
        /// </summary>
        /// <param name="board">Game board to use</param>
        /// <param name="name">Users name</param>
        public GameBoard(string board)
        {
            clientModel = (BoggleClientModel)Application.Current.Properties["clientModel"];

            InitializeComponent();

            p1Name.Text = clientModel.clientName;

            //Set up the event handler for incoming words
            clientModel.incomingWordEvent  = null;
            clientModel.incomingWordEvent += ReceiveCommand;

            DisplayBoard(board);
        }
Example #17
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 #18
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 #19
0
        /// <summary>
        /// Creats the summary window for the game.
        /// </summary>
        public EndGameWindow(BoggleClientModel model, string stopMessage)
        {
            this.model = model;

            InitializeComponent();

            // Updates the player scores and the other player's information.
            current_score_label.Content              = model.currentPlayerScore;
            other_score_label.Content                = model.otherPlayerScore;
            other_name_label.Content                 = model.otherPlayerName + "'s score";
            other_player_legal_words_label.Content   = model.otherPlayerName + "'s\nLegal Words";
            other_player_illegal_words_label.Content = model.otherPlayerName + "'s\nBad Words";

            // Sets the win/lose/tie message.
            if (model.currentPlayerScore > model.otherPlayerScore)
            {
                win_label.Content = "YOU WIN! :)";
            }
            else if (model.currentPlayerScore < model.otherPlayerScore)
            {
                win_label.Content = "YOU LOSE :(";
            }
            else
            {
                win_label.Content = "YOU TIE :/";
            }

            // Fills the text boxes with the played words.
            string[] split = stopMessage.Split(new Char[] { ' ' });
            int      x;

            current_player_legal_words.Text += getList(split, 2, Int32.Parse(split[1]), out x);
            other_player_legal_words.Text   += getList(split, x + 1, Int32.Parse(split[x]), out x);
            common_words.Text += getList(split, x + 1, Int32.Parse(split[x]), out x);
            current_player_illegal_words.Text += getList(split, x + 1, Int32.Parse(split[x]), out x);
            other_player_illegal_words.Text   += getList(split, x + 1, Int32.Parse(split[x]), out x);
        }
Example #20
0
        /// <summary>
        /// Creats the summary window for the game.
        /// </summary>
        public EndGameWindow(BoggleClientModel model, string stopMessage)
        {
            this.model = model;

            InitializeComponent();

            // Updates the player scores and the other player's information.
            current_score_label.Content = model.currentPlayerScore;
            other_score_label.Content = model.otherPlayerScore;
            other_name_label.Content = model.otherPlayerName + "'s score";
            other_player_legal_words_label.Content = model.otherPlayerName + "'s\nLegal Words";
            other_player_illegal_words_label.Content = model.otherPlayerName + "'s\nBad Words";

            // Sets the win/lose/tie message.
            if(model.currentPlayerScore>model.otherPlayerScore)
            {
                win_label.Content = "YOU WIN! :)";
            }
            else if (model.currentPlayerScore < model.otherPlayerScore)
            {
                win_label.Content = "YOU LOSE :(";
            }
            else
            {
                win_label.Content = "YOU TIE :/";
            }

            // Fills the text boxes with the played words.
            string[] split = stopMessage.Split(new Char[] { ' ' });
            int x;
            current_player_legal_words.Text += getList(split, 2, Int32.Parse(split[1]), out x);
            other_player_legal_words.Text += getList(split, x + 1, Int32.Parse(split[x]), out x);
            common_words.Text += getList(split, x + 1, Int32.Parse(split[x]), out x);
            current_player_illegal_words.Text += getList(split, x + 1, Int32.Parse(split[x]), out x);
            other_player_illegal_words.Text += getList(split, x + 1, Int32.Parse(split[x]), out x);
        }
Example #21
0
 public ConnectPage()
 {
     InitializeComponent();
     clientModel = new BoggleClientModel();
 }
Example #22
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);
        }
Example #23
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 #24
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);
        }
 public void BoggleClientModelConstructorTest()
 {
     BoggleClientModel target = new BoggleClientModel();
     //Not yet implemented
 }
            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 #28
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);
        }
 /// <summary>
 /// Creates a new BoggleClient.
 /// </summary>
 public BoggleClientController()
 {
     InitializeComponent();
     _boggleClientModel = new BoggleClientModel();
     _boggleClientModel.IncomingLineEvent += MessageReceived;
 }
Example #30
0
 public Form1()
 {
     InitializeComponent();
     model = new BoggleClientModel();
     model.IncomingLineEvent += StringReceived;
 }