Big Tuto on OOP & MVC with the Game Of Life


By Steph, 1 year ago

Controls: D-Pad: [Arrows / WASD] - A: [J] - B: [K] - Menu: [U] - Home: [I]
Enjoy games at full speed with sound and lights on the Gamebuino META!
Emulator by aoneill

Complete Tutorial on Game of Life

I propose here a very complete tutorial based on a small mathematical recreation, instead of a real game in the classical sense of the term, for the Gamebuino META: the famous Game of Life, designed by John Conway in the 1970s. You will see that this is a great little exercise, which will allow us to discuss many programming concepts and techniques. The main idea that guided me throughout the writing of this tutorial was to propose an exercise that was both simple and rich in possibilities, that we would be able to treat in a different way, through a gradual approach in the complexity of the programming, to achieve a finalized application with a controlled architecture.

I apologize to the English-speakers, my tutorial is written in French ... but you can get the English version here with Google Translate.

However, the French version of tutorial is available here. And you'll need it, because unfortunately Google Translate breaks the layout of code snippets and doesn't correctly show the YouTube videos...

What you will learn in this tutorial :

  • program a cellular automaton,
  • optimize your code for:
    • speed up the execution of your code,
    • save the memory space,
  • better organize your code with Object Oriented Programming,
  • design your applications with a Model View Controller architecture,
  • intercept events when the user presses the buttons,
  • handle menus in your applications,
  • program a LED manager for the META,
  • program a sound effects manager.

Feel free to send me your comments, or ask me for clarification on things you didn't understand correctly.

I would like to point out that this application is my first programming experience in C++... and yes ;-) I'm learning like you! My code is most likely to be perfectible, so I rely on the experienced coders in the community to let me know about possible (or necessary!) improvements. I will try to integrate them as soon as possible... because I still have a job in real life... and I can't spend all the time I want to have fun with this great little console!

Last comments

9 months ago
Author :  jicehel

Perso, quand je sais ce que j'aurais dans ma variable, je prĂ©fĂšre utiliser les notation type int8_t ou uint8_t que je trouve plus parlante et mĂȘme un bon vieux char quand c'est un caractĂšre. On peut faire autrement et size_t peut avoir son utilitĂ© notamment par ce qu'il transporte une idĂ©e de taille et que dans une fonction, comme le disait Steph si on met se type pour dimensionner un index de tableau, on est certain d'avoir le plus grand tableau possible. De plus comme il est non signĂ©, il permet de 'bloquer' un accĂšs Ă  un emplacement nĂ©gatif  suite Ă  une anomalie dans le code qui provoquerait une erreur. Pour moi, c'est bien dans des librairies que l'on veut rĂ©utiliser car on ne connait pas forcĂ©ment la taille des tableaux que l'on utilisera lors de la rĂ©utilisation mais en rĂšgle gĂ©nĂ©rale, je code pour moi (mĂȘme si je partage) et du coup, je ne l'utilise pas.

9 months ago
Author :  Codnpix

Ok merci ! 

si t'es un maniaque de l'occupation mémoire

Je pense que je m'en prĂ©occupais pas tant que ça avant, mais ton tuto propose une belle sensibilisation sur le sujet ! C'est assez chouette de dĂ©couvrir qu'en poussant un peu les meubles, mĂȘme une petite machine comme la META a des vraies possibilitĂ©s de calcul. J'adore cet environnement minimaliste^^. (ça change par rapport aux monstres d'ordi qu'on a l'habitude d'utiliser aujourd'hui)

9 months ago
Author :  Steph

Question logique :-) ... si t'es un maniaque de l'occupation mémoire, tu utiliseras un itérateur codé sur le nombre de bits suffisants (dans le cas que tu proposes, un uint8_t suffira amplement)... sinon tu te dis que, pour une variable volatile (qui sera détruite à la sortie de ta fonction), réserver 1 ou 4 octets... y a pas de quoi s'alarmer ;-)