Results 1 to 16 of 16
  1. #1
    leviathan is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default Cant figure out where went wrong.

    Hi, i somehow completed my codes but the codes get mixed up. Sometime it wont switch to next player or the desire result wont come out. Well take a look at part of my codes and hope someone could figure out for me.

    Java Code:
    		// player 1
    		while (playerTurn == true) {
    			System.out.print("Player 1  :");
    			generateRandom();
    			for (int j = 0; j < wordGame.length; j++) {
    				System.out.print(wordGame[j] + " ");
    			}
    			System.out.println();
    			System.out
    					.println("Enter your World ( or Press  @  to PASS or Press !  To Quit )");
    			inputs = scan.next();
    			playerInput = inputs.toCharArray();
    
    
    			// *****************************************************************************************************************
    			// Exiting the game
    			if (inputs.equals("!")) {
    				System.out.println("Player 1 score: " + player1);
    				System.out.println("Player 2 score: " + player2);
    
    				if (player1 > player2) {
    					System.out.println("player 1 won the game");
    				} else if (player1 == player2) {
    					System.out.println("Its a draw");
    				} else
    					System.out.println("Player 2 won the game");
    				System.exit(0);
    
    			}
    			// *****************************************************************************************************************
    			// Passing the game
    			else if (inputs.equals("@")) {
    				//System.out.println("Total score for word [Player 1]: 0");
    				//System.out.println("Total score for game: " + player1);
    				player1 += 0;
    				playerTurn = false;
    			}
    			// *****************************************************************************************************************
    			// Inputs for game
    
    			else if (inRandom(inputs, wordGame)) {
    				if (inDict(inputs, dict)) {
    					pointAssign();
    					System.out.println(playerInput);
    					System.out.println("Total score for word : " + points);
    					player1 += points;
    					System.out.println("Total score for game : " + player1);
    					points = 0;
    					playerTurn = false;
    				} else {
    					System.out.println("Error :An invalid word is formed.");
    					System.out
    							.println("Enter your World ( or Press  @  to PASS or Press !  To Quit )");
    					playerInput = null;
    					inputs = scan.next();
    					playerInput = inputs.toCharArray();
    					System.out.println("");
    				}
    			} else if (inDict(inputs, dict) && !inRandom(inputs, wordGame)) {
    				System.out
    						.println("Error : A valid word is formed but one or more letter(s) used are not yours   ");
    				System.out
    						.println("Enter your World ( or Press  @  to PASS or Press !  To Quit )");
    				playerInput = null;
    				inputs = scan.next();
    				playerInput = inputs.toCharArray();
    			} else if (!inDict(inputs, dict) && !inRandom(inputs, wordGame)) {
    				System.out
    						.println("Error : one or more letter(s) used are not yours   ");
    				System.out
    						.println("Enter your World ( or Press  @  to PASS or Press !  To Quit )");
    				playerInput = null;
    				inputs = scan.next();
    				playerInput = inputs.toCharArray();
    			}
    
    			// *****************************************************************************************************************
    			// Player 2 turn
    
    			while (playerTurn == false) {
    				generateRandom();
    				System.out.print("Player 2  :");
    				for (int k = 0; k < wordGame.length; k++) {
    					System.out.print(wordGame[k] + " ");
    				}
    				System.out.println();
    				System.out
    						.println("Enter your World ( or Press  @  to PASS or Press !  To Quit )");
    				inputs = scan.next();
    				playerInput = inputs.toCharArray();
    
    				// *****************************************************************************************************************
    				// Exiting the game for player2
    
    				if (inputs.equals("!")) {
    					System.out.println("Player 1 score: " + player1);
    					System.out.println("Player 2 score: " + player2);
    
    					if (player1 > player2) {
    						System.out.println("player 1 won the game");
    					} else if (player1 == player2) {
    						System.out.println("Its a draw");
    					} else
    						System.out.println("Player 2 won the game");
    					System.exit(0);
    
    				}
    				// *****************************************************************************************************************
    				// Passing the game for player2
    				else if (inputs.equals("@")) {
    					//System.out.println("Total score for word[Player 2]: 0");
    					//System.out.println("Total score for game: " + player2);
    					player2 += 0;
    					playerTurn = true;
    				}
    				// *****************************************************************************************************************
    				// Inputs for game for player2
    
    				else if (inRandom(inputs, wordGame)) {
    					if (inDict(inputs, dict)) {
    						pointAssign();
    						System.out.println(playerInput);
    						System.out.println("Total score for word : " + points);
    						player2 += points;
    						System.out.println("Total score for game : " + player2);
    						points = 0;
    						playerTurn = true;
    					} else {
    						System.out.println("Error :An invalid word is formed.");
    						System.out
    								.println("Enter your World ( or Press  @  to PASS or Press !  To Quit )");
    						playerInput = null;
    						inputs = scan.next();
    						playerInput = inputs.toCharArray();
    						System.out.println("");
    					}
    				} else if (inDict(inputs, dict) && !inRandom(inputs, wordGame)) {
    					System.out
    							.println("Error : A valid word is formed but one or more letter(s) used are not yours   ");
    					System.out
    							.println("Enter your World ( or Press  @  to PASS or Press !  To Quit )");
    					playerInput = null;
    					inputs = scan.next();
    					playerInput = inputs.toCharArray();
    				} else if (!inDict(inputs, dict) && !inRandom(inputs, wordGame)) {
    					System.out
    							.println("Error : one or more letter(s) used are not yours   ");
    					System.out
    							.println("Enter your World ( or Press  @  to PASS or Press !  To Quit )");
    					playerInput = null;
    					inputs = scan.next();
    					playerInput = inputs.toCharArray();
    				}
    			}
    seriously need these help

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,007
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by leviathan View Post
    Hi, i somehow completed my codes but the codes get mixed up. Sometime it wont switch to next player or the desire result wont come out. Well take a look at part of my codes and hope someone could figure out for me.
    We don't know the 'desire results' so the code is fine with us. We don't even know what your code is supposed to do and what it actually does.

    kind regards,

    Jos

  3. #3
    leviathan is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default

    oh ya, forgot to mention...this is those scrabble like games that you see often.

    Its suppose to generate 10letters and we have to form a valid word from these letters, when the words form were wrong they will inform what was wrong.

    The problem in this code will be, after typing in for error try it will work the first time but however when i try for a second time it will re-generate again the 10letters instead of giving the error statement.

    example:

    Find Your Words
    Player 1 :m i q i a w e g v m
    Enter your World ( or Press @ to PASS or Press ! To Quit )
    exit
    Error : A valid word is formed but one or more letter(s) used are not yours
    Enter your World ( or Press @ to PASS or Press ! To Quit )
    we
    Player 1 :z u n t m d k j d t
    Enter your World ( or Press @ to PASS or Press ! To Quit )

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,007
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by leviathan View Post
    oh ya, forgot to mention...this is those scrabble like games that you see often.
    There's already a thread running about this very same subject; maybe you can join it.

    kind regards,

    Jos

  5. #5
    leviathan is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default

    ya, im aware that theres multiple threads regrading this topic. However i believe java can have many different ways to reach the same result. There i deciede to open one thread of own, and because my previous thread did not recieve any response.:(

    Thanks for understanding.:o

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    A few comments on the posted code:
    player1 += 0;
    What is this supposed to do?

    player1
    Does this represent a player or a players score? Hard to tell from the name.
    Should it be: player1Score?

    wont switch to next player
    where in the code is this supposed to happen? How do you determine whose's turn it is?

  7. #7
    leviathan is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default

    player1 is the score im sorry...

    to determine the turn, theres this code "While playerTurn = True"

    true = player1
    false = player2

    another problem now is that, it wont run my error statement more than once or just re-generate the 10random letter which is not suppose to.

  8. #8
    somanayr is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    Where is your main?

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by somanayr View Post
    Where is your main?
    I've got a sneaking suspicion that his program is essentially one huge main method.

  10. #10
    leviathan is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default

    that codes follow after main, i didnot copy the full code, cause it will be 300line long.

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    You need to add some debug code to see what is happening.

    Break the compound statements into single statement and display the results
    inDict(inputs, dict) && !inRandom(inputs, wordGame)
    vs
    boolean inDict = inDict(inputs, dict);
    System.out.println("inDict(inputs, dict)=" + inDict + ", for inputs=" + inputs ...);

  12. #12
    somanayr is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    Quote Originally Posted by leviathan View Post
    that codes follow after main, i didnot copy the full code, cause it will be 300line long.
    What if the problem's in the main? Just copy the whole thing.

  13. #13
    leviathan is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default

    the code i post was the main stuff.

    the rest were my methods... which is considered done...

  14. #14
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,007
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    I've got a sneaking suspicion that his program is essentially one huge main method.
    That'd be a big nono on my code-metric-o-meter ...

    kind regards,

    Jos

  15. #15
    leviathan is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default

    i figured that theres no technical error, more like logic error around here...

    which im currently cant see it :(

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

Similar Threads

  1. Replies: 3
    Last Post: 01-11-2010, 06:48 AM
  2. Need help - I can't figure it out.
    By Joshsmith in forum New To Java
    Replies: 2
    Last Post: 10-23-2009, 10:12 PM
  3. [SOLVED] Can't figure out what's wrong
    By roach_van in forum New To Java
    Replies: 10
    Last Post: 09-05-2008, 07:09 AM
  4. Replies: 2
    Last Post: 07-11-2008, 09:41 AM
  5. I can't figure this out
    By silvia in forum New To Java
    Replies: 3
    Last Post: 07-20-2007, 04:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •