Exemple #1
0
        private void panels_Click(object sender, EventArgs e)
        {
            Panel panel = (Panel)sender;

            String[] str = (panel.Tag.ToString()).Split(';');
            if (Connection.wcfClient.SetInfoIntoField(name, Convert.ToInt32(str[0]), Convert.ToInt32(str[1])) == "SUCCESS")
            {
                MainTableLayout.Enabled = false;
                panel.BackgroundImage   = (gs.players[gs.idOfPlayer(this.name)].Symbol == 'X') ? Resource1.X : Resource1.O;
            }
            else if (gs == null)
            {
                MessageBox.Show("Начините поиск соперника чтобы играть", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
 public void runCheck()
 {
     while (true)
     {
         try
         {
             Connection.wcfClient.client.isConnected();
         }
         catch
         {
             Connection.MakeConnection(true);
             break;
         }
         gs = Connection.wcfClient.GetGameState(this.name);
         if (gs == null)
         {
             MessageBox.Show("Вы были кикнуты за бездействие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information);
             resetAll();
             break;
         }
         if (gs.state == 0)
         {
             labelStatus.Invoke(new Action(() => { labelStatus.Text = "Ожидание игрока"; }));
         }
         else if (gs.state == 1 || gs.state == 2)
         {
             String str = gs.players[gs.idOfPlayer(this.name)].Symbol.ToString();
             if (this.labelChar.Text != str)
             {
                 labelChar.Invoke(new Action(() => { labelChar.Text = str; labelChar.Visible = true; label2.Visible = true; }));
             }
             if (gs.players[gs.state - 1].name == name)
             {
                 if (gs.lastAction != null)
                 {
                     foreach (Control c in MainTableLayout.Controls.OfType <Panel>())
                     {
                         if (c.Tag.ToString().Contains(gs.lastAction))
                         {
                             Panel panel = c as Panel;
                             if (panel.BackgroundImage == null)
                             {
                                 panel.Invoke(new Action(() => { panel.BackgroundImage = (gs.players[gs.idOfPlayer(this.name)].Symbol != 'X') ? Resource1.X : Resource1.O; }));
                             }
                             break;
                         }
                     }
                 }
                 labelStatus.Invoke(new Action(() => { labelStatus.Text = "Ваш ход"; }));
                 MainTableLayout.Invoke(new Action(() => { MainTableLayout.Enabled = true; }));
             }
             else
             {
                 labelStatus.Invoke(new Action(() => { labelStatus.Text = "Ходит - " + gs.players[gs.state - 1].name; }));
                 MainTableLayout.Invoke(new Action(() => { MainTableLayout.Enabled = false; }));
             }
         }
         else if (gs.state == 3 || gs.state == 4)
         {
             if (gs.players[gs.state - 3].name == name)
             {
                 if (gs.players[(gs.state == 3) ? 1 : 0].name == "")
                 {
                     labelStatus.Invoke(new Action(() => { labelStatus.Text = "Соперник покинул игру"; }));
                 }
                 else
                 {
                     labelStatus.Invoke(new Action(() => { labelStatus.Text = "Вы победили"; }));
                 }
                 MessageBox.Show("Поздравляем с победой!", "Победа", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             else
             {
                 if (gs.lastAction != null)
                 {
                     foreach (Control c in MainTableLayout.Controls.OfType <Panel>())
                     {
                         if (c.Tag.ToString().Contains(gs.lastAction))
                         {
                             Panel panel = c as Panel;
                             if (panel.BackgroundImage == null)
                             {
                                 panel.Invoke(new Action(() => { panel.BackgroundImage = (gs.players[gs.idOfPlayer(this.name)].Symbol != 'X') ? Resource1.X : Resource1.O; }));
                             }
                             break;
                         }
                     }
                 }
                 labelStatus.Invoke(new Action(() => { labelStatus.Text = "Победил - " + gs.players[gs.state - 3].name; }));
                 MessageBox.Show("Вы проиграли. Повезет в следующий раз!", "Поражение", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             this.button1_Click(null, null);
             gs = null;
             break;
         }
         else if (gs.state == 5)
         {
             labelStatus.Invoke(new Action(() => { labelStatus.Text = "Ничья"; }));
             MessageBox.Show("Нет победивших. Конец игры", "Ничья", MessageBoxButtons.OK, MessageBoxIcon.Error);
             this.button1_Click(null, null);
             gs = null;
             break;
         }
         Thread.Sleep(1000);
     }
 }