Let’s play a game :D

So…. remember the time when there were games in ax2012? Me nether :D. But let’s bring some fun in d365 so I received the challenge to build the Hangman game. And now my manager will hang me if he sees me playing it…

Here it is a simple solution, for an easy game

The idea of the game is to have a collection of words. A random function will pick one of the words without displaying it, and the gamer needs to guess the letters.

First thing, let’s get a word. The app allows you to insert a list of words. If there is no list with words, then the functionality will insert a fixed one. 🙂 I’m not going to show it to you…. This is cheating. The Random function will pick one of the words from the table.
The idea for this method is to get the letter inserted by the player and check if is part of the word. The guessed letters will be displayed, the mistery letters will be displayed lie “_” 😉
When we open the ax form, we need to get the word, so we override init().
We have 2 buttons: one “Check“, will be clicked to check the letter and the validate letter functionality will be triggered, the other “Reset“, use it to start the game again.
Of course, we need to draw a “hanged man”. The way to do it is to display a list of pictures with different levels of the “hanging”. We store the pictures in resources and we display each picture per row for each wrong letter.
You are in control of the messages you display to the gamer if he loses or wins. You can also display funny pictures. But I wanted to keep it simple. Feel free to be creative.
Every time when the player wants to start from the beginning, he just needs to press the Reset button and the game will start again. Or if the gamer loses or wins needs to start from the beginning. A new word will be randomly selected and the “hanged man” will be sent away.

Good news, you find the game on github. Please feel free to try it, improve it and have fun.

The idea of building the game is not mine, it was a challenge to build hangman in 2 hours :D. This is how it went. 😀

Leave a Reply

Your email address will not be published. Required fields are marked *