Serialisation du premier pseudo

master
Baptiste ARNAUD 5 years ago
parent 2577e125f6
commit 130b603964

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="12" android:versionName="4.2" package="com.uca.thegameextreme" android:installLocation="auto">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="13" android:versionName="4.2" package="com.uca.thegameextreme" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:icon="@drawable/TrierImageB" android:label="OrderStacks"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

@ -12,6 +12,7 @@ namespace TheGameExtreme.IO
static string pathGameModeValue = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "GameModeValue.xml");
static string pathNbStacks = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NbStacks.xml");
static string pathNbCards = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NbCards.xml");
static string pathNameFirstPlayer = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NamePlayer.xml");
public static void SaveParamaterGamePreparationNbPlayers(int nbPlayers)
{
@ -113,5 +114,30 @@ namespace TheGameExtreme.IO
return 0;
}
}
public static void SaveParameterGamePreparationName(string namePseudo)
{
XmlSerializer xs = new XmlSerializer(typeof(string));
TextWriter tw = new StreamWriter(pathNameFirstPlayer);
xs.Serialize(tw, namePseudo);
tw.Close();
}
public static string LoadNameFromGamePrepararion()
{
XmlSerializer xs = new XmlSerializer(typeof(string));
try
{
using (FileStream fs = new FileStream (pathNameFirstPlayer, FileMode.Open))
{
string namePseudo = (string)xs.Deserialize(fs);
return namePseudo;
}
}
catch
{
return "";
}
}
}
}

@ -168,6 +168,7 @@
MinimumWidthRequest="50"
WidthRequest="200"
MaxLength="18"
x:Name="FirstEntry"
IsTextPredictionEnabled="False"/>
</StackLayout>

@ -18,6 +18,7 @@ namespace TheGameExtreme.view
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
LoadParameterName();
PlayerSelecter.ItemsSource = listNbPlayer;
LoadParameterNbPlayerGamePreparation();
@ -41,6 +42,7 @@ namespace TheGameExtreme.view
IOGamePreparation.SaveParameterGamePreparationGameModeValue(SelectMode.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationNbStacks(SelectNbStack.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationNbCards(SelectNbCard.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationName(FirstEntry.Text);
await Navigation.PopAsync();
}
@ -50,6 +52,7 @@ namespace TheGameExtreme.view
IOGamePreparation.SaveParameterGamePreparationGameModeValue(SelectMode.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationNbStacks(SelectNbStack.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationNbCards(SelectNbCard.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationName(FirstEntry.Text);
return base.OnBackButtonPressed();
}
@ -71,6 +74,7 @@ namespace TheGameExtreme.view
IOGamePreparation.SaveParameterGamePreparationGameModeValue(SelectMode.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationNbStacks(SelectNbStack.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationNbCards(SelectNbCard.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationName(FirstEntry.Text);
await Navigation.PushAsync(new MainPage(playersNames, (int)SelectNbStack.SelectedItem, (int)SelectMode.SelectedIndex, (int)SelectNbCard.SelectedItem));
}
@ -123,6 +127,11 @@ namespace TheGameExtreme.view
int nbCards = IOGamePreparation.LoadParameterGamePreparationNbCards();
SelectNbCard.SelectedIndex = nbCards;
}
public void LoadParameterName()
{
string pseudo = IOGamePreparation.LoadNameFromGamePrepararion();
FirstEntry.Text = pseudo;
}

@ -1,6 +1,7 @@
using System;
using Xamarin.Forms;
using TheGameExtreme.IO;
using TheGameExtreme.Resx;
namespace TheGameExtreme.view
{

Loading…
Cancel
Save