Beispiel #1
0
        public PlayingFieldHumanWindow(UsersInOnLineGame NewThisUser)
        {
            InitializeComponent();

            ThisUser = NewThisUser;
            Core.db  = new MainEntities();

            List <UsersInOnLineGame> AllEnemy = Core.db.UsersInOnLineGame.Where(item => item.GameID == ThisUser.GameID).ToList();
            var Enemy = AllEnemy.Find(item => item.UserID != ThisUser.UserID);

            EnemyLogin = Enemy.Users.Login;

            this.Title = "Игра против пользователя с ником " + EnemyLogin;
            if (ThisUser.StatusID == 1)
            {
                this.Title += " (Ваш ход)";
                MessageBox.Show("Вы играете за черные шашки", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                this.Title += " (Ход противника)";
                MessageBox.Show("Вы играете за белые шашки", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            CurrentGame = ThisUser.OnLineGames;

            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++)
                {
                    Button NewBtn = new Button();
                    NewBtn.Name    = "N" + i + j;
                    NewBtn.Content = "" + m[j] + (i + 1);
                    NewBtn.Style   = this.TryFindResource("Shashka") as Style;

                    if (NewBtn.Name.ToString().Substring(1) == "33" || NewBtn.Name.ToString().Substring(1) == "44")
                    {
                        NewBtn.Background = Brushes.White;
                        NewBtn.Foreground = Brushes.White;
                    }
                    if (NewBtn.Name.ToString().Substring(1) == "34" || NewBtn.Name.ToString().Substring(1) == "43")
                    {
                        NewBtn.Background = Brushes.Black;
                        NewBtn.Foreground = Brushes.Black;
                    }

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

            StartTimer();
        }
Beispiel #2
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                Core.db = new MainEntities();
                var         AllGames = Core.db.OnLineGames.ToList();
                OnLineGames FindGame = AllGames.Find(item => item.StatusID == 1);
                if (FindGame == null)
                {
                    OnLineGames CreateNewGame = new OnLineGames()
                    {
                        StatusID = 1
                    };
                    Core.db.OnLineGames.Add(CreateNewGame);
                    await Core.db.SaveChangesAsync();

                    var ChangeStatusUser = await Core.db.Users.FindAsync(Core.CurrentUser.ID);

                    ChangeStatusUser.StatusID = 3;

                    ThisUserInGame = new UsersInOnLineGame()
                    {
                        UserID   = Core.CurrentUser.ID,
                        GameID   = CreateNewGame.ID,
                        StatusID = 1
                    };

                    Core.db.UsersInOnLineGame.Add(ThisUserInGame);
                    await Core.db.SaveChangesAsync();

                    Core.CurrentUser = ChangeStatusUser;
                    StartTimer();
                }
                else
                {
                    var AllUsersInGame = Core.db.UsersInOnLineGame.Where(item => item.GameID == FindGame.ID).ToList();

                    if (AllUsersInGame.Count() == 1)
                    {
                        var ChangeStatus = await Core.db.Users.FindAsync(Core.CurrentUser.ID);

                        ChangeStatus.StatusID = 4;

                        ThisUserInGame = new UsersInOnLineGame()
                        {
                            UserID   = Core.CurrentUser.ID,
                            GameID   = FindGame.ID,
                            StatusID = 2
                        };

                        Core.db.UsersInOnLineGame.Add(ThisUserInGame);
                        await Core.db.SaveChangesAsync();

                        Core.CurrentUser = ChangeStatus;

                        Windows.PlayingFieldHumanWindow NewPlayingField = new Windows.PlayingFieldHumanWindow(ThisUserInGame);
                        GameFind = true;
                        this.NavigationService.Navigate(new GameSelectTypePage());
                        NewPlayingField.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show("Не удалось подключиться к игре", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                        this.NavigationService.Navigate(new GameSelectTypePage());
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    MessageBox.Show(ex.Message.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                if (ex.InnerException.InnerException == null)
                {
                    MessageBox.Show(ex.InnerException.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                MessageBox.Show(ex.InnerException.ToString() + "\n" +
                                ex.InnerException.InnerException.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }