///////////////////////////////////////////||\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ /////////////////////////////////////// METHODS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ///////////////////////////////////////////||\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //Pre: The map name //Post: The map is downloaded //Desc: A method for downloading the map public void DownloadHighscoresMap(string map) { //Resets the user names and user times lists UserNames = new List <string>(); UserTimes = new List <float>(); //If the file was able to be downloaded if (onlineHelper.DownloadFile(map + FILE_PATH_SUFFIX, map + FILE_NAME_SUFFIX)) { //Creates a strean reader with the map path reader = new StreamReader(map + FILE_PATH_SUFFIX); //Gets the score count from the file int scoreCount = Convert.ToInt32(reader.ReadLine()); //For each score that is saved for (int i = 0; i < scoreCount; i++) { //Reads the user name and the time for the current user UserNames.Add(reader.ReadLine()); UserTimes.Add((float)Convert.ToDouble(reader.ReadLine())); } //Closes the stream reader reader.Close(); } }
//Pre: The map name //Post: None //Desc: A new map is loaded to be played by the user public void LoadNewMap(string mapName) { //Creates temp data to store everything that is loaded from the server Tile[,] tempGameTiles; List <Enemy> tempEnemyList = new List <Enemy>(); Tile tempStartTile; //Downloads the map that is wanted to be played from the server onlineHelper.DownloadFile(mapName + NEW_MAP_PATH_SUFFIX, mapName + NEW_MAP_SUFFIX); //A stream reader is created with the path of the new map reader = new StreamReader(mapName + NEW_MAP_PATH_SUFFIX); //Creates the 2D array of game tiles using the sizes from the file tempGameTiles = new Tile[Convert.ToInt32(reader.ReadLine()), Convert.ToInt32(reader.ReadLine())]; //Loop for every value for the first dimension of the array for (int i = 0; i < tempGameTiles.GetLength(0); i++) { //Loop for every value of the seocnd dimension of the array for (int j = 0; j < tempGameTiles.GetLength(1); j++) { //Sets the current tile using the values of the loop and the tile type that is read from the file tempGameTiles[i, j] = new Tile(i, j, (TileType)Enum.Parse(typeof(TileType), reader.ReadLine())); } } //Gets the enemy count from the file int enemyCount = Convert.ToInt32(reader.ReadLine()); //Calculates the screen width and height int screenWidth = Tile.TILE_X_SIZE * tempGameTiles.GetLength(0); int screenHeight = Tile.TILE_Y_SIZE * tempGameTiles.GetLength(1); //Loop for every enemy for (int i = 0; i < enemyCount; i++) { //Adds the current enemy using data that is read from the file tempEnemyList.Add(new Enemy(tempGameTiles, Convert.ToInt32(reader.ReadLine()), Convert.ToInt32(reader.ReadLine()), humanWidth, humanHeight, screenWidth, screenHeight)); } //Reads the location of the start tile from the file and sets it tempStartTile = tempGameTiles[Convert.ToInt32(reader.ReadLine()), Convert.ToInt32(reader.ReadLine())]; //Closes the stream reader reader.Close(); //Sets the game tiles, enemies, and start tile to the properties which can be accessed by other classes which load the game GameTiles = tempGameTiles; Enemies = tempEnemyList; StartTile = tempStartTile; }
//Pre: None //Post: A boolean for whether the profiles were read //Desc: A method for reading all the profiles file public bool ReadProfiles() { //If the file with all the profiles is downloaded if (onlineHelper.DownloadFile(FILE_PATH, FILE_NAME)) { //Creates a stream reader to read all the profiles from the file reader = new StreamReader(FILE_PATH); //Clears the usernames and passwords currently saved userNames.Clear(); passWords.Clear(); //While the file still contains usernames and passwords to be read while (!reader.EndOfStream) { //The current username and password is read from the file and added to the lists userNames.Add(reader.ReadLine()); passWords.Add(reader.ReadLine()); } //The stream reader is closed reader.Close(); //True is returned representing that the profiles were read return(true); } //False is returned representing that the profiles were not read return(false); }
//Pre: The user profile, the amount of enemies killed, the amount of health lost, whether the player died again, the amount of extra game time, and the amount of projecitles shot //Post: A boolean for whether the profile stats were updated //Desc: A method for updating the profile stats for a specific profile public bool UpdateProfileStats(string userProfile, int extraEnemiesKilled, int extraHealthLost, int extraDeath, float extraGameTime, int extraBulletsShot) { //If the file for the profile stats exists if (onlineHelper.CheckFileExists(userProfile + FILE_NAME_SUFFIX)) { //If the file is downloaded if (onlineHelper.DownloadFile(userProfile + FILE_PATH_SUFFIX, userProfile + FILE_NAME_SUFFIX)) { //A stream reader is created to read the file reader = new StreamReader(userProfile + FILE_PATH_SUFFIX); //All the data from the file is read EnemiesKilled = Convert.ToInt32(reader.ReadLine()); HealthLost = Convert.ToInt32(reader.ReadLine()); DeathAmount = Convert.ToInt32(reader.ReadLine()); TotalGameTime = (float)Convert.ToDouble(reader.ReadLine()); BulletsShot = Convert.ToInt32(reader.ReadLine()); //The stream reader is closed reader.Close(); //All the extra values are added to the total values for the profile EnemiesKilled += extraEnemiesKilled; HealthLost += extraHealthLost; DeathAmount += extraDeath; TotalGameTime += extraGameTime; BulletsShot += extraBulletsShot; //A stream writer is created to save all the data in a new profile stats file writer = new StreamWriter(userProfile + FILE_PATH_SUFFIX); //All the data is writtern to the file writer.WriteLine(EnemiesKilled); writer.WriteLine(HealthLost); writer.WriteLine(DeathAmount); writer.WriteLine(TotalGameTime); writer.WriteLine(BulletsShot); //The stream writer is closed writer.Close(); //If the new file is uploaded if (onlineHelper.UpdateFile(userProfile + FILE_NAME_SUFFIX, userProfile + FILE_PATH_SUFFIX, FILE_TYPE, FILE_DESCRIPTION)) { //Returns that the profile stats were updated for the current profile return(true); } } //if the file was not downloaded else { //Returns that the profile stats were not updated for the current profile return(false); } } //If the profile stats for the current profile do not exist else { //A stream writer is created to write all the data to a file writer = new StreamWriter(userProfile + FILE_PATH_SUFFIX); //All the data is written to the profile stats file writer.WriteLine(extraEnemiesKilled); writer.WriteLine(extraHealthLost); writer.WriteLine(extraDeath); writer.WriteLine(extraGameTime); writer.WriteLine(extraBulletsShot); //The stream writer is closed writer.Close(); //If the file is uploaded onto the server if (onlineHelper.UpdateFile(userProfile + FILE_NAME_SUFFIX, userProfile + FILE_PATH_SUFFIX, FILE_TYPE, FILE_DESCRIPTION)) { //Returns that the profile stats were updated for the current profile return(true); } } //Returns that the profile stats were not updated for the current profile return(false); }