//Redraw player at new position and redraw previous player position static void PrintPlayer(Player player, bool isMoving) { if (player.positionY == 0 || player.positionY == riverHeight - 1) { SideColor(); } else { IceColor(); } Console.ForegroundColor = ConsoleColor.Red; if (isMoving) //Redraws the PREVIOUS player position { Console.SetCursorPosition(player.positionX + defaultRiverPositionX, player.positionY + defaultRiverPositionY); Console.Write(' '); } else //Redraw player at new position ( @ ) { //Check if the player has drowned. The check is made in the CheckForDrown() method and //the status of the isDrown player characteristic is changed. bool isOnCubeStartIndex, isOnCubeEndIndex; CheckForDrown(out isOnCubeStartIndex, out isOnCubeEndIndex); if (hasDrown) //If the player has drowned the background is water WaterColor(); Console.SetCursorPosition(player.positionX + defaultRiverPositionX, player.positionY + defaultRiverPositionY); Console.Write('@'); } Console.ResetColor(); }
//----------------------------------------------------------------------- static void Main() { Console.Title = GameName; Console.WindowWidth = gameWindowWidth; Console.WindowHeight = gameWindowHeight; Console.BufferHeight = Console.WindowHeight; Console.BufferWidth = Console.WindowWidth; PrintGameLogo(); //Initialize the player object player = new Player(); player.name = GetPlayerName(); player.lives = 3; player.scores = 0; //If there is a save game ith the same user name ask the user if the save should be loaded if (IndexOfUserInSaveFile(player.name) != -1) { Console.Clear(); PrintGameLogo(); Console.ForegroundColor = ConsoleColor.Green; PrintPrompt(new string[] { "Would you like to load your previous save?", "Y/N" }); ConsoleKeyInfo keyInfo = Console.ReadKey(); Console.WriteLine(); if (keyInfo.Key.ToString().Equals("Y")) { LoadGame(); } } Console.CursorVisible = false; //Play cicle while (currentLevel <= lastLevel && player.lives != 0) { PlayLevel(); if (isLevelComplete) { Console.ResetColor(); currentLevel++; if (currentLevel != 1) { LevelComplete(); } riverHeight += 2; } else { if (player.lives != 1) { LevelFailed(); Console.ResetColor(); player.lives--; } else { GameOver(); break; } } } }