using
System;
using
System.Collections.Generic;
using
Microsoft.Xna.Framework;
using
Microsoft.Xna.Framework.Content;
using
Microsoft.Xna.Framework.GamerServices;
using
Microsoft.Xna.Framework.Graphics;
using
Microsoft.Xna.Framework.Input;
using
Microsoft.Xna.Framework.Storage;
//**1**
//**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**
//**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**
using
System.IO;
public
class GameClass
: Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
//**2**
public GameClass()
{
graphics =
new
GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
//**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**
//**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**
Components.Add(new
GamerServicesComponent(this));
}
//**3**
protected override
void Update(GameTime
gameTime)
{
//**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**
//**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**
// Write some data to our storage when we press
'X'
if (GamePad.GetState(PlayerIndex.One).Buttons.X
== ButtonState.Pressed)
{
Object obj = (Object)"GetDevice
for Player One";
Guide.BeginShowStorageDeviceSelector(StorageDeviceSelected,
obj);
}
//**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**
//**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**
base.Update(gameTime);
}
//**4**
//**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**
//**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**SAVEFILE**
private void
StorageDeviceSelected(IAsyncResult
result)
{
// This is our function which gets called when we
are allowed to write
// or read data to the storagedevice file (gives
us a valid path)
StorageDevice device =
Guide.EndShowStorageDeviceSelector(result);
StorageContainer container =
device.OpenContainer("StorageDemo");
StreamWriter writer =
new StreamWriter(container.Path
+ "\\myfile.txt");
//
// On PC this would be in your MyDocuments
Folder under your games name
// else
// On XBOX360 its stored in a place you can only
get to through StorageDevice
//
writer.WriteLine("lalalalala\n");
writer.Close();
}
protected override
void Draw(GameTime
gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
}
}//End
GameClass Class
//
Program Entry Point
static
class Program
{
static void
Main(string[] args)
{
using (GameClass
game = new
GameClass())
{
game.Run();
}
}
} |