Question

There are a number of changes that we need to make: 1) We need to take...

There are a number of changes that we need to make:

1) We need to take the board size (width and height) as command line parameters. If these are not specified, we should print out a message informing the user how to call the program.

2) We need to initialize a game board. Allocate memory, decide if each square has bombs, and count the squares surrounding that have bombs.

3) We need to free the game board. Because we need the game board everywhere, it makes sense to make it a global variable.

4) We need to change the update of the world state to set squares as revealed and check to see if a square has a bomb to determine if the game ends or not. Squares should be flagged or unflagged if the user chooses those options.

Here is some sample output:

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

A

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

5

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

5

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 - 9) and press enter

4

Enter your vertical coordinate (0 - 9) 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 - 9) and press enter

3

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

3

BOOM!!!

Destroying the game

the program is

#include <stdio.h>
   int array[10][10];
   int horizontal;
   int vertical;
    int letter;
void initialization(){
printf("Setting up the game:\n");
}
// to start the game


void teardown(){
   printf("Destorying the game");
}
// the teardown part to clear the gameboard


void input(){  
   printf("Enter your horizontal coordinate (0 - 10) and press enter");
   scanf("%d",& horizontal);
   printf("Enter your vertical coordinate (0 - 10) and press enter");
   scanf("%d",& vertical);
}
// to accept the input letter

void update(){
int *x, *y;
x = &horizontal;
y = &vertical;
}

void display(){  
if((array[horizontal][vertical] == array[0][0]))
   printf("BOOM\n");
   else
   printf("OK!\n");
}
// to display the input to the gameboard and determined if is boom or ok


int main(){
   initialization();
  
   do{ //start a loop
  
   printf("(F)Flag a square:\n(R)unflag a square:\n(A)assert that the square is bomb-free:\n(Q)quit the game:\n");
   // to ask what move you want to da
   scanf("%c",&letter);
  
   if((letter=='F')||(letter=='f'))
   {
   input();
   display();
   }  
   else if((letter=='R')||(letter=='r'))

{
   input();
   display();
   }
  
   else if((letter=='A')||(letter=='a'))  
  
   {
   input();
   display();
   }
} while((letter !='Q')||(letter !='q'));
// to destroy the game
teardown();

}

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

#include <stdio.h>
#include<stdlib.h>
#include<time.h>
int r,c;
int **array; //3. the board is global
char **status;// to know the status of each square
// U=unrevealed V=unrevealed
// F=flagged R=remove flag

int horizontal;
int vertical;
char letter;
void initialization()
{
printf("Setting up the game:\n");
//1. take board size as input
printf("Enter the dimensions row and column");
scanf("%d",&r);
scanf("%d",&c);
array = new int* [r];
status=new char* [r];
for(int p=0;p<r;p++)
{
array[p]=new int[c];
status[p]=new char[c];
}
for(int q=0;q<r;q++)
{
array[q][c]={0};
for(int z=0;z<c;z++)
status[q][z]='U'; //put status as unrevealed
}
//2.lets randomly decide square having bombs
srand(time(0));
for(int i = 0; i<10 && i<r*c; i++) //let us have 10 bombs in the entire board
{
int r1=rand()%r;
int c1=rand()%c;
array[r1][c1]=1;
}
}
// to start the game


void teardown(){
printf("Destorying the game");
delete[] array;
}
// the teardown part to clear the gameboard


void input(char W){
printf("Enter your horizontal coordinate (0 - 10) and press enter");
scanf("%d",& horizontal);
printf("Enter your vertical coordinate (0 - 10) and press enter");
scanf("%d",& vertical);
status[horizontal][vertical]=W;
}
void input(){
printf("Enter your horizontal coordinate (0 - 10) and press enter");
scanf("%d",& horizontal);
printf("Enter your vertical coordinate (0 - 10) and press enter");
scanf("%d",& vertical);
}

// to accept the input letter

void display(){
if(array[horizontal][vertical] == 1)
printf("BOOM\n");
else
printf("OK!\n");
}
// to display the input to the gameboard and determined if is boom or ok


int main(){
initialization();
  
do{ //start a loop
  
printf("(F)Flag a square:\n(R)unflag a square:\n(A)assert that the square is bomb-free:\n(Q)quit the game:\n");
// to ask what move you want to da
scanf("%c",&letter);
  
if((letter=='F')||(letter=='f'))
{
input('F');
}
else if((letter=='R')||(letter=='r'))

{
input('R');
}
  
else if((letter=='A')||(letter=='a'))
{
input();
display();
}
} while((letter !='Q')||(letter !='q'));
// to destroy the game
teardown();

}

