PDA

View Full Version : Java Assistance - Timer Class


CharlieM
May 17th, 2007, 12:43 PM
Fucking timer class.
I have this assignment.
Prerequisites are a program of at least 5 classes, with 2 of them using inherritence.
I have decided to go with a hangman game, cause im just so full of imagination and creativity.

Anywho....my problem is this.

I have a timer that counts down from 90 secconds, and interrupts the event listener ever seccond.
On that seccond, it decrements a counter that controls when the timer stops.
There is also a conditional that the timer is to stop when the player accumulates 10 incorrect guesses (the final drawing on the hangman pic).
The game also ends the timer when it gets to zero.

The problem, it does not stop the timer when 10 guesses have been incorrectly accrued.

I have a class handling the drawing.
The main is controlling the timer, and has an object declared of the drawing class.
A counter is controlling what gets drawn, and has set and get methods to set the counter upon an incorrect guess.

I also have in there a system.out to show me that I am actually incrementing an incorrect guess counter....which is fucking pissing me off, cause the conditional within my "nest of doom" simply does not work as it should.

Heres the action listener portion, keep in mind its nested like a mother fucker to prevent other button pushes from intefering with the timer. I could of done an inner class, but fuck im trying to push myself here...inner classes are cheats way out.



public void actionPerformed(ActionEvent e)
{
//The following is a nest of DOOM!!!
if(e.getSource()==newMenu) //If new game is pressed within the menu heirachy
{
btnGuess.setEnabled(true); //Enable the functionality of the Guess button
dictionaryWord = newWord(); //getting a new word
lengthOfDictionary = dictionaryWord.length(); //Get the length (in integer) of the word fetched from the dictionary.
counter = 90; //resetting the timer to 90
startTime = 90; //resetting the counter to 90 (iterates to Label)
stringCounter=Integer.toString(startTime); //Parseing the counter to a String, to iterate it to the Label in GUI
lblTimer.setText(stringCounter); //Iterating the label to current timer
theTimer.start(); //Start the timer
System.out.println("The dictionary word is: " +dictionaryWord); //debugging the word
LeonardoDaVinci.resetPainter(); //Resetting the incorrect guesses to zero in DrawImage class
LeonardoDaVinci.repaint(); //Calling the DrawImage object to paint nothing on the canvas
dictionaryCompare = 0; //Setting a comparison integer for searching the dictionary String object to zero.
}
else //If NOT new menu - but something else is triggering the event listener :O
{
if(e.getSource()==btnGuess) //If the guess button is pressed
{
theTimer.stop(); //Stop the timer
guess = JOptionPane.showInputDialog("Enter a single letter"); //Query the user to input a character
guess.toLowerCase(); //parse the input to lower case
while(guess.equals("")) //Checking to ensure nothing is entered as a guess
{
JOptionPane.showMessageDialog(null,"Not a character!!!"); //Notifying user of error
guess = JOptionPane.showInputDialog("Enter a single letter"); //Query the user to input a character
guess.toLowerCase(); //Parse the chatacter to a lower case
}
if(dictionaryWord.contains(guess)) //Checking to see if the dictionary word contains the letter guessed
{
while(lengthOfDictionary>dictionaryCompare) //Looping the length of the word times, to search each character.
{ //Needs tweaking to capture ALL positions of the guess
System.out.println(dictionaryWord.indexOf(guess)); //Debug output to CMD window the index of the word which contains the guess
dictionaryCompare++; //Increase the comparrison search integer
}
dictionaryCompare = 0; //Resetting the comparrison search integer
}
else //Wrong Guess!!
{
LeonardoDaVinci.wrongGuess(); //Indicating a wrong guess, increasing the wrong guess counter by 1.
if(LeonardoDaVinci.getWrongGuesses() >= 10) //Checking to see that the wrong guess's havnt exceeded the end-game conditional
{
JOptionPane.showMessageDialog(null,"Game Over !"); //Inform user that the game is over, and they suck at life in general
btnGuess.setEnabled(false); //Remove functionality of the guess button
theTimer.stop(); //Timer does not stop - needs fixing //Stop the timer
//break;
}
//set visible letters guessed right
//set guess'd letter to the guessed letter collumn
}
theTimer.start(); //Start the timer
LeonardoDaVinci.repaint(); //Repaint the canvas
}
else //If NOT the guess button - but something else is triggering the event listener :O
{
if(e.getSource()==scoreMenu) //If the High Score is pressed within the menu heirachy
{
getHighScore(); //Display the Highest Score, or a dialog box if there is none recorded so far :(
}
else //If not High Score - but something else is triggering the event listener :O
{
if(e.getSource()==exitMenu) //If Exit Game is pressed within the menu heirachy
{
System.exit(0); //Close the application
}
else //If not Exit Game - but something else is triggering the event listener :O
{
if(theTimer!=null) //If the timer is triggering the event handler and is above zero
{
stringCounter = Integer.toString(counter); //Parseing the counter to a String, to iterate it to the Label in GUI
lblTimer.setText(stringCounter); //Iterating the label to current timer
counter = --startTime; //Decrementing the counter
if(counter<0) //If the timer reaches zero
{
btnGuess.setEnabled(false); //Remove functionality of the guess button
JOptionPane.showMessageDialog(null,"Game Over !"); //Inform the user of how horribly they fail at life
theTimer.stop(); //Stop the game
}
}
}
}
}
}
}


