Memory games have long been a popular way to kill time while improving cognitive skills. It’s no surprise that, with the increase of mobile devices, memory games have made their way onto our smartphones and tablets. If you want to create a memory game for Android devices, Delphi is a strong tool to assist you. In this article, we’ll look at how to make a memory game for Android with Delphi, a rapid application creation tool.
Table of Contents
Why Create a Memory Game Using Delphi For Python?
Using Delphi for Python to create a memory game can be advantageous for Python developers looking for an efficient way to build Graphical User Interfaces (GUIs) for their game. Delphi for Python gives developers powerful tools and cross-platform support. It allows them to build visually appealing and functional user interfaces that operate across multiple platforms without writing separate code for each. Developers can build sophisticated and flexible GUIs with access to the FireMonkey GUI framework, making the development process faster and more efficient.
Furthermore, Delphi’s UI design tools, such as the Delphi4PythonExporter tool, can help accelerate development while ensuring that the resulting GUIs are functional and aesthetically appealing. Finally, Delphi Community Edition and PythonFMXBuilder are open-source tools ideal for developers who prefer to work with open-source tools whenever feasible. In conclusion, using Delphi for Python to create a memory game can assist Python developers in streamlining their development process and ensuring that their game works smoothly and efficiently across all platforms.
How to Create this Game as a Desktop App?
Delphi offers powerful tools that make developing visually appealing and engaging games easily. So, let’s dive in and start creating your own memory game for Android using Delphi.
What Are the Requirements to Create this App?
To create the memory game desktop app, you must have Delphi installed on your device and the FireMonkey GUI framework. Additionally, you will need a text editor or IDE that supports Python, such as PyScripter and the Delphi4PythonExporter tool.
If you don’t have these tools installed, we recommend checking out the article “Powerful Python GUI Project Setup” to help you get started. Once you have all the required tools, you can proceed with the tutorial to create your memory game desktop app using Delphi
You can grab the code for this tutorial from our GitHub repository using the following link: https://github.com/Embarcadero/PythonBlogExamples/tree/main/Memory_Game
How to Create Forms in Delphi CE?
Begin by opening Delphi CE and creating a blank application. To do this, navigate to File > New > Multi-Device Application > Blank Application > Ok
. In this tutorial, we have named our project MemoryGame
.
If you are not familiar with the various sections of the Delphi IDE, we recommend referring to our free eBook bundle, which covers the Delphi Python EcoSystem and all Python GUI offerings.
To start, let’s give our form a name. Right-click on the form and select QuickEdit. Here, we will name our form MainForm
with the caption MainMenu
.
Next, let’s resize our form. Go to the object inspector and search ClientHeight
and ClientWidth
in the properties tab. We will set them to 500
and 360
, respectively.
We will also rename the source file of our main form to MainMenu.pas
to make it easier to keep track of.
This form will be the primary screen where users can start the game. To enhance the user experience, let us add a label that will display the title of our app. To do this, navigate to the standard palette and locate the TLabel
component. Next, drag and drop this component onto the form.
To modify the text style to reflect the title, we will use TextSettings
. Navigate to the Object Inspector
and locate TextSettings
. Select Font beneath it and click “...
” to see options for modifying the label’s font, size, and style based on your preferences. Here we have set our font family as Britannic with a font size of 48.
Rename each label’s text by right-clicking on the label and selecting Quick Edit
. Following an intuitive naming convention for the labels is crucial so they can be tracked more easily. Here, we called our TLabel
component “Title
” with the text “Memory Game
“.
Here we also centered the text using the HorzAlign
and VertAlign
properties to ensure that the text appears symmetrical.
We can adjust the form’s background color by navigating to the Object Inspector
and selecting the form’s fill
property.
Finally, we need a method for navigating to the next form where the main game would be played. To accomplish this, go to the Palette
and add a button using the TButton
component.
Let’s give this button a suitable name. Additionally, we changed the font size and style of these button texts (as we did for the TLabels above) to make them more prominent. Here, we used Segoe UI with a font size of 18.
After making these changes, our form will be much more visually appealing:
Now, let’s add some styles to our forms using the power of DelphiFMX styles. The Delphi ebook bundle comes shipped with a variety of styles that you can use for your applications.
So first download the free ebook bundle and extract the styles zip file into a folder of your choosing. Now select the style you want to choose, for this project we will be using Light.style
. You can find other styles online, such as delphistyles.com.
Head to the Palette and search of the TStyleBook
object. Add this to your form.
Next, double click on the object. This will open up your Style Designer. Now press the click on the open button.
Now head to the directory of your extracted style files, select the style of your choosing, and click on exit. Next, select the form and head over to the Object Inspector. Here we will search for the StyleBook property. Select the drop down menu and select StyleBook1.
This will apply the style to your form. Here is what our final MainForm
looks like:
Now that we are done with the main form of our app, let’s create a new form that will display our Memory Game. So right-click on MemoryGame.exe
and select Add New > Multi-Device Form
.
This will create a new form which we have named as GameForm
, and the corresponding source file as Game.pas
. We have also renamed the form caption to Memory Game
, and changed the form dimensions to match our MainForm
.
Next, let’s start by adding labels and buttons to our form. We will first add two labels to the top of our form which we will name ScoreLabel
and TriesLabel
, with the captions Score:
and Tries:
respectively. These labels will help us display the score the player has scored as well as the number of tries they have made.
We have also changed their font style to Britannica with a font size of 24.
Next, we will add 8 buttons to our form that will help us play our game.
For each button we added a default caption as ? and named each of them as Button1
, Button2
, and so on. We also added two extra buttons Back
and Reset
that will help us navigate our forms. As you can see we have disabled the Reset
button by default which will only open when the player has finished the game.
Finally, we added 3 new labels to the form. The Card1
and Card2
label will help the user remember the card he had selected in his try. The additional label, which we have named Status
, lies right above the Back
and Reset
buttons. It will help display the status of the game. Finally add the Light style to our form. Here is what our final form looks like:
Now that our forms are ready, the last step would be to add functionality to each button. So navigate to each form and double-click each button to create an OnClick
method for that button in your .pas
file corresponding to your .fmx
form. This will enable you to add distinct functionality for each button when clicked.
After creating the OnClick
method for each button, adding at least one comment (//
) to each procedure is recommended to preserve it when you save the Python file. As we do not export the run-time implementation using the Delphi4PythonExporter, there is no need to write any run-time implementation code.
How Can We Export this App as Python Code?
Now that our forms are ready, we can save our project as a Python script by selecting Tools > Export To Python > Export Current Entire Project
.
Here rename your project to MemoryGame
, and select the main form as MainForm
. Finally, select the directory of your choosing and click Export:
Delphi will generate 5 files, 3 Python scripts named MainMenu.py
, Game.py
, and MemoryGame.py
. The Game.py
, MainMenu.py
python files contain the classes for the individual forms, and the MemoryGame.py
is used to launch our Delphi app. Along with each Python file, Delphi also generates a .pyfmx
script of the same name as each form that contains the visual information of that form. Now, let’s take a look at the exported Python files.
MemoryGame.py
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
from delphifmx import * from MainMenu import MainForm def main(): Application.Initialize() Application.Title = 'MemoryGame' Application.MainForm = MainForm(Application) Application.MainForm.Show() Application.Run() Application.MainForm.Destroy() if __name__ == '__main__': main() |
Game.py
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import os from delphifmx import * class GameForm(Form): def __init__(self, owner): self.ScoreLabel = None self.TriesLabel = None self.Button1 = None self.Button2 = None self.Button3 = None self.Button4 = None self.Button5 = None self.Button6 = None self.Button7 = None self.Button8 = None self.Button9 = None self.Button10 = None self.BackButton = None self.ResetButton = None self.Card1Label = None self.Card2Label = None self.Status = None self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Game.pyfmx")) def Button1Click(self, Sender): pass def Button2Click(self, Sender): pass def Button3Click(self, Sender): pass def Button4Click(self, Sender): pass def Button5Click(self, Sender): pass def Button6Click(self, Sender): pass def Button7Click(self, Sender): pass def Button8Click(self, Sender): pass def Button9Click(self, Sender): pass def Button10Click(self, Sender): pass def BackButtonClick(self, Sender): pass def ResetButtonClick(self, Sender): pass |
MainMenu.py
:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import os from delphifmx import * class MainForm(Form): def __init__(self, owner): self.Title = None self.StartButton = None self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "MainMenu.pyfmx")) def StartButtonClick(self, Sender): pass |
How to Add Functionality to This App Using the Delphi FMX Library?
Now that our forms are ready, we can start adding functionality to our game. Let’s start by opening up MainMenu.py
and navigating to the StartButtonClick
function.
The MainForm
only serves the purpose of launching the game and the StartButtonClick
will help us do that. So start by importing the GameForm
, from Game.py
:
1 2 |
from Game import GameForm |
Next, in the StartButtonClick
function, create a new variable named Game
, and create a new instance of the GameForm
. We will then use the Show()
method to display our GameForm
. Here is what the StartButtonClick
function looks like:
1 2 3 4 |
def StartButtonClick(self, Sender): Game = GameForm(self) Game.Show() |
Here is what our MainMenu.py
looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import os from delphifmx import * from Game import GameForm class MainForm(Form): def __init__(self, owner): self.Title = None self.StartButton = None self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "MainMenu.pyfmx")) def StartButtonClick(self, Sender): Game = GameForm(self) Game.Show() |
Now that our MainForm
is ready, let’s now add functionality to our GameForm
. Start by opening Game.py
and navigating to the __init__
function. In the __init__
function the first thing we will have to do is initialize our score and tries. Along with this we will keep track of the previous attempt by the user and add a flag that will help us later on:
1 2 3 4 5 |
self.prev = (self.Button1, "") # Store the first selected card data self.score = 0 # Game score counter self.tries = 0 # Tries counter self.flag = 0 # Flag to check if one complete try/guess has been made |
Next, we will call a function called __RandomizeCards()
, which we will define later:
1 2 3 |
# Randomly assign values to all cards at the start self.__RandomizeCards() |
Here is what our final __init__
function looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
def __init__(self, owner): self.Button1 = None self.Button2 = None self.Button3 = None self.Button4 = None self.Button5 = None self.Button6 = None self.Button7 = None self.Button8 = None self.Button9 = None self.Button10 = None self.ScoreLabel = None self.Card1Label = None self.Card2Label = None self.Status = None self.BackButton = None self.ResetButton = None self.TriesLabel = None self.LoadProps(os.path.join(os.path.dirname( os.path.abspath(__file__)), "Game.pyfmx")) # Randomly assign values to all cards at the start self.__RandomizeCards() self.prev = (self.Button1, "") # Store the first selected card data self.score = 0 # Game score counter self.tries = 0 # Tries counter self.flag = 0 # Flag to check if one complete try/guess has been made |
Now the lets move on and define the __RandomizeCards()
function. Let’s start by importing random
:
1 2 3 |
# Additional imports import random |
The __RandomizeCards()
function uses the Keys
from all the buttons that we have defined for our GameForm
. It then shuffles a bunch of alphabets that we have defined in our values
variable. Finally, it assigns each button a sigle value by the means of a dictionary. This dictionary is stored in a new variable called self.d
. Here is what our final __RandomizeCards()
function looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
def __RandomizeCards(self): # Define the keys for the dictionary keys = ["Button1", "Button2", "Button3", "Button4", "Button5", "Button6", "Button7", "Button8", "Button9", "Button10"] # Define the values to randomly select from values = ["A", "A", "B", "B", "C", "C", "D", "D", "E", "E"] # Shuffle the values randomly random.shuffle(values) # Create the dictionary self.d = dict(zip(keys, values)) |
Now let’s define our Back
and Reset
buttons. Start by going to the BackButtonClick
function. Here all we need to do is destroy the current form. So here is what our BackButtonClick
function will look like:
1 2 3 4 |
# Go back to the main screen def BackButtonClick(self, Sender): self.Destroy() |
Next, we need to define our Reset
button. The Reset
button will call the __RandomizeCards
function once again, while resetting the tries
, score
, flag
and all the necessary labels of our form. It will then disable the Reset
button and reset the text on all the buttons on our form. Here is what our ResetButtonClick
function will look like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# Play game again so bring back to initial state def ResetButtonClick(self, Sender): # Randomize the card/button values and reset all labels self.__RandomizeCards() self.prev = (self.Button1, "") self.score = 0 self.tries = 0 self.flag = 0 self.TriesLabel.Text = "Tries: " self.ScoreLabel.Text = "Score: " self.Status.Text = "" self.ResetButton.Enabled = False # Hide all cards/buttons (so show ?) and enable them so that they can be clicked Buttons = [self.Button1, self.Button2, self.Button3, self.Button4, self.Button5, self.Button6, self.Button7, self.Button8, self.Button9, self.Button10] for Button in Buttons: Button.Text = "?" Button.Enabled = True |
Now let’s define the main functionality of our game. To do this, let’s create a function called __Functionality
that takes in two parameters, the button that presses it, as well as the name of the button. The function uses the name parameter in self.d
to get the value assigned to it:
1 2 3 |
def __Functionality(self, Button, name): val = self.d[name] # Get value against this button |
Now that we have our value, we need to check whether the user is one his first or second try. To do this we will use the flag
variable. If flag
is equal to 1
then the user is on his second try.
Now if the user is on his second try, we first need to update the tries
label and reset the flag
to 0
:
1 2 3 4 5 6 7 8 9 |
def __Functionality(self, Button, name): val = self.d[name] # Get value against this button # If one complete try has been done if self.flag == 1: self.tries += 1 # Then increase tries counter self.TriesLabel.Text = "Tries: "+str(self.tries) self.flag = 0 # Reset tires flag |
Next, we need to check whether the value of the previous try was the same as this new try. For this we will use the self.prev
variable. Now if the new values match, we increment the score
and update the relevant labels. Additionally, we also disable the new selected button, as well as the previous button.
Finally, once we have made the relevant updates, we need to check if the current score is equal to 5
. This would indicate that the user has selected all buttons, and thus has won the game. In this case, we update the Status
label and enable the Reset
button. Here is what our __Functionality
function looks like so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
def __Functionality(self, Button, name): val = self.d[name] # Get value against this button # If one complete try has been done if self.flag == 1: self.tries += 1 # Then increase tries counter self.TriesLabel.Text = "Tries: "+str(self.tries) self.flag = 0 # Reset tires flag # If the two cards/buttons selected are the same if self.prev[1] == val: self.score += 1 # Then increase score counter self.ScoreLabel.Text = "Score: "+str(self.score) Button.Text = val # Show the value behind Button.Enabled = False # Disable the cards/buttons so that they cannot be clicked self.prev[0].Enabled = False # If score is 5 then all the cards/buttons have been matched if self.score == 5: self.Status.Text = "You Win!" self.ResetButton.Enabled = True # Now reset button can be clicked |
Now, we add a check if the two buttons selected are not the same. In that case, we show the respective cards in the Card1Label
and Card2Label
, we then hide the previous button and reset the self.prev
variable:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
def __Functionality(self, Button, name): val = self.d[name] # Get value against this button # If one complete try has been done if self.flag == 1: self.tries += 1 # Then increase tries counter self.TriesLabel.Text = "Tries: "+str(self.tries) self.flag = 0 # Reset tires flag # If the two cards/buttons selected are the same if self.prev[1] == val: self.score += 1 # Then increase score counter self.ScoreLabel.Text = "Score: "+str(self.score) Button.Text = val # Show the value behind Button.Enabled = False # Disable the cards/buttons so that they cannot be clicked self.prev[0].Enabled = False # If score is 5 then all the cards/buttons have been matched if self.score == 5: self.Status.Text = "You Win!" self.ResetButton.Enabled = True # Now reset button can be clicked # If the two cards/buttons selected are not the same else: # Show the respective values below the cards self.Card1Label.Text = "Card 1: " + self.prev[1] self.Card2Label.Text = "Card 2: " + val Button.Text = val Button.Text = "?" # Hide the cards again0 self.prev[0].Text = "?" |
Finally, to complete the function we add an else
for when the user is on his first try. The Card1Label
and Card2Label
will remain the same, but the selected button flips to show the value behind it. We then update the flag
to 1
and then update the self.prev
variable. Here is what our completed __Functionality
function looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
def __Functionality(self, Button, name): val = self.d[name] # Get value against this button # If one complete try has been done if self.flag == 1: self.tries += 1 # Then increase tries counter self.TriesLabel.Text = "Tries: "+str(self.tries) self.flag = 0 # Reset tires flag # If the two cards/buttons selected are the same if self.prev[1] == val: self.score += 1 # Then increase score counter self.ScoreLabel.Text = "Score: "+str(self.score) Button.Text = val # Show the value behind Button.Enabled = False # Disable the cards/buttons so that they cannot be clicked self.prev[0].Enabled = False # If score is 5 then all the cards/buttons have been matched if self.score == 5: self.Status.Text = "You Win!" self.ResetButton.Enabled = True # Now reset button can be clicked # If the two cards/buttons selected are not the same else: # Show the respective values below the cards self.Card1Label.Text = "Card 1: " + self.prev[1] self.Card2Label.Text = "Card 2: " + val Button.Text = val Button.Text = "?" # Hide the cards again0 self.prev[0].Text = "?" # If just one card/button has been selected and # the other has to be selected to complete the guess else: self.Card1Label.Text = "Card 1:" self.Card2Label.Text = "Card 2:" Button.Text = val # Show the value behind self.flag += 1 # Increase flag to show that first card selected from the try and one more left self.prev = (Button, val) # Store this button info to compare |
Now all we need to do is call the __Functionality
function in each button. So head over to each button and call the function. Here is what this looks like for Button1
:
1 2 3 |
def Button1Click(self, Sender): self.__Functionality(self.Button1, "Button1") |
Here is what our final Game.py
file looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
import os from delphifmx import * # Additional imports import random class GameForm(Form): def __init__(self, owner): self.Button1 = None self.Button2 = None self.Button3 = None self.Button4 = None self.Button5 = None self.Button6 = None self.Button7 = None self.Button8 = None self.Button9 = None self.Button10 = None self.ScoreLabel = None self.Card1Label = None self.Card2Label = None self.Status = None self.BackButton = None self.ResetButton = None self.TriesLabel = None self.LoadProps(os.path.join(os.path.dirname( os.path.abspath(__file__)), "Game.pyfmx")) # Randomly assign values to all cards at the start self.__RandomizeCards() self.prev = (self.Button1, "") # Store the first selected card data self.score = 0 # Game score counter self.tries = 0 # Tries counter self.flag = 0 # Flag to check if one complete try/guess has been made def __RandomizeCards(self): # Define the keys for the dictionary keys = ["Button1", "Button2", "Button3", "Button4", "Button5", "Button6", "Button7", "Button8", "Button9", "Button10"] # Define the values to randomly select from values = ["A", "A", "B", "B", "C", "C", "D", "D", "E", "E"] # Shuffle the values randomly random.shuffle(values) # Create the dictionary self.d = dict(zip(keys, values)) def __Functionality(self, Button, name): val = self.d[name] # Get value against this button # If one complete try has been done if self.flag == 1: self.tries += 1 # Then increase tries counter self.TriesLabel.Text = "Tries: "+str(self.tries) self.flag = 0 # Reset tires flag # If the two cards/buttons selected are the same if self.prev[1] == val: self.score += 1 # Then increase score counter self.ScoreLabel.Text = "Score: "+str(self.score) Button.Text = val # Show the value behind Button.Enabled = False # Disable the cards/buttons so that they cannot be clicked self.prev[0].Enabled = False # If score is 5 then all the cards/buttons have been matched if self.score == 5: self.Status.Text = "You Win!" self.ResetButton.Enabled = True # Now reset button can be clicked # If the two cards/buttons selected are not the same else: # Show the respective values below the cards self.Card1Label.Text = "Card 1: " + self.prev[1] self.Card2Label.Text = "Card 2: " + val Button.Text = val Button.Text = "?" # Hide the cards again0 self.prev[0].Text = "?" # If just one card/button has been selected and # the other has to be selected to complete the guess else: self.Card1Label.Text = "Card 1:" self.Card2Label.Text = "Card 2:" Button.Text = val # Show the value behind self.flag += 1 # Increase flag to show that first card selected from the try and one more left self.prev = (Button, val) # Store this button info to compare # Implement this functionality when any of the 10 buttons/cards are selected def Button1Click(self, Sender): self.__Functionality(self.Button1, "Button1") def Button2Click(self, Sender): self.__Functionality(self.Button2, "Button2") def Button3Click(self, Sender): self.__Functionality(self.Button3, "Button3") def Button4Click(self, Sender): self.__Functionality(self.Button4, "Button4") def Button5Click(self, Sender): self.__Functionality(self.Button5, "Button5") def Button6Click(self, Sender): self.__Functionality(self.Button6, "Button6") def Button7Click(self, Sender): self.__Functionality(self.Button7, "Button7") def Button8Click(self, Sender): self.__Functionality(self.Button8, "Button8") def Button9Click(self, Sender): self.__Functionality(self.Button9, "Button9") def Button10Click(self, Sender): self.__Functionality(self.Button10, "Button10") # Go back to the main screen def BackButtonClick(self, Sender): self.Destroy() # Play game again so bring back to initial state def ResetButtonClick(self, Sender): # Randomize the card/button values and reset all labels self.__RandomizeCards() self.prev = (self.Button1, "") self.score = 0 self.tries = 0 self.flag = 0 self.TriesLabel.Text = "Tries: " self.ScoreLabel.Text = "Score: " self.Status.Text = "" self.ResetButton.Enabled = False # Hide all cards/buttons (so show ?) and enable them so that they can be clicked Buttons = [self.Button1, self.Button2, self.Button3, self.Button4, self.Button5, self.Button6, self.Button7, self.Button8, self.Button9, self.Button10] for Button in Buttons: Button.Text = "?" Button.Enabled = True |
Can I Create this Game for Android Devices?
Let’s proceed to convert our time widget application into an Android application.
As the Delphi4Python Exporter only exports the initialization logic for desktop-based applications, we need PythonFMXBuilder to convert it to an Android app. To begin, open FMXBuilder, click on the toolbar’s Project > New project
option, and provide the project’s name. We named ours MemoryApp
.
Before adding our Python files, we must modify some code to allow our project to run on Android. First, we need to create a new file called MemoryGame_Android.py
and copy the contents of MemoryGame.py
. Next, add your Python and other supporting project files used to build your application. We won’t add MemoryGame.py
; it will only run our desktop application.
Right-click on the MemoryGame_Android.py
file and set it as the main file. Before building the app, we need to make some important code changes.
In Android applications, Delphi applications are automatically initialized. Therefore, we don’t need to initialize or set a title manually. The Application.MainForm
variable only needs to be initialized without launching or destroying the program because Android handles both tasks.
After making the necessary code changes, save the file.
Now connect your mobile to your computer device and enable USB tethering. Next, click on the refresh icon and select your device from the drop down menu.
Finally, choose your device and click on the Run Project button. This will install the app on your Android phone and run it.
This will install the app directly on your mobile device.
Is this App Working as Expected?
Now that our app is ready, you can launch it on your Android device and be greeted with the MainForm
screen:
Next click on the START
button, which will open up the GameForm
:
As you can see the Reset button is disabled and will only open when the game has finished. You can then start playing the game. Clicking on each button will reveal the letter behind that button:
If you don’t guess your alphabet in your try, then the Card1
and Card2
labels show your previous attempt:
If you can guess a button correctly, then your score increments and the buttons get disabled:
Finally, you can continue along with the game until you get everything right:
As you can see the Reset
button gets enabled once the game is finished. You can click on it to restart the game with new random alphabets.
Are You Ready to Create Other Apps With Delphi?
To summarize, developing a memory game for Android with Delphi is a rewarding experience for developers looking to hone their skills and build engaging applications. Developers can quickly build visually appealing and functional user interfaces that work on multiple devices using Delphi’s powerful tools and cross-platform support. Whether you’re an experienced developer or a beginner, this piece has given you the information you need to create your own memory game for Android using Delphi.
Now that you’ve learned how to make a memorization game in Delphi for Android, it’s time to put your knowledge to use. You can improve your coding skills and make a game that is engaging and enjoyable to play by doing so. Remember to test your game on various devices to ensure it works smoothly and efficiently.
What Are Some FAQs Related to this Tutorial?
What is Delphi?
Delphi is a rapid application development tool for Windows that allows developers to create Graphical User Interfaces (GUIs) quickly and easily.
What is FireMonkey?
FireMonkey is a powerful, flexible GUI framework to create visually appealing and functional user interfaces.
Is Delphi for Python a good choice for developing memory games?
Delphi for Python is a great solution for developers looking to create memory games quickly and efficiently, with cross-platform support and powerful tools.
Do I need previous programming experience to use Delphi for Python?
Some programming experience is recommended, but beginners can still use Delphi for Python to create simple applications and gradually improve their skills.
Can I create a memory game for other platforms besides Android using Delphi for Python?
Yes, Delphi for Python provides cross-platform support, allowing you to create memory games that work on various platforms such as Windows, macOS, iOS, and more.
Are there any open-source tools available for Delphi for Python?
Delphi Community Edition and PythonFMXBuilder are open-source tools that offer an ideal solution for developers who prefer open-source tools whenever possible.