Question

Create functions: Initialization – print “Setting up the game” Teardown – print “Destroying the game” Accept...

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

and the output should look like

Setting up the game

(F) flag a spot as a mine, (R) remove a flag, (A) assert that a spot is mine free, (Q)uit

F

Enter your horizontal coordinate (0 - 10) and press enter

3

Enter your vertical coordinate (0 - 10) and press enter

4

OK!

(F) flag a spot as a mine, (R) remove a flag, (A) assert that a spot is mine free, (Q)uit

(F) flag a spot as a mine, (R) remove a flag, (A) assert that a spot is mine free, (Q)uit

A

Enter your horizontal coordinate (0 - 10) and press enter

0

Enter your vertical coordinate (0 - 10) and press enter

0

BOOM!

(F) flag a spot as a mine, (R) remove a flag, (A) assert that a spot is mine free, (Q)uit

(F) flag a spot as a mine, (R) remove a flag, (A) assert that a spot is mine free, (Q)uit

Q

Destroying the game

please correct those C program according to the above form thanks

#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:\n");
return 0;
}
intialization(){
   printf("(F)flag a spot as mine,(R) remove a flag,(A)assert that a spot is mine,(Q) quit\n",);
}

accept_input(){
scanf("%c",&letter);

if(letter == 'F'){

scanf("%c",&horizontal);
}
elseif (letter= ") {
return 0;
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi

I will not be writing the full solution code as it is not possible to do so within the given time frame. However I can tell you the approach and algorithm to do the same which can then be mapped into a C code for your assignment.

As far as I am getting from your query, this is a minesweeper game that has a flow diagram like this:

from this we can see that initialization and teardown will be called only once and that too following the order of initialization -> teardown .

Hence the accept input function will have an if else branch inside it that will either update the the state of the world or teardown based on the input provided. The loop can be called using the input stream that will stop once the exit condition of 'Q' will be pressed.

A simple code structure would be like this:-

initialization(){

//ask for inital input

acceptinput();

if(noInput)

teardown();

}

acceptInput(input){

if(input.exists() && input != q){

updateState();

}else{

teardown();

}

}

updateState(input){

//updation stuff

displayState();

}

displayState(input){

//display

acceptInput(input.hasNext);

}

teardown(){};

This code skeleton is what you have to follow in which you can specifics as asked in the question.

Thank you

Add a comment
Know the answer?
Add Answer to:
Create functions: Initialization – print “Setting up the game” Teardown – print “Destroying the game” Accept...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT