/// <summary> /// this method's use is to constantly print the information available /// to the player at all times during a level, returning nothing /// </summary> /// <param name="player"> receives the current player's info</param> public void GameText(Levels level, Player player, Inventory inventory, char key) { Console.OutputEncoding = Encoding.UTF8; if (key == 'W') { actions.Push("Moved to the North"); } if (key == 'S') { actions.Push("Moved to the South"); } if (key == 'D') { actions.Push("Moved to the East"); } if (key == 'A') { actions.Push("Moved to the West"); } if (key == 'Q') { actions.Push("Moved to the NorthWest"); } if (key == 'E') { actions.Push("Moved to the NorthEast"); } if (key == 'Z') { actions.Push("Moved to the SouthWest"); } if (key == 'X') { actions.Push("Moved to the SouthEast"); } if (key == 'M') { actions.Push("Picked up map!"); } if (key == 'T') { actions.Push("Fallen into a trap!!"); } if (key == 'P') { actions.Push("Picked up item"); } if (key == 'M') { actions.Push("Enemy attack!"); } Console.Write("last actions:"); Console.WriteLine("------------------------------------------------"); foreach (string action in actions) { Console.WriteLine(action); } if (actions.Count >= 3) { for (int i = 0; i < 3; i++) { actions.Pop(); } } Console.WriteLine("Player Stats:"); Console.WriteLine("------------------------------------------------"); Console.WriteLine($"Current Level:{level.Current}"); Console.WriteLine($"HP: {player.Health}"); if (player.SelectedWeapon != null) { Console.WriteLine($"Selected Weapon: {player.SelectedWeapon.Name}"); } Console.WriteLine($"Inventory occupation: {inventory.currentWeight}"); Console.WriteLine("Caption:"); Console.WriteLine("------------"); Console.Write($"SYMBOL - {(char)Chars.player}"); Console.Write($"SYMBOL - {(char)Chars.enemy}"); Console.WriteLine($"SYMBOL - {(char)Chars.empty}"); Console.Write($"SYMBOL - {(char)Chars.path}"); Console.Write($"SYMBOL - {(char)Chars.map}"); Console.WriteLine($"SYMBOL - {(char)Chars.food}"); Console.Write($"SYMBOL - {(char)Chars.weapon}"); Console.Write($"SYMBOL - {(char)Chars.trap}"); Console.WriteLine($"SYMBOL - {(char)Chars.exit}"); Console.WriteLine("Messages:"); Console.WriteLine("------------"); Console.WriteLine("Options:"); Console.WriteLine("------------"); Console.Write("\u2196\u2191\u2197 "); Console.Write(" Attack Enemy(1) "); Console.Write("Pick up Item(2) "); Console.Write("Use Item(3) "); Console.WriteLine("Drop Item(4) "); Console.Write("\u2190 \u2192 Move "); Console.Write("Look Around(5) "); Console.WriteLine("Help(6)"); Console.Write("\u2199\u2193\u2198 "); Console.Write(" Save Game(7) "); Console.WriteLine("Quit Game(8)"); }
/// <summary> /// This method contains the main loop cycle for the game, showing the /// start menu and registering player input for each action every turn, /// finishing whenever someone wins, loses or quits /// it returns nothing /// </summary> public void Loop(int chosenDiff) { // create new level based on the chosen difficulty and current lvl newLevel = new Levels(lvlCount, (chosenDiff * lvlCount)); // initialise the PrintText class so different texts can be printed PrintText gameInfo = new PrintText(); // only show the menu and create board at startup if (!start) { menu.Menu(); board.DefineBoard(newLevel); } // set start to true to hide menu and set the board start = true; // For reading the player's input ConsoleKey answer; // cycle to print board and run the game while conditions not met do { // render the board anew each time the cycle loops board.RenderBoard(newLevel); // Showcase player's current stats through level progression gameInfo.GameText(newLevel, board.player, board.inventory, key); // Read user's single key input answer = Console.ReadKey().Key; // Clear console for ease of view Console.Clear(); // check the action given by the player // activate look around if (answer == ConsoleKey.D5) { List <CurrentMapObjects> lookAroundItems = new List <CurrentMapObjects>(); // get the objects around the player foreach (CurrentMapObjects item in board.itemList) { board.player.Surroundings(lookAroundItems, item, board); } // show the look around menu gameInfo.LookAroundText(lookAroundItems); // clear the items for next movement positions lookAroundItems.Clear(); } // move to the south if (answer == ConsoleKey.S && Position.IsValidPosition ((new Position((board.player.Position.Row + 1), (board.player.Position.Col))), (GameBoard.RowSize - 1), (GameBoard.ColSize - 1))) { // set the key to print the action key = 'S'; // remove 1hp for turn board.player.HealthChange(-1); // reset the cell the player was on board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells((char)Chars.path, true); // set the cell at new player position board.player.Position.Row++; board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells(board.player.name, false); } if (answer == ConsoleKey.W && Position.IsValidPosition ((new Position((board.player.Position.Row - 1), (board.player.Position.Col))), (GameBoard.RowSize - 1), (GameBoard.ColSize - 1))) { key = 'W'; board.player.HealthChange(-1); board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells((char)Chars.path, true); board.player.Position.Row--; board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells(board.player.name, false); } if (answer == ConsoleKey.A && Position.IsValidPosition((new Position((board.player.Position.Row), (board.player.Position.Col - 1))), (GameBoard.RowSize - 1), (GameBoard.ColSize - 1))) { key = 'A'; board.player.HealthChange(-1); board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells((char)Chars.path, true); board.player.Position.Col--; board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells(board.player.name, false); } if (answer == ConsoleKey.D && Position.IsValidPosition(( new Position((board.player.Position.Row), (board.player.Position.Col + 1))), (GameBoard.RowSize - 1), (GameBoard.ColSize - 1))) { key = 'D'; board.player.HealthChange(-1); board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells((char)Chars.path, true); board.player.Position.Col++; board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells(board.player.name, false); } if (answer == ConsoleKey.Q && Position.IsValidPosition(( new Position((board.player.Position.Row - 1), (board.player.Position.Col - 1))), (GameBoard.RowSize - 1), (GameBoard.ColSize - 1))) { key = 'Q'; board.player.HealthChange(-1); board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells((char)Chars.path, true); board.player.Position.Col--; board.player.Position.Row--; board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells(board.player.name, false); } if (answer == ConsoleKey.E && Position.IsValidPosition(( new Position((board.player.Position.Row - 1), (board.player.Position.Col + 1))), (GameBoard.RowSize - 1), (GameBoard.ColSize - 1))) { key = 'E'; board.player.HealthChange(-1); board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells((char)Chars.path, true); board.player.Position.Col++; board.player.Position.Row--; board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells(board.player.name, false); } if (answer == ConsoleKey.Z && Position.IsValidPosition(( new Position((board.player.Position.Row + 1), (board.player.Position.Col - 1))), (GameBoard.RowSize - 1), (GameBoard.ColSize - 1))) { key = 'Z'; board.player.HealthChange(-1); board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells((char)Chars.path, true); board.player.Position.Col--; board.player.Position.Row++; board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells(board.player.name, false); } if (answer == ConsoleKey.X && Position.IsValidPosition((new Position(( board.player.Position.Row + 1), (board.player.Position.Col + 1))), (GameBoard.RowSize - 1), (GameBoard.ColSize - 1))) { key = 'X'; board.player.HealthChange(-1); board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells((char)Chars.path, true); board.player.Position.Col++; board.player.Position.Row++; board.cells[board.player.Position.Row, board.player.Position.Col] = new BoardCells(board.player.name, false); } if (answer == ConsoleKey.D2) { if (board.map.FallenInto(board.player)) { key = 'M'; board.itemList.Remove(board.map); foreach (CurrentMapObjects items in board.itemList) { board.cells[items.Position.Row, items.Position.Col] = new BoardCells((char)items.Name, false); } } else { key = 'P'; foreach (Food foode in board.food) { if (foode.FallenInto(board.player)) { board.player.Inventory.AddToInventory( new Food(foode.Position, foode.Name, foode.Info, foode.Weight, foode.HPIncrease)); } } board.inventory.WriteInfo(board, board.player, "pickup"); } } if (answer == ConsoleKey.D3) { key = 'D'; if (board.inventory.foodInInventory.Count > 0 || board.inventory.weaponsInInventory.Count > 0) { board.inventory.WriteInfo(board, board.player, "use"); } else { Console.Clear(); Console.WriteLine("your inventory is empty!!"); Console.ReadKey(); } } if (answer == ConsoleKey.D4) { if (board.inventory.foodInInventory.Count > 0 || board.inventory.weaponsInInventory.Count > 0) { board.inventory.WriteInfo(board, board.player, "drop"); } else { Console.Clear(); Console.WriteLine("your inventory is empty!!"); Console.ReadKey(); } } if (answer == ConsoleKey.D1) { gameInfo.EnemyAttackText(); } if (answer == ConsoleKey.D6) { gameInfo.HelpText(board.food, board.weapons, board.traps, board.inventory, board.player); } if (answer == ConsoleKey.D8) { Console.Clear(); Console.WriteLine("are you sure you wish to quit? y/n"); ConsoleKey quit = Console.ReadKey().Key; if (quit == ConsoleKey.Y) { //insert score stuff Console.WriteLine("thank you for playing!"); board.player.Health = 0; } } foreach (Enemy enemy in board.enemies) { if (enemy.FallenInto(board.player)) { board.player.HealthChange(-rnd.Next(enemy.AttackPower, enemy.MaxDamage)); key = 'L'; } } foreach (Trap trap in board.traps) { if (trap.FallenInto(board.player)) { board.player.HealthChange(-rnd.Next(trap.MaxDamage)); key = 'T'; trap.Active = false; } } if (board.cells[board.player.Position.Row, board.player.Position.Col] == board.cells[board.exit.Position.Row, board.exit.Position.Col]) { Console.WriteLine("Congratulations! you've reached the exit!"); Console.WriteLine("Press any key to continue to the next level"); Console.ReadKey(); Console.Clear(); start = true; board.ResetBoard(); board.DefineBoard(newLevel); lvlCount++; Loop(chosenDiff); } } // run the loop while the player hasn't won, lost or quit while (board.player.Health > 0); Console.WriteLine("please input your name for the score"); string name = Console.ReadLine(); score = new GameScore(name, newLevel.ScoreSetter(lvlCount)); score.SaveScoreOnFile(score); Environment.Exit(0); }