In: Computer Science
Looking for the layout.xml and Main_activity.java cide
for the following app:
A card flipping game
1 . When the application is started, it asks user to
:hoose a difficulty level between easy, medium,
or hard and presents the next activity to the user
2. Depending on the user's selection, this activity
shows a 2x3, 3x4 or 4x4 grid of cards to the user.
all cards must initially be closed.
3. The user clicks on a card. The cards face is
shown and if it is the same as the previous card,
these two cards are removed from the grid.
Otherwise, they get closed again.
4. The game continues until all cards are opened.
5. When the game is over, the user sees their score which is the
total number of clicks they performed to open all cards on a new
activity.
import java.io.*;
public class Game {
public static void main(String args[]) {
Scanner sc= new Scanner();
System.out.println("Enter the level for game");
String level= sc.next();
if(level.equals(easy)){
int [][]arr= new int[2][3];
boolean [][]face= new boolean[2][3];
int check= 2*3;
}
else if(level.equals(medium)){
int [][]arr= new int[3][4];
boolean [][]face= new boolean[3][4];
int check= 3*4;
}
else if(level.equals(hard)){
int [][]arr= new int[4][4];
boolean [][]face= new check[4][4];
int check= 4*4;
}
int a,b,c,d;
int click=0;
while(check !=0){
a= sc.nextInt(), b= sc.nextInt();
if(face[a][b]== 1)
continue;
click++;
c= sc.nextInt(), d=sc.nextInt();
if(face[c][d]== 1)
continue;
click++;
if(arr[a][b]==arr[c][d]){
face[a][b]= 1;
face[c][d]= 1;
check= check-2;
}
}
System.out.println("Score is "+click);
}
}