import java.util.Scanner;
import java.util.Arrays;
import java.util.Random;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] board = setupBoard();
int[] playingBoard = new int[board.length];
int[] pairs = new int[board.length/2];
Arrays.fill(pairs, 2);
placePairs(board, pairs);
int attempts = pairs.length + 2;
boolean playUnlimited = false;
while (true) {
displayMainMenu(attempts, playUnlimited);
int choice = scanner.nextInt();
if (choice == 1) {
playUnlimited = false;
break;
} else if (choice == 2) {
playUnlimited = true;
break;
} else if (choice == 3) {
System.exit(0);
} else {
System.out.println("Invalid choice. Please enter 1, 2, or 3.");
}
}
int foundPairs = 0;
while (playUnlimited || foundPairs < pairs.length) {
displayBoard(playingBoard);
int cell1, cell2;
do {
System.out.print("Enter the indexes of two undiscovered cells (separated by a space): ");
cell1 = scanner.nextInt();
cell2 = scanner.nextInt();
if (!isWithinBounds(board.length, cell1) || !isWithinBounds(board.length, cell2)) {
System.out.println("Invalid cell indexes. Please try again.");
continue;
}
if (isCellSelected(playingBoard, cell1) || isCellSelected(playingBoard, cell2)) {
System.out.println("One or both of the cells you selected has already been cleared. Please try again.");
continue;
}
break;
} while (true);
if (board[cell1] == board[cell2]) {
clearCell(playingBoard, cell1, board[cell1]);
clearCell(playingBoard, cell2, board[cell2]);
foundPairs++;
System.out.println("You found a pair!");
} else {
System.out.println("Sorry, those cells don't contain a pair.");
attempts--;
}
if (attempts == 5) {
System.out.println("Game over. You ran out of attempts.");
break;
} else if (foundPairs == pairs.length) {
System.out.println("Congratulations! You found all the pairs.");
break;
}
}
scanner.close();
}
public static int[] setupBoard() {
Scanner scanner = new Scanner(System.in);
int size;
do {
System.out.print("Enter the size of the board (even number): ");
size = scanner.nextInt();
if (size % 2 != 0) {
System.out.println("Invalid board size. Please enter an even number.");
continue;
}
break;
} while (true);
int[] board = new int[size];
return board;
}
}
What I have tried:
I have tried to putting a symbol for the method but nothing
Here are the Error codes I get
Main.java:14: error: cannot find symbol
placePairs(board, pairs);
^
symbol: method placePairs(int[],int[])
location: class Main
./Main.java:20: error: cannot find symbol
displayMainMenu(attempts, playUnlimited);
^
symbol: method displayMainMenu(int,boolean)
location: class Main
./Main.java:39: error: cannot find symbol
sh -c javac -classpath .:target/dependency