New project named SimonSaysLesson. Form rename size 6 2 0 6 2 0 x 5 5 0
Fantastic news! We've Found the answer you've been seeking!
Question:
New project named SimonSaysLesson.
Form
rename
size 620 x550
Add lblTitle and lblInstructions. See the exe for placement and text.
Add btnStart
Add tmrGame
There are several variables but we will add them as we see the need.
Create a List to hold the blocks.
Create a List to hold the chosenBlocks . Here is a tutorial on using ListsLinks to an external site.
List blocks = new List();
List chosenBlocks = new List();
Create strings for correctOrder and playerOrder.
Create a method called SetupBlocks (Refer to Click the Moving Target for help...yours and in the code notes)
create the 16 blocks
size 60 x 60
each box needs a name...pic1, pic2,...use the loop counter and an append to create this. Add an underscore to the end of the name.
each box needs a click event (ClickOnBlock)
pb.Click += pb_Click;
make the backcolor black or some other base color
add the pb to the controls...they need to move over to the right and each row moves down
add the pb to your list...( use the blocks.add(pb))
11. Call SetupBlocks from the constructor. It is the method with the same name as your class and has one line of code in it already.
12. Generate the ClickOnBlock()
( The easiest way is to add a pb to the form, double click it to generate the method, and then give it the exact same name as you used in SetupBlocks().)
tell the program that the sender is a picturebox
PictureBox temp =(PictureBox)sender;
temp has a name...you gave it on in SetUpBlocks. Add that name to the playerOrder String.
add the library using System.Diagnotistics at the top
add code for testing:
Debug.WriteLine("P "+ playerOrder);
Test it. You should see the names of the blocks you click in the debug window
13. Start code
Find a random color for each picture box.
in this version the player has to get it correct 3 times in each level before leveling up to a max level of 6. Write an if to do this.
When they level up, the score sets back to 0 and the level goes up
clear the strings
clear the chosen List
now we need to generate 3 unique numbers from 1 to 16 or whatever your box numbers are. They must be unique so there is a variety of ways to do this. Here is one:
chosenPB = picBoxes.OrderBy(x => rand.Next()).Take(level).ToList();
This way takes level (which is 3 at the beginning) random numbers and takes those blocks and adds them to the chosenPB List. This is higher level coding and a bit above the current level of learning.
A better way for beginners is to find a number and check to see if it has been used. You can use parallel arrays or even easier, a string, to see if this is true or not.
Debug.WriteLine the correct order
Set up some blinking variables:
timeLimit =0
index =0
selectingColors = true
start the timer
Test your code
14. Timer. The way this timer works is that every click it checks to see if the player is selectingColors. If they are, a counter goes up. When the counter gets to 10, the backcolor of the block changes to black. When it gets to 20, it changes back to its original color. At 30 it is black. At 40 it is original. At 50 we move on. We check to see if there is another block and if so, increase the block index value and resetting the counter. If there are no more blocks, stop selectingColors.
15. The last thing we need to do is finish ClickOnBlock. We don't want a reaction to a block click while one is still blinking. Use the boolean to be sure we are done selecting colors. Also, we don't want a reaction if there are no blocks chosen yet (meaning we haven't clicked start.) If both of these are true then we set the backcolor of the clicked block to black, add it's name to the player chosen string, output that in the debugger, and increase our number of tries.
That's it! If it isn't working, it is debug.png time. using C#
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date: