I use a switch with enums to divide my game in different parts. In the code below, that is simplified, I have a problem, becasue I need to show the same text in two or perhaps more parts and I wonder if there is a better way to do this, to avoid the use of the same code at several cases?
switch (currentGameState)
{
case GameState.Start:
// Code
break;
case GameState.Info:
// Code
break;
case GameState.PlayGame:
spriteBatch.Begin();
spriteBatch.DrawString(scoreFont, "Score : " + currentScore, new Vector2(10, 10), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1);
spriteBatch.DrawString(timeFont, "Time : " + secondsToDisplay, new Vector2(10, 30), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1);
spriteBatch.DrawString(timeFont, "Spaceship : " + numberOfSpaceship, new Vector2(10, 50), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1);
spriteBatch.End();
break;
case GameState.NewSpaceship:
spriteBatch.Begin();
spriteBatch.DrawString(scoreFont, "Score : " + currentScore, new Vector2(10, 10), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1);
spriteBatch.DrawString(timeFont, "Time : " + secondsToDisplay, new Vector2(10, 30), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1);
spriteBatch.DrawString(timeFont, "Spaceship : " + numberOfSpaceship, new Vector2(10, 50), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1);
spriteBatch.End();
break;
case GameState.GameOver:
// Code
break;
}