-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Source/UI/Santase.UI.WindowsUniversal/TotalResultPersister.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
namespace Santase.UI.WindowsUniversal | ||
{ | ||
using Windows.Storage; | ||
|
||
public class TotalResultPersister | ||
{ | ||
private const string PlayerValueName = "PlayerScore"; | ||
private const string OtherPlayerValueName = "OtherPlayerScore"; | ||
|
||
private int playerScore; | ||
private int otherPlayerScore; | ||
|
||
public TotalResultPersister() | ||
{ | ||
try | ||
{ | ||
if (!ApplicationData.Current.LocalSettings.Values.ContainsKey(PlayerValueName)) | ||
{ | ||
ApplicationData.Current.LocalSettings.Values.Add(PlayerValueName, 0); | ||
} | ||
|
||
if (!ApplicationData.Current.LocalSettings.Values.ContainsKey(OtherPlayerValueName)) | ||
{ | ||
ApplicationData.Current.LocalSettings.Values.Add(OtherPlayerValueName, 0); | ||
} | ||
|
||
int.TryParse(ApplicationData.Current.LocalSettings.Values[PlayerValueName].ToString(), out this.playerScore); | ||
int.TryParse(ApplicationData.Current.LocalSettings.Values[OtherPlayerValueName].ToString(), out this.otherPlayerScore); | ||
} | ||
catch | ||
{ | ||
this.playerScore = 0; | ||
this.otherPlayerScore = 0; | ||
} | ||
} | ||
|
||
public int PlayerScore => this.playerScore; | ||
|
||
public int OtherPlayerScore => this.otherPlayerScore; | ||
|
||
public void Update(bool playerWins) | ||
{ | ||
if (playerWins) | ||
{ | ||
this.playerScore++; | ||
} | ||
else | ||
{ | ||
this.otherPlayerScore++; | ||
} | ||
|
||
try | ||
{ | ||
ApplicationData.Current.LocalSettings.Values[PlayerValueName] = this.playerScore.ToString(); | ||
ApplicationData.Current.LocalSettings.Values[OtherPlayerValueName] = this.otherPlayerScore.ToString(); | ||
} | ||
catch | ||
{ | ||
} | ||
} | ||
} | ||
} |