Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sudoku Generator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nguyenha63321
Sudoku Generator
Commits
a1721abf
Commit
a1721abf
authored
Jun 9, 2020
by
nguyenha63321
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
62a334e0
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
HighscorePage.xaml.cs
+131
-0
131 additions, 0 deletions
HighscorePage.xaml.cs
with
131 additions
and
0 deletions
HighscorePage.xaml.cs
0 → 100644
+
131
−
0
View file @
a1721abf
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Text
;
using
System.Threading.Tasks
;
using
Xamarin.Forms
;
using
System.IO.IsolatedStorage
;
using
System.IO
;
using
System.Xml.Serialization
;
using
System.Collections.ObjectModel
;
namespace
App3
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[
DesignTimeVisible
(
false
)]
public
partial
class
Highscore
:
ContentPage
{
const
string
highscoresFilename
=
"highscores.xml"
;
public
static
List
<
HighscoreItem
>
scores
;
public
Highscore
()
{
InitializeComponent
();
// .ItemsSource = Scores;
BindingContext
=
new
List
<
HighscoreItem
>();
// 08.06.20
//Load();
}
/* private void InitializeComponent()
{
throw new NotImplementedException();
}
public void ToolbarItemActivatedStart(object sender, EventArgs e)
{
Navigation.PushAsync(new Page1());
}
static public void Load()
{
scores = new List<HighscoreItem> ();
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
// Create empty list if the highscores file does not exist.
// This is needed when the application is started for the first time.
if (!store.FileExists(highscoresFilename))
{
for (int i = 1; i <= 5; i++)
{
scores.Add(new HighscoreItem(i,
new TimeSpan(0, 59, 59)));
}
Save();
return;
}
// Open the file and use XmlSerializer to deserialize the xml file into
// a list of HighscoreItems.
using (IsolatedStorageFileStream stream = store.OpenFile(highscoresFilename, FileMode.Open))
{
using (StreamReader reader = new StreamReader(stream))
{
XmlSerializer serializer = new XmlSerializer(scores.GetType());
scores = (List <HighscoreItem>)serializer.Deserialize(reader);
}
}
}
/// <summary>
/// Saves the highscores to isolated storage.
/// </summary>
static public void Save()
{
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
// Open the file and use XmlSerializer to serialize the list into the file
using (IsolatedStorageFileStream stream = store.CreateFile(highscoresFilename))
{
using (StreamWriter writer = new StreamWriter(stream))
{
XmlSerializer serializer = new XmlSerializer(scores.GetType());
serializer.Serialize(writer, scores);
writer.Flush();
}
}
}
/// <summary>
/// Checks if given score is a new highscore
/// </summary>
/// <param name="score">Score to check. The score should contain at least the solving time and moves.</param>
/// <returns>The position in highscore list, or zero if the score doesn't make it to the list</returns>
public static int IsNewHighscore(HighscoreItem score)
{
foreach (HighscoreItem item in scores)
{
if (score.Time < item.Time ||
(score.Time == item.Time))
return item.Index;
}
return 0;
}
/// <summary>
/// Add a new score to highscore list
/// </summary>
/// <param name="score">Score to add. All members of the score should be filled.</param>
public static void AddNewHighscore(HighscoreItem score)
{
// Insert the score into the list, remove weakest score from the list
// and save the list.
if (score.Index <= 0)
return;
scores.Insert(score.Index - 1, score);
scores.RemoveAt(scores.Count - 1);
for (int t = score.Index; t < scores.Count; t++)
scores[t].Index++;
Save();
}
}*/
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment