serialisation valider

master
Baptiste ARNAUD 5 years ago
parent f3486e463b
commit 85f8a5db20

@ -9,15 +9,17 @@ namespace TheGameExtreme.IO
class IOGamePreparation
{
static string pathPlayers = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NbPlayers.xml");
static string pathGameModeValue = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "GameModeValue.xml");
static string pathNbStacks = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NbStacks.xml");
public static void SaveParamaterGamePreparation(int nbPlayers)
public static void SaveParamaterGamePreparationNbPlayers(int nbPlayers)
{
XmlSerializer ser = new XmlSerializer(typeof(int));
TextWriter tw = new StreamWriter(pathPlayers);
ser.Serialize(tw, nbPlayers);
tw.Close();
}
public static int LoadParameterGamePreparation()
public static int LoadParameterGamePreparationNbPlayers()
{
XmlSerializer xs = new XmlSerializer(typeof(int));
@ -27,13 +29,63 @@ namespace TheGameExtreme.IO
{
int players = (int)xs.Deserialize(fs);
return players;
}
}
}
catch
{
return 0;
}
}
public static void SaveParameterGamePreparationGameModeValue(int mode)
{
XmlSerializer xs = new XmlSerializer(typeof(int));
TextWriter tw = new StreamWriter(pathGameModeValue);
xs.Serialize(tw, mode);
tw.Close();
}
public static int LoadParameterGamePreparationGameModeValue()
{
XmlSerializer xs = new XmlSerializer(typeof(int));
try
{
using (FileStream fs = new FileStream(pathGameModeValue, FileMode.Open))
{
int gameMode = (int)xs.Deserialize(fs);
return gameMode;
}
}
catch
{
return 0;
}
}
public static void SaveParameterGamePreparationNbStacks(int nbStack)
{
XmlSerializer xs = new XmlSerializer(typeof(int));
TextWriter tw = new StreamWriter(pathNbStacks);
xs.Serialize(tw, nbStack);
tw.Close();
}
public static int LoadParamaterGamePreparationNbStacks()
{
XmlSerializer xs = new XmlSerializer(typeof(int));
try
{
using (FileStream fs = new FileStream(pathNbStacks, FileMode.Open))
{
int nbstacks = (int)xs.Deserialize(fs);
return nbstacks;
}
}
catch
{
return 0;
}
}
}
}

@ -21,18 +21,29 @@ namespace TheGameExtreme.view
LoadParameterNbPlayerGamePreparation();
SelectMode.ItemsSource = listGameMode;
SelectMode.SelectedIndex = 0;
LoadParameterGameModeValueGamePreparation();
SelectNbStack.ItemsSource = listNbStack;
SelectNbStack.SelectedIndex = 0;
LoadParameterNbStacksGamePreparation();
}
private async void Back(object sender, EventArgs e)
{
IOGamePreparation.SaveParamaterGamePreparationNbPlayers(PlayerSelecter.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationGameModeValue(SelectMode.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationNbStacks(SelectNbStack.SelectedIndex);
await Navigation.PopAsync();
}
protected override bool OnBackButtonPressed()
{
IOGamePreparation.SaveParamaterGamePreparationNbPlayers(PlayerSelecter.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationGameModeValue(SelectMode.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationNbStacks(SelectNbStack.SelectedIndex);
return base.OnBackButtonPressed();
}
private async void Play(object sender, EventArgs args)
{
@ -48,7 +59,9 @@ namespace TheGameExtreme.view
return;
}
}
IOGamePreparation.SaveParamaterGamePreparation(PlayerSelecter.SelectedIndex);
IOGamePreparation.SaveParamaterGamePreparationNbPlayers(PlayerSelecter.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationGameModeValue(SelectMode.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationNbStacks(SelectNbStack.SelectedIndex);
await Navigation.PushAsync(new MainPage(playersNames, (int)SelectNbStack.SelectedItem, (int)SelectMode.SelectedIndex));
}
@ -80,10 +93,22 @@ namespace TheGameExtreme.view
}
public void LoadParameterNbPlayerGamePreparation()
{
int nbJoueurs = IOGamePreparation.LoadParameterGamePreparation();
int nbJoueurs = IOGamePreparation.LoadParameterGamePreparationNbPlayers();
PlayerSelecter.SelectedIndex = nbJoueurs;
}
public void LoadParameterGameModeValueGamePreparation()
{
int gameModeValue = IOGamePreparation.LoadParameterGamePreparationGameModeValue();
SelectMode.SelectedIndex = gameModeValue;
}
public void LoadParameterNbStacksGamePreparation()
{
int nbStackSer = IOGamePreparation.LoadParamaterGamePreparationNbStacks();
SelectNbStack.SelectedIndex = nbStackSer;
}
}

@ -87,5 +87,11 @@ namespace TheGameExtreme.view
//serialisationSwitch();
await Navigation.PopAsync();
}
protected override bool OnBackButtonPressed()
{
IOOptions.SaveOptionParameter(swTheme.IsToggled);
return base.OnBackButtonPressed();
}
}
}

Loading…
Cancel
Save