Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: REVERSI aka OTHELLO GAME HELP. I need help with this program. please

  1. #1
    Junior Member
    Join Date
    Dec 2011
    My Mood
    Thanked 0 Times in 0 Posts

    Default REVERSI aka OTHELLO GAME HELP. I need help with this program. please

    Full description here if you guys need to reference it. I am just looking for some guidance. I am lost and would greatly appreciate any help.

    CS 302, Program 4

    I need to get a basic game going by expanding your work from the first two steps. Now only allow users to place disks in squares that correspond to valid moves and flip any disks that this move captured. Note that a player might capture disks on a horizontal, vertical, or diagonal line (or any combination of the three) between the newly placed piece and any of the player's old pieces. Also make sure to check if the game is over after each move. If the game is over, calculate who wins and pass all this information to the gui through the update method.

    Here is my code thus far. I am stuck on where to start the algorithm :
    Board class:

     import java.util.*;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.PrintWriter;
    public class Board {
        public final int rows = 8;
        public final int columns = 8;
        public String title = "Reversi";
        public Board(){       
        public void processButtons(int[][] board, boolean gameOver, boolean moveMade, int gameWinner, ReversiGUI gui){
            int turn = 1;
                moveMade = true;
                ReversiAction action = gui.getMouseInput();
                if(action.ACTION_TYPE == ReversiAction.LEFT_CLICK){
                    if(turn > 0){
                        board[action.ROW][action.COLUMN] = ReversiGUI.BLACK;
                        board[action.ROW][action.COLUMN] = ReversiGUI.WHITE;
                    gui.update(board, gameOver, gameWinner, true);
                    turn *= -1;
                if(action.ACTION_TYPE == ReversiAction.NEW_GAME){
                    moveMade = false;
                    gameWinner = 0;
                    gameOver = false;
                    Application.display(board, title, gameOver, gameWinner, moveMade, gui);
                if(action.ACTION_TYPE == ReversiAction.QUIT){
                if(action.ACTION_TYPE == ReversiAction.SAVE_GAME){
                    save(gui, board);
                if(action.ACTION_TYPE == ReversiAction.LOAD_GAME){
                    load(gui, board);
        public void save(ReversiGUI gui, int[][] board){
            File file = gui.getSaveFile();
            String[]stringBoard = new String[8];
                PrintWriter save = new PrintWriter(file);
                stringBoard[0]= "8 8 " + gui.getCurrentPlayer().getColor();
                for(int i = 0; i < rows; i++){
                    stringBoard[i] = "";
                    for(int j = 0; j < columns; j++){
                        if(board[i][j] == ReversiGUI.BLACK){
                            stringBoard[i] += "B";
                        if(board[i][j] == ReversiGUI.WHITE){
                            stringBoard[i] += "W";
                        if(board[i][j] == ReversiGUI.EMPTY){
                            stringBoard[i] += "0";
            catch(FileNotFoundException e){
                System.out.println("file not found");
        public void load(ReversiGUI gui, int[][] board){
            File file = gui.getLoadFile();

    Application class:

    import java.util.*;
    public class Application {
        public static void main (String[] args){
            Board gameBoard = new Board();
            boolean gameOver = false;
            int gameWinner = 0;
            boolean moveMade = false;
            int[][] board = new int[gameBoard.rows][gameBoard.columns];
            ReversiGUI gui = new ReversiGUI(gameBoard.title, gameBoard.rows, gameBoard.columns);
            display(board, gameBoard.title, gameOver, gameWinner, moveMade, gui);
            gameBoard.processButtons(board, gameOver, moveMade, gameWinner, gui);
            //gui.update(board, gameOver, gameWinner, moveMade);
        public static void display(int[][] board, String title, boolean gameOver, int gameWinner, boolean moveMade, ReversiGUI gui){
            final int rows = 8;
            final int columns = 8;
            for(int i = 0; i < rows; i++){
                for(int j = 0; j < columns; j++){
                    if((i == 4 && j == 4) || (i == 3 && j == 3)){
                        board[i][j] = ReversiGUI.BLACK;
                    else if((i == 3 && j == 4) || (i == 4 && j == 3)){
                        board[i][j] = ReversiGUI.WHITE;
                        board[i][j] = ReversiGUI.EMPTY;
            gui.update(board, gameOver, gameWinner, moveMade);

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 636 Times in 540 Posts

    Default Re: REVERSI aka OTHELLO GAME HELP. I need help with this program. please

    Recommended reading: http://www.javaprogrammingforums.com...e-posting.html
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Java Newbie..need help in guessing game program
    By confupavan in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 16th, 2011, 09:22 AM
  2. Help on some work i got ! Reversi game
    By benni7 in forum Algorithms & Recursion
    Replies: 9
    Last Post: September 22nd, 2011, 11:38 AM
  3. Game Program HELPPPP
    By nitwit3 in forum What's Wrong With My Code?
    Replies: 19
    Last Post: July 20th, 2011, 03:26 AM
  4. Breakout Game- program help
    By strength.honor in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 5th, 2010, 02:44 PM
  5. Error in Program for Game of Craps
    By TheAsianMenace in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 23rd, 2010, 04:31 AM