Question: Additional Information for the first homework problem: This part explains how I should create the slide puzzle. The 9 buttons will move around in exchange
Additional Information for the first homework problem:
This part explains how I should create the slide puzzle. The 9 buttons will move around in exchange of the btnblank. In addition, the reset button will reset the tiles back to its original location.
You will be creating a Visual Studio C# Form Project. This program is part 1 of a larger program. Eventually, it will play a game of a slide puzzle those games with tiles that you slide around to make a picture or put numbers in order.
Name the form, frmSlide, and set the title
The Start button (forms Accept button) will do nothing this week.
The Reset button will reset the puzzle (numbers 1 through 8 and the blank back to their original/solved spots)
. The Exit button (forms Cancel button) will end the program.
The 9 Buttons that make up the puzzle can be used to move a tile to a new location. I highly recommend that moving is really swapping the text, which means the 9 Buttons stay in their original locations, only the text changes. When the user clicks on a Button with text (the non-blank one), swap the text with the blank Button making it look like the 2 tiles switched places.
You MUST use a two-dimensional array to hold the 9 Buttons. Youll create the 9 Buttons using code, not the ToolBox and Properties window.
Heres sample of code that can create a Button, assign some properties, assign it an event handler, and place it on the form. You can put this in the Form Load event:
Button b;
This can be a single Button or an array of Buttons
If you have an array of buttons, // then all b references b = new Button();
will be a single element from the array
x and y of upper left corner (to put at x=100, y=200 b.Location = new Point(100, 200);
b.Height = 40; b.Width = 40;
b.Text = ""; b.TextAlign = ContentAlignment.MiddleCenter;
b.Font = new Font(FontFamily.GenericSerif, (float) 15.0); // allNumberButton_Click is the name of the // function that should be called on click
b.Click += new System.EventHandler(this.allNumberButton_Click); this.Controls.Add(b);
1 Slide Puzzle Sample Run #1: The user clicks on 6:
The user clicks on 5:
The user clicks on Reset Extra Notes:
Did you use appropriate names for the controls?
Do you have a reasonable tab order?
Did you set the CancelButton?
Did you set the Access keys?
Did you check your code with the style checker?
Using C Sharpe Program: The following explains what needs to be done. We have to use the start button to shuffle the tiles and use validation for the form. If you have any questions please let me know.
Description: This program is part 2 of the Move It program. You should be building on last weeks Slide Puzzle project.
For this part, youll be adding a way to validate each move, start the game (randomly shuffle the tiles), and check if the user has solved the puzzle
Whenever a tile (Button) is clicked, make sure that it is adjacent to the blank/open tile. If it is not adjacent, then do not perform the move. No message needs to be displayed to the user, just dont perform the move.
o You should be able to do this in a general way so if we change the size of the puzzle (two-dimensional array), it will still work.
o But if you need, you can start by hard-coding this. For example, the upper-left button can only be clicked if the blank is the upper middle or the left middle.
The Start button will randomly shuffle the tiles. Make sure that the puzzle remains solvable. One way to guarantee that the puzzle is solvable is to pretend that the user has clicked on many different Buttons. Choose a random button from your two-dimensional array and pretend to click on it (execute the code that happens when a Button is clicked). If you repeat this process many times, the tiles will be shuffled, yet the puzzle will be solvable.
To get random numbers, declare the following variable: Random rnd = new Random();
Then you can get random numbers in any range. For example, to get one between 0 and 9: int rndNumber = rnd.Next(10);
Every time a tile is moved, check if the puzzle is now solved. If it is, pop-up a Message that says Congratulations, along with the number of hours, minutes, and seconds since the last time the puzzle was solved. When you first start the program, save off the current time as the last solved time.
Sample Run #1: The user clicks on Start (note that each time Start is clicked, there will be a different result because you are using Random numbers):
Slide Puzzle The user clicks on Start again:
The user clicks on 4 (nothing happens because it isnt adjacent to the open tile):
The user clicks on 8 (it moves because it is adjacent the user could have clicked on 8, 2 or 6):
After many more clicks, the user solves the puzzle:
Slide Puzzle Extra Notes: Did you use appropriate names for the controls?
Do you have a reasonable tab order?
Did you set the CancelButton?
Did you set the Access keys?
Did you check your code with the style checker?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
