//game closed event
        private void Window_Closed(object sender, EventArgs e)
        {
            ClientCallback    callback = new ClientCallback();
            MineServiceClient client   = new MineServiceClient(new InstanceContext(callback));

            client.PlayerFinishedPlaying(username, opponent);
        }
        //Mouse event
        private void MouseClick(object sender, RoutedEventArgs e)
        {
            ClientCallback    callback    = new ClientCallback();
            MineServiceClient client      = new MineServiceClient(new InstanceContext(callback));
            Button            button      = (Button)sender;
            string            TextBoxName = button.Name;
            int col = Int32.Parse(TextBoxName.Substring(3, 2));
            int row = Int32.Parse(TextBoxName.Substring(1, 2));

            try
            {
                if (button.Background == Brushes.White) //empty tile
                {
                    if (client.PlayerTurn(row, col, username))
                    {
                        if (mineLocation[row].Contains(col)) //mined
                        {
                            button.Content    = "*";
                            button.Background = Brushes.Red;
                        }
                        else //not mined
                        {
                            button.Content = "" + numberOfMinesAround(row, col);

                            button.Background = Brushes.DeepSkyBlue;
                            Turn_lbl.Content  = "Yellow";
                        }
                    }
                }
            }
            catch (FaultException <UserFaultException> ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #3
0
        // Connection function.
        private Boolean isClientExist()
        {
            if (!string.IsNullOrEmpty(tbUsername.Text) && !string.IsNullOrEmpty(tbPassword.Password))
            {
                ClientCallback    callback = new ClientCallback();
                MineServiceClient client   = new MineServiceClient(new InstanceContext(callback));
                string            username = tbUsername.Text.Trim();
                string            password = tbPassword.Password.Trim();

                try
                {
                    if (client.ClientExist(username, password))
                    {
                        GameTypeChooseWindow gameTypeChooseWindow = new GameTypeChooseWindow(username, password);
                        gameTypeChooseWindow.Show();
                        this.Close();
                    }
                }
                catch (FaultException <UserFaultException> ex)
                {
                    MessageBox.Show(ex.Detail.Message);
                }
            }
            return(false);
        }
コード例 #4
0
        // Registration function.
        private void RegisterFunc()
        {
            if (!string.IsNullOrEmpty(tbUsername.Text) && !string.IsNullOrEmpty(tbPassword.Text))
            {
                ClientCallback    callback = new ClientCallback();
                MineServiceClient client   = new MineServiceClient(new InstanceContext(callback));
                string            username = tbUsername.Text.Trim();
                string            password = tbPassword.Text.Trim();

                try
                {
                    client.Register(username, password);
                    this.Close();
                    MessageBox.Show("Successfully registered.");
                }
                catch (FaultException <UserFaultException> ex)
                {
                    MessageBox.Show(ex.Detail.Message);
                }
            }
        }
コード例 #5
0
        public MinesweeperMatchHard(string player1, string player2, string userName)
        {
            InitializeComponent();
            ClientCallback    callback = new ClientCallback();
            MineServiceClient client   = new MineServiceClient(new InstanceContext(callback));

            player   = userName;
            opponent = userName == player1 ? player2 : player1;
            username = userName;

            //board initialize
            BoardManager = new List <Button> [_ROW];
            for (int i = 0; i < _ROW; ++i)
            {
                BoardManager[i] = new List <Button>();
            }
            Init();
            //mine generate
            if (userName == player2)
            {
                Turn_lbl.Content = "Yellow";
                mineLocation     = client.GenerateMines(_MINES, 16, true);
            }
            else
            {
                mineLocation     = client.GenerateMines(40, 16, false);
                Turn_lbl.Content = "Blue";
            }

            try
            {
                client.SendMineLocation(mineLocation, _SAFE_PLACES, username);
            }
            catch (FaultException <UserFaultException> ex)
            {
                MessageBox.Show(ex.Detail.Message);
            }
        }
コード例 #6
0
        //connect to the online players
        private void ConnetFunc()
        {
            ClientCallback    callback = new ClientCallback();
            MineServiceClient client   = new MineServiceClient(new InstanceContext(callback));


            try
            {
                client.ClientConnected(clientName, clientPassword);
                MainWindow mainWindow = new MainWindow
                {
                    Client   = client,
                    Callback = callback,
                    Username = clientName,
                    Title    = clientName
                };
                this.Close();
                mainWindow.Show();
            }
            catch (FaultException <UserFaultException> ex)
            {
                MessageBox.Show(ex.Detail.Message);
            }
        }