![]() One is an About/Help box and the other pops up when the puzzle is completed. To complete the View, I added two more forms to the project. ' Add code to process new game button command End Sub In the code behind the form, I have this: The code basically looks like this at the beginning. As I went along and worked on the UI logic, I added stub code in the Controller and some comments so that I know what to do later on. Basically, each button, checkbox, label, etc. Otherwise, Windows will ignore any attempts to position this form when you first open it. Here is how it looks in the designer view.īecause I want to position this number pad on the screen so that it overlays the cell that was just clicked, it is important to set the StartPosition property to Manual. Because of this, I added another button to the upper right corner with an " X" on it to allow the user to close this window without entering a value. I did this because the border would look bulky when placed on top of the main puzzle. I then turned off the border by setting FormBorderStyle = none. I added a new Form to the project and then added buttons with the numbers 1 through 9. That way, the user does not have to move the mouse far to enter values into the grid. I chose to use the latter method for my game. Some games use a series of number buttons at the top, bottom or side of the main grid. In Sudoku, the user needs to enter values into the empty cells. The following is a picture of the UI of the game as seen in the designer view. to complete the UI based on how I wanted the game to look and operate. By using the TableLayoutPanel and changing the CellBorderStyle and the Background color, it gave the board just the right emphasis to show the overall 9 x 9 grid as well as the 3 x 3 sub grids. I did this because each cell in the TableLayoutPanel can only accept a single control. In each cell, I added a Label control which I set the Dock property to Fill. Into each cell, I added another TableLayoutPanel which was divided into 3 rows and 3 columns to represent the smaller 3 x 3 grid. I divided the TableLayoutPanel into 3 rows and 3 columns to represent the outer grid. But in the end, I decided to use a TableLayoutPanel as the base grid. I could have used a DataGridView control like other people have done. But that would have required a lot of behind the scene code to check for mouse clicks and stuff like that. I could have used a Panel control and just drew the 9 x 9 grid and game on it. I started the project by designing the user interface, or UI, or the View, for the game. It is complete and can be loaded, compiled, and run. There are several excellent articles online that describe this programming pattern in more detail. The following is a diagram showing how the different parts of the MVC pattern interact with each other. Likewise, organizing the code in the same way makes it easier to maintain in the long run. By separating the different logical parts of the code, it makes updating and maintaining the code much easier. Likewise the Model does not know how the data is being used or displayed. The View does not know anything about the data that is being displayed. And the Controller contains the business logic as well as ties the Model and the View together. The View contains all the UI related code. It is used to separate the different parts of the program into its logical components. I used the MVC, or Model-View-Controller, programming pattern as a guide when I wrote the game. This article basically describes how the game was put together as well as some background on the design and code decisions I made along the way. The object of the game is to fill in the blank cells so that each row, column and 3 x 3 mini grid contains each number only once. The game starts out with some cells filled in with the numbers from 1 through 9. The basic Sudoku game is played on a 9 x 9 grid that is subdivided into 3 x 3 mini grids. This project demonstrates several programming concepts like Singletons, Shared code, Delegates and Events, multi-threading, as well as the MVC programming pattern. Over the course of 4 days, this is the result. After playing many versions of the game on the Web, newspapers, and on iOS devices, I decided to see if I could write my own. I started playing Sudoku when it became popular in the early 2000s. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |