I'm a self-taught programmer.

I have a button class runs like this:

Texture texture;
Color color;
Color differentColor;

SpriteFont font;
button1 = new Button(texture, font, ... , color);
button2 = new Button(texture, font, ... , color);
button20 = new Button(texture, font, ... , color);

This button will spawn 20 times in a set of specific locations on screen.

I want a set of 10 buttons to light up green at each level non-randomly.

Level 1: button 1,3,6,7,10,12,13,14,15,16 lights up green (must be in this seq)

Level 2: button 2,5,6,7,9,11,13,14,19,20 lights up green (must be in this seq)

Level 3: etc...

There will be 15 levels total.

How do I go about doing this the smart way?

What I think could work is to create a Level class, create 20 Color[] array in it:

Color[] color1;
Color[] color2;
Color[] color20;

color1 = {Color.Green, Color.Gray, Color.Green... }
color2 = {Color.Gray, Color.Green, Color.Gray... }

Input each of the color array into the constructor of a ButtonManager class, from the ButtonManager class, spawns the 20 buttons of differing color.

I will be adding more features into the button as time goes on. Will I benefit in using the command design pattern here?

  • \$\begingroup\$ Are you going with a specific pattern in your non-randomized buttons? Or do you declare them all by yourself? I recommend to use a 2D array (An array inside an array) to make declaring and using them easier. See here for more information: docs.microsoft.com/en-us/dotnet/csharp/programming-guide/arrays/… You can probably put your buttons in an array too. \$\endgroup\$ – Steven Nov 20 '19 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.