Create functions:
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;
}
}
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
Create functions: Initialization – print “Setting up the game” Teardown – print “Destroying the game” Accept...