Monday 7 September 2020

Chapter 16 // Exercise 2 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2017 and modified versions of the graphics files used throughout the chapters. You can find those versions through the link below.

Chapter 16 // Exercise 2

Make a window (based on My_window) with a 4-by-4 checkerboard of square buttons. When pressed, a button performs a simple action, such as printing its coordinates in an output box, or turns a slightly different colour (until another button is pressed).

Github: https://github.com/l-paz91/principles-practice/tree/master/Chapter%2016/Exercise%202


The main problem with this exercise is that I learnt that you cannot use a lambda as a callback function if it is capturing local variables. I managed to get rid of all the call back functions and have only 1 button action function but because of this constraint, I still had to have 16 separate push_backs in the constructor for CheckerboardWindow instead of being able to use a for loop.

I added a couple of new values to the Colour_type enum in Graph.h as well which gives us the exact background colour (handily called FL_BACKGROUND_COLOR by fltk). 

There was something oddly satsifying about this exercise though...maybe I can finally make Minesweeper live and reloaded now...


Chapter 16 // Exercise 2 - Principles & Practice Using C++

No comments:

Post a Comment