Posts

Check Sudoku - Unity Tutorial - 7. Hint legend, State persistence, Localization

Image
In the previous step we implemented hints . In this one we will add a legend for the hints, state persistence, and translation of the application to other languages (localization): Implementation Let's start from localization. Following this tutorial we install Localization package, add locale for languages: English (default), German, and Polish. We fix the names of all application strings, and add their translations. Next, we "Localize" each text element, and select the correct translation. We also add the option to change language in our settings panel. To do that we add a toggle group, containing: HorizontalLayoutGroup - to automatically place the toggles ToggleGroup - to make sure only toggles are exclusive Each toggle is a Toggle element, with a text field replaced by an image, with icon downloaded from pixabay.com ( english-flag , german-flag , polish-flag ) We add a script with localeName property and (so far empty) click handler to the language toggle ( Language...

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 ( ...