I am having trouble completing This hangman project. It mmost be done using model view controller pattern.
Here is what i have so far
//Header file declarations
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;
//Class declaration
class HangmanModel extends JFrame implements ActionListener {
public int attempts = 13;
private JTextField _tfWordIO = new JTextField();
private JTextField _tfGuessChar = new JTextField();
private JButton _resetBtn = new JButton("Restart");
private JLabel _lblResponse = new JLabel();
public int errors;
int wordlength;
boolean solved;
String secret;
//read in secret string
//String displaySecret;
//generate as many "*"s as secret is long and store them in displaySecret
//String Wordcollection[] = new String[] {"plasma", "chicken", "mouse"}; //Array of words
// Constructor
public void Hangman( )
{
add(new HangmanModel());
}
//main function
public static void main(String[] args) throws IOException{
//the fileScan gets the first word for the game
Scanner fileScan = new Scanner(new FileInputStream("words.txt"));
String secretWord = fileScan.next();
//Creates a StringBuffer for the viewing of the letters guessed
StringBuffer word = new StringBuffer();
for(int i = 0; i <= secretWord.length(); i++)
word.append("_");
System.out.println(word);
System.out.println("Welcome to the game of HANGMAN!!!!");
System.out.println("You will have 13 chances to guess what the word is.");
HangmanModel g = new HangmanModel();
//Set the title
g.setTitle("Hangman Game");
//Set the width and height
g.setSize(300, 400);
//Set close operation
g.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
g.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
}
import java.awt.Graphics;
public class HangmanView extends HangmanModel {
public void paint(Graphics g) {
// Draw the hangman
int baseY = 250;
if (errors > 0) { // ground
g.drawLine(90, baseY, 200, baseY);
}
if (errors > 1) { // bar up
g.drawLine(125, baseY, 125, baseY - 100);
}
if (errors > 2) {
g.drawLine(110, baseY, 125, baseY - 15);
}
if (errors > 3) {
g.drawLine(140, baseY, 125, baseY - 15);
}
if (errors > 4) { // side bar
g.drawLine(125, baseY - 100, 175, baseY - 100);
}
if (errors > 5) {
g.drawLine(125, baseY - 85, 140, baseY - 100);
}
if (errors > 6) { // rope
g.drawLine(175, baseY - 100, 175, baseY - 75);
}
if (errors > 7) { // body
g.drawOval(170, baseY - 75, 10, 12);
}
if (errors > 8) {
g.drawOval(170, baseY - 65, 15, 25);
}
if (errors > 9) { // arms
g.drawLine(160, baseY - 65, 170, baseY - 60);
}
if (errors > 10) {
g.drawLine(183, baseY - 60, 193, baseY - 65);
}
if (errors > 11) { // legs
g.drawLine(165, baseY - 30, 170, baseY - 45);
}
if (errors > 12) {
g.drawLine(183, baseY - 45, 193, baseY - 30);
}
}
}
public class HangmanController {
}