Ejemplo n.º 1
0
        // các xử lí của mainviewmodel
        public MainViewModel()
        {
            // ẩn mainWindow trước khi thực hiện đăng nhập - sử dụng truyền parameter p_Window
            LoadedWindowCommand = new RelayCommand <Window>((p_Window) => { return(true); }, (p_Window) => {
                if (p_Window == null)
                {
                    return;
                }
                else
                {
                    p_Window.Hide();
                    Isloaded = true;
                    LoginWindow loginWindow = new LoginWindow();
                    loginWindow.ShowDialog();

                    // dùng datacontext để lấy biến islogin bên LoginViewModel
                    if (loginWindow.DataContext == null)
                    {
                        return;
                    }

                    var login = loginWindow.DataContext as LoginViewModel;

                    if (login.IsLogin == true)
                    {
                        p_Window.Show();
                    }
                    else
                    {
                        p_Window.Close();
                    }
                }
            });

            // các comment
            SellCommand     = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { SellWindow wd = new SellWindow(); wd.ShowDialog(); });
            BillCommand     = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { BillWindow wd = new BillWindow(); wd.ShowDialog(); });
            RegisterCommand = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { RegisterWindow wd = new RegisterWindow(); wd.ShowDialog(); });

            // những chức năng chỉ người chủ mới được thực hiện
            StatisticCommand = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { StatisticWindow wd = new StatisticWindow(); wd.ShowDialog(); });
            InputCommand     = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { InputWindow wd = new InputWindow(); wd.ShowDialog(); });

            ShopCommand = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { ShopWindow wd = new ShopWindow(); wd.ShowDialog(); });
            QTVCommand  = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { QTVWindow wd = new QTVWindow(); wd.ShowDialog(); });
        }
Ejemplo n.º 2
0
        public GamesViewModel()
        {
            LoginViewModel      = new LoginViewModel();
            ScoreboardViewModel = new ScoreboardViewModel();
            TicTacToeViewModel  = new TicTacToeViewModel();
            PairGameViewModel   = new PairGameViewModel();
            RatingViewModel     = new RatingViewModel();
            SnakeViewModel      = new SnakeViewModel();
            DoorsGameViewModel  = new DoorsGameViewModel();
            MoneyViewModel      = new MoneyViewModel();

            _playerManager = new PlayerManager();


            NewGameCommand = new RelayCommand(param => StartGame((string)param));

            ShopCommand = new RelayCommand(param =>
            {
                ShopWindow shopWindow = new ShopWindow();
                shopWindow.ShowDialog();
            });

            ScoreboardCommand = new RelayCommand(param =>
            {
                ScoreboardViewModel.Refresh();
                ScoreboardView scoreboardView = new ScoreboardView();
                scoreboardView.ShowDialog();
            });

            RatingCommand = new RelayCommand(param =>
            {
                RatingView ratingView = new RatingView();
                ratingView.ShowDialog();
            });

            PlayerEditCommand = new RelayCommand(param =>
            {
                EditView editView = new EditView();
                editView.ShowDialog();
            });

            AddMoneyCommand = new RelayCommand(param =>
            {
                MoneyView moneyView = new MoneyView();
                moneyView.ShowDialog();
            });

            StartGameTestingCommand = new RelayCommand(param => { StartGameTesting((string)param); });


            BuyItemCommand = new RelayCommand(param =>
            {
                if (int.Parse(param.ToString()) > Money)
                {
                    MessageBox.Show("You do not have enough to buy this game.\n Consider adding money to your balance.",
                                    "Message", MessageBoxButton.OK);
                }
                else
                {
                    _playerManager.AddMoney(LoginViewModel.Player.Id, -int.Parse(param.ToString()));
                    Money = Money;
                }
            });
        }