Add a comment
Know the answer?
Add Answer to:
There are a number of changes that we need to make: 1) We need to take...
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
  • Need help with this C program? I cannot get it to compile. I have to use...

    Need help with this C program? I cannot get it to compile. I have to use Microsoft Studio compiler for my course. It's a word game style program and I can't figure out where the issue is. \* Program *\ // Michael Paul Laessig, 07 / 17 / 2019. /*COP2220 Second Large Program (LargeProg2.c).*/ #define _CRT_SECURE_NO_DEPRECATE //Include the following libraries in the preprocessor directives: stdio.h, string.h, ctype.h #include <stdio.h> /*printf, scanf definitions*/ #include <string.h> /*stings definitions*/ #include <ctype.h> /*toupper, tolower...

  • Please, I need help, I cannot figure out how to scan variables in to the function...

    Please, I need help, I cannot figure out how to scan variables in to the function prototypes! ******This is what the program should look like as it runs but I cannot figure out how to successfully build the code to do such.****** My code: #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> #include <conio.h> float computeSeriesResistance(float R1, float R2, float R3); float computeParallelResistance(float R1, float R2, float R3); float computeVoltage(int current, float resistance); void getInputR(float R1, float R2, float R3); void getInputCandR(int...

  • Missing multiple labeled functions. Card matching game in C. Shouldn't need any more functions. I am...

    Missing multiple labeled functions. Card matching game in C. Shouldn't need any more functions. I am lost on how to complete the main function (play_card_match) without the sub functions complete. The program runs fine as is, but does not actually have a working turn system. It should display question marks on unflipped cards when the player is taking a turn and should also clear the screen so the player can't scroll up to cheat. Thank you #include "cardMatch.h" //main function /*...

  • Need this in C The starter code is long, if you know how to do it...

    Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...

  • i need help converting this code to java please #include<stdio.h> typedef struct{ int pid,at,bt,ct,tat,wt,f; }process; int...

    i need help converting this code to java please #include<stdio.h> typedef struct{ int pid,at,bt,ct,tat,wt,f; }process; int main() { int n,i,j,st=0,c,tot=0,pno=0,swi=0; float atat=0,awt=0; printf("enter no of processes : "); scanf("%d",&n); process a[n],temp; for (i=0;i<n;i++){ a[i].pid=i+1; a[i].f=0; printf("enter at : "); scanf("%d",&a[i].at); printf("enter the bt : "); scanf("%d",&a[i].bt); printf("--------------------------- "); } while(1){ int min=999,c=n; if (tot==n) break; for (i=0;i<n;i++){ if ((a[i].at<=st)&&(a[i].f==0)&&(a[i].at<min)){ min=a[i].at; c=i; } } if(pno!=a[c].pid) swi++; if (c==n) st++; else{ a[c].ct=st+a[c].bt; st=st+a[c].bt; a[c].tat=a[c].ct-a[c].at; atat=atat+a[c].tat; a[c].wt=a[c].tat-a[c].bt; awt=awt+a[c].wt; a[c].f=1; tot++; } } printf("...

  • C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the class program with methods and variables 2. bill.cpp = contains the functions from class file 3. main.cpp = contains the main program. Please split this program into three files and make the program run. I have posted the code here. #include<iostream>...

  • I need a basic program in C to modify my program with the following instructions: Create...

    I need a basic program in C to modify my program with the following instructions: Create a program in C that will: Add an option 4 to your menu for "Play Bingo" -read in a bingo call (e,g, B6, I17, G57, G65) -checks to see if the bingo call read in is valid (i.e., G65 is not valid) -marks all the boards that have the bingo call -checks to see if there is a winner, for our purposes winning means...

  • I need to make a few changes to this C++ program,first of all it should read...

    I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...

  • So I have a question in regards to my program. I'm learning to program in C...

    So I have a question in regards to my program. I'm learning to program in C and I was curious about the use of functions. We don't get into them in this class but I wanted to see how they work. Here is my program and I would like to create a function for each of my menu options. I created a function to display and read the menu and the option that is entered, but I would like to...

  • I JUST NEED HELP WITH DISPLAY PART! please help! thanks in advance // This function saves...

    I JUST NEED HELP WITH DISPLAY PART! please help! thanks in advance // This function saves the array of structures to file. It is already implemented for you. // You should understand how this code works so that you know how to use it for future assignments. void save(char* fileName) { FILE* file; int i; file = fopen(fileName, "wb"); fwrite(&count, sizeof(count), 1, file); for (i = 0; i < count; i++) { fwrite(list[i].name, sizeof(list[i].name), 1, file); fwrite(list[i].class_standing, sizeof(list[i].class_standing), 1, file);...

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
ADVERTISEMENT