Exemplo n.º 1
0
        void CreateExplosion(GameModelBase gameModelHit) //The game piece that has been hit is passed in.
        {
            ExplosionModel explosionModel = new ExplosionModel();

            explosionModel.X              = gameModelHit.X;
            explosionModel.Y              = gameModelHit.Y;
            explosionModel.Height         = 30;
            explosionModel.Width          = 30;
            explosionModel.ExplosionState = 0;
            GameModels.Add(explosionModel);

            if (gameModelHit.ModelType == GameModelType.Saucer)
            {
                explosionModel.PointValue = ((SaucerModel)gameModelHit).PointValue;
            }
            if (gameModelHit.ModelType == GameModelType.Enemy)
            {
                explosionModel.PointValue = ((EnemyModel)gameModelHit).PointValue;
            }
            if (gameModelHit.ModelType == GameModelType.Player)
            {
                audioController.PlayPlayerExplosion();
            }
            else
            {
                audioController.PlayEnemyExplode();
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> SaveGame(GameModelBase model)
        {
            try
            {
                if (!GameStorage.HasGame(model.GameKey))
                {
                    return(NotFound($"Game with key {model.GameKey} doesn't exist. It may've finished"));
                }

                Game   game = GameStorage[model.GameKey];
                string key  = await GameManager.SaveGameAsync(game);

                return(Ok(new GameManagementBaseModel {
                    GameKey = key
                }));
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Couldn't save the game with params {@Model}", model);
                return(Error("An error occured while saving the game"));
            }
        }
Exemplo n.º 3
0
        void CheckForPlayerMissileHits()
        {
            var missileModels = GetPlayerMissileModels(); //Get list of player missiles in flight.
            var enemyModels   = GetEnemyModels();         //get lists of any potential targets.
            var bombModels    = GetEnemyBombModels();
            var saucerModels  = GetSaucerModels();

            foreach (var playerMissile in missileModels.ToList())                                                                          //Loop over player missile models (default is 1)
            {
                Rectangle     playerMissileRect = playerMissile.CollisionRectangle;                                                        //Get the missile rectangle.
                var           enemyHit          = enemyModels.FirstOrDefault(x => playerMissileRect.IntersectsWith(x.CollisionRectangle)); //Check if the missile collides with any enemies or bombs.
                var           enemyBombHit      = bombModels.FirstOrDefault(x => playerMissileRect.IntersectsWith(x.CollisionRectangle));
                GameModelBase gameModelHit      = null;                                                                                    //Used to track the hit piece to create an explosion on that piece.

                if (enemyHit != null && enemyBombHit != null)                                                                              //only 1 of either an enemy or bomb can be hit at once. Preference on Y position.
                {
                    if (enemyHit.Y > enemyBombHit.Y)
                    {
                        enemyBombHit = null;
                    }
                    else
                    {
                        enemyHit = null;
                    }
                }

                if (enemyHit != null) //If an enemy was hit update the current score.
                {
                    GameInfo.Score += enemyHit.PointValue;
                    gameModelHit    = enemyHit; //passed to create explosion.
                }

                if (enemyBombHit != null) //No points for hitting bombs.
                {
                    gameModelHit = enemyBombHit;
                }

                if (gameModelHit == null)
                {
                    //Check for saucer hit.
                    var saucerHit = saucerModels.FirstOrDefault(x => playerMissileRect.IntersectsWith(x.CollisionRectangle));
                    if (saucerHit != null)
                    {
                        GameInfo.Score += saucerHit.PointValue;      //Add point value of saucer to score.
                        GameInfo.SaucersSinceLastDanosSnap++;
                        if (GameInfo.SaucersSinceLastDanosSnap == 8) //After 8 saucers the player gets a new Danos Snap.
                        {
                            GameInfo.ThanosSnaps++;
                            GameInfo.SaucersSinceLastDanosSnap = 0; //Count is reset.
                        }
                        gameModelHit = saucerHit;
                    }
                }

                if (gameModelHit != null)            //Check if any hits occured.
                {
                    GameModels.Remove(gameModelHit); //Remove pieces that were hit from the board.
                    GameModels.Remove(playerMissile);
                    audioController.StopBulletFired();
                    CreateExplosion(gameModelHit); //Create the explosion for the piece that was hit.
                }
            }
        }