serialisation

master
Baptiste ARNAUD 5 years ago
parent 6664b8875d
commit d1d9d1a7b9

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml.Serialization;
namespace TheGameExtreme.IO
{
class IOGamePreparation
{
static string pathPlayers = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NbPlayers.xml");
public static void SaveParamaterGamePreparation(int nbPlayers)
{
XmlSerializer ser = new XmlSerializer(typeof(int));
TextWriter tw = new StreamWriter(pathPlayers);
ser.Serialize(tw, nbPlayers);
tw.Close();
}
public static int LoadParameterGamePreparation()
{
XmlSerializer xs = new XmlSerializer(typeof(int));
FileStream fs = new FileStream(pathPlayers, FileMode.Open);
try
{
int players = (int)xs.Deserialize(fs);
fs.Close();
return players;
}
catch
{
fs.Close();
return 0;
}
}
}
}

@ -2,24 +2,42 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Xml.Serialization;
namespace TheGameExtreme.IO namespace TheGameExtreme.IO
{ {
class IOOptions class IOOptions
{ {
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "file.xml"); static string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Options.xml");
public void SaveOptionParameter() public static void SaveOptionParameter(bool b)
{ {
/*if (!File.Exists(path))
XmlSerializer ser = new XmlSerializer(typeof(bool));
TextWriter ws = new StreamWriter(path);
ser.Serialize(ws, b);
ws.Close();
}
public static bool LoadOptionsParameter()
{
XmlSerializer xs = new XmlSerializer(typeof(bool));
try
{ {
XmlSerializer ser = new XmlSerializer(typeof(bool)); using(FileStream fs = new FileStream(path, FileMode.Open))
using (StreamWriter sw = File.CreateText(path))
{ {
sw.WriteLine(swTheme.IsToggled); bool b = (bool)xs.Deserialize(fs);
return b;
} }
}
catch
{
//fs.Close();
return false;
}
}*/
} }
} }

@ -3,9 +3,9 @@
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>
<Color x:Key="BlackColor">black</Color> <Color x:Key="BlackColor">black</Color>
<Color x:Key="WhiteColor">white</Color> <Color x:Key="WhiteColor">white</Color>
<Color x:Key="SkyBlueColor">SkyBlue</Color> <Color x:Key="SkyBlueColor">SkyBlue</Color>
</ResourceDictionary> </ResourceDictionary>

@ -90,7 +90,7 @@
<Picker <Picker
x:Name="SelectMode" x:Name="SelectMode"
BackgroundColor="{DynamicResource SkyBlueColor}" BackgroundColor="{DynamicResource SkyBlueColor}"
SelectedIndexChanged="SelectMode_SelectedIndexChanged"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center" VerticalOptions="Center"
MinimumWidthRequest="30" MinimumWidthRequest="30"
@ -109,7 +109,7 @@
HorizontalTextAlignment="Center"/> HorizontalTextAlignment="Center"/>
<Picker x:Name="SelectNbStack" <Picker x:Name="SelectNbStack"
BackgroundColor="{DynamicResource SkyBlueColor}" BackgroundColor="{DynamicResource SkyBlueColor}"
SelectedIndexChanged="SelectNbStack_Changed"
Margin="0,0,10,0" Margin="0,0,10,0"
MinimumWidthRequest="30" MinimumWidthRequest="30"
WidthRequest="100" WidthRequest="100"

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using TheGameExtreme.IO;
using Xamarin.Forms; using Xamarin.Forms;
namespace TheGameExtreme.view namespace TheGameExtreme.view
@ -18,13 +18,15 @@ namespace TheGameExtreme.view
NavigationPage.SetHasNavigationBar(this, false); NavigationPage.SetHasNavigationBar(this, false);
PlayerSelecter.ItemsSource = listNbPlayer; PlayerSelecter.ItemsSource = listNbPlayer;
PlayerSelecter.SelectedIndex = 0; LoadParameterNbPlayerGamePreparation();
SelectMode.ItemsSource = listGameMode; SelectMode.ItemsSource = listGameMode;
SelectMode.SelectedIndex = 0; SelectMode.SelectedIndex = 0;
SelectNbStack.ItemsSource = listNbStack; SelectNbStack.ItemsSource = listNbStack;
SelectNbStack.SelectedIndex = 0; SelectNbStack.SelectedIndex = 0;
} }
private async void Back(object sender, EventArgs e) private async void Back(object sender, EventArgs e)
@ -46,7 +48,7 @@ namespace TheGameExtreme.view
return; return;
} }
} }
IOGamePreparation.SaveParamaterGamePreparation(PlayerSelecter.SelectedIndex);
await Navigation.PushAsync(new MainPage(playersNames, (int)SelectNbStack.SelectedItem, (int)SelectMode.SelectedIndex)); await Navigation.PushAsync(new MainPage(playersNames, (int)SelectNbStack.SelectedItem, (int)SelectMode.SelectedIndex));
} }
@ -66,16 +68,7 @@ namespace TheGameExtreme.view
HorizontalOptions = LayoutOptions.Center HorizontalOptions = LayoutOptions.Center
}; };
//Frame myFrame = new Frame
//{
// BackgroundColor = (Color)Application.Current.Resources["SkyBlueColor"],
// HeightRequest = 45,
// VerticalOptions = LayoutOptions.Center,
// HorizontalOptions = LayoutOptions.Center,
// WidthRequest = 120,
// CornerRadius = 10,
// Content = e
//};
NameList.Children.Add(e); NameList.Children.Add(e);
} }
@ -85,17 +78,13 @@ namespace TheGameExtreme.view
} }
} }
} }
public void LoadParameterNbPlayerGamePreparation()
private void SelectNbStack_Changed(object sender, EventArgs args)
{ {
int nbJoueurs = IOGamePreparation.LoadParameterGamePreparation();
PlayerSelecter.SelectedIndex = nbJoueurs;
} }
private void SelectMode_SelectedIndexChanged(object sender, EventArgs e)
{
}
} }
} }

