Hangman with reading text files

Need help figuring out a few things

Page 1 of 1

0 Replies - 7126 Views - Last Post: 19 October 2005 - 03:00 PM Rate Topic: -----

#1 Mooonky  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-October 05

Hangman with reading text files

Posted 19 October 2005 - 03:00 PM

I cannot figure out how to extract text from a file of words (one per line) to make it the word that needs to be guessed in hangman. Also, I'm having problems with creating a class to ask for the players name and to keep track of how many wins and loses they have.

import java.util.*;
import java.io.*;


public class hangman
{
	public static void main(String [] args) throws IOException
	{
  int maxTries = 7;
  int secretWordLen;
  
  
  Scanner fileScan = new Scanner(new FileInputStream("words.txt"));
  String wordlist = fileScan.next();
  String secretWord [] = wordlist[(int)Math.floor(Math.random() * wordlist.length)];
  secretWordLen = Math.min(s.length(), maxWordLen);
  
        for (i=0; i<secretWordLen; i++)
        {
            secretWord[i] = s.charAt(i);
        }
  
  System.out.println("Welcome to the game of HANGMAN!!!!");
  System.out.println("You will have 7 chances to guess what the word is.");
  
  Scanner inScan = new Scanner(System.in);
  System.out.print("Please Enter Your name: ");
  String name = inScan.next();
  
  hangPlayer = new player(name);
  System.out.println(hangPlayer);
  
  
  
	
	}
}

private class player
{
	private player(String name)
	{
  int winCount = 0;
  int loseCount = 0;
  
  System.out.print(name + (", you have won " + winCount + " and you have lost ") + loseCount);
  return name;
	}
}



Any suggestions or hints are helpful.

THANKS

Is This A Good Question/Topic? 0
  • +

Page 1 of 1