1
Answer

HELP! Make my program choose 4 random colors from a list

Photo of Clover

Clover

10y
644
1
SORRY FOR THE LONG POST BUT PLS TRY TO READ :)

Okay. So Im a programming newbie. Ive only begun to learn C# for a month.
So bear with my limited knowledge. :D

Anyway... I want my program to pick 4 random colors (from a list of colors that I made) everytime I start the program.

I already did the list. I just dont know how I can make it pick 4 random colors from the list..
And not only that. I want that the 4 random colors, would be associated with those 4 buttons shown there in the picture.


Ill just explain the program if it helps.
Everytime the program starts, it will generate 4 random colors. (it will not be shown)
The User will then guess what those 4 colors are by clicking the buttons (the button changes its backcolor everytime the user clicks it). The user will have to click the check button in every try he makes.

Its like a mastermind-ish game (for those of you who knows what that game is).

What Ive done so far...

(These are for the buttons)

        private void Form1_Load(object sender, EventArgs e)
        {
            Color[] MMColors = {Color.Red, Color.Green, Color.Blue, Color.Yellow,Color.Orange,Color.DeepPink};

            button1.Tag = -1;
            button2.Tag = -1;
            button3.Tag = -1;
            button4.Tag = -1;

            Color[] GuessColors = {Color.Red, Color.Green, Color.Blue, Color.Yellow,Color.Orange,Color.DeepPink};
                   }        

        void CycleColor(Button button)
        {
            int ButtonColor = (int)button.Tag;
            if (ButtonColor == 5)
                ButtonColor = -1;
            ButtonColor = ButtonColor + 1;
            button.BackColor = MMColors[ButtonColor];
            button.Tag = ButtonColor;
        }

And for each button....
        private void button1_Click(object sender, EventArgs e)
        {
            CycleColor(button1);
        }



and just FYI. This is a class activity.. So I cant really change the rules or codes or anything here..

I know there are better ways to do this but
IT HAS TO BE MADE LIKE THIS.. 

So.. How can I finish the program? HELP pls?

Im seriously stuck. 

Answers (1)

0
Photo of venkatesh p
NA 7 0 17y
thanks for your reply. i got it. but when i start the service "it shows some errors " please help me to rectify that. the errror was  service could not be started on this computer . since no timely fashion reply from service.
0
Photo of Scott Lysle
NA 28.5k 14.4m 17y
You can start by overriding the OnStart event for your service; in that code you can use Process.Start to kick on some other application (in the below example, I start internet explorer and pass it the URL for MSN as a argument so that whenever the service starts, it opens up MSN in an explorer window)
protected override void OnStart(string[] args) {  System.Diagnostics.Process.Start("iexplore.exe", "http://www.msn.com"); }   Process.Start accepts a couple of arguments, the first is the executable to launch (e.g., iexplore.exe in this example) and the second argument is any optional arguments that the executable may use (in this case, a URL).  Of course the executable can be any executable and may include a full path to that executable and the arguments to the executable are optional.