Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- //change to reversi.java
- public class Reversi {
- public static final int ROWS = 8;
- public static final int COLS = 8;
- public static void main(String[] args) throws FileNotFoundException{
- Scanner input = new Scanner(System.in);
- ReversiGUI newGame = new ReversiGUI("Reversi Game",ROWS,COLS);
- Board board1 = new Board(ROWS,COLS);
- //HumanPlayer player1 = new HumanPlayer("ERIC","WHITE");
- newGame.update(board1.grid(), false, ReversiGUI.WHITE, false);
- ReversiAction action = newGame.getMouseInput();
- while (action.ACTION_TYPE != ReversiAction.QUIT){
- Player currentPlayer = newGame.getCurrentPlayer();
- String currentColor = currentPlayer.getColor();
- int colorInt = -1;
- int otherColor = -1;
- if (currentColor == "black"){
- colorInt = -3;
- otherColor = -2;
- }
- else if (currentColor == "white"){
- colorInt = -2;
- otherColor = -3;
- }
- if (action.ACTION_TYPE == ReversiAction.LEFT_CLICK){ //left click
- Tile thisTile = board1.getTile(action.ROW, action.COLUMN);
- if (thisTile.getState() == -1){
- thisTile.setState(colorInt);
- //check columns/rows for flips
- ArrayList<Tile> switchTiles = new ArrayList<Tile>();
- int[][] currentGrid = board1.grid();
- //column down
- if (board1.getTile(action.ROW + 1, action.COLUMN).getState() != -1
- && board1.getTile(action.ROW + 1, action.COLUMN).getState() != colorInt){
- for (int i = action.ROW+1; i < ROWS; i++){
- if (currentGrid[i][action.COLUMN] == otherColor){
- //switchTiles.add(board1.getTile(i,action.COLUMN));
- board1.getTile(i,action.COLUMN).setState(colorInt);
- }
- }
- }
- newGame.update(board1.grid(), false, ReversiGUI.WHITE, true);
- }
- }
- if (action.ACTION_TYPE == ReversiAction.NEW_GAME){ //new game
- newGame = new ReversiGUI("Reversi Game",ROWS,COLS);
- board1 = new Board(ROWS,COLS);
- newGame.update(board1.grid(), false, ReversiGUI.WHITE, false);
- }
- if (action.ACTION_TYPE == ReversiAction.SAVE_GAME){ //saves by writing a txt file
- //not done
- try{
- PrintWriter out = new PrintWriter(newGame.getSaveFile());
- out.println("testing 1");
- }
- catch (FileNotFoundException e) {
- System.out.println("Error: Output file invalid!");
- }
- // int[][] printgrid = board1.grid();
- // for (int i = 0; i < printgrid.length; i++){
- // System.out.print("\n");
- // for (int j = 0; j < printgrid[i].length; j++){
- // System.out.print(printgrid[i][j]);
- // }
- // }
- }
- if (action.ACTION_TYPE == ReversiAction.LOAD_GAME){ //loads a txt file and constructs game
- //nextLine gets full line
- //charAT gets char at a point
- // to read first line --> next int, next int, next()
- //for rest of lines --> next line, next line, etc
- }
- action = newGame.getMouseInput();
- }
- newGame.quit();
- }
- }
Add Comment
Please, Sign In to add comment