I have a more generic code theory question. I have a program I am writing that is a companion program for a board game. As the board game develops, more pieces are added to the board. The board initially has no pieces on it and by the end of the first few turns will have 8 pieces. That number will go up as the game progresses. In my current design those pieces are individual objects within the companion program that have their own attributes. Those attributes will be tracked for various in-game mechanics (total player points, distribution of player resources, etc).
When you start my program, you open on an empty board and then customize it for the game you want to review. All objects that will be placed are placed after the initial program setup() runs.
How do I deal with objects that will be created at a time after the initial setup() runs? Is it possible to create new objects without initializing them in the setup() function and if so how is this done?
I have two solutions that I think work but they seem a little crude.
I could create all of the objects that could potentially be in the game, make them “empty”, and then just fill in each object with the needed attributes when it is called. This would I think solve the problem but create a lot of objects at the initial running of the program that simply aren’t ever needed. I don’t have the exact answer, but I think you would only ever realistically see about half of those objects put in play before the game ended.
The spots are also objects in my current design, but are always in the same location every single time the game is played and will be in the same location every time the program runs. Rather than create objects for these pieces, I can create a boolean for each of the spots those pieces would go on. If there is a game piece on that spot, the boolean is true and the attributes of the space are tracked through the spot on the board itself and not as individual objects.
Is there a more standard way to go about solving this problem?
Thank you all for the help.