Sponsors: Michael Fertik - Best JAVA Web hosting Company & 30% off


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-19-2010, 01:05 PM
Member
 
Join Date: Mar 2010
Posts: 14
Rep Power: 0
nobody58 is on a distinguished road
Default is there anyway to replace java.IO
hi I made this hang man game

but my teacher doesn't want me to use java.IO

or buffer reader

this is my code

Code:
import java.io.*;
public class HangmanGame{ 
 static BufferedReader br    
 = new BufferedReader(new InputStreamReader(System.in));  
 public static void main(String[] args) 
 throws IOException{    
     System.out.println("What is the word I'm thinking of? you got a guess limit of 12 (guess the word letter by letter)");      
     boolean playAgain;   
      
         playGame();     
         String input = br.readLine();  
        System.out.println("you lost"); 
    } 
    static void playGame() 
    throws IOException{   
        String word[] = {"apple", "orange", "computer", "jokes", "testing", "names", "laptop", "java", "bluej", "paper","stone","rock","world"};   
        char Guesses;   
        String Word, Save;   
        char[] Words, visible;   
        int letters, letterguesses;   
        Word = word[(int)(Math.random() * word.length)];   
       Save = Word;   
        for(char alphabet= 'a'; alphabet <= 'z'; alphabet++){  
            Word = Word.replace(alphabet,'*');  
        }   
        letters = Word.length(); 
        System.out.println("The word is " + letters + " letters long"); 
        System.out.println(Word);    
        Words = Save.toCharArray();   // saving the word   
        visible = Word.toCharArray(); // show the guesses letters in place of the stars *********  (e.g. c*m*u*t*r (computer))  
        letterguesses = 0;   
        while (letterguesses < 12 ) { 
            System.out.println();    
            System.out.print ("What is you guess? > "); 
            String i = br.readLine();      
            if (i.length() < 1){    
                i = "?";      
            }      
            Guesses = i.charAt(0);  
            boolean inWord = false;    
            for (int j = 0; j < Words.length; j++) { 
                if (Words[j] == Guesses){       
                    inWord = true;       
                    visible[j] = Guesses;      
                }     
            }    
            for (int j = 0; j < Words.length; j++) {   
                System.out.print(visible[j]);    
            }     
            System.out.println(); 
            if ((new String(visible)).indexOf('*') == -1){  
                break;    
            }   
            if (inWord == false){  
                System.out.println(" You've entered an incorrect wrong"); 
                letterguesses++;    
            }    
        }  
        if ((new String(visible)).equals(Save)){ 
            System.out.println("you win");  
{
System.exit(0);
}

        }    
        else{  
            System.out.println("The word I'm thinking of is: " + Save);  
        }  
    }
}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 03-19-2010, 01:19 PM
RamyaSivakanth's Avatar
Senior Member
 
Join Date: Apr 2009
Location: Chennai
Posts: 703
Rep Power: 2
RamyaSivakanth is on a distinguished road
Default
Use Scanner class for getting the inputs...so that you can Bypass io
__________________
Ramya
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hot Code Replace JavaForums Java Blogs 0 10-07-2008 03:20 PM
How to search and replace a tag value in xml file using java karthik84 XML 2 08-18-2008 02:59 PM
[SOLVED] how to replace exact string in java pankaj_salwan New To Java 22 07-08-2008 09:28 AM
Java 1.4 api replace for javax.activity ( java 1.5) agrawal27 Advanced Java 0 12-17-2007 07:41 PM
Using a replace method... paul New To Java 2 08-07-2007 04:50 AM


Java Forums is supported by the best jsp hosting.

All times are GMT +2. The time now is 05:38 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org