I am creating a TictTacToe for my school project (object-orientated) but I ran into this problem where when I try to call the class I get an error saying "method placements in class placePiece can not be applied ton given types". I tried passing in char[][] and int into: new placePiece(char[][] GameBoard, int PlayerPiece); like this but then it gives me an error saying ";" expected and .class expected.
Like I said Im new to programming so literally anything will help.
import java.util.Arrays;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
GameBoard g = new GameBoard();
g.print();
SelectPlayingPiece s = new SelectPlayingPiece();
s.Scan();
PlacePiece p = new PlacePiece();
p.placements();
}
import java.util.Arrays;
public class GameBoard{
public static void print(){
//create a game board for the user to play.
char[][] gameBoard = {{' ','|' ,' ', '|', ' '},
{'-','+' ,'-', '+', '-'},
{' ','|' ,' ', '|', ' '},
{'-','+' ,'-', '+', '-'},
{' ','|' ,' ', '|', ' '}};
//print gameboard 2D array.
for ( char[] row : gameBoard){
for ( char c : row ){
System.out.print(c);
}
System.out.println();
}
}
}
import java.util.Scanner;
import java.util.Arrays;
public class PlacePiece{
public static void placements(char[][] gameBoard, int playerPiece){
//game starts and player selects a column to place thier piece.
System.out.print("Game has begun,please enter where you would like to place (1~9):");
Scanner scan = new Scanner(System.in);
int placement = scan.nextInt();
char piece = 'X';
if( playerPiece == 1){
piece = 'X';
} else {
piece = 'O';
}
switch(placement){
case 1: gameBoard[0][0] = piece;
break;
case 2: gameBoard[0][2] = piece;
break;
case 3: gameBoard[0][4] = piece;
break;
case 4: gameBoard[2][0] = piece;
break;
case 5: gameBoard[2][2] = piece;
break;
case 6: gameBoard[2][4] = piece;
break;
case 7: gameBoard[3][0] = piece;
break;
case 8: gameBoard[3][2] = piece;
break;
case 9: gameBoard[3][4] = piece;
break;
}
}
}
import java.util.Scanner;
public class SelectPlayingPiece{
//allow players to pick thier playing piece.
public void Scan(){
Scanner scan = new Scanner(System.in);
System.out.println("Welcome to TicTacToe! Frist, pick your playing piece: Type 1 to be X and type 0 to be O ");
int playerPiece = scan.nextInt();
char player1 = 'X';
if( playerPiece == 1){
System.out.print("player 1 is X!");
player1 = 'X';
} else{
System.out.print("Player 1 is O!");
player1 = 'O';
}
}
}
question from:
https://stackoverflow.com/questions/65875809/im-getting-an-error-and-cannot-find-a-way-to-solve-it 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…