public void Update() { LaserFactory laserFactory = new LaserFactory(laserSpeed, laserWidth, laserHeight, numRows * numColumns); BombFactory bombFactory = new BombFactory(bombSpeed, bombWidth, bombHeight, numBombSlots); ScoreAndLife scoreAndLife = new ScoreAndLife(lives, laserFactory, bombFactory); Player player = new Player(screenWidth, screenHeight, playerSpeed, playerWidth, playerHeight, laserFactory, bombFactory, scoreAndLife, timerIntervalPlayerRespawn); Bunkers bunkers = new Bunkers(numBunkers, screenWidth, screenHeight, bunkerWidth, bunkerHeight, bunkerHealth, playerHeight, spaceBetweenBunkerAndPlayer); Mothership mothership = new Mothership(screenWidth, mothershipWidth, mothershipHeight, mothershipSpeed, mothershipPoints, timerIntervalMothership, mothershipSpacerFromTop); //int screenWidth = 100; //int alienWidth = 1; //int alienHeight = 2; //int alienSpeed = 1; //int spacer = 1; //int numRows = 1; //int rowLength = 1; //int playerHeight = 0; //arrange //Bunkers bunkers = new Bunkers(numBunkers, screenWidth, screenHeight, bunkerWidth, bunkerHeight, bunkerHealth, playerHeight, spaceBetweenBunkerAndPlayer); BombFactory bf = new BombFactory(0, 0, 0, 0); AlienSquad alienS = new AlienSquad(bunkers, bombFactory, laserFactory, player, mothership, scoreAndLife, numRows, numColumns, screenWidth, player.BoundingBox.Height, alienWidth, alienHeight, alienSpeed, spacer, bombFrequency, alienPointStart, alienPointDecrement, alienSpacerFromTop, speedIncrease, bombFrequencyIncrement, bombFrequencyMin); //act alienS.Update(); //assert //Assert.AreEqual(,); //expected, actual }
public void UpdateProjectiles_TouchTop() { //arrange int laserSpeed = -5; int laserWidth = 1; int laserHeight = 1; int alienCount = 5; LaserFactory laser = new LaserFactory(laserSpeed, laserWidth, laserHeight, alienCount); //act int xLaser = laser.Laser.BoundingBox.X; int yLaser = laser.Laser.BoundingBox.Y; laser.UpdateProjectiles(); int xLaser1 = laser.Laser.BoundingBox.X; int yLaser1 = laser.Laser.BoundingBox.Y; //assert Assert.AreEqual(0, xLaser); //expected, actual Assert.AreEqual(0, yLaser); Assert.AreEqual(0, xLaser1); //expected, actual Assert.AreEqual(0, yLaser1); }
public PlayerController(Data data, InputModel inputModel, PlayerModel playerModel, PauseModel pauseModel) { _controllerList = new ControllerList(); var cameraFactory = new CameraFactory(data.CameraData); var laserFactory = new LaserFactory(); var cameraModel = new CameraModel(cameraFactory); var moveController = new MoveController(inputModel.GetInputKeyboard(), data.PlayerData, playerModel.Transform); var shootController = new ShootController(data.BulletData, playerModel, laserFactory); var cameraController = new CameraController(cameraModel, playerModel, data.CameraData, pauseModel); var explosion = new Explosion(data.ExplosionData, playerModel); var abilityController = new AbilityController(inputModel, explosion); _controllerList.Add(moveController).Add(shootController). Add(cameraController).Add(abilityController).Initialize(); }
public ScoreAndLife(int lives, LaserFactory laserFactory, BombFactory bombFactory) { this.bombFactory = bombFactory; this.laserFactory = laserFactory; this.lives = lives; laserFactory.alienDeath += OnAlienDeath; laserFactory.mothershipDeath += OnAlienDeath; gameOver += laserFactory.EndGame; }
static void Main(string[] args) { string defFilePath = args[0]; if (IsPathValid(defFilePath)) { try { string[] lines = File.ReadAllLines(defFilePath); BoardFactory brdFactory = new BoardFactory(); Board board = brdFactory.BuildBoard(lines[0]); RoomFactory rmFactory = new RoomFactory(); for (int w = 0; w <= board.Width - 1; w++) { for (int h = 0; h <= board.Height - 1; h++) { Room rm = rmFactory.BuildRoom(w, h); board.Rooms.Add(rm); } } MirrorFactory mrFactory = new MirrorFactory(); int i = 2; string line = lines[i]; while (line != "-1") { Mirror mirror = mrFactory.BuildMirror(line); i++; line = lines[i]; board.AddMirror(mirror); } LaserFactory laserFactory = new LaserFactory(); Laser laser = laserFactory.BuildLaser(lines[lines.Count() - 2]); board.SetLaserDirection(laser); string exitConditions = board.FindExit(laser); Console.WriteLine($" Dimensions of Board: {board.Width}, {board.Height}\n Laser Starting Position {laser.XLoc}, {laser.YLoc}\n Laser Exit is at {exitConditions}"); } catch (Exception ex) { Console.WriteLine($"Error Occurred! Exception: {ex.Message} \nStackTrace\n: {ex.StackTrace}"); } } else { Console.WriteLine("File is not found or is invalid. Please select a new file."); } }
public void Fire() { if (timeToCoolDown > 0) { return; } if (muzzle != null) { muzzle.SetActive(true); muzzleCoolDown = coolDown / 2f; } LaserFactory.CreateLaser(this); timeToCoolDown = coolDown; }
public ShootController(BulletData bulletData, PlayerModel playerModel, LaserFactory laserFactory) { _data = bulletData; var ratio = _data.BulletLifespan / _data.ShootCooldown; var poolSize = (int)Math.Ceiling(ratio); _bulletPool = new BulletPool(poolSize, _data, laserFactory); _playerModel = playerModel; _barrelTransform = _playerModel.BarrelTransform; _audioSource = _playerModel.AudioSource; _bulletLifespan = _data.BulletLifespan; _shootCooldown = _data.ShootCooldown; }
public void UpdateProjectiles_TouchMothership() { //arrange int laserSpeed = -5; int laserWidth = 1; int laserHeight = 1; int alienCount = 5; LaserFactory laser = new LaserFactory(laserSpeed, laserWidth, laserHeight, alienCount); int mothershipW = 10; int screenW = 20; int speed = 5; //should end up at 0 Mothership ms = new Mothership(screenW, mothershipW, mothershipHeight, speed, mothershipPoints, timerIntervalMothership, mothershipSpacerFromTop); //act int xMothership = ms.BoundingBox.X; int yMothership = ms.BoundingBox.Y; int xLaser = laser.Laser.BoundingBox.X; int yLaser = laser.Laser.BoundingBox.Y; laser.UpdateProjectiles(); int xMothership1 = ms.BoundingBox.X; int yMothership1 = ms.BoundingBox.Y; int xLaser1 = laser.Laser.BoundingBox.X; int yLaser1 = laser.Laser.BoundingBox.Y; //assert Assert.AreEqual(0, xMothership); //expected, actual Assert.AreEqual(0, yMothership); Assert.AreEqual(0, xLaser); //expected, actual Assert.AreEqual(0, yLaser); Assert.AreEqual(0, xMothership1); //expected, actual Assert.AreEqual(0, yMothership1); Assert.AreEqual(0, xLaser1); //expected, actual Assert.AreEqual(0, yLaser1); }
public void MoveLeft_EnoughSpace() { int playerW = 10; int screenW = 20; int speed = 5; //should end up at 0 LaserFactory laserFactory = new LaserFactory(laserSpeed, laserWidth, laserHeight, numRows * numColumns); BombFactory bombFactory = new BombFactory(bombSpeed, bombWidth, bombHeight, numBombSlots); // Create game objects ScoreAndLife scoreAndLife = new ScoreAndLife(lives, laserFactory, bombFactory); //arrange Player player = new Player(screenW, 100, speed, playerW, 2, laserFactory, bombFactory, scoreAndLife, timerIntervalPlayerRespawn); //act player.MoveLeft(); int x = player.BoundingBox.X; //assert Assert.AreEqual(0, x); //expected, actual }
public void UpdateProjectiles_TouchBunkers() { //arrange int laserSpeed = -5; int laserWidth = 1; int laserHeight = 1; int alienCount = 5; LaserFactory laser = new LaserFactory(laserSpeed, laserWidth, laserHeight, alienCount); int numBunkers = 1; int screenWidth = 100; int screenHeight = 100; int bunkerWidth = 5; int bunkerHeight = 5; int bunkerHealth = 3; int playerHeight = 5; int spaceBetweenBunkerAndPlayer = 1; Bunkers bunkers = new Bunkers(numBunkers, screenWidth, screenHeight, bunkerWidth, bunkerHeight, bunkerHealth, playerHeight, spaceBetweenBunkerAndPlayer); //act int xLaser = laser.Laser.BoundingBox.X; int yLaser = laser.Laser.BoundingBox.Y; laser.UpdateProjectiles(); int xLaser1 = laser.Laser.BoundingBox.X; int yLaser1 = laser.Laser.BoundingBox.Y; //assert Assert.AreEqual(0, xLaser); //expected, actual Assert.AreEqual(0, yLaser); Assert.AreEqual(0, xLaser1); //expected, actual Assert.AreEqual(0, yLaser1); }
public void UpdateProjectiles_TouchPlayer() { int bombSpeed = 5; int bombWidth = 1; int bombHeight = 1; int numBombSlots = 5; LaserFactory laserFactory = new LaserFactory(laserSpeed, laserWidth, laserHeight, numRows * numColumns); BombFactory bombFactory = new BombFactory(bombSpeed, bombWidth, bombHeight, numBombSlots); // Create game objects ScoreAndLife scoreAndLife = new ScoreAndLife(lives, laserFactory, bombFactory); Player player = new Player(screenWidth, screenHeight, playerSpeed, playerWidth, playerHeight, laserFactory, bombFactory, scoreAndLife, timerIntervalPlayerRespawn); //arrange BombFactory bomb = new BombFactory(bombSpeed, bombWidth, bombHeight, numBombSlots); //int playerW = 10; //int screenW = 20; //int speed = 5; //should end up at 0 //act int xBomb = bomb.Bombs[0].BoundingBox.X; int yBomb = bomb.Bombs[0].BoundingBox.Y; bomb.UpdateProjectiles(); int xBomb1 = bomb.Bombs[0].BoundingBox.X; int yBomb1 = bomb.Bombs[0].BoundingBox.Y; //assert Assert.AreEqual(0, xBomb); //expected, actual Assert.AreEqual(0, yBomb); Assert.AreEqual(0, xBomb1); //expected, actual Assert.AreEqual(0, yBomb1); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // Create textures Texture2D textureAlien = this.Content.Load <Texture2D>(@"assets/bug"); Texture2D textureBomb = this.Content.Load <Texture2D>(@"assets/bomb"); Texture2D textureBunker = this.Content.Load <Texture2D>(@"assets/bunker"); Texture2D textureLaser = this.Content.Load <Texture2D>(@"assets/laser"); Texture2D textureMothership = this.Content.Load <Texture2D>(@"assets/mothership"); Texture2D texturePlayer = this.Content.Load <Texture2D>(@"assets/player"); // Initialize variables alienHeight = textureAlien.Height; alienWidth = textureAlien.Width; bombHeight = textureBomb.Height; bombWidth = textureBomb.Width; bunkerHeight = textureBunker.Height; bunkerWidth = textureBunker.Width; laserHeight = textureLaser.Height; laserWidth = textureLaser.Width; mothershipHeight = textureMothership.Height; mothershipWidth = textureMothership.Width; playerHeight = texturePlayer.Height; playerWidth = texturePlayer.Width; // Create factories laserFactory = new LaserFactory(laserSpeed, laserWidth, laserHeight, numRows * numColumns); bombFactory = new BombFactory(bombSpeed, bombWidth, bombHeight, numBombSlots); // Create game objects scoreAndLife = new ScoreAndLife(lives, laserFactory, bombFactory); player = new Player(screenWidth, screenHeight, playerSpeed, playerWidth, playerHeight, laserFactory, bombFactory, scoreAndLife, timerIntervalPlayerRespawn); bunkers = new Bunkers(numBunkers, screenWidth, screenHeight, bunkerWidth, bunkerHeight, bunkerHealth, playerHeight, spaceBetweenBunkerAndPlayer); mothership = new Mothership(screenWidth, mothershipWidth, mothershipHeight, mothershipSpeed, mothershipPoints, timerIntervalMothership, mothershipSpacerFromTop); alienSquad = new AlienSquad(bunkers, bombFactory, laserFactory, player, mothership, scoreAndLife, numRows, numColumns, screenWidth, player.BoundingBox.Height, alienWidth, alienHeight, alienSpeed, spacer, bombFrequency, alienPointStart, alienPointsPerRow, alienSpacerFromTop, speedIncrease, bombFrequencyIncrement, bombFrequencyMin); // Create sprite objects laserSprite = new LaserSprite(this, laserFactory.Laser, textureLaser); mothershipSprite = new MothershipSprite(this, mothership, player, textureMothership); playerSprite = new PlayerSprite(this, player, texturePlayer); scoreSprite = new ScoreSprite(this, scoreAndLife); for (var x = 0; x < alienSquad.Length; x++) { Components.Add(new AlienSprite(this, (Alien)alienSquad[x], textureAlien)); } foreach (Bunker bunker in bunkers) { Components.Add(new BunkerSprite(this, bunker, textureBunker)); } foreach (Projectile bomb in bombFactory.Bombs) { Components.Add(new BombSprite(this, bomb, textureBomb)); } // Add components Components.Add(mothershipSprite); Components.Add(playerSprite); Components.Add(scoreSprite); Components.Add(laserSprite); // Register objects laserFactory.RegisterAlienSquad(alienSquad); laserFactory.RegisterBunkers(bunkers); laserFactory.RegisterMothership(mothership); bombFactory.RegisterBunkers(bunkers); bombFactory.RegisterPlayer(player); base.Initialize(); }