public void AddToBuffer(GameObject gameObject) { Coordinate objectTopLeftPosition = gameObject.TopLeftPosition; char[,] objectBody = gameObject.Body; int objectBodyStartRow = gameObject.TopLeftPosition.Row; int objectBodyStartCol = gameObject.TopLeftPosition.Col; int objectBodyEndRow = gameObject.TopLeftPosition.Row + gameObject.BodyHeight - 1; int objectBodyEndCol = gameObject.TopLeftPosition.Col + gameObject.BodyWidth - 1; int objectBodyCurrentRow = 0; for (int row = objectBodyStartRow; row <= objectBodyEndRow; row++) { int objectBodyCurrentCol = 0; for (int col = objectBodyStartCol; col <= objectBodyEndCol; col++) { if (row >= 0 && row < buffer.GetLength(0) && col >= 0 && col < buffer.GetLength(1)) { if (objectBody[objectBodyCurrentRow, objectBodyCurrentCol] != EmptyCellChar) { buffer[row, col] = objectBody[objectBodyCurrentRow, objectBodyCurrentCol]; } } objectBodyCurrentCol++; } objectBodyCurrentRow++; } }
public void AddGameObject(GameObject gameObject) { if (gameObject is SpaceUnit) { this.spaceUnits.Add(gameObject as SpaceUnit); } this.gameObjects.Add(gameObject); }
public Engine(IGameController gameController, IRenderer renderer, ISpaceUnitFactory spaceUnitFactory, int canvasRows, int canvasColumns) { this.gameController = gameController; this.renderer = renderer; this.spaceUnitFactory = spaceUnitFactory; this.gameObjects = new List<GameObject>(); this.spaceUnits = new List<SpaceUnit>(); this.producedSpaceUnits = new List<SpaceUnit>(); this.healthUi = null; this.scoreUi = null; this.player = null; this.randomGenerator = new Random(); this.lastSpawnedEnemy = DateTime.Now; this.canvasRows = canvasRows; this.canvasCols = canvasColumns; }
public override bool CanShootAt(GameObject other) { int targetCol = other.TopLeftPosition.Col; for (int col = 0; col < other.BodyWidth; col++) { if (this.GetShootingPoint().Col == targetCol && this.IsReadyForShooting()) { this.loopTicks = 0; return true; } targetCol++; } return false; }
public virtual bool CanShootAt(GameObject other) { if (this.CollisionGroupString == "player") { return true; } int targetRow = other.TopLeftPosition.Row; for (int row = 0; row < other.BodyHeight; row++) { if (this.GetShootingPoint().Row == targetRow && this.IsReadyForShooting() && this.TopLeftPosition.Col > other.TopLeftPosition.Col) { this.loopTicks = 0; return true; } targetRow++; } return false; }
public Game() { this.mode = GameMode.MainMenu; this.menuItems = ConsoleUI.MainMenuItems; this.menuItemIndex = 0; this.cursorMoved = false; this.keyboard = new KeyboardController(); this.renderer = new Renderer(ConsoleUI.BufferRows, ConsoleUI.BufferCols, new Coordinate(ConsoleUI.BufferPositionRow, ConsoleUI.BufferPositionCol)); this.spaceUnitFactory = new SpaceUnitFactory(); this.gameLogo = new GameObject(new Coordinate(ConsoleUI.LogoPositionRow, ConsoleUI.LogoPositionCol), ConsoleUI.LogoBody); this.bottomWall = new GameObject(new Coordinate(ConsoleUI.BottomWallPositionRow, ConsoleUI.BottomWallPositionCol), ConsoleUI.BottomWallBody); this.cursor = new GameObject(new Coordinate(ConsoleUI.MainMenuCursorPositionRow, ConsoleUI.MainMenuCursorPositionCol), ConsoleUI.CursorBody); this.mainMenu = new GameObject(new Coordinate(ConsoleUI.MainMenuPositionRow, ConsoleUI.MainMenuPositionCol), ConsoleUI.MainMenuBody); this.controlsMenu = new GameObject(new Coordinate(ConsoleUI.ConstrolsMenuPositionRow, ConsoleUI.ConstrolsMenuPositionCol), ConsoleUI.ControlsMenuBody); this.highScoreMenu = new GameObject(new Coordinate(ConsoleUI.HighScoreMenuPositionRow, ConsoleUI.HighScoreMenuPositionCol), ConsoleUI.HighScoreMenuBody); this.gameOverMenu = new GameObject(new Coordinate(ConsoleUI.GameOverMenuPositionRow, ConsoleUI.GameOverMenuPositionCol), ConsoleUI.GameOverMenuBody); this.hittedHighScore = new GameObject(new Coordinate(ConsoleUI.HittedHighScorePositionRow, ConsoleUI.HittedHighScorePositionCol), ConsoleUI.HittedHighScoreBody); this.highScore = FileManager.ParseHighScore(); this.gameEngine = null; this.player = null; }
public void AddScoreUi(GameObject scoreUi) { this.scoreUi = scoreUi; }
public void AddHealthUI(GameObject healthUi) { this.healthUi = healthUi; }
private bool IsOutOfCanvas(GameObject gameObject) { return gameObject.TopLeftPosition.Col < -gameObject.BodyWidth || gameObject.TopLeftPosition.Row < -gameObject.BodyHeight || gameObject.TopLeftPosition.Col >= this.canvasCols || gameObject.TopLeftPosition.Row >= this.canvasRows; }
private void Play() { this.PrintGameLogo(); this.mode = GameMode.Play; SpaceUnitType playerSpaceshipType = SpaceUnitType.Banshee; Coordinate playerSpaceshipPosition = new Coordinate(ConsoleUI.PlayerInitPositionRow, ConsoleUI.PlayerInitPositionCol); Coordinate playerSpaceshipSpeed = new Coordinate(ConsoleUI.PlayerInitSpeedRow, ConsoleUI.PlayerInitSpeedCol); string playerSpacesheepCollisionGroup = "player"; Spaceship playerSpaceship = this.spaceUnitFactory.ProduceSpaceUnit(playerSpaceshipType, playerSpaceshipPosition, playerSpaceshipSpeed, playerSpacesheepCollisionGroup) as Spaceship; this.player = new Player(playerSpaceship); GameObject healthUi = new GameObject(new Coordinate(ConsoleUI.HealthPositionRow, ConsoleUI.HealthPositionCol), ConsoleUI.HealthBody); GameObject scoreUi = new GameObject(new Coordinate(ConsoleUI.ScorePositionRow, ConsoleUI.ScorePositionCol), ConsoleUI.ScoreBody); this.gameEngine = new Engine(this.keyboard, this.renderer, this.spaceUnitFactory, ConsoleUI.CanvasRows - this.gameLogo.BodyHeight, ConsoleUI.CanvasCols); this.gameEngine.AddPlayer(this.player); this.gameEngine.AddHealthUI(healthUi); this.gameEngine.AddScoreUi(scoreUi); this.gameEngine.Run(); this.mode = GameMode.GameOver; }