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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 10 of 10

Thread: Hey I need some help on this program. ANY help would be greatly appreciated.

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

    Default Hey I need some help on this program. ANY help would be greatly appreciated.

    Below is a set of instructions for this game I'm trying to make step by step. I honestly don't know where to start or how to properly code this... currently my code looks like this... My objective is to get the Graphic User Interface to show up that's it for now. Thanks guys. SKIP THROUGH MOST OF EVERYTHING UNTIL THE BOTTOM WHERE IT SAYS A WINDOW OPENS(REST IS JUST GAME DESCRIPTION). At the end the info is provided for the ReversiGUI premade class that we need to implement to display the interface.

    import java.util.*;


    public class Application {
    public static void main(String[] args){


    int[][] grid;
    boolean gameOver;
    int gameWinner;
    boolean moveMade;



    ReversiGUI ak = new ReversiGUI(grid,gameOver,gameWinner,moveMade);

    }
    }











    ------------------------------------------------------------------------------

    Assignment Goals:

    Design and implement one or more instantiable classes.
    Use arrays of objects.
    Read from and write to files
    Implement basic exception handling

    Description: You'll implement a game called Reversi (also known as Othello). It's a game that's played on a grid of squares, which we'll call the reversi board. The game is played by two players who take alternating turns. Each turn a player can place a single disk of their color (black or white) on the board based on certain Rules. Depending on the player's disk placement, they may convert opponent pieces to their color. The game ends when a player has no more moves to make (either the board is full or the player has no valid moves) and at this point the player with more disks of their color wins.

    Rules:

    The game grid consists of an 8x8 matrix of squares
    The game always starts with a certain initial configuration where each player starts with two pieces diagonally next to each other in the center of the board as seen in the picture below:


    Each player can place only one disk of their color per turn. Black plays first. When placing a disk, the player must place it in a square such that there is at least one straight (horizontal, vertical, or diagonal) line filled with enemy disks between the new disk and another disk of the player's color. To start off with, Black has four possible moves shown as empty black circles in the picture below:


    After placing a disk, the player converts all enemy disks that lie on a straight line (horizontal, vertical, or diagonal) between their new disk and any of their old disks to their color. Another way of thinking about valid moves is that any move that converts at least one enemy disk is a valid move.
    Players take alternating turns, each placing only one disk of their color per turn. The game ends when a player has no valid moves left to play. The winner is the player with more disks of their color.
    If you have never played before, try playing a few games here to familiarize yourself with the rules. NOTE: this does not follow the exact same rules that we will follow - in particular in our version the game ends when a player has no moves remaining.

    SPECIFICATIONS:
    Provided Files:

    Start by creating a new project and downloading the code that we've provided in the jar:

    ReversiClasses.jar Add this jar file to your project in the same manner that you've been doing in the lab exercises and in Program 3. You will NOT be able to look at or modify our code. In order to know how to interact with our code, you must read the JavaDocs which describe their public interfaces.
    There is NO skeleton code provided for this project. You must determine what classes to use and how they should interact with the classes provided in the jar file

    Classes We've Already Implemented:

    The ReversiGUI class sets up and displays the gui. You must query it to figure out what the user clicked on as well as tell it what to display.

    The ReversiAction class represents an action that the user took (for example, clicking on a square in the game grid or clicking a button).

    The Player class represents a player in the game (human or AI). You will need to extend this class for the Extra Credit (see EC below).

    The HumanPlayer class represents a Human player. You will not need to use this class.

    The RandomPlayer class represents a Computer player that makes random moves. You will need to call the calcMove(int[][] board) method for Step 7.

    The CompPlayer class represents a "smart" Computer player. You will need to call the calcMove(int[][] board) method for Step 7.
    How To Develop This Program

    One of the goals of this assignment is for you to design your own instantiable class(es), so how you choose to accomplish the required tasks is your responsibility. Part of your grade on this program will be based on your design. We recommend using at least three classes:

    An application class - this will contain your main method and will run the program as well as updating the gui
    A board class - this will represent the backend and store the state of the game such as what disks are in what squares
    A square/cell/tile class - this represents a single square of the reversi board and can be empty, or have a black or white disk in it

    A window opens :
    The program will use a GUI as well as console input. To display the GUI, your program must call the update(int[][] grid, boolean gameOver, int gameWinner, boolean moveMade) method on a properly constructed ReversiGUI object. The gui will display a game grid based on the 2D int array you pass it - all values in this array should be one of the class constants defined in ReversiGUI. When the program starts, display an 8x8 grid with the starting initial configuration as defined in the program description above. Nothing really happens yet when you run the program, but at least the user interface shows up.


    ReversiGUI
    Last edited by succ3ss91; December 12th, 2011 at 12:05 AM.


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Hey I need some help on this program. ANY help would be greatly appreciated.

    Can you provide SSCCE

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    6
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Hey I need some help on this program. ANY help would be greatly appreciated.

    I need to open up this window using this premade class: ReversiGUI.


    **********************MY ATTEMPT******************************************* ***
    import java.util.*;


    public class Application {
    public static void main(String[] args){


    int[][] grid = new int[8][8];
    boolean gameOver = false;
    int gameWinner = 0;
    boolean moveMade = false;



    ReversiGUI ak = new ReversiGUI(grid,gameOver, gameWinner,moveMade);

    }
    }



    ************************************************** *****************************

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Hey I need some help on this program. ANY help would be greatly appreciated.

    And hopefully it will be giving error, right?
    The reason is ReverseGUI has only one constructor that takes String, Integer, Integer as arguments.
    But you are giving Integer Array (TwoD), Boolean, Boolean which is not true and so it's giving error.

    Read the doc carefully.

  5. The Following User Says Thank You to Mr.777 For This Useful Post:

    succ3ss91 (December 12th, 2011)

  6. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    6
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Hey I need some help on this program. ANY help would be greatly appreciated.

    Thanks for the help. . Yes, I am getting errors. I have tried multiple attempts at making this. Am I on the right track? I can seem to get the grid to display and the board looks different than it should.

    String title = "Reversi";
    final int rows = 8;
    final int columns = 8;
    Board gameBoard = new Board();
    int[][] board = gameBoard.board;
    boolean gameOver = false;
    int gameWinner = 0;
    boolean moveMade = false;
    display(title, board, gameOver, gameWinner, moveMade);
    //ReversiGUI gui = new ReversiGUI(title, rows, columns);
    //gui.update(board, gameOver, gameWinner, moveMade);
    }
    public static void display(String title, int[][] board, boolean gameOver, int gameWinner, boolean moveMade){
    final int rows = 8;
    final int columns = 8;
    ReversiGUI gui = new ReversiGUI(title, rows, columns);
    gui.update(board, gameOver, gameWinner, moveMade);
    }
    //public void mouse(){
    //gui.getMouseInput();
    //if(gui.getMouseInput().equals(ReversiAction.LEFT_C LICK)){
    //boards.addPiece(boards);

    // }
    //}
    }

  7. #6
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Hey I need some help on this program. ANY help would be greatly appreciated.

    1. Wrap your code in code tags.
    2. I can't judge if you are going on right track or not, by looking at the provided information as this is not enough to say anything.
    An advise,
    final int rows = 8;
    final int columns = 8;
    No need to declare rows and columns final inside the function as they are not being used anywhere else, are they?
    Also,
    Update the game grid. Each value in the 2D array should be one of ReversiGUI.EMPTY, ReversiGUI.WHITE, or ReversiGUI.BLACK.
    from ReversiGUI doc (update method). Make sure that in 2D array, you are passing to the update function should match the quoted criteria.

  8. The Following User Says Thank You to Mr.777 For This Useful Post:

    succ3ss91 (December 12th, 2011)

  9. #7
    Junior Member
    Join Date
    Dec 2011
    Posts
    6
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Hey I need some help on this program. ANY help would be greatly appreciated.

    Ok thanks again. I will comment my code from now on.

    The problem is that I do not know where to construct the board with the pattern and everything. Can I use the display method within the Applications class as shown above or do I need to construct this in the main? Also there is something inherently wrong with what I tried to make the rows/columns visible.

    public static void display(String title, int[][] board, boolean gameOver, int gameWinner, boolean moveMade){
    final int rows = 8;
    final int columns = 8;
    ReversiGUI gui = new ReversiGUI(title, rows, columns);
    gui.update(board, gameOver, gameWinner, moveMade);
    }

  10. #8
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Hey I need some help on this program. ANY help would be greatly appreciated.

    1. For wrapping code in code tags, use [code] paste your code here and then /code]

    2. Let's make it simple. Assume i want you to write the steps you will take to complete this assignment, what will you write? Write here and i will guide you further.

  11. #9
    Junior Member
    Join Date
    Dec 2011
    Posts
    6
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Hey I need some help on this program. ANY help would be greatly appreciated.

    Here are the specifications/general outline for the program:


    We recommend using at least three classes:

    An application class - this will contain your main method and will run the program as well as updating the gui
    A board class - this will represent the backend and store the state of the game such as what disks are in what squares
    A square/cell/tile class - this represents a single square of the reversi board and can be empty, or have a black or white disk in it

    ************************OUTLINE******************* *****************

    A window opens :

    The program will use a GUI as well as console input. To display the GUI, your program must call the update(int[][] grid, boolean gameOver, int gameWinner, boolean moveMade) method on a properly constructed ReversiGUI object. The gui will display a game grid based on the 2D int array you pass it - all values in this array should be one of the class constants defined in ReversiGUI. When the program starts, display an 8x8 grid with the starting initial configuration as defined in the program description above. Nothing really happens yet when you run the program, but at least the user interface shows up.
    -----------------------------------------------------------------------------------------------------------
    User Interaction (5 of 45 for design and code correctness):
    Allow the user to interact with the game and place disks on squares. To handle GUI input, your program should repeatedly call the getMouseInput() method on a properly constructed ReversiGUI object. This method returns a ReversiAction object that indicates what action the mouse click corresponds to via the ACTION_TYPE instance constant which will correspond to one of the class constants defined in ReversiAction. For now, we are only concerned with ReversiAction.LEFT_CLICK - if it is a left click, we can also get the row and column index of the clicked square from the ROW and COLUMN instance constants. For this part, allow the user to click on any square and simply place a disk there.

    Basic game (15 of 45 for design and code correctness):
    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.

    Basic Buttons :
    Get the "New Match" and "Quit Game" buttons working. As before, you can figure out what the user clicked on via the getMouseInput() method. The "New Match" button should initialize a new game with the default starting configuration. The "Quit Game" button should exit your program (make sure to exit the gui as well).

    Save Game :

    Allow the user to save the game state when the "Save Game" button is pressed. When the save game button is pressed, a dialog will automatically open that prompts the user to save the file.

    Today I got the gameboard to display properly with the grids but I need to get the user to be able to put a gamepiece on the board.

    Application class:
     public class Application {
        public static void main (String[] args){
            Board gameBoard = new Board();
            int[][] board = gameBoard.board;
            boolean gameOver = false;
            int gameWinner = 0;
            boolean moveMade = false;
            ReversiGUI gui = gameBoard.gui;
            display(gameBoard.title, board, gameOver, gameWinner, moveMade, gui);
            while(gameOver == false ){
                if(gui.getMouseInput().equals(ReversiAction.LEFT_CLICK)){
                    moveMade = true;
                	gameBoard.addPiece(board);
                    display(gameBoard.title, board, gameOver, gameWinner, moveMade, gui);
                }
            }
     
        }
        public static void display(String title, int[][] board, 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] = -3;
                    }
                    else if((i == 3 && j == 4) || (i == 4 && j == 3)){
                        board[i][j] = -2;
                    }
                    else{
                        board[i][j] = -1;
                    }
                }
            }
            gui.update(board, gameOver, gameWinner, moveMade);
     
        }
     
    }

    here is my board class
     public class Board {
        public final int rows = 8;
        public final int columns = 8;
        public String title = "Reversi";
        public int board[][] = new int[rows][columns];
        ReversiGUI gui;
        public Board(){
            //this.board = board;
            this.gui = new ReversiGUI(title, rows, columns);
        }
     
     
        public void addPiece(int[][] board){
            int color;
            if(gui.getCurrentPlayer().getColor().equals("White")){
                color = -2;
            }
            else{
                color = -3;
            }
     
            board[gui.getMouseInput().ROW][gui.getMouseInput().COLUMN] = color;
     
     
        }
    }

  12. #10
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Hey I need some help on this program. ANY help would be greatly appreciated.

    After drawing the mainBoard, call addPiece function of the Board class and that will draw piece on the game board.
    I assume that addPiece() is working fine.

Similar Threads

  1. Replies: 3
    Last Post: November 18th, 2011, 08:33 AM
  2. Help really appreciated
    By Thermal_Vent in forum Java Theory & Questions
    Replies: 1
    Last Post: November 15th, 2010, 08:42 AM
  3. any help is much appreciated
    By Schmitz14 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 8th, 2009, 07:51 PM
  4. nextLine problems, any help appreciated
    By Schmitz14 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: October 5th, 2009, 01:23 AM
  5. Need a little help. would be greatly appreciated
    By ryan29121 in forum Java Theory & Questions
    Replies: 4
    Last Post: September 27th, 2009, 02:03 PM