#include <iostream>
#include <cstdlib>
using namespace std;
int p1=0,p2=0,count=0;
int turn=0;
void disp(int cards[4][4])
{
//display board
cout<<" 1 2 3 4\n";
cout<<" ";
for (int i=0; i<=8; i++)
{
cout<<"-";
}
cout<<endl;
for (int r=0; r<4; r++)
{
cout<<r+1<<" | ";
for (int c=0; c<4; c++)
{
cout<<"* ";
}
cout<<"\n";
}
}
void reveal(int cards[4][4],int r1,int c1,int r2, int c2)
{
//reveal
cout<<" 1 2 3 4\n";
cout<<" ";
for (int i=0; i<=8; i++)
{
cout<<"-";
}
cout<<endl;
for (int r=0; r<4; r++)
{
cout<<r+1<<" | ";
for (int c=0; c<4; c++)
{
if ((r==r1)&&(c==c1))
{
cout<<cards[r][c]<<" ";
}
else if((r==r2)&&(c==c2))
{
cout<<cards[r][c]<<" ";
}
else
{
cout<<"* ";
}
}
cout<<"\n";
}
}
void game(int cards[4][4],int n)
{
char comma,any;
int r1, c1, r2, c2;
turn=n;
cout<<"Press any character to continue\n";
cin>>any;
system("cls");
disp(cards);
//selection
while(true){
if(turn==1)
cout<<"Player 1 turn\n";
else if(turn==2)
cout<<"Player 2 turn\n";
cout<<"Please insert the first card row and
column seperated by a comma.\n";
cin>>r1>>comma>>c1;
cout<<"Please insert the second card row and column seperated
by a comma.\n";
cin>>r2>>comma>>c2;
//checking
if(cards[r1-1][c1-1]==0 || cards[r2-1][c2-1]==0)
cout<<"Card already checked. Enter new position\n";
else if(r1>4 || c1>4 || r2>4 || c2>4)
cout<<"Position out of range. Enter again \n";
else if(r1==r2 && c1==c2)
cout<<"Same position enter again\n";
else{
//fix
r1--;
c1--;
r2--;
c2--;
break;
}
}
reveal(cards,r1,c1,r2,c2);
if(cards[r1][c1]==cards[r2][c2])
{
cout<<"There is a match
\n";
cards[r1][c1]=0;
cards[r2][c2]=0;
count++;
if(count==8)
{
if(p1>p2)
{
cout<<"Player 1 wins. Score
"<<p1<<"\n";
exit(0);
}
else
if(p2>p1)
{
cout<<"Player 2 wins. Score
"<<p2<<"\n";
exit(0);
}
else
if(p1==p2)
{
cout<<"Its a tie!!!\n";
exit(0);
}
}
if(turn==1)
{
p1++;
cout<<"Player 1 Score: "<<p1<<"\n";
cout<<"Player 2 Score: "<<p2<<"\n";
game(cards,1);
}
else if(turn==2)
{
p2++;
cout<<"Player 1 Score: "<<p1<<"\n";
cout<<"Player 2 Score: "<<p2<<"\n";
game(cards,2);
}
}
else
{
cout<"No match. Changing
Player";
if(turn==1)
game(cards,2);
else if(turn==2)
game(cards,1);
}
}
int gen(int a[8])
{
int k;
while(true)
{
k=rand()%8;
if(k<8 && a[k]!=2
)
{
a[k]++;
return
k+1;
}
}
}
int main()
{
int cards[4][4];
int a[]={0,0,0,0,0,0,0,0};
//fill board
for (int r=0; r<4; r++)
{
for (int c=0; c<4; c++)
{
cards[r][c]=gen(a);
cout<<cards[r][c];
}
cout<<endl;
}
game(cards,1);
return 0;
}
can someone solve this program using c++ (visual studio)? You have a grid of 4x4 cells...
The game Battleship is played on a grid board. Each opponent has multiple ships that are placed on the grid where the other opponent cannot see them. In order to attack, each player takes turns calling out coordinates on a grid. If the attacker calls out a coordinate that hits their opponent's ship, they must call out, "Hit." You are going to be developing a computer program to mimic this game. Use the Gridlayout that is six columns by six...
The game Battleship is played on a grid board. Each opponent has multiple ships that are placed on the grid where the other opponent cannot see them. In order to attack, each player takes turns calling out coordinates on a grid. If the attacker calls out a coordinate that hits their opponent's ship, they must call out, "Hit." You are going to be developing a computer program to mimic this game. Use the Gridlayout that is six columns by six...
Program in C++
Implement Conway's Game of Life using 2-dimensional arrays. All the tips, tricks, techniques we have been using in class are allowed. Nothing else. The program should read the initial state of the board by reading in "alive" cells from a user input data file. Meaning your program should ask the user the name of the data file. Assume all the other cells are "dead." Make sure to use modular coding techniques. The main program should be pretty...
Please program this in Visual Basic 6.
You have chosen to create an electronic version of the sliding tile puzzle game. The object of the game is to slide the tiles so that they end up in the required order. The images shown below are examples of the two different versions of this puzzle (numeric and graphical) Puzzle Board-Numeric Puzzle Board-Graphical File Options Help Elapsed Time File Options Help Elapsed Time 00:02:12 00:04:20 5 6 7 8 9 10 11...
*Using C++* You will create a program that uses a Critter class to move around a Grid, which is also a class. The Critter and the Grid classes will be in separate files. The Critter class will have a data member to count the number of moves made. It will also need data members to hold the current x and y coordinates. It will have a member function that randomly moves it one space in one of 4 directions. You...
C++ Project - Create a memory game in c++ using structs and pointers. For this exercise, you will create a simple version of the Memory Game. You will again be working with multiple functions and arrays. You will be using pointers for your arrays and you must use a struct to store the move and pass it to functions as needed. Program Design You may want to create two different 4x4 arrays. One to store the symbols the player is...
Please use C++, thank you!
The life game consists of a board with size of NxN cells and cells are occupied by creatures. Each cell can have at most one creature. The surrounding cells are called the neighbors of this cell Each game state is called "generation". The game progresses from one generation to the next according to the following rules: A creature that has more than 3 neighbors- dies of crowding. Its cell will be empty in the next...
Using java :
In this exercise, you need to implement a class that encapsulate
a Grid. A grid is a useful concept in creating board-game
applications. Later we will use this class to create a board game.
A grid is a two-dimensional matrix (see example below) with the
same number of rows and columns. You can create a grid of size 8,
for example, it’s an 8x8 grid. There are 64 cells in this grid. A
cell in the grid...
***Java Project***
Please upload the entire code and attach the screenshots of the
code. The screenshots help me to write the code, so please attach
that. Thank you so much. If you could use the comment to explain
the code, it would be perfect! Thank you so much~
Design and code a Swing GUl for a two-player tic-tac-toe (noughts and crosses) game on a 3 x 3 game board. The JFrame should use a BorderLayout with a JLabel in the...
with C++ You will create a program that uses a Critter class to move around a Grid, which is also a class. The Critter and the Grid classes will be in separate files. The Critter class will have a data member to count the number of moves made. It will also need data members to hold the current x and y coordinates. It will have a member function that randomly moves it one space in one of 4 directions. You...