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;
}
I need just homework#6, I post homework# 5 to understand how to do it ? Please...
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 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. 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 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 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 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 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...
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 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 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...