Exceptions et gestion des fichiers : sauvegarder et charger un niveau
CHAPITRE 8
173
public ChapitreHuit()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
this.Components.Add(new GamerServicesComponent(this));
}
protected override void Initialize()
{
base.Initialize();
Guide.BeginShowStorageDeviceSelector(new AsyncCallback(GetDevice), null);
}
protected override void Update(GameTime gameTime)
{
if (Keyboard.GetState().IsKeyDown(Keys.C))
{
try
{
if(!File.Exists(Path.Combine(container.Path, "test.sav")))
File.Create(Path.Combine(container.Path, "test.sav")).Close();
if(File.Exists(Path.Combine(container.Path, "test.sav")))
File.Copy(Path.Combine(container.Path, "test.sav")
➥,Path.Combine(container.Path, "test_copy.sav"), true);
}
catch (Exception e)
{
Guide.BeginShowMessageBox(PlayerIndex.One, "Erreur", e.Message,
➥new string[] { "Ok" }, 0, MessageBoxIcon.Error, new
➥AsyncCallback(EndShowMessageBox), null);
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.D))
{
try
{
if (File.Exists(Path.Combine(container.Path, "test.sav")))
File.Delete(Path.Combine(container.Path, "test.sav"));
}
catch (Exception e)
{
Guide.BeginShowMessageBox(PlayerIndex.One, "Erreur", e.Message,
➥new string[] { "Ok" }, 0, MessageBoxIcon.Error, new
➥AsyncCallback(EndShowMessageBox), null);
}
}
base.Update(gameTime);
}
=Labat FM.book Page 173 Vendredi, 19. juin 2009 4:01 16
CHAPITRE 8
173
public ChapitreHuit()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
this.Components.Add(new GamerServicesComponent(this));
}
protected override void Initialize()
{
base.Initialize();
Guide.BeginShowStorageDeviceSelector(new AsyncCallback(GetDevice), null);
}
protected override void Update(GameTime gameTime)
{
if (Keyboard.GetState().IsKeyDown(Keys.C))
{
try
{
if(!File.Exists(Path.Combine(container.Path, "test.sav")))
File.Create(Path.Combine(container.Path, "test.sav")).Close();
if(File.Exists(Path.Combine(container.Path, "test.sav")))
File.Copy(Path.Combine(container.Path, "test.sav")
➥,Path.Combine(container.Path, "test_copy.sav"), true);
}
catch (Exception e)
{
Guide.BeginShowMessageBox(PlayerIndex.One, "Erreur", e.Message,
➥new string[] { "Ok" }, 0, MessageBoxIcon.Error, new
➥AsyncCallback(EndShowMessageBox), null);
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.D))
{
try
{
if (File.Exists(Path.Combine(container.Path, "test.sav")))
File.Delete(Path.Combine(container.Path, "test.sav"));
}
catch (Exception e)
{
Guide.BeginShowMessageBox(PlayerIndex.One, "Erreur", e.Message,
➥new string[] { "Ok" }, 0, MessageBoxIcon.Error, new
➥AsyncCallback(EndShowMessageBox), null);
}
}
base.Update(gameTime);
}
=Labat FM.book Page 173 Vendredi, 19. juin 2009 4:01 16
