Welcome to Dream.In.Code
Become a Java Expert!

Join 149,585 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,772 people online right now. Registration is fast and FREE... Join Now!




can any1 help me have a look on my game?!

 
Reply to this topicStart new topic

can any1 help me have a look on my game?!, ima done this game. but it's still got some error=[

alexakakazaf
11 Oct, 2007 - 07:06 PM
Post #1

New D.I.C Head
*

Joined: 4 Sep, 2007
Posts: 3


My Contributions
Thanks for helping!
plz try to play it
u will know what error it has..
thanks alot cuz i am still a Newbie
plz tell me if i did wrong
CODE

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class GuessinGame extends Applet implements ActionListener{
    int zeros, tens, twenties, thirties, forties, fifties, sixties, seventies, eighties, nineties;
    int number, guess, random, count, counts;
    Button reset;
    Button answer;
    Label prompt;
    TextField value;
    
public void init(){
    random = (int) (Math.random()*100+1);
    number = 0;
    guess = 0;
    zeros = 0;
    tens = 0;
    twenties = 0;
    thirties = 0;
    forties = 0;
    fifties = 0;
    sixties = 0;
    seventies = 0;
    eighties = 0;
    nineties = 0;
    count = 1;
    value = new TextField(1);
    add (value);
    reset = new Button(" Reset ");
    answer = new Button(" Answer ");
    add(reset);
    add(answer);
    value.addActionListener(this);
    reset.addActionListener(this);
    answer.addActionListener(this);
    }
    
public void actionPerformed(ActionEvent e){
    guess ++;
    if(e.getSource() == answer)
        {
        count = 10;
        }
    if(e.getSource() == reset)
        {
        random = (int) (Math.random()*100+1);
        number = 0;
        guess = 0;
        zeros = 0;
        tens = 0;
        twenties = 0;
        thirties = 0;
        forties = 0;
        fifties = 0;
        sixties = 0;
        seventies = 0;
        eighties = 0;
        nineties = 0;
        counts = 0;
        }
    number = Integer.parseInt(value.getText());
    if(number < 10)zeros = zeros + 1;
    else
    if(number < 20)tens = tens + 1;
    else
    if(number < 30)twenties = twenties + 1;
    else
    if(number < 40)thirties = thirties + 1;
    else
    if(number < 50)forties = forties + 1;
    else
    if(number < 60)fifties = fifties + 1;
    else
    if(number < 70)sixties = sixties + 1;
    else
    if(number < 80)seventies = seventies + 1;
    else
    if(number < 90)eighties = eighties + 1;
    else
    if(number < 100)nineties = nineties + 1;
    else
    nineties = nineties + 1;
    /*if (random == number);
    if (random == number) guess = 0;
    if (random == number) zeros = 0;
    if (random == number) tens = 0;
    if (random == number) twenties = 0;
    if (random == number) thirties = 0;
    if (random == number) forties = 0;
    if (random == number) fifties = 0;
    if (random == number) sixties = 0;
    if (random == number) seventies = 0;
    if (random == number) eighties = 0;
    if (random == number) nineties = 0;*/
    value.setText("");
    repaint();
    }
    
public void paint (Graphics g){
    g.fillRect(0, 0, 1280, 800);
    g.setColor(Color.white);
    g.drawString("Enter a number between 1 and 100,then press enter. Check it out! Good Luck! Man!", 285, 70);
    g.drawString("Hey! What's up? Ya know what it's. A guessin' game! Just put your guess in the text filed.", 275, 50);
    g.drawString("You have had " + guess + " guesses", 450, 90);
    g.drawString("Value 0 to 9     " + zeros, 25, 50);
    g.drawString("Value 10 to 19   " + tens, 25, 75);
    g.drawString("Value 20 to 29   " + twenties, 25, 100);
    g.drawString("Value 30 to 39   " + thirties, 25, 125);
    g.drawString("Value 40 to 49   " + forties, 25, 150);
    g.drawString("Value 50 to 59   " + fifties, 25, 175);
    g.drawString("Value 60 to 69   " + sixties, 25, 200);
    g.drawString("Value 70 to 79   " + seventies, 25, 225);
    g.drawString("Value 80 to 89   " + eighties, 25, 250);
    g.drawString("Value 90 to 99    " + nineties, 25, 275);
    g.drawString("alex a.k.a kazaf, all rights reserved", 425, 680);
    g.setColor(Color.red);
    if (count == 10){g.drawString("Answer is " + random, 900, 630);}
    g.drawString("answer: " + random, 900, 650);
    g.setFont(new Font("SANSSERIF", Font.BOLD, 12));
    g.setColor(Color.yellow);
        if(random > number){
            g.drawString("Sorry, man! Your guess is smaller than the answer. Try again!", 350, 110);
            }
         if(random < number){
            g.drawString("Sorry, man! Your guess is bigger than the answer. Try again!", 350, 110);
            }
        if (random == number){
            g.drawString("Good job, man! Your guess is exactly the answer. Good guess!", 350, 110);
            g.drawString("Let's play one more!", 375, 130);
            }
    }
}

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Can Any1 Help Me Have A Look On My Game?!
11 Oct, 2007 - 09:58 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
How about you tell us what is wrong because I see lots of things I would change. My only guess is that it prints out a message saying you guessed wrong when you first start the game? Or is it the fact that you have to have a number in the box before you can reset it? Or is it the fact that if you put in a letter and hit answer that it counts it as a guess but won't show until you put in a number again only to have it then show you how many guesses you made with the letter?

You have to be more clear as to what error you are talking about. Thanks! smile.gif
User is offlineProfile CardPM
+Quote Post

alexakakazaf
RE: Can Any1 Help Me Have A Look On My Game?!
12 Oct, 2007 - 04:01 AM
Post #3

New D.I.C Head
*

Joined: 4 Sep, 2007
Posts: 3


My Contributions
thanks alot..
i will try to fix it and check back soon..
thank you very much=]
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 10:53PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month