In this game, the user enters a number, and the computer has to guess the number entered by the user. They way this works is we provide hints to the computer whether the number it guessed is lower or higher than the number the user has entered. We will additionally show an alert or a modal to prevent the user from cheating as well, where one might provide a wrong hint to the computer. The final screen where the game gets over, will display the number of tries in which the computer guessed the number.
Wirefames
Components
Let's start by building the core components of the app!
Header
This is the Header component for our app, inside the components/ folder.
This is how our app looks as of now on both iOS and android devices:
Card
In the above component, we saw that we can add shadow to a component. It would be useful if we could use this as an independent component, which almost resembles like a Card, which has it's own custom styles, and in which we can add on more styles as we like. Let's have a look how to do this:
Since we will be using a lot of custom colors in our app, it is easier to refer to them via constants, rather than copy-pasting the color code to the places where we need to use them. It is also useful if we have to change the color that we use at multiple places, where we would need to change the value only at one place, rather than updating it at all the places we use this value.
We can not only use this for colors, but also for general layout of our app, for example, having a constant for margin and padding, placement of View in our app, etc, that makes our lives as developers, easier. But, here let us focus only on colors.
Let's create the Input component, where we will enter the number which the computer has to guess. We will also "configure" the Input component, meaning, we will provide the properties to the TextInput component provided by react native via the parent component!