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

Thread: Could someone fix this game?

  1. #1
    Junior Member
    Join Date
    Dec 2021
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Could someone fix this game?

    .
    Last edited by An6ie; December 10th, 2021 at 07:43 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Could someone fix this game?

    it doesnt play as it should.
    Please explain.
    Post the program's output that shows what you are asking about.

    One big problem is the end of the source code is missing.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2021
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Could someone fix this game?

    This is the output with examples


    | | | | | | |
    | | | | | | |
    | | | | | | |
    | | | | | | |
    | | | | | | |
    1 2 3 4 5 6 7
    2
    | | | | | | |
    | | | | | | |
    | | | | | | r |
    | | | | | | |
    | | | | | | |
    1 2 3 4 5 6 7
    3
    | | | | | | |
    | | | | | | |
    | | | | | y | r |
    | | | | | | |
    | | | | | | |
    1 2 3 4 5 6 7
    You Have Won!!!

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Could someone fix this game?

    OK, thanks for that. Can you explain what is wrong with that output?
    Add some comments showing what the expected output is.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2021
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Could someone fix this game?

    When you type '1' to place the counter in number '1', the code executes' it in number '5'. None of the numbers correspond to their correct position. Also, to win the game you should connect 4 counters vertically or horizontally, but the code executes "you have won" after just placing 2 counters down randomly.

    | | | | | | |
    | | | | | | |
    | | | | | | |
    | | | | | | |
    | | | | | | |
    1 2 3 4 5 6 7

    Input: 2

    | | | | | | |
    | | | | | | |
    | | | | | | r |
    | | | | | | |
    | | | | | | |
    1 2 3 4 5 6 7

    Input: 3

    | | | | | | |
    | | | | | | |
    | | | | | y | r |
    | | | | | | |
    | | | | | | |
    1 2 3 4 5 6 7

    what is should be

    | | | | | | |
    | | | | | | |
    | | | | | | |
    | | | | | | |
    | | | | | | |
    1 2 3 4 5 6 7

    Input: 2

    | | | | | | |
    | | | | | | |
    | | | | | | |
    | | | | | | |
    | | r| | | | |
    1 2 3 4 5 6 7

    input: 3

    | | | | | | |
    | | | | | | |
    | | | | | | |
    | | | | | | |
    | | r|y | | | |
    1 2 3 4 5 6 7

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Could someone fix this game?

    Ok, Now how are you going to debug the code to see why the values are incorrect?
    I use print statements to show the values of variables as they are used and changed.

    Look at the code to see what values in what variables will cause it to print: You Have Won!!!
    Then back trace in the code to see why those variables have the values they have.

    One of the first changes I recommend for the code is to add comments.
    Another change would be to the names of the variables used to index into board.
    instead of using i and j use row and column
    board appears to be an array of 6 rows with 7 columns in each row.
    To index into board, code it like this: board[row][column]
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2021
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Could someone fix this game?

    Thank you for your help, but I think this is too tricky for me to do

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Could someone fix this game?

    Moved out of section where posters are trying to fix their code.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. LWJGL Game: Odd behavior in game. Need help.
    By vividMario52 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 2nd, 2013, 05:43 PM
  2. Replies: 3
    Last Post: March 1st, 2013, 11:01 PM
  3. Help with Snake Game Java Code: It's Impossible to Lose the Game
    By haruspex_icis in forum What's Wrong With My Code?
    Replies: 20
    Last Post: December 17th, 2012, 12:21 PM
  4. Game Maker Language and Game Maker and Zelda Classic thread
    By Fira in forum Other Programming Languages
    Replies: 3
    Last Post: April 17th, 2012, 08:59 AM
  5. Simple game that requires me to load game settings from a file
    By 14fenix in forum Java Theory & Questions
    Replies: 5
    Last Post: December 1st, 2011, 09:21 PM