Question
please help me to program using C according to the following instruction I have tried but try to correct it as much as possible For
please help me to program using C according to the following instruction I have tried but try to correct it as much as possible
For this assignment, we will be creating our project and getting some of the structure in place.
Most computer games have a particular structure, whether guess a number or Battlefront II. They start with some initialization set up the data structures that model the game world. Then there is the game loop a (nearly) infinite loop that accepts user input, updates the state of the game world, and updates the display. Finally, there is the teardown sequence that happens at game exit.
Your assignment: Create a program that models the structure above.
Create functions:
- Initialization print Setting up the game
- Teardown print Destroying the game
- Accept Input accept a letter for a command. The commands are the things that you can do to the board: Flag a square, unflag a square, assert that the square is bomb-free, and quit the game. Accept coordinates if appropriate. Prompt and error check appropriately.
- Update the state of the world pass the input data to this function. Since we do not have a world right now, choosing (0,0) as bomb free will print BOOM, other moves will print OK
- Display the state of the world Print the result calculated in the state of the world. Later, this should print the board.
- Main call initialization, then loop until a flag is set, calling accept input, update and display. Outside of the loop, call teardown.
Make variables to define the size of the board (width and height). These can be global variables.
#include
char letter;
int horizontal; int vertical;
void main(){
intialization(); while(flag == true){
accept_input(); update_state(); display_state();
teardown(){ printf("setting up the game: "); return 0; } intialization(){ printf("(F)flag a spot as mine,(R) remove a flag,(A)assert that a spot is mine,(Q) quit ",); }
accept_input(){ scanf("%c",&letter);
if(letter == 'F'){
scanf("%c",&horizontal); } elseif (letter=" ") { return 0; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started