Question:
java hangman HELP! please i need help..ive been struggling for weeks without results...?
Java
2010-10-18 00:34:13 UTC
Create a Hangman game using Java with OOP concept. The game consists of two types
of users namely administrator and player. Administrator can edit his profile and change
password. Besides, administrator can add new player and create new phrase with
description. Player can edit his/her profile and change password. Besides, player can
view his/her historical game records.
Each user is required to login before entering to the game. When the game is started, the
program will randomly select a phrase and description. Player can start to guess a letter or
the phrase. The player will score five points for each letter guess correctly. An extra
thirty points is given if the players manage to guess the complete phrase with three or
more dashes left (blank letter). Once the letter has been selected, the letter must be
removed from the list. Three points will be deducted from the player for each guess of the
vowels letter (a, e, i, o, u).
there should be 3 classes the player class,admin class and game class....
words are read from a text file
the program shud use codes that are simple as possible

please i need help..ive been struggling for weeks without results...
Three answers:
Lucho
2010-10-18 01:11:04 UTC
If you want code already written, just use Google. Actually you will find hangman already done on Yahoo! Answers. I've seen it here.



There aren't many (if any) people here interested in writing long programs that have already been written many times over. They mostly like to solve real problems, like helping someone debug some new code they've written.



NOTE

Think of how this user administration works and make a design. Decide what components are needed and how they fit together.



Get someone to look at the design before you start coding, then code the components one by one. Once you're coding you can help there too.



You can get ideas thinking of how existing systems work, like logging on to a computer, or a database. This is still reinventing the wheel, so the concept is well documented. Either read about it, try Wikipedia, or you can find some code and try to understand it.



Most importantly, learn to get motivated:

1. Research, look for a description of the technology you need.

2. Find an implementation (or various) and try to understand it. Maybe you'll find a tutorial.

3. Make your own design and when the technology makes sense, start coding.



In this case look a some hangman programs, and some login programs and try to understand them. When you feel comfortable, write your own. Next put the two together; it should be easy to put them together, after writing them separately.



NOTES

Here are some ideas for the login management. Make a record of 'Passwd' type. It has a field to say if the user isAdmin::boolean.



The Passwd records also contains login and password. Save all Passwd records to the disk.



When user logs in, check the field to know what kind of user it is. Then show a menu with things only for that user.
anonymous
2010-10-22 00:09:32 UTC
public class Hangman {

public static void main( String[] args ) {

HangmanSession hangmanSession = new HangmanSession();

hangmanSession.play();

}

}



class HangmanSession {

private Player player;

private HiddenKeyword hiddenKeyword;

private LetterBox letterBox;

private int triesNumber = 7;



public HangmanSession() {

player = new Player();

player.askName();

hiddenKeyword = new HiddenKeyword();

letterBox = new LetterBox();

}



private void printState() {

letterBox.print();

System.out.print( "Hidden word : " );

hiddenKeyword.print();

System.out.print( "Tries left: " + triesNumber + "" );

}



public void play() {

boolean bool = true;

while( true ) {

bool = true;

printState();

char ch = player.takeGuess();

if( letterBox.contains( ch ) ) {

System.out.println( "Try again, you've already used letter " + ch );

bool = false;

}

if( bool ) {

if( hiddenKeyword.guess( ch ) ) {

System.out.println( "Success, you have found letter " + ch );

}

else {

triesNumber--;

}

if( triesNumber < 1 )

gameOver();



if( hiddenKeyword.found() )

congratulations();

}

} //end of bool

}



public void congratulations() {

System.out.println( "Congratulations " + player + ", you win a banana!" );

System.exit( 0 );

}



public void gameOver() {

System.out.println( "Sorry " + player + ", this time you lose!" );

System.exit( 0 );

}

}



class HiddenKeyword {

private String fValue;

private StringBuffer pValue;

private int lfoundNumber = 0;



public HiddenKeyword() {

fValue = new String( "banana" );

pValue = new StringBuffer( "------" );

}



public boolean found() {

System.out.println( "Letters found:" + lfoundNumber + "/" + fValue.length() );

return ( lfoundNumber == fValue.length() );

}





public boolean guess( char c ) {

int index = fValue.indexOf( c );

if( index == -1 )

return false;

else {

lfoundNumber = lfoundNumber + findOccurances( c );

return true;

}

}



private int findOccurances( char c ) {

int idx = fValue.indexOf( c );

pValue.setCharAt( idx, fValue.charAt( idx ) );

int counter = 1;

while( idx != -1 ) {

int idxx = fValue.indexOf( c, idx + 1 );

idx = idxx;

if( idx != -1 ) {

counter++;

pValue.setCharAt( idx, fValue.charAt( idx ) );

}

}

return counter;

}



public void print() {

System.out.println( pValue );

}



}





class Player {

private String fName = "";

private String password="";



public void askName() {

System.out.print( "\nPlayer, enter your name:" );



fName = receiveInput();

System.out.print("\nenter password:");

password=receiveInput();

}



public char takeGuess() {

return receiveInput().charAt( 0 );

}



private String receiveInput() {

String str = " ";

BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );

try {

str = br.readLine();

}

catch( IOException ex ) {

ex.printStackTrace();

}

return str;

}



public String toString() {

return fName;

}



}





class LetterBox {

private char[] lbox = new char[24];

private int counter = 0;



public boolean contains( char c ) {

for( int i = 0; i < counter; i++ ) {

if( lbox[i] == c )

return true;

}

lbox[counter] = c;

counter++;

return false;

}



public void print() {

System.out.print( "\nLetterBox:" );

for( int i = 0; i < counter; i++ ) {

System.out.print( lbox[i] );

}

System.out.println( "" );







}





}
Imad Eddin
2010-10-18 00:38:23 UTC
Hi,

Did you start coding..

If yes give us some code, if not, it means you want the whole

thing done from the scratch?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...