Question
I need just homework#6, I post homework# 5 to understand how to do it ?
Please do it and please don't copy the answer
CSCE 1030 Homework 5 Due: 11:59 PM on Monday, April 17,2017 PROGRAM DESCRIPTION: In this C++ program, you will start building the software infrastructure that will allow you to play a simplified version of the class game of Minesweeper that will display to the screen. In Homework 6, you will continue the work begun here to finish the development of the game Your programs output should initially call a function to display the department and course number, your name, your EUID, and your e-mail address. In the function, your program will prompt the user to enter the number of mines main as an integer between 5 and 10, inclusively, that will be placed in a randomly selected location on the 5-by-5 board used for the game. If the user does not enter a valid response, you will repeat this process until a valid response is entered. To start the game, you will display an introductory message, giving details about the game, including the size of the board, the number of number of mines placed on the board, and the objective of the game (i.e., how many squares are needed to be selected without hitting a mine to win). This implemented will be as a function, passing in parameters as needed. in main to represent the 5-by-5 board as You shall declare a two-dimensional array m type you declare to represent the various values that a square can assume. an Each square on your board may contain one of the following values (according to the rules of the game) initial value of square not revealed (may or may not contain mine) a mine is present at this location the user selected a square containing a mine the number of mines contained in the immediately adjacent squares The size of the square board should be declared as a constant, but it is up to you whether or not it is a local or global constant. You will initialize the board using a function, passing in the two-dimensional array and the size. This function will simply initialize each position on the board to the enumerated type representing the initial value, which is the character You will then assign the number of mines between 5 and 10, inclusively, specified by the user to randomly generated locations on the board using a b l function, passing in the two-dimensional array and the size. This function will generate a random row- column position and then attempt to place a mine at that row-column position on the board. Since the row-column position is randomly generated, if the function attempts to place a mine on a square that already contains a mine, the method will return false indicating that the assignment was not successful. If the square, however, does not already contain a mine, then the function will assign a mine to that location by assigning that row-column position with the enumerated type representing the mine and return true, indicative that the assignment was successful. Note that this function attempts to 1 of 5
media%2Fb20%2Fb208a28f-1afe-40c8-a3e5-9e
media%2F7f8%2F7f80b90d-80fb-48a8-8d99-d8
media%2F18d%2F18d7aa87-513e-4d04-9a2c-c2
media%2F6ee%2F6ee064c5-f68a-443d-920c-44
media%2F326%2F326e60cb-8aef-4eee-b69e-f1
media%2F224%2F224fba0d-f305-4d01-ac7b-61
media%2F6b6%2F6b615c41-d069-4e6f-a3c1-46
media%2Ff74%2Ff746289b-1996-49b0-95a7-0c
media%2F8a6%2F8a60f293-7afc-41fb-82af-70
media%2Fd0d%2Fd0d70e33-9402-47d8-902d-a8
0 0
Add a comment Improve this question Transcribed image text
Answer #1

void main()
{
int b;
do
{
cout << "Enter number of squares per side (2 - 10)" << endl;
cin >> b;
}while(b < 1 && b >= 10);
int board[b][b]; //0 - 8 = # of mines, 9 is mine
int revealed[b][b]; //1 is revealed
int i = 0;   
int j = 0;
int x = 0;   
int y = 0;
int z; //number of mines
int q;
int t = 0; //game over input
int dead = 0;
do
{
cout << "How many mines? (1 - " << ((b*b)-1) << ")" << endl;
cin >> z;
}while(z <= 0 && z >= ((b*b)-1));
for(i=0;i<b;i++)
for(j=0;j<b;j++)
board[i][j] = 0;
i = random(i, b);
j = random(j, b);
cout << "Generating board..." << endl;
do
{
i+=3;
j+=6;
x = random(i, b);
y = random(j, b);
if(board[y][x] != 9)
{
board[y][x] = 9;
z--;
if((y-1) >= 0)
if(board[y-1][x] != 9)
board[y-1][x]++;
if((y-1) >= 0 && (x-1) >= 0)
if(board[y-1][x-1] != 9)
board[y-1][x-1]++;
if((x-1) >= 0)
if(board[y][x-1] != 9)
board[y][x-1]++;
if((y+1) < b)
if(board[y+1][x] != 9)
board[y+1][x]++;
if((y+1) < b && (x+1) < b)
if(board[y+1][x+1] != 9)
board[y+1][x+1]++;
if((x+1) < b)
if(board[y][x+1] != 9)
board[y][x+1]++;
if((y-1) >= 0 && (x+1) < b)
if(board[y-1][x+1] != 9)
board[y-1][x+1]++;
if((y+1) < b && (x-1) >= 0)
if(board[y+1][x-1] != 9)
board[y+1][x-1]++;
}
}while(z>0);
for(i = 0; i < b; i++)
for(j=0;j<b;j++)
revealed[i][j]=0;
//board creation end
//ask for input/check squares loop
do
{
system ("clear");
q = 0;
z = 0;
cout << " ";
for(i=0;i<b;i++)
cout << i << " ";
cout << endl;
for(i=0;i<b;i++)
{
for(j=0;j<b;j++)
{
if(j==0)
cout << i << " |";
if(revealed[i][j]==1)
reveal(board[i][j]);
else
cout << "_|";
if(j==(b-1))
cout << endl;
if(board[i][j]!=9 && revealed[i][j]==1)
q++;
if(board[i][j] == 9)
z++;
}
}
if(q >= ((b*b) - z))
{
cout << "You win!" << endl;
dead = 1;
}
if(dead == 0)
{
cout << "X: ";
cin >> x;
cout << "Y: ";
cin >> y;
}
if(board[y][x] == 9)
{
system ("clear");
cout << "You hit a mine!" << endl;
cout << " ";
for(i=0;i<b;i++)
cout << i << " ";
cout << endl;
dead = 1;
for(i=0; i<b; i++)
{
for(j=0;j<b;j++)
{
if(j==0)
cout << i << " |";
if(board[i][j]==9)
revealed[i][j]=1;
if(revealed[i][j]==1)
reveal(board[i][j]);
else
cout << "_|";
if(j==(b-1))
cout << endl;
}
}

}
if(board[y][x]==0)
{
revealed[y][x] = 1;
for(i=0;i<b;i++)
{
for(j=0;j<b;j++)
{
if(i>(y-2)&&i<(y+2))
if(j>(x-2)&&j<(x+2))
if(board[i][j]!=9)
revealed[i][j]=1;
}
}
}
if(board[y][x]>0 && board[y][x]<9)
revealed[y][x] = 1;
} while(dead == 0);
if (dead == 1)
replay();
}

