public GameField10x10View()
        {
            InitializeComponent();
            GameFieldViewModel vm = new GameFieldViewModel();

            vm.OnShowSummary += vm_OnShowSummary;
            DataContext       = vm;
        }
Example #2
0
        public GameField(Game game, GameStateInfo gameStateInfo, INavigation navigation)
        {
            InitializeComponent();
            ViewModel                = new GameFieldViewModel(game, gameStateInfo, navigation);
            BindingContext           = ViewModel;
            canvasView.PaintSurface += OnCanvasViewPaintSurface;

            StartGameControls();
            NavigationPage.SetHasNavigationBar(this, false);
        }
Example #3
0
        public GameControls(GameFieldViewModel gameFieldViewModel, Color backgroundColor, Action UpdateGameField)
        {
            this.UpdateGameField = UpdateGameField;
            ViewModel            = new GameControlsViewModel(gameFieldViewModel, StartTurn, FinishTurn);

            BackgroundColor = backgroundColor;

            MakeGameControl();
            CanvasView[0].PaintSurface += (sender, args) => OnCanvasViewPaintSurface(sender, args, 0);
            CanvasView[1].PaintSurface += (sender, args) => OnCanvasViewPaintSurface(sender, args, 1);

            CanvasView[0].InvalidateSurface();
            CanvasView[1].InvalidateSurface();
        }
        private void GameFieldWin10x10_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Escape)
            {
                return;
            }
            GameFieldViewModel vm = DataContext as GameFieldViewModel;

            vm.BackToMenuCommand.Execute(null);

            this.Hide();
            Owner.Show();
            e.Handled = true;
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GamePageViewModel"/> class with
        /// the specified game settings.
        /// </summary>
        /// <param name="parameter">The game settings.</param>
        public GamePageViewModel(GameSettings gameSettings)
        {
            // Initialize the stopwatch and run the timer that will update the time every second
            mStopWatch      = new Stopwatch();
            mTimer          = new Timer(1000);
            mTimer.Elapsed += (o, e) => ElapsedTime = mStopWatch.Elapsed;

            // Create the game field and listen for when the game is started and is over
            GameField              = new GameFieldViewModel(gameSettings);
            GameField.GameStarted += (o, e) =>
            {
                // Start measuring the time when the game starts
                mStopWatch.Start();
                mTimer.Start();
            };
            GameField.GameOver += async(o, e) =>
            {
                // Stop measuring the time when the game is over
                mStopWatch.Stop();
                mTimer.Stop();

                // Show a modal with content based on the game result
                ConfirmModalViewModel modalViewModel;
                if (e.PlayerWon)
                {
                    modalViewModel = new ConfirmModalViewModel("Congratulations", "You successfully finished the game", "OK");
                }
                else
                {
                    modalViewModel = new ConfirmModalViewModel("Game Over", "You clicked on a bomb", "OK");
                }

                // And wait until the modal is exited
                var modalService = IoC.Get <IModalService>();
                await modalService.ShowConfirmModal(modalViewModel);

                // Handle game over
                OnGameOver();
            };

            ExitCommand = new RelayCommand(p => OnGameOver());
        }
        private void Timeline_Completed(object sender, EventArgs e)
        {
            GameFieldViewModel vm = DataContext as GameFieldViewModel;

            if (vm.Game.GravityRequire())
            {
                vm.Game.BallsGravityDown();
                Console.WriteLine("gravity require");
            }
            else if (vm.Game.FillEmptyRequire())
            {
                vm.Game.FillEmptyCells();
                Console.WriteLine("fill empty cells require");
            }
            else
            {
                vm.Game.CheckField();
                //Console.WriteLine("check field require");
            }
        }
        void vm_OnShowSummary(GameFieldViewModel vm)
        {
            // У родительского окна меняем лейбл на кнопке запускающей новую игру
            object btn = Owner.FindName("newGameBtn");

            if (btn != null && btn as Button != null)
            {
                (btn as Button).Content = "Новая игра";
            }
            GameSummaryView gameSummary = new GameSummaryView(vm);

            gameSummary.Owner = this;
            gameSummary.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            gameSummary.ShowDialog();
            // Показываем родительское окно
            Owner.Show();

            if (vm.CallClose)
            {
                this.Close();
            }
        }
Example #8
0
 public RotateCommand(GameFieldViewModel viewModel)
 {
     _ViewModel = viewModel;
 }
 public ChangePositionCommand(GameFieldViewModel viewModel)
 {
     _ViewModel = viewModel;
 }
        // При закрытии окна
        private void GameField_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            GameFieldViewModel vm = DataContext as GameFieldViewModel;

            vm.StopCommand.Execute(1);
        }
 public StartGameCommand(GameFieldViewModel viewModel)
 {
     _ViewModel = viewModel;
 }