Développement XNA pour la XBox et le PC
170
L’exemple suivant utilise ces trois méthodes. Si le joueur presse la touche C et que le
répertoire test n’existe pas dans le dossier de l’utilisateur (on récupère le chemin via la
propriété Path de l’objet de type StorageContainer), on le crée. Si le joueur presse la
touche D et que le répertoire existe, on le supprime.
Gérer les dossiers dans le répertoire de l’utilisateur
public class ChapitreHuit : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
StorageDevice device;
StorageContainer container;
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(!Directory.Exists(Path.Combine(container.Path, "test")))
Directory.CreateDirectory(Path.Combine(container.Path, "test"));
}
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
{
=Labat FM.book Page 170 Vendredi, 19. juin 2009 4:01 16
170
L’exemple suivant utilise ces trois méthodes. Si le joueur presse la touche C et que le
répertoire test n’existe pas dans le dossier de l’utilisateur (on récupère le chemin via la
propriété Path de l’objet de type StorageContainer), on le crée. Si le joueur presse la
touche D et que le répertoire existe, on le supprime.
Gérer les dossiers dans le répertoire de l’utilisateur
public class ChapitreHuit : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
StorageDevice device;
StorageContainer container;
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(!Directory.Exists(Path.Combine(container.Path, "test")))
Directory.CreateDirectory(Path.Combine(container.Path, "test"));
}
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
{
=Labat FM.book Page 170 Vendredi, 19. juin 2009 4:01 16