void replay()
{
char a;
cout << "1) Replay 2) Quit" << endl;
cin >> a;
switch(a)
{
case '1':
main();
break;
case '2':
cout << "Quit" << endl;
break;
default:
cout << "Invalid input" << endl;
replay();
break;
}
}

void reveal(int x)
{
if(x == 0)
cout << "o|";
else if(x == 9)
cout << "x|";
else
cout << x << "|";
}

int random(int i, int b)
{
long ran;
int t = time(0);
int s;
srand(t);
s = ran;
ran = rand();
ran >>= ran / (ran * i) + (i * 1337);
ran = ran % b;
return ran;
}

Add a comment
Know the answer?
Add Answer to:
I need just homework#6, I post homework# 5 to understand how to do it ? Please...
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
  • Please help me write a Pseudocode (please do NOT answer in JAVA or Python - I...

    Please help me write a Pseudocode (please do NOT answer in JAVA or Python - I will not be able to use those). Please ALSO create a flowchart using Flowgarithm program. Thank you so much, if answer is provided in Pseudocode and Flowchart, I will provide good feedback and thumbs up to the resonder. Thank you! Tic-Tac-Toe Game Write a program that allows two players to play a game of tic-tac-toe. Use a two- dimensional char array with three rows...

  • I need screenshots for this solution done in Flowgorithm. Thank you. Tic-Tac-Toe Game Design a program...

    I need screenshots for this solution done in Flowgorithm. Thank you. Tic-Tac-Toe Game Design a program that allows two players to play a game of tic-tac-toe. Use a two- dimensional String array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: a. Displays the contents of the board array. b. Allows player 1 to select a location...

  • Code in JAVA You are asked to implement “Connect 4” which is a two player game....

    Code in JAVA You are asked to implement “Connect 4” which is a two player game. The game will be demonstrated in class. The game is played on a 6x7 grid, and is similar to tic-tac-toe, except that instead of getting three in a row, you must get four in a row. To take your turn, you choose a column, and slide a checker of your color into the column that you choose. The checker drops into the slot, falling...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • 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...

  • I am having trouble figuring out why my program will not make any columns, just rows....

    I am having trouble figuring out why my program will not make any columns, just rows. I need to display a square. The instructions are provided below. (This for my C++ class) Write a program that displays a square. Ask the user for the square’s size. Only accept positive integer numbers (meaning choose a data type that holds positive integer values). The size the user gives you will determine the length and width of the square. The program should then...

  • I need help as quick as possible, thanks beforehand. Please provide the test output The Lo...

    I need help as quick as possible, thanks beforehand. Please provide the test output The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown below. 35 The Lo Shu Magic Square has the following properties: The grid contains the numbers 1 - 9 exactly The sum of each row, each column and each diagonal all add up to the same number. This is shown below: 15 4 92 15 - 81 + 15 15 15...

  • PROGRAM DESCRIPTION: In this assignment, you will be creating a memory matching game in C++. In t...

    c++ PROGRAM DESCRIPTION: In this assignment, you will be creating a memory matching game in C++. In this game, the user will need to match up the pairs symbols A,B,C,D,E on a 4x4 array. For example, the array could be initialized like the following: In this case, X represents an empty slot. The goal is for the user to match the A to the A, the B to the B, etc, until all pairs are matched up to win the...

  • Please help i need a C++ version of this code and keep getting java versions. Please...

    Please help i need a C++ version of this code and keep getting java versions. Please C++ only Purpose: This lab will give you experience harnessing an existing backtracking algorithm for the eight queens problem, and seeing its results displayed on your console window (that is, the location of standard output). Lab A mostly complete version of the eight queens problem has been provided for you to download. This version has the class Queens nearly completed. You are to provide...

  • I only need the "functions" NOT the header file nor the main implementation file JUST the impleme...

    I only need the "functions" NOT the header file nor the main implementation file JUST the implementations for the functions Please help, if its difficult to do the complete program I would appreciate if you could do as much functions as you can especially for the derived class. I am a beginer so I am only using classes and pointers while implementing everything using simple c++ commands thank you in advanced Design and implement two C++ classes to provide matrix...

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