Exemplo n.º 1
0
        private void SeeLogBtn_Click(object sender, RoutedEventArgs e)
        {
            foreach (Window item in Application.Current.Windows)
            {
                if (item.Name == "LogGameWindow")
                {
                    MessageBox.Show("Окно с логом игры уже открыто", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
            }

            var           newGameLogDocument = GameLogDocument;
            GameLogWindow window             = new GameLogWindow(newGameLogDocument);

            window.Show();
        }
Exemplo n.º 2
0
        private async void LoseBtn_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult UserSelect = MessageBox.Show("Вы действительно хотите сдаться?\nЕсли вы нажмете \"Да\" то вам будет засчитано поражение", "Предупреждение", MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation);

            if (UserSelect == MessageBoxResult.Yes)
            {
                var H = Hours * 60 * 60;
                var M = Minutes * 60;
                var S = Seconds + M + H;

                Paragraph newparagraph = new Paragraph();
                Run       newRun       = new Run();
                newRun.Text = "Ход " + WalksNumber + "\n";


                if (WalksNumber % 2 == 0)
                {
                    newRun.Text += "Белые сдались";
                }
                else
                {
                    newRun.Text += "Черные сдались";
                }

                newparagraph.Inlines.Add(newRun);
                GameLogDocument.Blocks.Add(newparagraph);
                newparagraph.Inlines.Clear();
                newRun.Text = "Итоговый счет игры:\n"
                              + "Всего белых шашек на поле:" + User1Quantity + "; Очки белого:" + (User2Quantity * S)
                              + "\nВсего черных шашек на поле:" + User2Quantity + "; Очки черного:" + (User1Quantity * S);
                newparagraph.Inlines.Add(newRun);
                GameLogDocument.Blocks.Add(newparagraph);

                var GameLogText = new TextRange(GameLogDocument.ContentStart, GameLogDocument.ContentEnd);

                try
                {
                    CurrentGame.GameLog  = GameLogText.Text;
                    CurrentGame.Duration = new TimeSpan(Hours, Minutes, Seconds);
                    CurrentGame.StatusID = 3;
                    var EditGame = await Core.db.OnLineGames.FindAsync(CurrentGame.ID);

                    EditGame = CurrentGame;

                    var ThisUserInGame = await Core.db.UsersInOnLineGame.FindAsync(ThisUser.ID);

                    ThisUserInGame.StatusID = 4;

                    // Работа со статистикой и рекордами осталась

                    await Core.db.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }

                if (WalksNumber % 2 != 0 && ThisUser.StatusID == 1)
                {
                    MessageBox.Show("Ваши очки: " + User1Quantity * S, "Вы проиграли", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else if (WalksNumber % 2 == 0 && ThisUser.StatusID == 2)
                {
                    MessageBox.Show("Ваши очки: " + User2Quantity * S, "Вы проиграли", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                foreach (Window item in Application.Current.Windows)
                {
                    if (item.Name == "LogGameWindow")
                    {
                        this.Close();
                        return;
                    }
                }

                Timer.Stop();

                var           newGameLogDocument = GameLogDocument;
                GameLogWindow window             = new GameLogWindow(newGameLogDocument);
                window.Show();

                this.Close();
            }
        }
Exemplo n.º 3
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.LogGameWindow = ((BarsGroup.View.Windows.GameLogWindow)(target));

            #line 8 "..\..\..\..\View\Windows\GameLogWindow.xaml"
                this.LogGameWindow.Closing += new System.ComponentModel.CancelEventHandler(this.LogGameWindow_Closing);

            #line default
            #line hidden
                return;

            case 2:
                this.MainFlowDocument = ((System.Windows.Controls.FlowDocumentScrollViewer)(target));
                return;

            case 3:
                this.Text16 = ((System.Windows.Controls.RadioButton)(target));

            #line 23 "..\..\..\..\View\Windows\GameLogWindow.xaml"
                this.Text16.Checked += new System.Windows.RoutedEventHandler(this.SelectFontSizeRadioBtn);

            #line default
            #line hidden
                return;

            case 4:
                this.Text18 = ((System.Windows.Controls.RadioButton)(target));

            #line 24 "..\..\..\..\View\Windows\GameLogWindow.xaml"
                this.Text18.Checked += new System.Windows.RoutedEventHandler(this.SelectFontSizeRadioBtn);

            #line default
            #line hidden
                return;

            case 5:
                this.Text20 = ((System.Windows.Controls.RadioButton)(target));

            #line 25 "..\..\..\..\View\Windows\GameLogWindow.xaml"
                this.Text20.Checked += new System.Windows.RoutedEventHandler(this.SelectFontSizeRadioBtn);

            #line default
            #line hidden
                return;

            case 6:
                this.Text24 = ((System.Windows.Controls.RadioButton)(target));

            #line 26 "..\..\..\..\View\Windows\GameLogWindow.xaml"
                this.Text24.Checked += new System.Windows.RoutedEventHandler(this.SelectFontSizeRadioBtn);

            #line default
            #line hidden
                return;

            case 7:
                this.Text30 = ((System.Windows.Controls.RadioButton)(target));

            #line 27 "..\..\..\..\View\Windows\GameLogWindow.xaml"
                this.Text30.Checked += new System.Windows.RoutedEventHandler(this.SelectFontSizeRadioBtn);

            #line default
            #line hidden
                return;

            case 8:
                this.Text32 = ((System.Windows.Controls.RadioButton)(target));

            #line 28 "..\..\..\..\View\Windows\GameLogWindow.xaml"
                this.Text32.Checked += new System.Windows.RoutedEventHandler(this.SelectFontSizeRadioBtn);

            #line default
            #line hidden
                return;

            case 9:
                this.Text34 = ((System.Windows.Controls.RadioButton)(target));

            #line 29 "..\..\..\..\View\Windows\GameLogWindow.xaml"
                this.Text34.Checked += new System.Windows.RoutedEventHandler(this.SelectFontSizeRadioBtn);

            #line default
            #line hidden
                return;

            case 10:
                this.Text38 = ((System.Windows.Controls.RadioButton)(target));

            #line 30 "..\..\..\..\View\Windows\GameLogWindow.xaml"
                this.Text38.Checked += new System.Windows.RoutedEventHandler(this.SelectFontSizeRadioBtn);

            #line default
            #line hidden
                return;

            case 11:
                this.Text50 = ((System.Windows.Controls.RadioButton)(target));

            #line 31 "..\..\..\..\View\Windows\GameLogWindow.xaml"
                this.Text50.Checked += new System.Windows.RoutedEventHandler(this.SelectFontSizeRadioBtn);

            #line default
            #line hidden
                return;

            case 12:
                this.SaveLogBtn = ((System.Windows.Controls.Button)(target));

            #line 37 "..\..\..\..\View\Windows\GameLogWindow.xaml"
                this.SaveLogBtn.Click += new System.Windows.RoutedEventHandler(this.SaveLogBtn_Click);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
Exemplo n.º 4
0
        public async void TickTimer(object sender, EventArgs e)
        {
            Seconds++;
            if (Seconds == 59)
            {
                Seconds = 0;
                Minutes++;
            }
            if (Minutes == 59)
            {
                Minutes = 0;
                Hours++;
            }

            Core.db = new MainEntities();
            OnLineGames Gamesdb = await Core.db.OnLineGames.FindAsync(CurrentGame.ID);

            if (CurrentGame != Gamesdb)
            {
                CurrentGame = Gamesdb;

                if (CurrentGame.StatusID == 3)
                {
                    Timer.Stop();
                    var H = Hours * 60 * 60;
                    var M = Minutes * 60;
                    var S = Seconds + M + H;

                    try
                    {
                        var ThisUserInGame = await Core.db.UsersInOnLineGame.FindAsync(ThisUser.ID);

                        ThisUserInGame.StatusID = 3;

                        // Работа со статистикой и рекордами осталась

                        await Core.db.SaveChangesAsync();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString());
                    }

                    if (WalksNumber % 2 != 0 && ThisUser.StatusID == 2)
                    {
                        MessageBox.Show("Ваш противник сдался\nВаши очки: " + User2Quantity * S, "Вы выиграли!", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else if (WalksNumber % 2 == 0 && ThisUser.StatusID == 1)
                    {
                        MessageBox.Show("Ваш противник сдался\nВаши очки: " + User1Quantity * S, "Вы выиграли!", MessageBoxButton.OK, MessageBoxImage.Information);
                    }

                    foreach (Window item in Application.Current.Windows)
                    {
                        if (item.Name == "LogGameWindow")
                        {
                            this.Close();
                            return;
                        }
                    }

                    string    str       = Gamesdb.GameLog;
                    Paragraph paragraph = new Paragraph();
                    paragraph.Inlines.Add(str);

                    GameLogDocument = new FlowDocument();
                    GameLogDocument.Blocks.Add(paragraph);

                    var           newGameLogDocument = GameLogDocument;
                    GameLogWindow window             = new GameLogWindow(newGameLogDocument);
                    window.Show();

                    this.Close();
                }

                var CurrentLocationOfChekersStr = String.Empty;
                var GameLogText = new TextRange(GameLogDocument.ContentStart, GameLogDocument.ContentEnd);

                foreach (var item in CurrentGameArea)
                {
                    CurrentLocationOfChekersStr += item + " ";
                }

                if (/*Gamesdb.GameLog != GameLogText.Text && */ Gamesdb.LocationOfCheckers != String.Empty && Gamesdb.LocationOfCheckers != CurrentLocationOfChekersStr)
                {
                    string[] words = CurrentGame.LocationOfCheckers.Split(new char[] { ' ' });

                    var a = 0;
                    User1Quantity = 0;
                    User2Quantity = 0;

                    PlayingField.Children.RemoveRange(0, PlayingField.Children.Count);

                    for (int i = 0; i <= 7; i++)
                    {
                        StackPanel newStackpanel = new StackPanel();
                        newStackpanel.Orientation = Orientation.Horizontal;
                        newStackpanel.Name        = "N" + i;
                        PlayingField.Children.Add(newStackpanel);
                        for (int j = 0; j <= 7; j++)
                        {
                            CurrentGameArea[i, j] = words[a];

                            Button NewBtn = new Button();
                            NewBtn.Name    = "N" + i + j;
                            NewBtn.Content = "" + m[j] + (i + 1);
                            NewBtn.Style   = this.TryFindResource("Shashka") as Style;

                            if (CurrentGameArea[i, j].ToString()[0] == 'W')
                            {
                                User2Quantity++;
                                NewBtn.Background = Brushes.White;
                                NewBtn.Foreground = Brushes.White;
                            }
                            if (CurrentGameArea[i, j].ToString()[0] == 'B')
                            {
                                User1Quantity++;
                                NewBtn.Background = Brushes.Black;
                                NewBtn.Foreground = Brushes.Black;
                            }

                            NewBtn.Click      += Shashka_Click;
                            NewBtn.MouseEnter += Shashka_MouseEnter;
                            NewBtn.MouseLeave += Shashka_MouseLeave;
                            newStackpanel.Children.Add(NewBtn);

                            a++;
                        }
                    }

                    string    str       = Gamesdb.GameLog;
                    Paragraph paragraph = new Paragraph();
                    paragraph.Inlines.Add(str);

                    GameLogDocument = new FlowDocument();
                    GameLogDocument.Blocks.Add(paragraph);

                    WalksNumber++;
                }
            }

            this.Title = "Игра против пользователя с ником " + EnemyLogin;
            if (WalksNumber % 2 != 0 && ThisUser.StatusID == 1)
            {
                this.Title += " (Ваш ход)";
            }
            else if (WalksNumber % 2 == 0 && ThisUser.StatusID == 2)
            {
                this.Title += " (Ваш ход)";
            }
            else
            {
                this.Title += " (Ход противника)";
            }

            if (WalksNumber % 2 == 0)
            {
                WhoWalks = "Белые";
            }
            else
            {
                WhoWalks = "Черные";
            }

            WhoWalksTxt.Text   = WhoWalks;
            WalksNumerTxt.Text = WalksNumber.ToString();
            InfoTimer.Text     = string.Format("{0:00}:{1:00}", Hours, Minutes);
            InfoTimer.ToolTip  = string.Format("{0:00}:{1:00}:{2:00}", Hours, Minutes, Seconds);
            ScoreBlack.Text    = User1Quantity.ToString();
            ScoreWhite.Text    = User2Quantity.ToString();
        }