Last active
February 3, 2019 03:58
-
-
Save StripedMonkey/4b1c1ecd7bdf662856404ef91ab0cb42 to your computer and use it in GitHub Desktop.
Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import java.lang.Math; | |
public class MyClass { | |
//Init a bunch of vars for everything to use | |
int board[][] = new int[3][3]; | |
Scanner read = new Scanner(System.in); | |
boolean won = false; | |
int BLANK = 0; | |
int X = 1; | |
int O = 2; | |
public static void main(String[] args) { | |
MyClass TicTacToe = new MyClass(); | |
while(!TicTacToe.won){ | |
TicTacToe.printBoard(); | |
TicTacToe.nextMove(); | |
TicTacToe.checkWin(); | |
} | |
} | |
public void printBoard() { | |
System.out.println("-------"); | |
for(int x=0; x<3;x++) { | |
System.out.print("|"); | |
for(int y =0; y<3;y++) { | |
switch(board[x][y]) { | |
case 0: | |
System.out.print(((x*3)+y) + "|"); | |
//System.out.print(j); | |
break; | |
case 1: | |
System.out.print('X' + "|"); | |
break; | |
case 2: | |
System.out.print('O' + "|"); | |
break; | |
} | |
} | |
System.out.println(); | |
System.out.println("-------"); | |
} | |
} | |
public void nextMove() { | |
System.out.println("Choose a square:"); | |
int move = Integer.parseInt(read.next()); | |
System.out.println("Chose " + move); | |
if(BLANK < move+1) { | |
board[][] = X; | |
} else { | |
System.out.println("Invalid move, try again?"); | |
printBoard(); | |
nextMove(); | |
} | |
} | |
public void opponentMove() { | |
} | |
public void checkWin() { | |
//Check for wining here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment