示例#1
0
        private void mnGame_Click(object sender, EventArgs e)
        {
            if (this.InGame) { return; }    //На всякий случай :)

            try
            {
                frmLogin loginForm = new frmLogin();
                if (loginForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    this.cFactory = new ChannelFactory<TicTacService>("ENDPOINT");
                    this.ticTacClient = cFactory.CreateChannel();

                    if (this.ticTacClient.Login(loginForm.UserLogin) == true)
                    {
                        this.InGame = true;
                        this.login = loginForm.UserLogin;
                        this.Text = "TicTac - " + this.login;
                        GameState gameState = this.ticTacClient.GetState(this.login);
                        this.character = (gameState.firstPlayer == this.login) ? GameState.FIELD_STATE.CROSS : GameState.FIELD_STATE.ZERO;
                        this.getGameThr = new Thread(GetGame);
                        this.getGameThr.IsBackground = true;
                        this.getGameThr.Start();
                    }
                    else
                    {
                        string message = "Не удалось присоединиться к игре. Возможно уже существует такой логин. Возможно другие проблемы с сервером. Попробуйте позже";
                        MessageBox.Show(message, "TicTac", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                Console.WriteLine(exc.StackTrace);
                MessageBox.Show(exc.Message, "Соединение с сервером", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#2
0
 private GameState.FIELD_STATE[,] GetField(GameState game)
 {
     try
     {
         GameState.FIELD_STATE[,] field = new GameState.FIELD_STATE[3, 3];
         for (int i = 0; i < 3; i++)
         {
             for (int j = 0; j < 3; j++)
             {
                 field[i, j] = game.field[i * 3 + j];
             }
         }
         return field;
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return null;
     }
 }