/// <summary> /// Draw the map /// </summary> static public int Update() { if (ThePlayer.Life < 1) { Console.Clear(); MessageBrd.Add($"You have DIED!"); MessageBrd.Update(); return(-1); } var origRow = Console.CursorTop; var origCol = Console.CursorLeft; UpdateFogOfWar(); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { Tiles[y, x].Draw(); } } Dirty = false; //foreach player in players coming soon.... ThePlayer.Update(); MonsterMgr.UpdateAll(); MessageBrd.Update(); ScoreCard.Update(); //if there is a keypress available to capture, take it and perform its action if (Console.KeyAvailable) { var ch = Console.ReadKey(true).Key; switch (ch) { case ConsoleKey.Escape: Log.Information("User is quitting."); return(-1); case ConsoleKey.F2: CheatToggleFOW(); break; case ConsoleKey.UpArrow: PlayerTryMoveOffsetTo(0, -1); break; case ConsoleKey.DownArrow: PlayerTryMoveOffsetTo(0, 1); break; case ConsoleKey.RightArrow: PlayerTryMoveOffsetTo(1, 0); break; case ConsoleKey.LeftArrow: PlayerTryMoveOffsetTo(-1, 0); break; } } //Console.SetCursorPosition(0, 0); return(0); }
/// <summary> /// Draw the map /// </summary> public int Update() { var origRow = Console.CursorTop; var origCol = Console.CursorLeft; if (NeedsRedrawing) { Console.Clear(); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { Tiles[y, x].Draw(); } Console.WriteLine(); //carriage return at end of each line because we're not using SetCursorPosition. } NeedsRedrawing = false; } //if there is a keypress available to capture, take it and perform its action if (Console.KeyAvailable) { var ch = Console.ReadKey(true).Key; switch (ch) { case ConsoleKey.Escape: Log.Information("User is quitting."); return(-1); case ConsoleKey.UpArrow: //perform boundary checking if (ThePlayer.X > 0) { //if the space moving upwards is a blank space then move up if (GetTileAtPos(ThePlayer.X, ThePlayer.Y - 1).IsWalkable) { MovePlayer(PlayerMovement.Up); } } break; case ConsoleKey.DownArrow: if (ThePlayer.Y < Height - 1) { if (GetTileAtPos(ThePlayer.X, ThePlayer.Y + 1).IsWalkable) { MovePlayer(PlayerMovement.Down); } } break; case ConsoleKey.RightArrow: if (ThePlayer.X < Width - 1) { if (GetTileAtPos(ThePlayer.X + 1, ThePlayer.Y).IsWalkable) { MovePlayer(PlayerMovement.Right); } } break; case ConsoleKey.LeftArrow: if (ThePlayer.X > 0) { if (GetTileAtPos(ThePlayer.X - 1, ThePlayer.Y).IsWalkable) { MovePlayer(PlayerMovement.Left); } } break; } } //foreach player in players coming soon.... ThePlayer.Update(); MonsterMgr.UpdateAll(this); MessageBrd.Update(); Console.SetCursorPosition(0, 0); return(0); }
/// <summary> /// Draw the map /// </summary> static public int Update() { switch (GameState) { case GameStateType.MainMenu: if (Dirty) { Console.Clear(); Console.WriteLine(FiggleFonts.Ogre.Render("Mud2D")); #if DEBUG Console.WriteLine("DEBUG version"); Log.Information("DEBUG version"); #elif RELEASE Console.WriteLine("RELEASE version"); Log.Information("RELEASE version"); #endif Console.WriteLine("------===== Main Menu =====-------"); Console.WriteLine("Press S to start game"); Console.WriteLine("Press L to load last save game"); Console.WriteLine("Press ESC to exit"); Dirty = false; } //if there is a keypress available to capture, take it and perform its action if (Console.KeyAvailable) { var ch = Console.ReadKey(true).Key; switch (ch) { case ConsoleKey.Escape: GameState = GameStateType.Quit; Log.Information("User is quitting game."); return(-1); case ConsoleKey.L: GameState = GameStateType.InGame; LoadLastGame(); break; case ConsoleKey.S: GameState = GameStateType.InGame; InitializeGame(); break; } } break; case GameStateType.InGame: if (ThePlayer.Life < 1) { Console.Clear(); MessageBrd.Add($"You have DIED!"); MessageBrd.Update(); return(-1); } var origRow = Console.CursorTop; var origCol = Console.CursorLeft; UpdateFogOfWar(); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { Tiles[y, x].Draw(); } } Dirty = false; //foreach player in players coming soon.... ThePlayer.Update(); MonsterMgr.UpdateAll(); MessageBrd.Update(); ScoreCard.Update(); //if there is a keypress available to capture, take it and perform its action if (Console.KeyAvailable) { var ch = Console.ReadKey(true).Key; switch (ch) { case ConsoleKey.Escape: GameState = GameStateType.MainMenu; Dirty = true; SaveGame(); Log.Information("User is quitting game, going back to main menu."); break; case ConsoleKey.F2: CheatToggleFOW(); break; case ConsoleKey.UpArrow: PlayerTryMoveOffsetTo(0, -1); break; case ConsoleKey.DownArrow: PlayerTryMoveOffsetTo(0, 1); break; case ConsoleKey.RightArrow: PlayerTryMoveOffsetTo(1, 0); break; case ConsoleKey.LeftArrow: PlayerTryMoveOffsetTo(-1, 0); break; } } //Console.SetCursorPosition(0, 0); return(0); } return(0); }