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 11 of 11

Thread: Game Board Help

  1. #1
    Junior Member monikathelover1999's Avatar
    Join Date
    Sep 2019
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Game Board Help

    Hello, I'm trying to get this program to test three different game boards and put them in three separate files. I have everything working except the RandomLocation method, which I'm struggling to figure out what tod do with.

    package boardgametester;
     
    import games.board.*;
    import games.utilities.*;
     
    public class BoardGameTester {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            RandomLocation rl = new RandomLocation();
            Board ticTacToe = new Board(3,3);
     
            ticTacToe.setCell(Mark.CROSS, Mark.NOUGHT, rl.getRandom(3), rl.getRandom(3));
     
            System.out.println("TIC TAC TOE BOARD");
            System.out.println(ticTacToe.toString());
     
            Board connectFour = new Board(6,7);
     
            connectFour.setCell(Mark.YELLOW, Mark.RED, rl.getRandom(6), rl.getRandom(7));
     
            System.out.println("CONNECT FOUR BOARD");
            System.out.println(connectFour.toString());
     
            Board mastermind = new Board(5,8);
     
            mastermind.setCell(Mark.YELLOW, Mark.RED, Mark.GREEN, Mark.BLUE, Mark.MAGENTA, Mark.ORANGE, rl.getRandom(5), rl.getRandom(8));
     
            System.out.println("MASTERMIND BOARD");
            System.out.println(connectFour.toString());
     
    FileManager.writeToFileAsync(connectFour.toString(),
    "c4.txt");
     
    FileManager.writeToFileAsync(ticTacToe.toString(),
    "ttt.txt");
     
    FileManager.writeToFileAsync(mastermind.toString(),
    "mm.txt");
    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,383
    Thanks
    53
    Thanked 2,398 Times in 2,351 Posts

    Default Re: Game Board Help

    the RandomLocation method, which I'm struggling to figure out what tod do with.
    The posted code shows that RandomLocation is a class not a method and that it contains a method named: getRandom
    Can you explain what that class and method is supposed to do?

    Before writing any code you need to have a design for what that code is supposed to do.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member monikathelover1999's Avatar
    Join Date
    Sep 2019
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Game Board Help

    Yes.

    The Random Location is supposed to select a random location on the game boards to put the corresponding marks on, and getRandom is supposed to extract that mark from the class.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,383
    Thanks
    53
    Thanked 2,398 Times in 2,351 Posts

    Default Re: Game Board Help

    Random Location is supposed to select a random location
    Class's don't normally do anything. They contain methods that do things.

    getRandom is supposed to extract that mark from the class.
    Does that method return a value? What kind of value is it?

    What is a mark? A String? An int? A pair of int (x,y)?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member monikathelover1999's Avatar
    Join Date
    Sep 2019
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Game Board Help

    The method is empty, I'm trying to figure out what I should put in it.

    The marks are a group of string used to mark a location on the boards, they're stored in a class called Mark.java, should I post that class here too?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,383
    Thanks
    53
    Thanked 2,398 Times in 2,351 Posts

    Default Re: Game Board Help

    I'm trying to figure out what I should put in it.
    Can you describe what the method is supposed to do?
    What arguments does it take?
    What computations will it need to do?
    What value will it return?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member monikathelover1999's Avatar
    Join Date
    Sep 2019
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Game Board Help

    Okay. So, the code is supposed to create three boards like this.

    | | | |
    ———-

    | | | |
    ———-

    | | | |
    ———-

    And fill them with random Marks (NOUGHT and CROSS for TicTacToe, RED and YELLOW for Connect Four and YELLOW, RED, GREEN, BLUE, MAGENTA, ORANGE for Mastermind), then put them in three separate files. The getRandom is for placing these marks on the board.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,383
    Thanks
    53
    Thanked 2,398 Times in 2,351 Posts

    Default Re: Game Board Help

    The getRandom is for placing these marks on the board.
    Can you be more detailed about what that method needs to do?

    What arguments does it take?
    What computations will it need to do?
    What value will it return?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member monikathelover1999's Avatar
    Join Date
    Sep 2019
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Game Board Help

    It'll need to take the string arguments from the Mark.java class which are "O","X","Y","R","B","G","M","N".

    It well then need to set these onto the board at random locations.

    Then it should return one of those random strings as the corresponding value.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,383
    Thanks
    53
    Thanked 2,398 Times in 2,351 Posts

    Default Re: Game Board Help

    it should return one of those random strings
    Are you talking about what the getRandom method is supposed to do? I assume the method does not take any arguments because you left it off.
    Ok can you write the statement that declares a method that takes no arguments and returns a String?
    Don't worry about the computations yet. To have a working method for testing, just have it return the first String in the array.

    Those three steps look like too many steps for a small, simple method to do. Are you sure the getRandom method is supposed to do all those steps? Or are there other methods involved?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member monikathelover1999's Avatar
    Join Date
    Sep 2019
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Game Board Help

    Okay, I think I got it now.

Similar Threads

  1. Simple java board game exercise
    By Ferky in forum Java Theory & Questions
    Replies: 1
    Last Post: January 26th, 2019, 01:52 PM
  2. Problem in my 2-Dimensional Array Board Game
    By rodneybunkley in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 9th, 2013, 09:00 PM
  3. Replies: 5
    Last Post: May 27th, 2013, 11:44 AM
  4. help with board game assignment
    By pjay in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 19th, 2011, 12:58 PM
  5. DOS board game
    By SageNTitled in forum Java Theory & Questions
    Replies: 5
    Last Post: March 4th, 2010, 02:53 PM