Grid GameI created this game as a Java GUI lab. Click on a grid location and the "distance" to the target is displayed. "Distance" is defined as "delta X plus delta Y". To the right, I clicked on the cell at row 2 and column 2. My second selection was 4 rows down and 4 columns right. My third selection was 3 columns right and 5 rows up. You will notice the "16" cell is 8 steps away from both "8" cells. The fourth selection was off by 2 steps. And the fifth selection hit the target.This is a remarkable vehicle for iteratively demonstrating programming ... 1. Draw the board and quit.
Do you need a data structure to represent
the board? 2. Move the "draw board" functionality to a function. 3. Add random number generation of the target location. 4. Add an infinite loop and prompt/accept row & col input. Simply put a "marker" at the specified location. 5. Add the "delta X plus delta Y" algorithm.
How should integer-to-string conversion
be implemented?
How should "right justification" be
implemented?
6. Replace arrays with 7. Refactor the game "engine" as a class.
int main( void ) { Grid_Game game; int row, col; while (1) { cout << "row col ... "; cin >> row >> col; game.make_guess( row, col ); } } | ![]()
|