Guest User

Untitled

a guest
Apr 25th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.PrintWriter;
  6. //change to reversi.java
  7. public class Reversi {
  8. public static final int ROWS = 8;
  9. public static final int COLS = 8;
  10.  
  11. public static void main(String[] args) throws FileNotFoundException{
  12. Scanner input = new Scanner(System.in);
  13. ReversiGUI newGame = new ReversiGUI("Reversi Game",ROWS,COLS);
  14. Board board1 = new Board(ROWS,COLS);
  15.  
  16. //HumanPlayer player1 = new HumanPlayer("ERIC","WHITE");
  17.  
  18. newGame.update(board1.grid(), false, ReversiGUI.WHITE, false);
  19. ReversiAction action = newGame.getMouseInput();
  20. while (action.ACTION_TYPE != ReversiAction.QUIT){
  21. Player currentPlayer = newGame.getCurrentPlayer();
  22. String currentColor = currentPlayer.getColor();
  23. int colorInt = -1;
  24. int otherColor = -1;
  25. if (currentColor == "black"){
  26. colorInt = -3;
  27. otherColor = -2;
  28. }
  29. else if (currentColor == "white"){
  30. colorInt = -2;
  31. otherColor = -3;
  32. }
  33. if (action.ACTION_TYPE == ReversiAction.LEFT_CLICK){ //left click
  34. Tile thisTile = board1.getTile(action.ROW, action.COLUMN);
  35. if (thisTile.getState() == -1){
  36. thisTile.setState(colorInt);
  37. //check columns/rows for flips
  38. ArrayList<Tile> switchTiles = new ArrayList<Tile>();
  39. int[][] currentGrid = board1.grid();
  40. //column down
  41. if (board1.getTile(action.ROW + 1, action.COLUMN).getState() != -1
  42. && board1.getTile(action.ROW + 1, action.COLUMN).getState() != colorInt){
  43. for (int i = action.ROW+1; i < ROWS; i++){
  44. if (currentGrid[i][action.COLUMN] == otherColor){
  45. //switchTiles.add(board1.getTile(i,action.COLUMN));
  46. board1.getTile(i,action.COLUMN).setState(colorInt);
  47. }
  48. }
  49. }
  50. newGame.update(board1.grid(), false, ReversiGUI.WHITE, true);
  51.  
  52. }
  53.  
  54.  
  55. }
  56. if (action.ACTION_TYPE == ReversiAction.NEW_GAME){ //new game
  57. newGame = new ReversiGUI("Reversi Game",ROWS,COLS);
  58. board1 = new Board(ROWS,COLS);
  59. newGame.update(board1.grid(), false, ReversiGUI.WHITE, false);
  60.  
  61. }
  62. if (action.ACTION_TYPE == ReversiAction.SAVE_GAME){ //saves by writing a txt file
  63. //not done
  64. try{
  65. PrintWriter out = new PrintWriter(newGame.getSaveFile());
  66. out.println("testing 1");
  67.  
  68.  
  69. }
  70. catch (FileNotFoundException e) {
  71. System.out.println("Error: Output file invalid!");
  72. }
  73. // int[][] printgrid = board1.grid();
  74. // for (int i = 0; i < printgrid.length; i++){
  75. // System.out.print("\n");
  76. // for (int j = 0; j < printgrid[i].length; j++){
  77. // System.out.print(printgrid[i][j]);
  78. // }
  79. // }
  80. }
  81. if (action.ACTION_TYPE == ReversiAction.LOAD_GAME){ //loads a txt file and constructs game
  82. //nextLine gets full line
  83. //charAT gets char at a point
  84. // to read first line --> next int, next int, next()
  85. //for rest of lines --> next line, next line, etc
  86. }
  87.  
  88. action = newGame.getMouseInput();
  89. }
  90. newGame.quit();
  91.  
  92.  
  93.  
  94. }
  95. }
Add Comment
Please, Sign In to add comment