samedi 5 septembre 2020

Best practice to return an integer in an array to represent a special condition

I am working on a board game program that is generated using an array of integers. The array has random numbers between 0 and 2 that represents an additional number of points the player gets when they land on that piece. I use this array to build the front end of the app - Each piece will denote how many extra points they get.

Ex: int[] board = [0, 1, 1, 0, 2, 2, 1]

I need to modify this to add a special condition that if they land on the piece, it's game over for that player. This condition is completely unrelated to how the array is being used currently. How do I represent this special condition in the array that when read, my front end knows that it's used to represent this special condition. I could hack it and use a random int say 99 and check if the number is 99 and add this special logic. Somehow this feels like a hack.

PS: I cannot modify the int array to be of a custom type.

Aucun commentaire:

Enregistrer un commentaire