Posts

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

Check Sudoku - Unity Tutorial - 2. Setup

Image
Unity Since I haven't used Unity for a few years I installed Unity Hub and the latest version of Unity (2022.1.20f1) from the  official site . In oder to record animation GIFs I also installed  LICEcap . Font location Adding the first"Text - TextMeshPro" element to the UI show the prompt for importing essential and additional resources (e.g. fonts). We import both: Next, we move the fonts that we plan to use (e.g. "Roboto-Bold.ttf") to the new "Fonts" folder: Script location By default all Unity C# scripts (e.g. for "GameManager" game object) are created directly under "Assets". We move them to the new "Scripts" folder: Audio files location We put audio files (e.g. background music) into the new "Audio" folder: GitHub We save the project locally. To prevent losing it in case of computer failure, we also store it in a private repository at  gihub.com  using e.g. GitHub Desktop . Next steps The next step will be c...

Check Sudoku - Unity Tutorial - 1. An idea

Image
Problem statement Let's start from something simple. Let's implement an app for solving  classical Sudoku . Users The intended audience are people who want to learn how to solve even the hardest classical Sudoku themselves. Functionality The app will help with solving Sudoku, by: highlighting cells with deduced values for a cell with deduced value, explaining why this value needs to be there The app WILL NOT (at least in the 1st version): generate Sudoku boards solve Sudoku automatically scan Sudoku board with the use of phone / computer camera User interface The UI will be very simple. When solving the board, the app will highlight cells with deduced values: After selecting a highlighted cell, visual indicators and textual explanation appears, explaining why this value needs to be there. After selecting suggested value, the field is now filled, and is taken into account when deducing values for other fields: Let's start with the setup  :-D Polish | English