/// <inheritdoc/>
        public IGameModel Play()
        {
            this.gameModel = this.saveGameRepository.GetSaveGame();
            AutoSaveGameRepository asgr = new AutoSaveGameRepository();

            asgr.Insert(this.gameModel as GameModel);
            if (this.gameModel == null)
            {
                this.GenerateMap();
                this.saveGameRepository.Insert(this.gameModel as GameModel);
                return(this.gameModel);
            }

            return(this.gameModel);
        }
示例#2
0
        private void Win_KeyDown(object sender, KeyEventArgs e)
        {
            if (this.canmove && !this.model.GameIsPaused)
            {
                switch (e.Key)
                {
                case Key.A:
                    this.gameLogic.MovePlayer(-1, 0);
                    this.canmove        = false;
                    this.moveOnce.Tick += delegate
                    {
                        this.canmove = true;
                        this.moveOnce.Stop();
                    };
                    this.moveOnce.Interval = TimeSpan.FromMilliseconds(100);
                    this.moveOnce.Start();
                    break;

                case Key.D:
                    this.gameLogic.MovePlayer(1, 0);
                    this.canmove        = false;
                    this.moveOnce.Tick += delegate
                    {
                        this.canmove = true;
                        this.moveOnce.Stop();
                    };
                    this.moveOnce.Interval = TimeSpan.FromMilliseconds(100);
                    this.moveOnce.Start();
                    break;

                case Key.W:
                    this.gameLogic.MovePlayer(0, -1);
                    this.canmove        = false;
                    this.moveOnce.Tick += delegate
                    {
                        this.canmove = true;
                        this.moveOnce.Stop();
                    };
                    this.moveOnce.Interval = TimeSpan.FromMilliseconds(100);
                    this.moveOnce.Start();
                    break;

                case Key.S:
                    this.gameLogic.MovePlayer(0, 1);
                    this.canmove        = false;
                    this.moveOnce.Tick += delegate
                    {
                        this.canmove = true;
                        this.moveOnce.Stop();
                    };
                    this.moveOnce.Interval = TimeSpan.FromMilliseconds(100);
                    this.moveOnce.Start();
                    break;

                default:
                    break;
                }
            }

            if (e.Key == Key.Return && this.model.GameIsPaused)
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.OverwritePrompt  = true;
                saveFileDialog.CreatePrompt     = true;
                saveFileDialog.Filter           = "Json File (*.json)|*.json";
                saveFileDialog.FileName         = "*.json";
                saveFileDialog.InitialDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + $@"\Saves\";
                if (saveFileDialog.ShowDialog() == true)
                {
                    ManualSaveGameRepository msgr = new ManualSaveGameRepository(saveFileDialog.FileName);
                    AutoSaveGameRepository   asgr = new AutoSaveGameRepository();
                    this.model.MyPlayer.IsReloading = false;
                    msgr.Insert(this.model as GameModel);
                    asgr.Insert(this.model as GameModel);
                }
            }

            if (e.Key == Key.Q && this.model.GameIsPaused)
            {
                Window   win  = Window.GetWindow(this);
                MainMenu menu = new MainMenu();
                menu.Show();
                win.Close();
            }

            if (e.Key == Key.Escape)
            {
                this.model.GameIsPaused = !this.model.GameIsPaused;
                if (!this.model.GameIsPaused)
                {
                    foreach (var item in this.model.Projectiles)
                    {
                        item.Timer.Start();
                        item.Timer.Tick += delegate
                        {
                            this.gameLogic.MoveProjectile(item);
                        };
                    }

                    this.updateTimer.Start();
                    this.levelTimer.Start();
                    if (this.reloadTimer != null)
                    {
                        this.reloadTimer.Start();
                    }
                }
                else
                {
                    this.levelTimer.Stop();
                    foreach (var item in this.model.Projectiles)
                    {
                        item.Timer.Stop();
                    }

                    this.shootOnce.Stop();
                    this.moveOnce.Stop();
                    this.updateTimer.Stop();
                    if (this.reloadTimer != null)
                    {
                        this.reloadTimer.Stop();
                    }
                }

                this.InvalidateVisual();
            }
        }