Someone find out why my timer is not stopping when I reach 10 guesses, ill be greatful.
The drawing class extends JPanel because it is emedded in the GUI as a panel...essentially a canvas panel.

Edit: goddamnit wig, these code tags fucked up my indentation.
Fucking sad face. :(

Grog
May 17th, 2007, 12:49 PM
the first one

CharlieM
May 17th, 2007, 12:55 PM
Nevermind, I got it.
Ill donate points if you can find it though.

LinnEva
May 17th, 2007, 01:03 PM
general custard with the rope in the s&m room

Pseudonymous
May 17th, 2007, 03:06 PM
general custard with the rope in the s&m room

sorry, it was general custard with the rope in the kitchen. were close though, you were close;)

Monroe
May 17th, 2007, 03:56 PM
I thoought you were in Australian cia or something, what happen charlie, couldnt make the cut/


Anyway ill help ya out:

Step 1: Take a computer

Step 2: Shove it up your ass

Repeat as needed

Talorth
May 17th, 2007, 04:19 PM
I thoought you were in Australian cia or something, what happen charlie, couldnt make the cut/


Anyway ill help ya out:

Step 1: Take a computer

Step 2: Shove it up your ass

Repeat as needed

A fraps of that would be pretty hot imo.

CharlieM
May 18th, 2007, 12:36 AM
I thoought you were in Australian cia or something, what happen charlie, couldnt make the cut/


Anyway ill help ya out:

Step 1: Take a computer

Step 2: Shove it up your ass

Repeat as needed

I take it this means you have no fucking idea what it means ?

I passed every test to get into army intelligence, got knocked back cause of flat feet.
There are other avenues of getting in that dont have the strict physical requirements of the army, ill be trying them in due course. Thanks for the concern though marci, appreciated :)

Talorth
May 18th, 2007, 01:03 AM
dw charlie, monroe is just trying to make a friend.

