Here is how the entire thing looks like now.
And then there is the details that you're forced to add and more details and more details and more details and more and more and more and more and more and more and more and more and more and more and more
import java.util.Scanner;
public class Tictactoe {
static char[][] MakeMove(char[][] spelplan, char spelare, int rad, int kolumn) {
spelplan[rad][kolumn] = spelare;
char[][] board = new char[4][4];
System.out.println(spelplan[rad][kolumn]);
return spelplan;
}
static boolean CheckMove(char[][] spelplan, int x, int y) {
if (spelplan[x][y] != ' ') {
return false;
} else {
return true;
}
}
static void SkrivUtSpelplan(char[][] spelplan) {
System.out.println("-------");
System.out.println("|" + spelplan[1][1] + "|" + spelplan[1][2] + "|" + spelplan[1][3] + "|");
System.out.println("|-+-+-|");
System.out.println("|" + spelplan[2][1] + "|" + spelplan[2][2] + "|" + spelplan[2][3] + "|");
System.out.println("|-+-+-|");
System.out.println("|" + spelplan[3][1] + "|" + spelplan[3][2] + "|" + spelplan[3][3] + "|");
System.out.println("-------");
}
static boolean KollaVinst(char[][] spelplan) {
return false;
}
public static void main(String[] args) {
char spelplan[][] = new char[4][4];
char spelare;
int rad = 3, kolumn = 3, i = 0;
for (int x = 1; x < 4; x++) {
for (int y = 1; y < 4; y++) {
spelplan[x][y] = ' ';
}
}
System.out.println("-------");
System.out.println("| | | |");
System.out.println("|-+-+-|");
System.out.println("| | | |");
System.out.println("|-+-+-|");
System.out.println("| | | |");
System.out.println("-------");
while (KollaVinst(spelplan) == false) {
CheckMove(spelplan, rad, kolumn);
for (i = 0; i < 9; i++) {
if (i % 2 == 0) {
spelare = 'X';
} else {
spelare = 'O';
}
System.out.println("Spelare 1 skriv vilken rad: 1-3");
int x = new Scanner(System.in).nextInt();
System.out.println("Spelare 1 skriv vilken kolumn: 1-3");
int y = new Scanner(System.in).nextInt();
if (CheckMove(spelplan, x, y) == true) {
MakeMove(spelplan, spelare, x, y);
}
System.out.println(" ");
SkrivUtSpelplan(spelplan);
}
}
}
}
Based on what you posted so far (I am really hoping for an edit that clarifies what you are attempting)
I am assuming you are trying to build a loop that doesn't end until the board is finished. until it is finished, a move is asked from the player. the move is made (if legal). Then the board is printed.
your code has a number of issues:
I am fighting the urge to write out suggestions / code as you indicated you didn't want it. In pseudocode, you would want your loop structured like:
in your printBoard method, you should loop. you currently have hardcoded [0] [1] etc. use a forloop for row and forloop for col.
your checkmove doesn't check the board. it checks if the board[x][y] != board[x][y] which is never true. (well ok technically in a multithreaded environment, it could be true if a racecondition occurs and it's accessible) You have to think what checkMove does.
MakeMove is ok, except you don't need to return the new playing field. if you do
then board gets updated and the a is printed.
ok I'm trying not to spoil your fun, just giving pointers. Please update the question with the details of your problem. where are you stuck, what do you need.
When you have this working I recommend posting it to https://codereview.stackexchange.com/ and get some more feedback on good coding style and practices.
to test diagonals, you could use:
Can't promise it's error less but this is roughly what I would do. for diagonal, traverse topleft to bottom right (0,0) (1,1) (2,2) and topright to bottom left (0, 2), (1,1) (2,0)
with a gameboard of 3*3 you can hardcode this but I'm used to using loops.