Nim is a mathematical strategy game which two players take turn to remove any number from different piles. There are many variations of the game, in this tutorial, there will be three piles with number three, four and five respectively. The winner is the player who takes the last number.
Create three variables to keep track of the number in different piles and also a variable to keep track the player’s turn. This below example, updateButton procedure is created to update the text of all three buttons when any of the number changes. When RestartGameButton is clicked, reset the variables and UI.
When user clicked any of the three buttons, we will use Notifier text dialog to ask for the number user will be taking away from the selected button. After user input a number, we will need to check for several invalid input conditions:
Input number should be less than remaining number on the button
input number should not be less than zero
If input is valid, we will then check for the winning condition. If the sum of all three piles is zero, then the player wins the game.
Above example shows only the logic for Button1, the same logic needs to be done for Button2 and Button3. If the winning condition is not met, update the isPlayerOne variable. We will also change the UI to indicate different player’s turn.
This app will generate a QR code using string input by user. The QRCodeCreator extension was used for the QR generation. Add BarcodeScanner and File components to provide required dependency and permission for the app to function correctly.
The rise of low-code/no-code platforms allow anyone to easily create mobile apps. In the low-code/no-code mobile apps development space, three notable platforms are MIT App Inventor, Thunkable, and Kodular. Both Thunkable and Kodular originated from MIT App Inventor, hence they all have similar interfaces and mechanics on the app building process. MIT App Inventor is maintained by Massachusetts Institute of Technology for educational purposes while the latter two aimed to help users create commercial applications.
All three platforms use Google’s Blockly visual programming language as their foundation for app development. Even though no code needs to be “written” and the complex programming syntax is abstracted away with Blockly, users ought to understand the fundamental concepts of programming in order to achieve different results effectively. Here are some of the fundamental concepts in programming that will help you in your app building process:
In computer programming, a variable or scalar is a storage location (identified by a memory address) paired with an associated symbolic name, which contains some known or unknown quantity of information referred to as a value.
Primitive Data Type
null / undefined (special data types)
Composite Data Type
Object / Dictionary
Array / List
Function / Procedure (Not assignable in Blockly)
Examples of creating variables with different data types in Kodular.
Operators are used to perform mathematical, relational or logical operation. We can combine more than one math operator to perform a more complex calculation. Computation of result follows convention math precedence that is:
Multiplication and Division
Addition and Subtraction
A relational operator is used to create conditional expression which will return a Boolean – either true or false. Using it with if statements, we will be able to create algorithms where program can make decision to execute different code based on the given conditional expression.
In programming, conditional statements are used to decide different computations at run time. There are several types of conditional statements:
if…else if…else statement
switch statement (not available in Blockly)
The if statement checks whether a given conditional expression evaluates to true, if so, the statement will be executed.
If the conditional expression of an if statement evaluates to false, then the else statement will be executed.
The else if statement adds another condition to check when the first if statement is false.
Iteration / Loops
In programming is used to repeat a block of code until a specific condition is met. There are two main types of loop:
A for loop requires an initialization statement to declare a loop control variable, a test statement to test against the variable and an increment statement to update the variable. The test statement will be evaluated after every loop and if it is true, the process repeat itself. In the example below, the code blocks in the for loop will be executed for 5 times.
A while loop allows code to be executed repeatedly until a given conditional expression is evaluated as false.
Function / Procedure
Even a simple computer program contains hundreds if not thousands of lines of code. Most of the time, part of these codes is repeated. Instead of typing out the same instructions over and over, we can group them into chunks called function or procedure. Value can also be passed into a function as variables, they are also known as parameters.
Function can have return values – the values that a function returns when it has completed.
In order to develop any logic in your mobile app using either Kodular, Thunkable or MIT App Inventor, understanding the basic concepts of programming give you the ability to achieve it effectively. Diving in without the fundamentals is like solving complex equations without know basic algebra. Our interactive block-based coding platform is designed to help students learn the fundamentals so that they have the skill to build more advance application.
First, generate a list with incremental numbers from 1 to 16. Then, apply Fisher-Yates algorithm to shuffle the list to have random permutation.
Show Numbers when Game Start
When the start game button is clicked, generate the random number list and show the numbers on all 16 buttons from left to right.
Enable the clock when game start to start the timer. In this example, the time interval was set to 5000ms and once the Clock.Timer event called, disable the timer and hide all the text on buttons.
Finally, we need a variable to keep track of the button clicks and the number will be displayed using the top label.
For each button click, increase the clickCount variable by one and check if the number on the button matches the number in our generated array based on its sequence. In below example, checkClick function will take in an argument which will be used as index to get the value in the generated list.