I am struggling to make use of classes in my coding, as I am new to C#. I’m trying to make a function that effectively says A += B; in a separate Class (Scoring) and when I run the game the changes aren’t showing up in the text. Here’s what I have right now. I’m not sure how formatting works either so if someone could tell me that would be great.
'public class Game1 : Game
{
KeyboardState state = Keyboard.GetState();
private KeyboardState oldState;
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;
public SpriteFont font;
public int score;
public int multiplier;
Scoring Scoring = new Scoring();
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
score = 0;
multiplier = 1;
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
font = Content.Load<SpriteFont>("File");
}
protected override void Update(GameTime gameTime)
{
KeyboardState newState = Keyboard.GetState();
if (oldState.IsKeyUp(Keys.Q) && newState.IsKeyDown(Keys.Q ))
{
// It's not adding 1 every time I press Q
Scoring.Add(score, multiplier);
}
if (newState.IsKeyDown(Keys.W) && score >= 100)
{
// You pay 100 score to get an extra multiplier, though what happens is you don't actually get it
score -= 100;
Scoring.Add(multiplier, 1);
}
oldState = newState;
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Wheat);
spriteBatch.Begin();
spriteBatch.DrawString(font, score.ToString(), new Vector2(100,100), Color.Black);
spriteBatch.DrawString(font, multiplier.ToString(), new Vector2(100, 150), Color.Black);
spriteBatch.End();
base.Draw(gameTime);
}
}
public class Scoring
{
public void Add(int A, int B)
{
A += B;
}
}'