@ -4,6 +4,7 @@ using System.IO;
using System.Xml.Serialization; using System.Xml.Serialization;
using Xamarin.Forms; using Xamarin.Forms;
using System.Diagnostics; using System.Diagnostics;
using TheGameExtreme.IO;
namespace TheGameExtreme.view namespace TheGameExtreme.view
{ {
@ -14,12 +15,9 @@ namespace TheGameExtreme.view
{ {
InitializeComponent(); InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false); NavigationPage.SetHasNavigationBar(this, false);
/*string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "file.xml");
XmlSerializer xs = new XmlSerializer(typeof(bool)); LoadParameterOptionOnHomepage();
FileStream fs = new FileStream(path, FileMode.Open);
bool test = (bool)xs.Deserialize(fs);
Debug.WriteLine(test);*/
} }
private async void OpenGame(object sender, EventArgs args) private async void OpenGame(object sender, EventArgs args)
{ {
@ -41,6 +39,22 @@ namespace TheGameExtreme.view
await DisplayAlert("Règles", AppRessource.StrRules, "Fermer"); await DisplayAlert("Règles", AppRessource.StrRules, "Fermer");
} }
public void LoadParameterOptionOnHomepage()
{
bool b = IOOptions.LoadOptionsParameter();
if (!b)
{
Application.Current.Resources["BlackColor"] = Color.Black;
Application.Current.Resources["WhiteColor"] = Color.White;
}
else
{
Application.Current.Resources["BlackColor"] = Color.White;
Application.Current.Resources["WhiteColor"] = Color.Black;
}
}
} }
} }

@ -7,6 +7,7 @@ using System.Runtime.Serialization.Json;
using System.Text; using System.Text;
using System.Xml; using System.Xml;
using System.Xml.Serialization; using System.Xml.Serialization;
using TheGameExtreme.IO;
using Xamarin.Forms; using Xamarin.Forms;
namespace TheGameExtreme.view namespace TheGameExtreme.view
@ -15,7 +16,7 @@ namespace TheGameExtreme.view
public partial class Settings : ContentPage public partial class Settings : ContentPage
{ {
private bool bSwitchSerialisation;
public Settings() public Settings()
{ {
InitializeComponent(); InitializeComponent();
@ -24,12 +25,12 @@ namespace TheGameExtreme.view
if(pageContentSetting.BackgroundColor == Color.Black) if(pageContentSetting.BackgroundColor == Color.Black)
{ {
swTheme.IsToggled = false; swTheme.IsToggled = false;
bSwitchSerialisation = swTheme.IsToggled;
} }
else else
{ {
swTheme.IsToggled = true; swTheme.IsToggled = true;
bSwitchSerialisation = swTheme.IsToggled;
} }
} }
@ -69,37 +70,22 @@ namespace TheGameExtreme.view
{ {
Application.Current.Resources["BlackColor"] = Color.Black; Application.Current.Resources["BlackColor"] = Color.Black;
Application.Current.Resources["WhiteColor"] = Color.White; Application.Current.Resources["WhiteColor"] = Color.White;
Application.Current.Resources["SkyBlueColor"] = Color.SkyBlue;
} }
else else
{ {
Application.Current.Resources["BlackColor"] = Color.White; Application.Current.Resources["BlackColor"] = Color.White;
Application.Current.Resources["WhiteColor"] = Color.Black; Application.Current.Resources["WhiteColor"] = Color.Black;
Application.Current.Resources["BlueSkyColor"] = Color.SkyBlue;
} }
} }
private async void SettingToHomePage(object sender, EventArgs e) private async void SettingToHomePage(object sender, EventArgs e)
{ {
IOOptions.SaveOptionParameter(swTheme.IsToggled);
//serialisationSwitch(); //serialisationSwitch();
await Navigation.PopAsync(); await Navigation.PopAsync();
} }
/*public void serialisationSwitch()
{
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "file.xml");
if (!File.Exists(path))
{
XmlSerializer ser = new XmlSerializer(typeof(bool));
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine(swTheme.IsToggled);
}
}
}*/
} }
} }

Loading…
Cancel
Save