Results 1 to 7 of 7
- 02-04-2009, 05:51 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 3
- Rep Power
- 0
Problem with an assignment: Backgammon game
Hi, i currently am a student for java.
I have been given an assignment to create a backgammon game, although i have encountered a problem.
I created a function that is supposed to check if a player has all it's checkers in his "away" box(the 6 columns that are the target to reach).
Returning a boolean if he can "check out".
Although even when i know the result should be true, it returns false and throws an error message.
If anyone could assist me on this i would be very grateful.
Calling to the function
the function:Java Code:System.out.println("Please enter the ending column"); String input; input=in.nextLine(); if (input.equalsIgnoreCase("end")) { current_player.turns=0; continue; } else if (input.equalsIgnoreCase("out")) { readyToCheckOut=Utility.readyToCheckOut(readyToCheckOut, column, current_player, player1, player2); if(readyToCheckOut) Utility.checkOut(column, input, start, current_player); else { System.out.println("You are not ready to checkout. please get all your checkers to the away box."); continue; } }
Java Code:// Checks if the user is ready to check out. public static boolean readyToCheckOut(boolean readyToCheckOut,Column[] column, Player current_player, Player player1, Player player2) { while(readyToCheckOut) { if(current_player==player2) { for(int i=0;i<18;i++) { if(column[i].checkersCount==0 && column[i].player == player2) continue; else readyToCheckOut=false; } } else { for(int i=23;i>6;i--) { if(column[i].checkersCount==0 && column[i].player == player1) continue; else readyToCheckOut=false; } } } return readyToCheckOut; }
- 02-04-2009, 06:11 PM #2
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
what is the error that you are getting?
- 02-04-2009, 06:58 PM #3
Member
- Join Date
- Feb 2009
- Posts
- 3
- Rep Power
- 0
The error is being:
Java Code:System.out.println("You are not ready to checkout. please get all your checkers to the away box."); continue;
executed
which prints the message and goes to the start of the loop, which is triggering by a false check of the boolean statement from the function.
in short i just need to get the function to return true when it is so.Last edited by Poddy; 02-04-2009 at 06:59 PM. Reason: formatting
- 02-04-2009, 07:40 PM #4
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
Utility.readyToCheckOut loops as long as readyToCheckOut is true... maybe you meant to have it loop as long as it is false?
- 02-04-2009, 08:59 PM #5
Member
- Join Date
- Feb 2009
- Posts
- 3
- Rep Power
- 0
-
If you cross-post a question on multiple fora, the polite thing to do would be at least to place links in each thread to all the others. No one likes putting in effort to answer questions that have already been answered elsewhere.
- 02-05-2009, 05:32 AM #7
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
if it continue, readyToCheckOut remains true,
then loop again, and continue, and loop again....
non-stop looping....
have you think of how to break the loop?
Similar Threads
-
Jtable duplicates through Hashtable (JTable condition problem) my assignment plz help
By salmanpirzada1 in forum Advanced JavaReplies: 2Last Post: 05-15-2008, 10:15 AM -
Problem using buttons to creat a magic square game
By goldman in forum New To JavaReplies: 5Last Post: 05-05-2008, 04:04 AM -
Game of Life assignment
By javan00b in forum New To JavaReplies: 4Last Post: 04-28-2008, 05:49 AM -
assignment problem help needed
By tiggz1980 in forum New To JavaReplies: 2Last Post: 02-06-2008, 11:14 PM -
Cannot solve the coding problem of my assignment
By elimmom in forum New To JavaReplies: 3Last Post: 08-13-2007, 11:33 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks