public void CreateLevel(int level) { Clear(); //Game Settings // if we send {50, 50} - the right top position is {0, 0} and the left bottom position is {50, 50}. int[] MapEndPoint = new int[] { 30 + (level * 5), 30 + (level * 5) }; CurrentWorld = new World(MapEndPoint, BoxSymbols, 2 + (level * 2), new int[] { 2 + (level * 3), 2 + (level * 3) }, new int[, ] { { 3, 3 }, { 35, 35 } }); //Player(x,y) CurrentPlayer = new Player(new int[, ] { { 1, 1 }, { 7, 7 } }); CurrentWorld.AddGameObject(CurrentPlayer); //Enemy(x,y) int[,] EnemyAndTreasureSpawnZone = new int[, ] { { MapEndPoint[0] - 5, MapEndPoint[1] - 5 }, { MapEndPoint[0] - 1, MapEndPoint[1] - 1 } }; CurrentEnemy = new Enemy(CurrentPlayer, CurrentWorld, EnemyAndTreasureSpawnZone); CurrentWorld.AddGameObject(CurrentEnemy); //Treasure(x,y) CurrentTreasure = new Treasure(EnemyAndTreasureSpawnZone); CurrentWorld.AddGameObject(CurrentTreasure); CurrentTrap = new Traps(EnemyAndTreasureSpawnZone); CurrentWorld.AddGameObject(CurrentTrap); CurrentWorld.DrawWorld(); CurrentWorld.SpawnGameObjects(); DrawFrame(); SetWindowSize(CurrentWorld.MapGrid.GetLength(0) + 5, CurrentWorld.MapGrid.GetLength(1) + 5); SetCursorPosition(0, 0); SetBufferSize(CurrentWorld.MapGrid.GetLength(0) + 15, CurrentWorld.MapGrid.GetLength(1) + 15); }
private void HandleMovement() { ConsoleKey key = ReadKey(true).Key; GameObject.direction direction = GameObject.direction.Other; switch (key) { case ConsoleKey.UpArrow: direction = GameObject.direction.Up; break; case ConsoleKey.DownArrow: direction = GameObject.direction.Down; break; case ConsoleKey.LeftArrow: direction = GameObject.direction.Left; break; case ConsoleKey.RightArrow: direction = GameObject.direction.Right; break; case ConsoleKey.Z: if (!CurrentWorld.HasGameObject(CurrentTreasure)) { if (CurrentWorld.HasGameObject(CurrentLaser)) { return; } Beep(466, 52); if (!CurrentWorld.HasGameObject(CurrentLaser) && CurrentWorld.HasGameObject(CurrentEnemy)) { CurrentLaser = new Laser(CurrentPlayer.X, CurrentPlayer.Y, CurrentGame, CurrentPlayer, CurrentWorld, CurrentEnemy); CurrentWorld.AddGameObject(CurrentLaser); } } break; case ConsoleKey.S: CurrentPlayer.Y++; CurrentPlayer.Y++; CurrentWorld.DrawWorld(); break; case ConsoleKey.W: CurrentPlayer.Y--; CurrentPlayer.Y--; CurrentWorld.DrawWorld(); break; case ConsoleKey.D: CurrentPlayer.X++; CurrentPlayer.X++; CurrentWorld.DrawWorld(); break; case ConsoleKey.A: CurrentPlayer.X--; CurrentPlayer.X--; CurrentWorld.DrawWorld(); break; } if (direction != GameObject.direction.Other) { CurrentWorld.MoveGameObject(CurrentPlayer, direction); CurrentEnemy.EnemyMoveToTarget(); CurrentLaser?.MoveLaser(); } }