want to know how to pass a random number to text to be displayed
could anyone tell me what im doing wrong here?
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont font;
Rectangle spriterect;
int roll = 0;
public Game1()
{
graphics =
new GraphicsDeviceManager(this);
Content.RootDirectory =
"Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
spriterect =
new Rectangle(30, 20, 600, 450);
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch =
new SpriteBatch(GraphicsDevice);
font = Content.Load<
SpriteFont>("Kootenay");
// TODO: use this.Content to load your game content here
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
Random dieroll = new Random();
int d4 = 4;
int d6 = 6;
int d8 = 8;
int d10 = 10;
int d12 = 12;
int d20 = 20;
// Allows the game to exit
if(GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)
{
d4 = dieroll.Next(1,d4+1);
d4 = roll;
}
if (GamePad.GetState(PlayerIndex.One).Buttons.B== ButtonState.Pressed)
{
d6 = dieroll.Next(1, d6 + 1);
d6 = roll;
}
if (GamePad.GetState(PlayerIndex.One).Buttons.X== ButtonState.Pressed)
{
d8 = dieroll.Next(1, d8 + 1);
d8 = roll;
}
if (GamePad.GetState(PlayerIndex.One).Buttons.Y == ButtonState.Pressed)
{
d10 = dieroll.Next(1, d10 + 1);
d10 = roll;
}
if (GamePad.GetState(PlayerIndex.One).Buttons.LeftShoulder == ButtonState.Pressed)
{
d12 = dieroll.Next(1, d12 + 1);
d12 = roll;
}
if (GamePad.GetState(PlayerIndex.One).Buttons.RightShoulder == ButtonState.Pressed)
{
d20 = dieroll.Next(1, d20 + 1);
d20 = roll;
}
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
Vector2 text = new Vector2(200, 300);
GraphicsDevice.Clear(
Color.CornflowerBlue);
spriteBatch.DrawString(font, roll.ToString, spriterect.X, spriterect.Y,
Color.Black);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}
i just want to make a simple d and d dice roller for marketplace, any help would be great
Comments
Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!










