Posts

Check Sudoku - Unity Tutorial - 6. Suggestions

Image
In the previous step we implemented game rules . In this one we will add suggestions helping solve the Sudoku: Implementation Let's start from the suggestions in the work cell. We want it to suggestion options visually, i.e. the only possible value in the column will be marked blue ( #1E88E5 ), in the row will be marked red ( #D81B60 ), in the 3x3 square will be marked yellow ( #FFC107 ). We download a free crosshair icon from pixabay.com , which, using GIMP, we turn into three other colors: In the possibility ( PossibilityRect ) we add three images ( OnlyValueColImage , OnlyValueRowImage , OnlyValueGroupImage ) rotated so that a few of them can be displayed at the same time (if e.g. given value is the only one both in the column, and in the row): We add methods activating suggestions to the possibility ( PossibilityRect ): public class PossibilityRect : MonoBehaviour { public GameObject onlyValueColImage; public GameObject onlyValueRowImage; public GameObject onlyValue...

Check Sudoku - Unity Tutorial - 5. Game rules

Image
In the previous step we have implemented setting board cell values . In this one, we will add checking Sudoku rules, to prevent user from "clicking" illegal Sudoku board: Implementation At this stage, we need to create the game model. In order to do that, we create three classes: BoardModel  for storing the whole board model CellModel  for storing single cell model CellSetModel  for storing a set of cells (e.g. column, row, or 3x3 square) Question 1: Which element should store the board model? Options: Game manager ( GameManager ) The board ( BoardImage ) The work cell ( WorkCellImage ) Decision: Since we need to join the model with board images anyway, it's easiest if the board ( BoardImage ) creates the model upon creation and feeds all its cells into it. In order to simplify testing, we set the initial values for some of the board cells, getting a solvable Sudoku: public class BoardImage : MonoBehaviour { ... private BoardModel model; private void Aw...

Check Sudoku - Unity Tutorial - 4. Setting values

Image
In the previous step we have created app skeleton . In this one we will implement setting the values of board cells: Implementation In order to fill the board with 3x3 squares (we need 9 of those) and individual cells (we need 81) we create prefabs and use the  GridLayout  to display them. We create one  GroupRect  for each 3x3 group and one  CellImage  for each cell: We follow the same pattern with the work cell, where we display possible values. We create  PossibilityRect  to display possible cell value: After clicking the cell ( CellImage ), we want something (???) to highlight the selected cell with a frame, and we want the work cell ( WorkCellImage ) to display current cell value. After clicking another cell, something (???) should deselect the previous cell, highlight the new one, and display the new cell value in the work cell. Question 1: Which element should store the information about which cell is selected? Options: The game manager ( ...

Check Sudoku - Unity Tutorial - 3. App skeleton

Image
In the previous step we have  set up Unity and GitHub . In this one, we will create an app skeleton, with home page, settings panel, empty board: Implementation Since a lot has changed in Unity over the years (e.g. TextMeshPro is used instead of regular text) we start from completing a simple tutorial: Creative Core: UI Let's start with the home page. We want to have a Sudoku background, but without paying for any "stock" photos, therefore we print one page of problems from  WSPC 2021  and take the picture ourselves: The first challenge is making the home page look good in both portrait and landscape orientation. We achieve it by using AspectRatioFitter for the background as explained  here .  After reading  this  we add a title anchored to the upper left corner of the screen, and panel with buttons anchored to the lower right corner.  This gives us the following UI: We add some background music from pixabay.com . Following Creative Core UI : Ad...