0

Hi, Daniweb
I am stuck on my hangman game project, I don't know where to start with my last four methods

import java.util.*;
import java.awt.*;
import java.applet.*;
import java.io.*;
import java.net.*;

public class Hangman() {
	
	final int maxTries = 5;
	final int maxWordLen = 20;
	char secretWord[];
	int secretWordLen;
	char wrongLetters[];
	int wrongLettersCount;
	char word[];
	int wordLen;
	
}
	public Hangman() {
		wrongLettersCount = 0;
		wrongLetters = new char[maxTries];
		secretWordLen = 0;
		secretWord = new char[maxWordLen];
		word = new char[maxWordLen];
		
		processFile();
		String category = "";
		String phrase = "";
		
		Random generator = new Random();
		int rand = generator.nextInt();
	}
	
	public Hangman(int) {
		Hangman();
		rand.setSeed(0);
	}

	private void processFile() {
		Scanner console = new Scanner(System.in);
		Scanner input = new Scanner(clues);
		while (input == clues) {
			String name = console.nextLine();
			try {
				input = new Scanner(new File(name));
				} catach (FileNotFoundException e) {
					System.out.println("File not found." + "Please try again.")
				}
			}
			System.exit(1);
		}
	}
	private Clue processLine(String line) {
		Scanner lineScanner = new Scanner(line);
		lineScanner.useDelimiter(":");
		lineScanner.next();
	}
	public void newGame() {
		int i;
		String s = wordlist[(int)Math.floor(Math.random()*wordlist.length)];
		secretWordlLen = Math.min(s.length(), maxWordLen);
		
		for (i = 0; i < secretWordLen; i++) {
			secretWord[i] = s.charAt(i);
		}
		
		for (i = 0; i < maxWordLen; i++) {
			word[i] = 0;
		}
		
		wordLen = 0;
		for (i=0; i < maxTries; i++) {
			wrongLetters[i] = 0;
		}
		
		wrongLettersCount = 0;
		
	}
	private void generateClue() {
		Scanner fileScan = new Scanner(new FileInputStream("clues.txt"));
		String secretWord = fileScan.next();
		StringBuffer word = new StringBuffer();
		for (int i = 0; i <= secretWord.length(); i++)
			word.append("_");
		System.out.println(word);
	}
	public boolean isCorrectGuess(char c) {
		for (i = 0; i < secretWordLen; i++) {
			if (key == word[i]) {
				found = true;
				return true;
			}
		}
	
	/**
	 *Check if letter is in secret word? if so, add it
	 */
		if (!found) {
			for (i=0; i < secretWordLen; i++) {
				if (key ==secretWord[i]) {
					word[i] = (char)key;
					wordLen++;
					found = true;
				}
			}
		}
	/**
	 *Check if already in wrong letters
	 */
		if(!found) {
			for (i=0; i < maxTries; i++) {
				if (key == wrongLetters[i]) {
					found = true;
					return true;
				}
			}
		/**
		 *If wrong letter; add to wrong letters
		 */
		 if (wrongLettersCount < wrongLetters.length) {
		 	wrongLetters[wrongLettersCount++] = (char)key;
		 	if (wrongLettersCount < maxTries) {
		 		return false;
		 	}
		 	else {
		 		for (i=0; i < secretWordLen; i++) {
		 			word[i] = secretWord[i];
		 		}
		 }
		 return true
		
		}
		
	}
	public boolean isGameOver() {
		if (secretWordLen == wordLen || wrongLettersCount == maxTries) {
			newGame ();
			return true;
		}
		return false
	}		
	}
		
		
	public boolean isComplete() {
	
	}
	public String getVisiblePhrase() {
		
	}
	public String getCurrentCategory() {
		
	}
	public String getCurrentPhrase() {
		
	}

The isComplete() method determines if the game has ended by the user completing the phrase by guessing all the correct letters needed to fill in the clue. If the player has won, this method returns true. If the player has not yet won, this method returns false.
The getVisiblePhrase() method simply returns the phrase the player is currently trying to guess. Spaces should be added between each character in the phrase so that the number of blank spaces is easily seen in the GUI. If you don't add the spaces, the underscores used to as a letter placeholder will run together.
The getCurrentCategory method returns the category of the current Clue object being used in the Hangman game.
The getCurrentPhrase method returns the phrase of the current Clue object being used in the Hangman game.

Your time much appreciated

Edited by jh9t: n/a

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by mellowmike
0

For the isComplete() method, you can use the wordLength at the top. I would add an integer every time there was a correct guess and once the number of correct guesses equals the wordLength, return true.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.