// Function to Add a new Profile into the Profile List public void AddProfileToListAndSetItAsTheCurrentProfile(CProfile cProfile) { // Add the Profile into the List and use it as the new Current Profile mcProfileList.Add(cProfile); mcCurrentProfile = mcProfileList[mcProfileList.IndexOf(cProfile)]; }
// Load Profiles in from the file, overwriting any current ones public void LoadProfilesFromFile() { // Clear the List mcProfileList.Clear(); try { // Open an Input File Stream FileStream cInStream = new FileStream(msFILE_NAME, FileMode.Open, FileAccess.Read); BinaryReader cBinaryIn = new BinaryReader(cInStream); // Read in the name of the Current Profile first string sCurrentProfileName = cBinaryIn.ReadString(); // While we haven't reached the end of the file while (cBinaryIn.PeekChar() > 0) { // Create a new temp Profile CProfile sProfile = new CProfile(); // Read in the Profiles data sProfile.sName = cBinaryIn.ReadString(); sProfile.iLowerPitch = cBinaryIn.ReadInt32(); sProfile.iUpperPitch = cBinaryIn.ReadInt32(); sProfile.iScoreSpong = cBinaryIn.ReadInt32(); sProfile.iScoreShootingGallerySong1 = cBinaryIn.ReadInt32(); sProfile.iScoreShootingGallerySong2 = cBinaryIn.ReadInt32(); sProfile.iScoreShootingGallerySong3 = cBinaryIn.ReadInt32(); sProfile.iScorePitchMatcher = cBinaryIn.ReadInt32(); sProfile.iScoreTargetPractice = cBinaryIn.ReadInt32(); // Store this Profile in the List mcProfileList.Add(sProfile); } // Close the file cBinaryIn.Close(); // Save the handle to the Current Profile mcCurrentProfile = mcProfileList[mcProfileList.IndexOf(new CProfile(sCurrentProfileName))]; // Use the Current Profiles Settings CopyCurrentProfileSettingsToCurrentSoundInputSettings(); } // If the end of the stream is reached before reading in a full Profile catch (EndOfStreamException) { MessageBox.Show("End of file reached before full Profile was read in. Using default profile", "Error Loading Profiles"); // Load the Default Profile ClearAllProfilesExceptDefault(); } // If the file was not found catch (FileNotFoundException) { MessageBox.Show("Could not find Profiles.dat to load profiles from. Using default profile", "Error locating file Profiles.dat"); // Load the Default Profile ClearAllProfilesExceptDefault(); } catch (Exception e) { MessageBox.Show(e.ToString(), "Error Loading Profiles; Using Default Profile"); // Load the Default Profile ClearAllProfilesExceptDefault(); } }
// Do game processing and update the display public override void Update(float fTimeSinceLastUpdateInSeconds, Graphics cBackBuffer) { Brush cBrush; // Used to draw text Brush cGameNameBrush; // Used to draw the Name of the Games text // Save a handle to the Current Profile for readability CProfile cProfile = CProfiles.Instance().mcCurrentProfile; // Clear the scene cBackBuffer.Clear(Color.Black); // Display the High Scores title and the Players High Scores title cBrush = new SolidBrush(Color.RoyalBlue); cBackBuffer.DrawString("High Scores", mcFontTitle, cBrush, 250, 50); cBackBuffer.DrawString(" Your\nHigh Scores", mcFontTitle, cBrush, 550, 10); // Change the Brush Color cBrush = new SolidBrush(Color.LightBlue); cGameNameBrush = new SolidBrush(Color.LightGreen); // Display the Spong Scores cBackBuffer.DrawString("Spong", mcFontText, cGameNameBrush, 10, 110); cBackBuffer.DrawString(msSpongHighScoreName, mcFontText, cBrush, 250, 110); cBackBuffer.DrawString(miSpongHighScore.ToString(), mcFontText, cBrush, 325, 140); cBackBuffer.DrawString(cProfile.iScoreSpong.ToString(), mcFontText, cBrush, 625, 140); // Display the Shooting Gallery Song 1 Scores cBackBuffer.DrawString("Shooting Gallery", mcFontText, cGameNameBrush, 10, 180); cBackBuffer.DrawString("Song 1", mcFontText, cGameNameBrush, 50, 230); cBackBuffer.DrawString(msShootingGallerySong1HighScoreName, mcFontText, cBrush, 250, 230); cBackBuffer.DrawString(miShootingGallerySong1HighScore.ToString(), mcFontText, cBrush, 325, 260); cBackBuffer.DrawString(cProfile.iScoreShootingGallerySong1.ToString(), mcFontText, cBrush, 625, 260); // Display the Shooting Gallery Song 2 Scores cBackBuffer.DrawString("Song 2", mcFontText, cGameNameBrush, 50, 290); cBackBuffer.DrawString(msShootingGallerySong2HighScoreName, mcFontText, cBrush, 250, 290); cBackBuffer.DrawString(miShootingGallerySong2HighScore.ToString(), mcFontText, cBrush, 325, 320); cBackBuffer.DrawString(cProfile.iScoreShootingGallerySong2.ToString(), mcFontText, cBrush, 625, 320); // Display the Shooting Gallery Song 3 Scores cBackBuffer.DrawString("Song 3", mcFontText, cGameNameBrush, 50, 350); cBackBuffer.DrawString(msShootingGallerySong3HighScoreName, mcFontText, cBrush, 250, 350); cBackBuffer.DrawString(miShootingGallerySong3HighScore.ToString(), mcFontText, cBrush, 325, 380); cBackBuffer.DrawString(cProfile.iScoreShootingGallerySong3.ToString(), mcFontText, cBrush, 625, 380); // Display the Pitch Matcher Scores cBackBuffer.DrawString("Pitch Matcher", mcFontText, cGameNameBrush, 10, 420); cBackBuffer.DrawString(msPitchMatcherHighScoreName, mcFontText, cBrush, 250, 420); cBackBuffer.DrawString(miPitchMatcherHighScore.ToString(), mcFontText, cBrush, 325, 450); cBackBuffer.DrawString(cProfile.iScorePitchMatcher.ToString(), mcFontText, cBrush, 625, 450); // Display the Target Practice Scores cBackBuffer.DrawString("Target Practice", mcFontText, cGameNameBrush, 10, 490); cBackBuffer.DrawString(msTargetPracticeHighScoreName, mcFontText, cBrush, 250, 490); cBackBuffer.DrawString(miTargetPracticeHighScore.ToString(), mcFontText, cBrush, 325, 520); cBackBuffer.DrawString(cProfile.iScoreTargetPractice.ToString(), mcFontText, cBrush, 625, 520); // Release the Brush resources cBrush.Dispose(); cGameNameBrush.Dispose(); }