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.IO;
using System.Text;
using System.Xml.Serialization;
namespace TheGameExtreme.IO
{
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()
{
/*if (!File.Exists(path))
public static void SaveOptionParameter(bool b)
{
XmlSerializer ser = new XmlSerializer(typeof(bool));
using (StreamWriter sw = File.CreateText(path))
TextWriter ws = new StreamWriter(path);
ser.Serialize(ws, b);
ws.Close();
}
public static bool LoadOptionsParameter()
{
XmlSerializer xs = new XmlSerializer(typeof(bool));
try
{
sw.WriteLine(swTheme.IsToggled);
using(FileStream fs = new FileStream(path, FileMode.Open))
{
bool b = (bool)xs.Deserialize(fs);
return b;
}
}
catch
{
//fs.Close();
return false;
}
}*/
}
}

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

@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using TheGameExtreme.IO;
using Xamarin.Forms;
namespace TheGameExtreme.view
@ -18,13 +18,15 @@ namespace TheGameExtreme.view
NavigationPage.SetHasNavigationBar(this, false);
PlayerSelecter.ItemsSource = listNbPlayer;
PlayerSelecter.SelectedIndex = 0;
LoadParameterNbPlayerGamePreparation();
SelectMode.ItemsSource = listGameMode;
SelectMode.SelectedIndex = 0;
SelectNbStack.ItemsSource = listNbStack;
SelectNbStack.SelectedIndex = 0;
}
private async void Back(object sender, EventArgs e)
@ -46,7 +48,7 @@ namespace TheGameExtreme.view
return;
}
}
IOGamePreparation.SaveParamaterGamePreparation(PlayerSelecter.SelectedIndex);
await Navigation.PushAsync(new MainPage(playersNames, (int)SelectNbStack.SelectedItem, (int)SelectMode.SelectedIndex));
}
@ -66,16 +68,7 @@ namespace TheGameExtreme.view
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);
}
@ -85,17 +78,13 @@ namespace TheGameExtreme.view
}
}
}
private void SelectNbStack_Changed(object sender, EventArgs args)
public void LoadParameterNbPlayerGamePreparation()
{
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 Xamarin.Forms;
using System.Diagnostics;
using TheGameExtreme.IO;
namespace TheGameExtreme.view
{
@ -14,11 +15,8 @@ namespace TheGameExtreme.view
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
/*string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "file.xml");
XmlSerializer xs = new XmlSerializer(typeof(bool));
FileStream fs = new FileStream(path, FileMode.Open);
bool test = (bool)xs.Deserialize(fs);
Debug.WriteLine(test);*/
LoadParameterOptionOnHomepage();
}
private async void OpenGame(object sender, EventArgs args)
@ -41,6 +39,22 @@ namespace TheGameExtreme.view
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.Xml;
using System.Xml.Serialization;
using TheGameExtreme.IO;
using Xamarin.Forms;
namespace TheGameExtreme.view
@ -15,7 +16,7 @@ namespace TheGameExtreme.view
public partial class Settings : ContentPage
{
private bool bSwitchSerialisation;
public Settings()
{
InitializeComponent();
@ -24,12 +25,12 @@ namespace TheGameExtreme.view
if(pageContentSetting.BackgroundColor == Color.Black)
{
swTheme.IsToggled = false;
bSwitchSerialisation = swTheme.IsToggled;
}
else
{
swTheme.IsToggled = true;
bSwitchSerialisation = swTheme.IsToggled;
}
}
@ -69,37 +70,22 @@ namespace TheGameExtreme.view
{
Application.Current.Resources["BlackColor"] = Color.Black;
Application.Current.Resources["WhiteColor"] = Color.White;
Application.Current.Resources["SkyBlueColor"] = Color.SkyBlue;
}
else
{
Application.Current.Resources["BlackColor"] = Color.White;
Application.Current.Resources["WhiteColor"] = Color.Black;
Application.Current.Resources["BlueSkyColor"] = Color.SkyBlue;
}
}
private async void SettingToHomePage(object sender, EventArgs e)
{
IOOptions.SaveOptionParameter(swTheme.IsToggled);
//serialisationSwitch();
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