AC3 help (number guessing game)

Hello I have a problem, im fairly new to action script and flash in general but heres my code:
//These are the variables.
var beginMessage:String;
var randomNumber:uint;
var guess:uint;
//It disables the play again button so only the guess button is usable.
playagain_btn.enabled =false;
guess_btn.enabled = true;
//shows a message in the message_txt box.
beginMessage="Choose a number between 1 - 100.";
message_txt.text=beginMessage;
//Basically only allows numbers between 0-9...
input_txt.restrict="0-9";
input_txt.text="";
//This stores a random number between 100 and 1.
randomNumber = Math.floor(Math.random() * 100 + 1);
//Adds an event listener to the guess button.
guess_btn.addEventListener(MouseEvent.CLICK, yourGuess);
function yourGuess(event:MouseEvent):void {
guess=uint(input_txt.text);
//This checks if the guessed number is greater than the random number.
if (guess > randomNumber) {
message_txt.text = "Your guess, " +  guess + " is too damn high.";
//This checks if the guessed number is lower than the random number.
else if (guess < randomNumber) {                       
message_txt.text = "Your guess, " +  guess + " is too low.";         
//This displays a message when the correct number is guessed.  
else{        
message_txt.text = "congratulations ,the number is " + randomNumber + ".";
winGame();        
function winGame():void{       
//Disables the guess button and enables the play again button.         
guess_btn.enabled = false;         
playagain_btn.enabled = true;          
//This removes a listener from the yourguess button and adds a
//listener to playagain
guess_btn.removeEventListener(MouseEvent.CLICK, yourGuess);         
playagain_btn.addEventListener(MouseEvent.CLICK, guessAgain);
function guessAgain(event:MouseEvent):void{         
//Runs the init() method.         
init();
//Runs the init() method.
init();
//this part of the script is for the number
//Declare variables
var numOfGuesses:uint ;
var numOfGuessesMessage:String;
function init():void {
    //Displays a message showing the total number of guessing remaining
    numOfGuesses = 6;
    numOfGuessesMessage = " Guesses remaining";
    guess_txt.text = numOfGuesses + numOfGuessesMessage;
if(numOfGuesses == 0){
        message_txt.text = "The number was " + randomNumber + "."; 
        guess_txt.text = "you lose!!!!!! D:!!.";
        winGame();
function yourGuess(event:MouseEvent):void {
    guessMessage();
function guessMessage():void{
    //Only decrement the numOfGuesses if the text field contains characters.
    if(input_txt.length > 1 && numOfGuesses != 0){
        numOfGuesses--;
        guess_txt.text = numOfGuesses + numOfGuessesMessage;
And my errors are duplicate function definition. theres the code its crying about.
function yourGuess(event:MouseEvent):void {
    guessMessage();
what Im doing here is making a number guessing game, everything works but the number of guesses wont go down.

Put a trace in the function where you try to decrease the number of guesses and see if the logic is letting you get in to change it...
  function guessMessage():void {
   //Only decrement numofGuess if the input field has characters.
trace(input_txt.length, numOfGuesses)
   if(input_txt.length > 1 && numOfGuesses != 0){
    numOfGuesses--;
    guess_txt.text = numOfGuesses + numOfGuessesMessage;
  //When guesses have ran out, A message will appear saying you can reset.
  if(numOfGuesses == 0){
   message_txt.text = "The number I was thinking was " + randomNumber + ".";
   guess_txt.text = "Press play again to try again";
  winGame(event:MouseEvent);
If you happen to be changing frames where you leave the frame with this code and then come back to it, then you are likely running into this line again....
numOfGuesses = 6;
which resets the number of guesses.

Similar Messages

  • Need help with " Number guessing game " please?

    This is what teacher requires us to do for this assignment:
    Write a program that plays a simple number guessing game. In this game the user will think of a number and the program will do the guessing. After each guess from the program, the user will either indicate that the guess is correct (by typing �c�), or that the next guess should be higher (by typing �h�), or that it should be lower (by typing �l�). Here is a sample output for a game. In this particular game the user thinks of the number 30:
    $java GuessingGameProgram
    Guess a number between 0 and 100
    Is it 50? (h/l/c): l
    Is it 25? (h/l/c): h
    Is it 37? (h/l/c): l
    Is it 31? (h/l/c): l
    Is it 28? (h/l/c): h
    Is it 29? (h/l/c): h
    Is it 30? (h/l/c): c
    Thank you for playing.
    $
    This program is implementing a binary search algorithm, dividing the range of possible values in half with each guess. You can implement any algorithm that you want, but, all things being equal, binary search is the best algorithm.
    Write the program so that the functionality is split between two classes: GuessingGameProgram, and NumberGuesser.
    GuessingGameProgram will only be used for its main function. It should instantiate a NumberGuesser, and it will be responsible for the loop that notifies the user of the next guess, reads the �h�, �l�, or �c� from the user, and sends an appropriate message to the number guesser accordingly.
    The guesses themselves should all be generated by the NumberGuesser class. Here is a diagram of the members and methods for the class. Notice that the members are unspecified. Feel free to give your NumberGuesser class any members (which we have also been calling fields, or instance variables) that you find useful. Make them all private.
    NumberGuesser
    NumberGuesser(int upperLimit, int lowerLimit)
    int guess()
    void higher()
    void lower()
    The constructor should take two integer arguments, a lower and upper bound for the guesses. In your program the constructor will be called with bounds of 0 and 100.
    The guess method should return the same value if it is called more than once without intervening calls to the lower or higher methods. The class should only change its guess when it receives a message indicating that its next guess should be higher or lower.
    Enjoy. Focus your attention on the NumberGuesser class. It is more interesting than the GuessingGameProgram class because it is a general-purpose class, potentially useful to anybody who is writing a number guessing game. Imagine, for instance, that a few weeks from now you are asked to write a number guessing game with a graphical Java Applet front end. If you NumberGuesser class is well written, you may be able to reuse it without any modifications.
    I'm new to JAVA and I'm set with my 2nd homework where I'm so confused. I know how to do something of this source in C language, but I'm a bit confused with Java. This is the code me and my classmate worked on, I know it's not 100% of what teacher asked, but is there any way possibly you guys could help me? I wrote this program if the game is played less then 10 times, thought I would then re-create a program without it, but now I'm confused, and my class book has nothing about this :( and I'm so confused and lost, can you please help? And out teacher told us that it's due the end of this week :( wish I knew what to do. Thank you so so much.
    Here's the code:
    import java.text.*;
    import java.io.*;
    class GuessingGame
    public static void main( String[] args ) throws IOException
    BufferedReader stdin = new BufferedReader(new InputStreamReader( System.in ) );
    int guess = 0, limit = 9, x = 0, n, a = 0 ;
    double val = 0 ;
    String inputData;
    for ( x = 1; x <= 10; x++)      //number of games played
    System.out.println("round " + x + ":");
    System.out.println(" ");
    System.out.println("I am thinking of a number from 1 to 10. ");
    System.out.println("You must guess what it is in three tries. ");
    System.out.println("Enter a guess: ");
    inputData = stdin.readLine();
    guess = Integer.parseInt( inputData );
    val = Math.random() * 10 % limit + 1;     //max limit is set to 9
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(0);               //format number of decimal places
    String s = nf.format(val);
    val = Integer.parseInt( s );
         for ( n = 1; n <= 3; n++ )      //number of guess's made
                   if ( guess == val)
                        System.out.println("RIGHT!!");                    //if guess is right
                        a = a + 1;
                        System.out.println("You have won " + a + " out of " + x + " rounds");
    System.out.println(" ");
    n = 3;
    continue;
              if (n == 3 && guess != val)                         //3 guesses and guess is wromg
                        System.out.println("wrong");
    System.out.println("The correct number was " + val);
                        System.out.println("You have won " + a + " out of " + x + " rounds");
    System.out.println(" ");
    continue;
                   //how close guess is to value
                   if ( guess == val - 1 || val + 1 == guess) //Within 1
                   System.out.println("hot");
         else if ( guess == val - 2 || val + 2 == guess) // Within 2
                   System.out.println("warm");
              else
                   System.out.println("cold");                         // Greater than 3
         inputData = stdin.readLine();
         guess = Integer.parseInt( inputData );
    //ratings
    if ( a <= 7)
         System.out.println("Your rating is: imbecile.");
    else if ( a <= 8)
         System.out.println("Your rating is: getting better but, dumb.");
    else if (a <= 9)
         System.out.println("Your rating is: high school grad.");
    else if ( a == 10)
         System.out.println("Your rating is: College Grad.!!!");

    Try this.
    By saying that, I expect you ,and your classmate(s), to study this example and then write your own. Hand it in as-is and you'll be rumbled as a homework-cheat in about 20ms ;)
    When you have an attempt where you can explain, without refering to notes, every single line, you've cracked it.
    Also (hint) comment your version well so your tutor is left with the impression you know what you're doing.
    In addition (huge hint) do not leave the static inner class 'NumberGuesser' where it is. Read your course notes and find out where distinct classes should go.
    BTW - Ever wonder if course tutors scan this forum for students looking for help and/or cheating?
    It's a double edged sword for you newbies. If you ask a sensible, well researched question, get helpful answers and apply them to your coursework, IMHO you should get credit for doing that.
    On the other hand, if you simply post your assignment and sit there hoping some sucker like me will do it for you, you should be taken aside and given a good kicking - or whatever modern educational establishments consider appropriate abmonishment ;)
    I'd say this posting is, currently, slap bang between the two extreemes, so impress us. Post your solution in the form you intend to hand it in, and have us comment on it.
    Good luck!
    import java.io.InputStreamReader;
    import java.io.BufferedReader;
    public class GuessingGame
         public static void main(String[] args)
              throws Exception
              BufferedReader reader= new BufferedReader(
                   new InputStreamReader(System.in));
              NumberGuesser guesser= new NumberGuesser(0, 100);
              System.out.println(
                   "\nThink of a number between 0 and 100, oh wise one...");
              int guess= 0;
              while (true) {
                   guess= guesser.guess();
                   System.out.print("\nIs it " +guesser.guess() +"? (h/l/c) ");
                   String line= reader.readLine();
                   if (line == null) {
                        System.out.println(
                             "\n\nLeaving? So soon? But we didn't finish the game!");
                        break;
                   if (line.length() < 1) {
                        System.out.println("\nPress a key, you muppet!");
                        continue;
                   switch (line.toLowerCase().charAt(0)) {
                        case 'h':  
                             guesser.higher();
                             break;
                        case 'l':     
                             guesser.lower();
                             break;
                        case 'c':
                             System.out.println("\nThank you for playing.");
                             System.exit(0);
                        default:
                             System.out.println(
                                  "\nHow hard can it be? Just press 'h' 'l' or 'c', ok?");
                             continue;
                   if (guess == guesser.guess()) {
                        System.out.println(
                             "\nIf you're going to cheat, I'm not playing!");
                        break;
         private static class NumberGuesser
              private int mLower;
              private int mUpper;
              private int mGuess;
              NumberGuesser(int lowerLimit, int upperLimit)
                   mLower= lowerLimit;
                   mUpper= upperLimit;
                   makeGuess();
              private void makeGuess() {
                   mGuess= mLower + ((mUpper - mLower) / 2);
              int guess() {
                   return mGuess;
              void higher()
                   mLower= mGuess;
                   makeGuess();
              void lower()
                   mUpper= mGuess;
                   makeGuess();
    }                  

  • Help with action script number guessing game

    can someone help me in flash cs6 to make a simple guessing game, i just need help with the coding. making a guessing game from 1-100
    The constructor is coded to assign a random number for
    the user to guess
    • In the section of code indicated by the comments
    (within the handler function doGuess()), write condition
    statements that guide the user to guessing the number
    using text written to the output
    • Trace out the users' guess, plus a message
    • Messages for the user depending how close they are from the
    guess, condition each of the following:
    • Guesses correctly, +/-1 from the guess, +/-10 from the guess,
    +/-20 from the guess, +/-40 from the guess, all other guesses

    close, it's actually an in class practice lab. After doing this we have to do another one that needs to be submitted. I just need help with the coding for this because i dont know how to start at all. let alone the actual lab.

  • Number Guessing Game Help

    this is my current code it works ok, but i need a bit of help with when they get it right, and I have to start converting it to graphical in Borland Jbuilder.
    import java.io.*;
         import java.util.*;
    public class Numb{
         public static void main (String [] args){
              //Game State     
              int magicNumb = Math.abs(new Random().nextInt() % 100) + 1;
              //Output instructions
              System.out.println("I Feel Numb!");
              System.out.print("Do you feel Loved? Y/N");
              //Read from input
              InputStreamReader inStream = new InputStreamReader(System.in);
              BufferedReader keyboard = new BufferedReader(inStream);
              String line = null;
              try{
                   line=keyboard.readLine();
              }catch(IOException ioe){}
              boolean acrobat = true;
              //If they pressed y let them play
              if(line.equalsIgnoreCase("y")){
                   //Game stuff goes here
                   System.out.println("Don't Expect Suggest a NUMBer between 1 and 100");
                   System.out.print("Enter a guess:");               
                   //LOOP
                   while (acrobat=true){
                   //Read user input
                   {try{
                        line=keyboard.readLine();
                   }catch(IOException ioe){}
                   //Convert the inpt to an int value
                   int guess = (int)Integer.parseInt(line);
                   //If Right
                   if (guess==magicNumb)
                        System.out.println("Green Light Seven Eleven You stop in for a pack of cigaretes");
                        acrobat=false;               
                   //If too High
                   if (guess>magicNumb)
                        System.out.println("Too Much is Not Enough");
                   //If too Low
                   if (guess<magicNumb)     
                        System.out.println("Gimme Some more, Gimme some more");}
    }

    Ok what i need help with is when they get the
    integer, i need to either state another message and
    quit, or give them the option to play again?Okay, so, your overall code structure will look something like this: do {
        play();
        again = askIfPlayAgain();
    } while again;
    void play() {
        do {
            ask for a guess
            give answer
        } while (incorrect);
    } You don't have to use do/while. Plain old while will work.
    The main points are:
    1) You need two loops. The inner one keeps going within one round until they guess correctly, and the outer one keeps starting new rounds until they quit.
    2) You should break the problem down into smaller, more elemental pieces, rather than stuffing everything into one big blob in main.
    #1 will help you solve this problem, but #2 is an absolutely essential skill to learn.

  • "HiLo" number guessing game not working - Help please!

    My game is compiling and read's right (in my head) but doesn't appear to work, any help is highly appreciated, thank you.
    Source code. More specifically, I think that it's properly getting the random number, but the guess prompt is not appearing, probably because of my while(random!=number) line?
    import javax.swing.JOptionPane;
    import java.util.Random;
    * High-Low (HiLo) game.
    * @author
    * @version 11/18/2010
    public class HiLo
        String randomNumber = "";
        int random;
        String userNum = "";
        int number;
         * Asks player if he wants to play, gets random number, gets user guess, checks the users guess, asks to repeat.
        public void play()
            getRandom();
            while(random!=number)
                getGuess();
                checkGuess();
         * Gets the users guess.
        public int getGuess()
            userNum = JOptionPane.showInputDialog ("Please Guess the number");
            int number = Integer.parseInt(userNum);
            return number;
         * Gets a random number between 0 and 100
         * int named random
        public int getRandom()
            Random randomNumber = new Random();
            int random = randomNumber.nextInt(101);
            return random;
         * Checks to see if the user's guess is an integer, between 0 and 100, and returns if
         * they're guess is too high or too low.
        public void checkGuess()
            if (number==random)
                JOptionPane.showMessageDialog(null, "You Win!");
            else if (number<random)
                JOptionPane.showMessageDialog(null, "Too low, guess again!");
            else if (number>random)
                JOptionPane.showMessageDialog(null, "Too high, guess again!");
    }Edited by: 811146 on Nov 18, 2010 3:11 PM

    Sorry about that Darryl,
    a few more questions on this code though.
    1.How can I have my getGuess() only accept integers?
    here it is now:
    public int getGuess()
            userNum = JOptionPane.showInputDialog ("Guess a number between 0 and 100");
            number = Integer.parseInt(userNum);
            return number;
        }and 2. How can I keep my whole play() in a loop? So that the game starts over
    my play() right now:
    public void play()
            getRandom();
            while(random!=number)
                getGuess();
                checkGuess();
            numberGuesses = 0;
            playAgain();
        }sorry, first year student!
    thanks for any help. All of the code if needed:
    import javax.swing.JOptionPane;
    import java.util.Random;
    * High-Low (HiLo) game. User guesses numbers while trying to guess a random number. Number of guesses is recorded and the user is told
    * at the end of the game after winning.
    * @author ----------
    * @version 11/18/2010
    public class HiLo
        String randomNumber = "";
        String userNum = "";
        int random;
        int number;
        int numberGuesses;
         * Asks player if he wants to play, gets random number, gets user guess, checks the users guess, asks to repeat.
        public void play()
            getRandom();
            while(random!=number)
                getGuess();
                checkGuess();
            numberGuesses = 0;
            playAgain();
         * Gets the users guess.
        public int getGuess()
            userNum = JOptionPane.showInputDialog ("Guess a number between 0 and 100");
            number = Integer.parseInt(userNum);
            return number;
         * Gets a random number between 0 and 100
         * int named random
        public int getRandom()
            Random randomNumber = new Random();
            random = randomNumber.nextInt(101);
            return random;
         * Checks to see if the user's guess is an integer, between 0 and 100, and returns if
         * they're guess is too high or too low.
        public void checkGuess()
            numberGuesses = numberGuesses+1;
            if (number==random)
                JOptionPane.showMessageDialog(null, "You Win!" + " " + "Number of guesses:" + " " + numberGuesses);         
            else if (number<random)          
                JOptionPane.showMessageDialog(null, "Too low, guess again!");
            else if (number>random)      
                JOptionPane.showMessageDialog(null, "Too high, guess again!");
         * Asks the user if they want to play again.
        public void playAgain()
            JOptionPane.showMessageDialog(null, "play again?");         
    }-javaStudent

  • Need help with a guessing game

    Hi. hopefully, this is a really easy issue to resolve. I had to write a program that administers a guessing game, where the computer chooses a random number, and the user has to guess the number. If the user doesn't get it within 5 guesses, they lose and start all over with a new number. I have this all in a while loop (as per my instructions). My issue is that whenever the user enters 0, the program should quit with the users final score and so on. My program will not quit unless the 0 is entered on the last (fifth) guess. please help, it would be very appreciated. Here is my code:
    import java.util.Scanner;
      public class guessgame {
        public static void main(String[] args) {
          Scanner scanner = new Scanner (System.in);
            int randnum;        //random number generated by computer
            int userguess = 1;      //number the user guesses
            int userscore = 0;      //number of correct guesses by user
            int compscore = 0;      //number of times not guessed
            int guessnum = 0;       //number of guesses for one number
            int gamenum = 0;        //number of games played
        System.out.println ("I will choose a number between 1 and 10");
        System.out.println ("Try to find the number using as few guesses as possible");
        System.out.println ("After each guess i will tell you if you are high or low");
        System.out.println ("Guess a number (or 0 to quit)");
        while (userguess != 0) {
          randnum = 1 + (int)(Math.random() * 10); //generates random number
          gamenum ++;
          userguess = userguess;
            for (guessnum = 1; guessnum < 6 && userguess != randnum; guessnum ++) {
                userguess = scanner.nextInt();
                userguess = userguess;
               if (guessnum >= 5) {
                  System.out.println ("You did not guess my number!");
                                  } //closes if statement
               if (userguess == randnum) {
                 userscore ++;
                 System.out.println ("You guessed it! It took you " + guessnum + " tries.");
                 System.out.println ("If you want to play again, enter a guess");
                 System.out.println ("If you do not want to play again, enter 0");
                                        } //closes if statement
               else if (userguess < randnum)
                 System.out.println ("Your guess is too low");
               else if (userguess > randnum)
                 System.out.println ("Your guess is too high");
                                                          }//closes for loop
                              } //closes while loop
    compscore = gamenum - userscore;
            System.out.println ("Thanks for playing! You played " + gamenum + " games");
            System.out.println ("Out of those " + gamenum + " games, you won " + userscore + " times");
            System.out.println ("That means that I won " + compscore + " times"); 
    } //closes main
    } //ends guessgame class

    The problem with your program is that the while loop doesn't get checked. The condition of the while loop will only get checked each iteration, and not during one iteration. The time you are in your for-loop is still one iteration so it won't check if userguess is 0. see it liek this
    While: is userguess 0, no, do 1 iteration
    while-iteration-forloop: check 5 guesses, userguess can be anything even 0 while loop won't stop.
    end of for loop
    end of while-iteration
    new while iteration, is userguess 0?
    and so on.
    HTH,
    Lima

  • Guessing Game Problem

    I'm having a problem thinking of a way to think of a solution to this. Basically, what I am trying to do is have a guessing game with the computer. What happens is I think of a number from 1000 to 9999, let's say 3741. Then the computer randomnly guesses from an ArrayList of 1000-9999, and asks if its the right number, or not. Let's say the computer guesses 5312. I would respond by saying how many matches there are 0-4, in this case 4. Then my idea is to update the arrayList, by deleting all the necessary values. I would do this continuously until one number is left, which would be the correct answer. I am trying to think of an algorithm that would do this in 15 guesses or less (aiming for 10ish).
    My code so far:
    // fill in your information in the line below, and comment it out in order to compile
    // Name: ???   Student ID: ???;
    import java.util.ArrayList;
    import java.util.Random;
    import javax.swing.JOptionPane;
    public class Assignment2 {
    private int totalGuesses;
    private ArrayList<Integer> guess;
    private int myGuess;
    public Assignment2 ( ){
    totalGuesses = 0;
    myGuess = 0;
    guess = new ArrayList<Integer>();
    for(int i = 1000; i <= 9999 ; i++) // Adds numbers 1000 to 9999 initially.
       guess.add(i);
    public int myGuessIs() {
      return myGuess;
    public int totalNumGuesses() {
      return totalGuesses;
    public void updateMyGuess(int nmatches) {
      // fill in code here
      // update the guess based on the number of matches claimed by the user
    if(guess.size() == 0)
      myGuess = -1;
    // you shouldn't need to change the main function
    public static void main(String[] args) {
      Assignment2 gamer = new Assignment2( );
      JOptionPane.showMessageDialog(null, "Think of a number between 1000 and 9999.\n Click OK when you are ready...", "Let's play a game", JOptionPane.INFORMATION_MESSAGE);
      int numMatches = 0;
      int myguess = 0;
      do {
       myguess = gamer.myGuessIs();
       if (myguess == -1) {
        JOptionPane.showMessageDialog(null, "I don't think your number exists.\n I could be wrong though...", "Mistake", JOptionPane.INFORMATION_MESSAGE);
        System.exit(0);
       String userInput = JOptionPane.showInputDialog("I guess your number is " + myguess + ". How many digits did I guess correctly?");
       // quit if the user input nothing (such as pressed ESC)
       if (userInput == null)
        System.exit(0);
       // parse user input, pop up a warning message if the input is invalid
       try {
        numMatches = Integer.parseInt(userInput.trim());
       catch(Exception exception) {
        JOptionPane.showMessageDialog(null, "Your input is invalid. Please enter a number between 0 and 4", "Warning", JOptionPane.WARNING_MESSAGE);
        numMatches = 0;
       // the number of matches must be between 0 and 4
       if (numMatches < 0 || numMatches > 4) {
        JOptionPane.showMessageDialog(null, "Your input is invalid. Please enter a number between 0 and 4", "Warning", JOptionPane.WARNING_MESSAGE);
        numMatches = 0;
       if (numMatches == 4)
        break;
       // update based on user input
       gamer.updateMyGuess(numMatches);
      } while (true);
      // the game ends when the user says all 4 digits are correct
      System.out.println("Aha, I got it, your number is " + myguess + ".");
      System.out.println("I did it in " + gamer.totalNumGuesses() + " turns.");
    Obviously, I'm having trouble thinking of a solution to updateMyGuess...I don't know why but I'm most likely making this way harder than it actually is.. Can anyone help?

    borisan wrote:
    What happens is I think of a number from 1000 to 9999, let's say 3741. Then the computer randomnly guesses from an ArrayList of 1000-9999, and asks if its the right number, or not. Let's say the computer guesses 5312. I would respond by saying how many matches there are 0-4, in this case 4. Don't you mean 0?
    What if computer's guess is 2795. I assume number of matches then would be 1 (the 7). How exactly is your code going to know that 7 is the lone match and not the 2 or the 9 or the 5?

  • Color and Num guessing game

    Okay so for my final project we have to make any program we want to do. I am trying to make a game that the user has to guess the color and number but as if it was picking a card and the user had to guess it. Colors include yellow, green, red, blue, and it's numbers 0-9 So basically I was just wondering if I did my class correct for creating my cards.
    public class Cards {
       public final static int red=0, blue=1, yellow=2, green=3;
       private final int deck;
       private final int value;
       public Cards(int cardValue, int deckValue)
           value=cardValue;
           deck=deckValue;
       public int getCard()
           return deck;
       public int getValue()
           return value;
       public String toString()
           switch (deck)
               case red:
                   return "Red";
               case blue:
                   return "Blue";
               case yellow:
                   return "Yellow";
               case green:
                   return "Green";
               default:
                   return "Invalid";
       public String valueToString()
           switch (value)
               case 1:
                   return "0";
               case 2:
                   return "1";
               case 3:
                   return "2";
               case 4:
                   return "3";
               case 5:
                   return "4";
               case 6:
                   return "5";
               case 7:
                   return "6";
               case 8:
                   return "7";
               case 9:
                   return "8";
               case 10:
                   return "9";
               default:
                   return "Invalid";
       public String toFullString()
           return toString() + " of " + valueToString();
    }I could be going about this all wrong. I think I am.....but yeah.
    Now I was also wondering when I go to have it where the card is drawn and the user guesses it, I would do it as a random number but I'm also stuck there as well, I haven't created the code yet but I am working on it now..and quick sugestions? I don't want any code just a brief explanation on how I can go about it just to jump start it.
    Edited by: FAF101 on Dec 3, 2007 5:11 PM
    Edited by: FAF101 on Dec 3, 2007 5:16 PM

    Okay so I changed things around a little bit on my program.
    This is my card class...
    public class Card
         private int number, colorNumber;
         private String color;
         public Card (int n, int c) {
              number = n;
              colorNumber = c;
         public String toString() {
              String cardValue;
              cardValue = "" + number;
              switch(colorNumber) {
              case 1: color = "Blue";
              break;
              case 2: color = "Red";
              break;
              case 3: color = "Green";
              break;
              case 4: color = "Yellow";
              break;
              cardValue += color;
              return cardValue;
    }Then I have a Number Guess class which has errors in it and I don't know why.
    import java.util.Random;
    public class NumberGuess {
         private int userColorInt;
         public NumberGuess() {
              number = num;
              Random generator = new Random();
              int k = 0;
              Card[] deck = new Card[40];
         for ( int c =0; c<=4; c++)
                              for(int n = 0; n <= 10; n++) {
                                   deck[k] = new Card(n, c);
                                   k++;
              public int convertUserString(String userColor) {
              if(userColor .equals("Blue")) {
                   userColorInt = 1;
              if(userColor .equals("Red")) {
                   userColorInt = 2;
              if(userColor.equals("Green")){
                   userColorInt = 3;
              if(userColor.equals("Yellow")){
                   userColorInt = 4;
              return userColorInt;
         I think I am doing everything right so far but I just am not quite sure if it's just right yet. Any suggestions on what needs to be fixed? Cause I am at a loss.
    What I am trying to do now is have it store the number and the color for when the user enters it in it can check them seperatly

  • My ipod nano 4th generation will plug into itunes and if i push buttons i can hear music, however the whole time the screen is black so its a guessing game. how do i fix this?

    my 4th generation ipod nano works but its a guessing game. the screen is totally black even when plugged into my computer. itunes still recognizes it. is the screen broke is it the backlight, any suggestions how to find out or to fix this? oh and ive completely restored the ipod several times. i let someone borrow it and this is how i got it back so i dont know what caused the problem.
    Message was edited by: robynd369

    I checked for anything either bent or broken, and as far as I know everything looks fine, though I could probably clean out the dust and dirt collected in there after a year. I could take a picture if that would help. Would being dirty inside there cause this to happen? It's one thing I guess I never thought of and probably should do.

  • Creating a word-based guessing game

    Hi...
    I'm currently producing a experimental flash project, which
    involves both comic-book style imagery, animation and
    puzzle-solving whereby the user must solve a riddle in order to
    progress through the story. Of course, the whole project involves
    one bit of Actionscript 2 on each page in order to get it to work
    but so far I've only been able to find code for a guessing game
    with numbers.
    The following code is how I've tried to handle this: I'm
    fairly new to Actionscript so please forgive me! I've attached this
    code to my "answer_btn" button. "Input" refers to the input textbox
    in which the correct answer must be typed.
    Thanks for your help!

    Input is not the same as input.
    if input is the instance name of your textfield, you need to
    use its text property. if input is the variable associated with
    your textfield, you're ok.
    you have a paranthesis mismatch on your 2nd line of code.
    remove one right paranthesis.
    if your button is a true button (not a movieclip button),
    you're directing the parent timeline of the timeline that contains
    your button to play "riddle_story".

  • Help with rhythm game

    So i am starting university in late september (to learn 3d character animation) and need to get the grades to get in, sadly we have a flash programming unit in the college course im in now and we didnt get taught anything at all and i mean nothing, we were given printed sheets and told to copy the code word for word. so i really need help with my game. how would i make the movement of something my cursor? so when i move the cursor it follows it? also how do i play an animation on click?
    My  idea for the game is to have a rhythm style game where the player moves the net and catches the bee's, something i thought would be simple to figure out how to do
    This is my game at the minute, ive used the code we were told to copy from sheets and just changed the sprites :\ any help would be amazing!
    https://www.dropbox.com/s/1pjbv2mavycsi3q/sopaceship%20rev7%20%20moving%20bullet.fla

    http://orangesplotch.com/blog/flash-tutorial-elastic-object-follower/
    var distx:Number;
    var disty:Number;
    var momentumx:Number;
    var momentumy:Number;
    follower.addEventListener(Event.ENTER_FRAME, FollowMouse)
    function FollowMouse(event:Event):void {
         // follow the mouse in a more elastic way
         // by using momentum
         distx = follower.x - mouseX;
         disty = follower.y - mouseY;
         momentumx -= distx / 3;
         momentumy -= disty / 3;
         // dampen the momentum a little
         momentumx *= 0.75;
         momentumy *= 0.75;
         // go get that mouse!
         follower.x += momentumx;
         follower.y += momentumy;

  • The game "horn" does'nt open and shows installing but nothing happens. it was transferred from the computer to the ipad. help!, The game horn does'nt open and shows installing but nothing happens. it was transferred from the computer to the ipad. help!

    The game "horn" does'nt open and shows installing but nothing happens. it was transferred from the computer to the ipad. help!, The game horn does'nt open and shows installing but nothing happens. it was transferred from the computer to the ipad. help!

    Try this  - Reset the iPad by holding down on the Sleep and Home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons. (This is equivalent to rebooting your computer.) No data/files will be erased. http://support.apple.com/kb/ht1430
    iOS 7: Help with how to fix a crashing app on iPhone, iPad (Mini), and iPod Touch
    http://teachmeios.com/help-with-how-to-fix-a-crashing-app-on-iphone-ipad-mini-an d-ipod-touch/
    Troubleshooting apps purchased from the App Store
    http://support.apple.com/kb/TS1702
    Delete the app and redownload.
    Downloading Past Purchases from the iTunes Store, App Store and iBooks Store
    http://support.apple.com/kb/ht2519
     Cheers, Tom 

  • Why is the Linksys Help Number a Scam?

    Yesterday I call the Linksys Help number and got somebody in Arabia that I could barely understand to help me re-connect my Extenders (one was disconnected and the software wasn't working to re-connect it).
    Because this was the Linksys Help Number (gotten directly off the Linksys website 888-351-0767), I thought I should "Trust" them (please read on).
      He proceeded to tell me that my Wireless network was taken over by foriener's IP addresses, and the reason my signal strength was so bad & eratic.
    And wanted to use a service of their's that would allow them to fix the problems I was having.
    I agreed because it was Linksys's help partners...
      He then showed me a few google searches that proved what he was telling me was the truth.
    Then he ran a DOS shell program and found all the problems I was having while explianing to me how these foriener's have hijacked my computer & wireless network.
      Then he told me he could fix everthing for $69.99...
    I didn't say another word, I just turned my computer off (holding the start button until it turned off).
    Then when I rebooted, I had his software automaticly re-start.
    I found a way to shut their software off by searching for a few answer on my cell phone.
    This seems to be a scam number, please let everyone know!
    Linksys should appoligize to me for this kind of behavoir...
    I will search hard for customer happiness when I decide to upgrade to a new wireless router.
    Thanks,
    D
    Solved!
    Go to Solution.

    Vince_02,
    I looked at the link, the pictures of the techs don't resemble the person's language that was talking to me.
    Not unless all of them was fluient in broken islamic/indian/english, If so they should get an award for their perforamnce!
    Note:
    Sounded like there were at least 10+ other people in the background that "were" fluient in islamic/indian all telling the person what to do next.
    Seriously,
    Thanks for the feedback and help guys.
    D

  • Guys need help is regarding games. I want to install games like commandos, gta vice city, counter strike etc I mean action games in which we do levels, like games in playsatation and xbox ?

    Guys need help is regarding games. I want to install games like commandos, gta vice city, counter strike etc I mean action games in which we do levels, like games in playsatation and xbox ?

    You can only install games that are in the iTunes app store on your computer and the App Store app directly on the iPad - if there are games like those that you mention in your country's store then you can buy and install them. Have you had a look in your country's store ?

  • Is the apple help number for free?

    Is the apple help-number for free?

    Only for 90 days after purchase unless you purchased the extended AppleCare warranty. If you did then it is two years.

Maybe you are looking for