Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Replacing UNDERSCORE with LETTER

    i have question on how to replace underscore with letter that the player guesses in hangman, im almost done but cant get that part right, some help with explanation would be great, Thank You,

    and this is my code...


    Code:
    public static void InitializeCurrent(String current[], String phrase[], int r){
    		int counter=0;
    		int i=0;
    		while (countercurrent.length){
    			current[counter]=_;
    			counter=counter+1;
    		}//while
    		
    		i=phrase[r].indexOf( );
    		while (i!=-1){
    			current [i]= ;
    			i=phrase [r].indexOf( , i+1);
    		}//while
    		
    	}//current
    	
    	public static void InitializePhrase(String phrase[]){
    		phrase[0]=stubborn to ask;
    		phrase[1]=just took a wrong turn;
    		phrase[2]=people have the right to be stupid;
    		phrase[3]=nothing is impossible;
    		phrase[4]=roses are red violets are blue;
    		phrase[5]=today isnt your day;
    		phrase[6]=try walking on water ;
    		phrase[7]=please dont interupt ;
    		phrase[8]=people wonder ;
    		phrase[9]=i have a work station;
    		Random r=new Random();
    		int random=r.nextInt(10);
    		
    	}
    	
    	public static void main (String args[]){
    		int r=0;
    		int counter=0;
    		int chances=6;
    		String current[];
    		String phrase[];
    		phrase = new String [10];
    		String guess=;
    		String again=;
    		Random generator = new Random();
    		int randomIndex = generator.nextInt( 10 );
    		String repeat=yes;
    		other variables
    		
    		while (repeat.equalsIgnoreCase(yes)repeat.equalsIgnoreCase(y)){
    			body of program
    		
    		InitializePhrase(phrase);	
    		randomIndex = generator.nextInt( 10 );
    		current=new String [phrase[randomIndex].length()];
    		chances=6;
    		InitializeCurrent(current,phrase, randomIndex);
    			
    		Outln(             ''''''''''''HELLO''''''''''');
    		Outln();
    		Outln(             WELCOME TO HANGMAN);
    		Outln();
    		Outln(!!!!!You Have Six chances to guess a wrong letter!!!!!);
    		Outln();
    		Outln(                GOOD LUCK);
    		Outln();
    		
    	
    		
    	
    
    		while (chances0){
    			
    			counter=0;
    			while (countercurrent.length){
    			Out( +current[counter]);
    			counter=counter+1;
    			
    			
    		}//output
    			Outln();
    			Outln();
    			Out(Guess a letter );
    				guess=LineInput();
    Last edited by VIPStephan; 04-10-2013 at 10:50 AM. Reason: added code BB tags

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Not to sound condescending, but:
    A) this is the wrong forum for seeking help - this is for posting code that is functional and the author thinks others might like (a la READ THIS BEFORE YOU POST A SCRIPT), and
    B) please place code between [ c o d e ] and [ / c o d e ] tags.
    Last edited by WolfShade; 04-09-2013 at 09:43 PM.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,590
    Thanks
    0
    Thanked 644 Times in 634 Posts
    Also the code you posted is NOT JavaScript.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    Banned
    Join Date
    Mar 2013
    Posts
    139
    Thanks
    0
    Thanked 9 Times in 9 Posts
    Quote Originally Posted by juventus1994 View Post
    some help with explanation would be great,
    For starters, do you know the difference between java and javascript.

    Your code is JAVA code but you have posted in a javascript forum

  • #5
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,606
    Thanks
    6
    Thanked 997 Times in 970 Posts
    Moved to the Java forum.

  • #6
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    i know i just got confused on where to post it SORRY FOR THE INCONVENIENCE

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You don't really *replace* it anywhere. You simply have two strings or arrays, one that tracks the actual word, and one that tracks the guessed word. You go through the actual word with the letter chosen, and when it finds a match in the original word, it replaces the same chars in the guessed string. This is why I'd use a char[] since its just that much easier.
    As for the actual code you have here, you'll need to rework that. There are a lot of errors here and you seem to be missing a lot of operators.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    juventus1994 (04-10-2013)


  •  

    Posting Permissions

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