WiGgLr
May 18th, 2007, 02:35 AM
Edit: goddamnit wig, these code tags fucked up my indentation.
Fucking sad face. :(

Yeah.. that's why I use the PHP tag instead of the CODE one

WiGgLr
May 18th, 2007, 02:46 AM
BTW, Aren't you starting the timer again right after you stopped it, regardless of number of guesses? (line 54 of actionPerformed)

CharlieM
May 18th, 2007, 03:00 AM
BTW, Aren't you starting the timer again right after you stopped it, regardless of number of guesses? (line 54 of actionPerformed)

GJ sir, you win the cookie.

Zelandra
May 19th, 2007, 06:40 PM
BTW, Aren't you starting the timer again right after you stopped it, regardless of number of guesses? (line 54 of actionPerformed)

:'( I didn't get the points. I guess I should troll this forum more :<

CharlieM
May 20th, 2007, 01:21 AM
Anyone care to suggest where I set up inherritence in the program ?
The 5 classes I have:

Hangman.java - has the main and the gui constructor and all the logic
DictionaryFileController.java - handles fetching a random word from the dictionary file
HighScoreFileController.java - handles getting the current highest score, and setting the highest score.
Rot13.java - Handles decryption of encrypted dictionary words
DrawImage.java - handles drawing of the hangman in the gui.

I need at least 2 classes performing inheritence.

Monroe
May 20th, 2007, 10:53 AM
who gives a shit, there is no money in computing anywya

Talorth
May 20th, 2007, 02:10 PM
who gives a shit, there is no money in computing anywya



AHHHHHAHAHAHAHAHAHHAHAHAHAHAHAHHAHAHAHAHAHHAHAHAHA HAAHAHAHHAHAHA



fucking idiot i 'tells ya'.

Archaos
May 20th, 2007, 06:30 PM
Instead sell your body for money, its simpler than this jive computer talk.

CharlieM
May 21st, 2007, 01:29 AM
who gives a shit, there is no money in computing anywya

A 6 figure income isnt money ?
Wigg, fill us all in....how much money is involved in being a software developer ?

WiGgLr
May 21st, 2007, 04:33 AM
A 6 figure income isnt money ?
Wigg, fill us all in....how much money is involved in being a software developer ?

enough

Monroe
May 21st, 2007, 07:10 AM
A 6 figure income isnt money ?
Wigg, fill us all in....how much money is involved in being a software developer ?

Dude, at least in america they outsoursed all the shit to India and shit. Fuck man, I was gonna go into comp sci, in fact I wasted an entire semester taking comp sci shit i will never use again, both of my parents are software developers, they both had to learn farsi or some shit because nearly everyone under them is a fucken punjabi or some shit like that. Its a dead end proffesion.

WiGgLr
May 21st, 2007, 07:35 AM
It's not completely like that, although I have stepped back from full time development and more into a business analyst, project management and personnel role (2 staff and interviewing for a 3rd).

That said, there will always be space for developers who speak English as their first language

Monroe
May 21st, 2007, 07:54 AM
If I wanted to manage a bunch of indians I would move to a bollywood or something, at least they sing annd dance and shit there

CharlieM
May 21st, 2007, 09:07 AM
No need to rage on the profession cause you are too dumb to understand it. Thats like the republicans and religious nutbags raging on darwin, cause their primitive little nuggets of shit in their skull they like to call a 'brain' cant comprehend the immense periods of time in which the process of evolution takes place..etc.

Its just silly brah...silly.

Monroe
May 21st, 2007, 09:10 AM
No need to rage on the profession cause you are too dumb to understand it. Thats like the republicans and religious nutbags raging on darwin, cause their primitive little nuggets of shit in their skull they like to call a 'brain' cant comprehend the immense periods of time in which the process of evolution takes place..etc.

Its just silly brah...silly.


Never said I was too dumb to understand it. Actually programming was pretty easy for me, its just that having to do that as a career sucks. Then again if you got kicked out of intellegence services or w/e, i guess there isnt a lot of options left for ya.

WiGgLr
May 21st, 2007, 09:19 AM
Never said I was too dumb to understand it. Actually programming was pretty easy for me, its just that having to do that as a career sucks. Then again if you got kicked out of intellegence services or w/e, i guess there isnt a lot of options left for ya.

You realise that where the US job market is saturated with IT people, the Australian one is quite the opposite. For example, the immigration websites advertise for IT professionals to help fill the IT skill deficit that Aus has.

CharlieM
May 21st, 2007, 09:24 AM
Never said I was too dumb to understand it. Actually programming was pretty easy for me, its just that having to do that as a career sucks. Then again if you got kicked out of intellegence services or w/e, i guess there isnt a lot of options left for ya.


If you knew what you were talking about you would be dangerous.

Grog
May 21st, 2007, 09:46 AM
If you knew what you were talking about hell would freeze over
fixt