Help with text based game.

SO I've just begun to make a text based game and i've already ran into a problem :/
I've made a switch statement that has cases for each of the classes in the game..for example
Output will ask what you want to be
1. Fighter
2. etc
3. etc
case 1: //Fighter
My problem is i want to be able to display the class
as in game class not java class
as Fighter
That may be a bit confusing to understand sorry if it isn't clear
Here is my code that i'm using this may help.
import java.util.Scanner;
public class main {
     public static void main(String args[]) {
          Scanner input = new Scanner(System.in);
          int health = 0;
          int power = 0;
          int gold = 0;
          System.out.println("Welcome to my game!");
          System.out.println("First of what is your name?");
          String name = input.next();
          System.out.println(name + " you say? Interesting name. Well then " + name + " what is your race?");
          System.out.println();
          System.out.println("Press 1. for Human");
          System.out.println("Press 2. for Elf");
          System.out.println("Press 3. for Orc");
          int Race = input.nextInt();
          switch (Race) {
          case 1: // Human
               String race = "Human";
               health = 10;
               power = 10;
               gold = 25;
          break;
          case 2: // Elf
               health = 9;
               power = 13;
               gold = 25;
          break;
          case 3: // Orc
               health = 13;
               power = 9;
               gold = 30;
          break;
          default:
               System.out.println("Invalid choice Please choose 1-3");
          break;
          System.out.println("Now what is your class?");
          System.out.println("Press 1. Fighter");
          System.out.println("Press 2. Mage");
          System.out.println("Press 3. Rogue");
          int Class = input.nextInt();
          switch (Class) {
          case 1: // Fighter
               health = health + 1;
               power = power + 1;
               gold = gold + 1;
          break;
          case 2: // Mage
               health = health + 1;
               power = power + 1;
               gold = gold + 1;
          break;
          case 3: // Rogue
               health = health + 1;
               power = power + 1;
               gold = gold + 1;
          break;
          default:
               System.out.println("Invalid choice Please choose 1-3");
          break;
          System.out.println("So your name is " + name );
          System.out.println("and your race is: " + race);
          System.out.println("and your class is: " + Class);
}Thanks in advance!

Brushfire wrote:
So you're advising him to run his console based game on the EDT, why?Far King good question... To which I suspect the answer is "Ummm... Ooops!" ;-)
@OP: Here's my 2c... if you don't follow then ask good questions and I'll consider giving good answers.
package forums;
import java.util.Scanner;
abstract class Avatar
  public final String name;
  public int type;
  public int health;
  public int power;
  public int gold;
  protected Avatar(String name, int health, int power, int gold) {
    this.name = name;
    this.health = health;
    this.power = power;
    this.gold = gold;
  public String toString() {
    return "name="+name
         +" health="+health
         +" power="+power
         +" gold="+gold
class Human extends Avatar
  public Human(String name) {
    super(name, 10, 11, 31);
class Elf extends Avatar
  public Elf(String name) {
    super(name, 9, 13, 25);
class Orc extends Avatar
  public Orc(String name) {
    super(name, 6, 17, 13);
interface AvatarFactory
  public Avatar createAvatar();
class PlayersAvatarFactory implements AvatarFactory
  private static final Scanner scanner = new Scanner(System.in);
  public Avatar createAvatar() {
    System.out.println();
    System.out.println("Lets create your avatar ...");
    String name = readName();
    Avatar player = null;
    switch(readRace(name)) {
      case 1: player = new Human(name); break;
      case 2: player = new Elf(name); break;
      case 3: player = new Orc(name); break;
    player.type = readType();
    return player;
  private static String readName() {
    System.out.println();
    System.out.print("First off, what is your name : ");
    String name = scanner.nextLine();
    System.out.println(name + " you say? Interesting name.");
    return name;
  private static int readRace(String name) {
    System.out.println();
    System.out.println("Well then " + name + ", what is your race?");
    System.out.println("1. for Human");
    System.out.println("2. for Elf");
    System.out.println("3. for Orc");
    while(true) {
      System.out.print("Choice : ");
      int race = scanner.nextInt();
      scanner.nextLine();
      if (race >= 1 && race <= 3) {
        return race;
      System.out.println("Bad Choice! Please try again, and DO be careful! This is important!");
  private static int readType() {
    System.out.println();
    System.out.println("Now, what type of creature are you?");
    System.out.println("1. Barbarian");
    System.out.println("2. Mage");
    System.out.println("3. Rogue");
    while(true) {
      System.out.print("Choice : ");
      int type = scanner.nextInt();
      scanner.nextLine();
      if (type >= 1 && type <= 3) {
        return type;
      System.out.println("Look, enter a number between 1 and 3 isn't exactly rocket surgery! DO atleast try to get it right!");
public class PlayersAvatarFactoryTest {
  public static void main(String args[]) {
    try {
      PlayersAvatarFactoryTest test = new PlayersAvatarFactoryTest();
      test.run();
    } catch (Exception e) {
      e.printStackTrace();
  private void run() {
    AvatarFactory avatarFactory = new PlayersAvatarFactory();
    System.out.println();
    System.out.println("==== PlayersAvatarFactoryTest ====");
    System.out.println("Welcome to my game!");
    Avatar player1 = avatarFactory.createAvatar();
    System.out.println();
    System.out.println("Player1: "+player1);
}It's "just a bit" more OOified than your version... and I changed random stuff, so you basically can't cheat ;-)
And look out for JSG's totally-over-the-top triple-introspective-reflective-self-crushing-coffeebean-abstract-factory solution, with cheese ;-)
Cheers. Keith.
Edited by: corlettk on 25/07/2009 13:38 ~~ Typo!
Edited by: corlettk on 25/07/2009 13:39 ~~ I still can't believe the morons at sun made moron a proscribed word.

Similar Messages

  • Need help creating text based game in Java

    Alright, I'm taking a big leap and I'm jumping a little out of league here. Anyways here are my two classes...I'm sure I've got plenty of errors :-/ One other thing. I have only programmed the battle section of the program so don't worry about the other 5 sections when fixing the code.
    import cs1.Keyboard;
    public class Knights
        public static void main (String[] args)
            // Object Declaration
            KnightsAccount player1 = new Account (1, 100, 200);
            // variable declarations
            boolean run = true;
            int choice;
            // Game Start
            System.out.println ("Welcome to Knights.");
            System.out.println ("--------------------------------------");
            System.out.println ("You are a level 1 character.  With 100 HP and 200 gold...good luck.");
            System.out.println ();
            while (run == true)
                System.out.println ();
                System.out.println ("Enter the number of the option you would like to do");
                System.out.println ();
                System.out.println ("1. Battle");
                System.out.println ("2. Train");
                System.out.println ("3. Work");
                System.out.println ("4. Rest");
                System.out.println ("5. Stats");
                System.out.println ("6. Quit");
                choice = Keyboard.readInt();
                if (choice == 1)
                    player1.battle();
                else if (choice == 2)
                    player1.train();
                else if (choice == 3)
                    player1.work();
                else if (choice == 4)
                    player1.rest();
                else if (choice == 5)
                    player1.stats();
                else
                    run = false;
    }And here is the second class...
    import java.util.Random;
    public class KnightsAccount
        public String winner;
        public int exp = 0;
        public void Account (int level, int hitPoints, int gold) {}
        public battle ()
            Random generator = new Random();
            int pumpkinHP = 80;
            int playerAttack, pumpkinAttack;
            System.out.println ("Engaged in combat with an Evil Pumpkin!");
            while (hitPoints > 0 && pumpkinHP > 0)
                if (pumpkinHP > 0)
                    playerAttack = generator.nextInt(15);
                    hitPoints -= playerAttack;
                    System.out.println ("Player 1 attacked Evil Pumpkin for " + playerAttack + ".");
                    System.out.println ("Evil Pumpkin has " + hitPoints + " HP left.");
                if (pumpkinHP <= 0)
                    pumpkinDead();
                if (hitPoints > 0 && !(pumpkinHP <= 0))
                    pumpkinAttack = generator.nextInt(12);
                    hitPoints -= pumpkinAttack;
                    System.out.println ("Evil Pumpkin attacked Player1 for " + pumpkinAttack + ".");
                    System.out.println ("Player 1 has " + pumpkinHP + " HP left.");
                if (hitPoints <= 0)
                    playerDead();
            return winner;
        private pumpkinDead ()
            System.out.println ("Success!  You have defeated the Evil Pumpkin with " + hitPoints + "HP left!");
            System.out.println ("For you good deed you earned 20 exp.");
            exp += 20;
            return exp;
        private void playersDead ()
            System.out.println ("You have been defeated.  Go home before we pelt melty cheeze at you.");
    }Whoever can help me I'd be grateful. I know there are probably a lot of things wrong here. Also if some of you could post your AIM or MSN so that I can get some one on one help on any of the smaller problems I run acrost that would help a lot too.
    Duke dollars to whoever helps me ;)
    AIM: Trebor DoD
    MSN: [email protected]

    You should really create a GameCharacter object that contains the
    statistics for a character (player or non-player) in the game.
    public class GameCharacter {
       private double attackStrength;
       private double defenseStrength;
       private String name;
       private String[] bodyParts;
       private Random = new Random();
    public GameCharacter(String name, String[] bodyParts, double attackSt, double defenseSt){
       this.attackStrength = attackSt;
       this.defenseStrength = defenseSt;
       this.bodyParts = bodyParts;
       this.name = name;
    // put lots of methods in here to get and set the information
    public String getName(){
      return this.name;
    public String getRandomBodyPart(){
       return this.bodyParts[random.nextInt(this.bodyParts.length)];
    }You then create your "knight" character and your "rabid pumpkin"
    character.
    Your fight method then just takes two GameCharacter objects and uses
    the information they contain to fight the battle.
    public void fight(GameCharacter a, GameCharacter b) {
       boolean fightOver = false;
       Random rn = new Random();
       double attackValue;
       while(!fightOver) {
           attackValue = a.getAttackStrength()*rn.nextDouble();
           System.out.println(a.getName()+" attacks "+b.getName()+"'s "+b.getRandomBodyPart()+" for "+attackValue+" points");
    }The above is not the fighting loop of course. I just put it in to
    demostrate how the fight method can be made generic. It takes any
    two characters and uses their defensive and attack information to
    calculate the fight outcome. It also uses the descriptions that the characters have
    to make the fight more interesting. (the getRandomBodyPart method in
    particular)
    matfud

  • How to make an a basic attack in my text based game

    hey guys! i really need some genuine help on how to create an attack for my monsters and player. the attack should be basic: if the room contains a monster, then the monster attacks when the player goes inside the room. then the player can type a command to attack the monster. the attack should just deduct the hp of the monster. so the player can keep attacking till the monster is "dead"(this is where i remove the monster).
    anyway i tried alot in creating the attack but i failed all the time, messing my code even more. please!!!!! help!!!
    my monster class:
    public class Monster
    private int hp, stage;
    private String name;
    public Monster(String name, int stage)
    this.name = name;
    this.stage = stage;
    if(stage == 1) {
    hp = 1;
    else if(stage == 2) {
    hp = 2;
    else if(stage == 3) {
    hp = 2;
    else if(stage == 4) {
    hp = 3;
    else if(stage == 5) {
    hp = 4;
    else if(stage == 6) {
    hp = 6;
    public int monsterStage()
    return stage;
    public String getName()
    return name;
    this is where i created the monsters in my main game class:
    private Monster skeleton, sphinx, zombie, vampire, werewolf, undeadking;
    setting the monster to a room:
    skeleton = new Monster("skeleton1", 1);
    skeleton = new Monster("skeleton2", 1);
    sphinx = new Monster("sphinx1", 2);
    sphinx = new Monster("sphinx2", 2);
    sphinx = new Monster("sphinx3", 2);
    zombie = new Monster("zombie", 3);
    vampire = new Monster("vampire1", 4);
    vampire = new Monster("vampire2", 4);
    werewolf = new Monster("werewolf", 5);
    undeadking = new Monster("undeadking", 6);
    //setting the monster to a place
    bridge.addMonster("skeleton1", skeleton);
    castleDoor.addMonster("sphinx1", sphinx);
    castleChest.addMonster("zombie", zombie);
    dungeonDoor.addMonster("sphinx2", sphinx);
    castleStair.addMonster("werewolf", werewolf);
    dungeonBridge.addMonster("vampire2", vampire);
    dungeonBook.addMonster("sphinx3", sphinx);
    dungeonChest.addMonster("skeleton2", skeleton);
    throneCenter.addMonster("undeadking", undeadking);
    ps.: please help me! each room has one monster only and they are stored in hashmaps

    Here is a start of a basic text based game--it doesn't level or regen characters nor give healing or have new weapons...
    package ForumJunk;
    import java.util.Random;
    import java.util.Scanner;
    public class ForumJunk{
      private final int widthX;
      private final int heightY;
      private int myX;
      private int myY;
      private int myLevel;
      private int baseHP;
      private int myHP;
      private int myTreasure;
      private String[] myWeapon = {"fist", "open hand", "dagger", "short sword", "long sword", "b-sword", "2H sword"};
      private int[] myWeaponMaxDamage = {2, 3, 4, 6, 10, 12, 16};
      private int monsterFillFactor = 40;
      private int[][] monsterLevel = {{1, 1, 1}, {2, 2, 2}, {3, 3, 3}};
      private String[][] monsterName = {{"Skeleton", "Orac", "Kobald"}, {"Zombi", "Wolf", "Giant Rat"}, {"Bandit", "Mummy", "Ghost"}};
      private int[] monsterMaxDamage = {2, 4, 6};
      private myRoom[][] room;
      private Random rand;
      public ForumJunk(){
        widthX  = 100;
        heightY = 100;
        myLevel = 1;
        rand = new Random();
        baseHP   = 16;
        myHP     = baseHP;
        for(int i=0; i<myLevel; i++) myHP = myHP + rand.nextInt(4) + 4;
        room = new myRoom[widthX][heightY];
        for(int i=0; i<widthX; i++)for(int j=0; j<heightY; j++)room[i][j]=new myRoom();
        myX = rand.nextInt(widthX);
        myY = rand.nextInt(heightY);
        myTreasure = 0;
        fillMonster();
      public void doAttack(){
        if(!(room[myX][myY].monster != null)){
          System.out.println("Oh, it must have been my shadow; there's no monsters here \n");
          return; //no monster
        if(rand.nextBoolean()){
         doHumanAttack();
         if(room[myX][myY].monster.hp > 0) doMonsterAttack();
        }else{
          doMonsterAttack();
          doHumanAttack();
      public void doHumanAttack(){
        int weaponIndex = 0;
        if(myLevel<myWeaponMaxDamage.length) weaponIndex = myLevel;else weaponIndex = myWeaponMaxDamage.length-1;
        System.out.println("Attacking with " + myWeapon[weaponIndex] + " ...");
        int damage = myLevel * rand.nextInt(myWeaponMaxDamage[myLevel]);
        room[myX][myY].monster.hp -= damage;
        if(damage>0) System.out.println("Hit for " + damage + " damage\n");
        else System.out.println("I missed!\n");
        if(room[myX][myY].monster.hp <= 0) System.out.println("The " + room[myX][myY].monster.name  + " is dead.");
      public void doMonsterAttack(){
        System.out.println("The " + room[myX][myY].monster.name  + " is attacking...");
        int damage = rand.nextInt(monsterMaxDamage[room[myX][myY].monster.level-1]);
        myHP -= damage;
        if(damage>0) System.out.println("I've been hit for " + damage + " damage\n");
        else System.out.println("It missed me!\n");
        if(myHP<=0){
          System.out.println("Oh no, I'm dead!!!!!");
          System.exit(0);
      public void doStatus(){
        System.out.println();
        System.out.println("  Status:");
        System.out.println("    Room: " + myX + ":" + myY);
        System.out.println("      HP: " + myHP);
        System.out.println("Treasure: " + myTreasure + " gp");
        System.out.println("   Level: " + myLevel);
        System.out.println();
      public void doTreasure(){
        if(!(room[myX][myY].monster != null)){
          System.out.println("What--do you expect it just to be laying around in every room? \n");
          return; //no monster
        if(room[myX][myY].monster.hp>0){
          System.out.println("If there is any treasure that " + room[myX][myY].monster.name + " is guarding it.\n");
          return; //no monster
        myTreasure += room[myX][myY].monster.treasure;
        System.out.println("I found " + room[myX][myY].monster.treasure + " gp\n");
        room[myX][myY].monster = null;
      public void fillMonster(){
        int fill = (widthX * heightY * monsterFillFactor) / 100;
        int x = 0;
        int y = 0;
        boolean gen = false;
        for(int i=0; i<fill; i++){
          gen = true;
          while(gen){
            x = rand.nextInt(widthX);
            y = rand.nextInt(heightY);
            if(!(room[x][y].monster != null)){
              room[x][y].monster = new Monster(rand.nextInt(3)+1);
              gen = false;
      class Monster{
        int level = 0;
        int hp   = 0;
        int treasure = 0;
        String name = "";
        Monster(int level){
          this.level = level;
          hp = 1;
          for(int i = 0; i<level; i++) {
            hp += rand.nextInt(6);
            treasure += rand.nextInt(100);
          name = monsterName[level-1][rand.nextInt(3)];
      class myRoom{
        Monster monster = null;
        //what ever else you want to put in here
      public static void main(String[] args){
        String myIN = "";
        Scanner scan = new Scanner(System.in);
        ForumJunk fj = new ForumJunk();
        System.out.print("I am in room: " + fj.myX + ", " + fj.myY + " I have " + fj.myHP + " hit points and " + fj.myTreasure + " treasure ");
        if(fj.room[fj.myX][fj.myY].monster!=null){
          System.out.println("There is a  " + fj.room[fj.myX][fj.myY].monster.name + " here!");
        System.out.println("\n");
        while(!(myIN=scan.next()).equals("exit")){
          if(myIN.equals("north")){
            fj.myY -=1;
            if(fj.myY<0) fj.myY=fj.heightY-1;
          }else if(myIN.equals("south")){
            fj.myY +=1;
            if(fj.myY==fj.heightY) fj.myY=0;
          }else if(myIN.equals("west")){
            fj.myX -=1;
            if(fj.myX<0) fj.myX=fj.widthX-1;
          }else if(myIN.equals("east")){
            fj.myX +=1;
            if(fj.myX==fj.widthX) fj.myX=0;
          }else if(myIN.equals("attack")){
            fj.doAttack();
          }else if(myIN.equals("weapon")){
            System.out.println("I'll be using my " + fj.myWeapon[fj.myLevel] + " to attack\n");
          }else if(myIN.equals("treasure")){
            fj.doTreasure();
          }else if(myIN.equals("status")){
            fj.doStatus();
        System.out.print("I am in room: " + fj.myX + ", " + fj.myY + " I have " + fj.myHP + " hit points and " + fj.myTreasure + " treasure ");
        if(fj.room[fj.myX][fj.myY].monster!=null){
          System.out.print("There is a ");
          if(fj.room[fj.myX][fj.myY].monster.hp<=0) System.out.print("dead ");
          System.out.println(fj.room[fj.myX][fj.myY].monster.name + " here!");
        System.out.println("\n");
      System.out.println("Bye!");
    }

  • Ideas For A Text-Based Game

    I tried working on Graphics a while ago, but I didn't have too much luck with that ;)
    Just wondering if anyone here has any ideas about a 'fun' text-based game, that wouldn't be really based on RPG style stuff, because I don't really want to bother with having characters save and stuff(I kno how to though...)
    Something like Rock/Paper/Siscors(spelling? lol), but kinda more adicting...oh right, forgot to tell you...idea for a MULTIPLAYER text-based game ;)
    Thanks
    -Been trying to think of a good idea all day, no luck ;)

    Think of an existing exciting game, and make a clone. Thinking of new games is hard.
    Scissors.
    Addicting.

  • Anybody know where I could download free text based games?

    Hi, I own a MacBook Pro that runs OS X 10.7.2, does anybody know a website were I could download free text based games? I would really appreciate it, and if any one knows another game, other than the command emacs -batch -l dunnet, that would be awesome too.
    Thanks, James

    You can't forget Zork I, II, III.   You need to download Boxer to run DOS games (in other words, don't download the Mac Version, because it needs to run in OS9 to work). You can also play it online just google it.
    Go south. 
    You have entered a forest with a tall tree.
    Climb tree. 
    You are at the top of the tree and you can see Cupertino off in the distance.  A troll followed you up the tree.
    Kill troll with sword. 
    Troll dies easily since it couldn't defend itself while climbing tree.
    Eat dead troll. 
    Nom nom.  Could have used a little salt.
    Message was edited by: OrangeMarlin

  • After the recent update I am having issues with Flash based games freezing and not responding.

    After the recent update I am having issues with flash based programs not running or loading correctly.  The programs will not load or take an extremely long time to load compared to jsut a few days ago.  This happens across the board on anything flash based.  Also, once they do load they will freeze, stop responding or need to be constantly refreshed to come back alive which is short lived at best.  I went thru the help and did all the file deleting, cache clearing, disabling hardware acceleration, removing then reinstalling flash, and even removing and reinstalling my browsers.  None of this has helped at all.  I am using Chrome and it is up to date and I checked my Flash player and it is up to date.  I am running windows 7 64bit.

    Here's what you're up against guys,
    Adobe writes the base code for Flash Player, and then hands it off to Google, who adapt it to a PPAPI plug-in (it's NPAPI when Adobe writes it). It's then "PepperFlash" and Google embeds it in their Chrome browser. While Google is pushing a "webwide" move to PPAPI Flash Content, a reinvention of the wheel so to speak, not everyone "got the memo", and Google is slowly making it so that PepperFlash will block NPAPI Flash content from running properly, and you have to disable PepperFlash to force the NPAPI plug-in to work, which sometimes fixes it, sometimes not. I have a feeling this is only going to get worse. HTML5 will eventually resolve the video end but game developers need to come up with something that won't require a plug-in.
    And to the first post:  Since PepperFlash is embedded in Chrome by Google, you can uninstall and reinstall Flash Player from here until your hard drive literally seizes up.... guess what? It has NO EFFECT at all on the PepperFlash plug-in in Chrome because it's a separate file in a separate folder and the uninstaller & installers don't have anything to do with it.

  • Please Help with text parsing problem

    Hello,
    I have the following text in a file (cut and pasted from VI)
    12 15 03 12 15 03 81 5 80053 1 1,2,3 $23.00 1 ^M
    12 15 03 12 15 03 81 5 84550 1 1,2,3 $15.00 1 ^M
    12 15 03 12 15 03 81 5 84100 1 1,2,3 $15.00 1 ^M
    12 15 03 12 15 03 81 5 83615 1 1,2,3 $15.00 1 ^M
    12 15 03 12 15 03 81 5 82977 1 1,2,3 $15.00 1 ^M
    12 15 03 12 15 03 81 5 80061 1 1,2,3 $44.00 1 ^M
    12 15 03 12 15 03 81 5 83721 1 1,2,3 $15.00 1 ^M
    12 15 03 12 15 03 81 5 84439 1 1,2,3 $44.00 1 ^M
    12 15 03 12 15 03 81 5 84443 1 1,2,3 $40.00 1 ^M
    12 15 03 12 15 03 81 5 85025 1 1,2,3 $26.00 1 ^M
    12 15 03 12 15 03 81 5 85008 1 1,2,3 $5.00 1 ^M
    this method reads the text from a file and stores it in a ArrayList
        public ArrayList readInData(){
            File claimFile = new File(fullClaimPath);
            ArrayList returnDataAL = new ArrayList();
            if(!claimFile.exists()){
                System.out.println("Error: claim data - File Not Found");
                System.exit(1);
            try{
                BufferedReader br = new BufferedReader(new FileReader(claimFile));
                String s;
                while ((s = br.readLine()) != null){
                         System.out.println(s + " HHHH");
                        returnDataAL.add(s);
            }catch(Exception e){ System.out.println(e);}
            return returnDataAL;
        }//close loadFile()if i print the lines from above ... from the arraylist ... here is waht i get ...
    2 15 03 12 15 03 81 5 80053 1 1,2,3 $23.00 1 HHHH
    HHHH
    12 15 03 12 15 03 81 5 84550 1 1,2,3 $15.00 1 HHHH
    HHHH
    12 15 03 12 15 03 81 5 84100 1 1,2,3 $15.00 1 HHHH
    HHHH
    12 15 03 12 15 03 81 5 83615 1 1,2,3 $15.00 1 HHHH
    HHHH
    12 15 03 12 15 03 81 5 82977 1 1,2,3 $15.00 1 HHHH
    HHHH
    12 15 03 12 15 03 81 5 80061 1 1,2,3 $44.00 1 HHHH
    HHHH
    12 15 03 12 15 03 81 5 83721 1 1,2,3 $15.00 1 HHHH
    HHHH
    12 15 03 12 15 03 81 5 84439 1 1,2,3 $44.00 1 HHHH
    HHHH
    12 15 03 12 15 03 81 5 84443 1 1,2,3 $40.00 1 HHHH
    HHHH
    12 15 03 12 15 03 81 5 85025 1 1,2,3 $26.00 1 HHHH
    HHHH
    12 15 03 12 15 03 81 5 85008 1 1,2,3 $5.00 1 HHHH
    HHHH
    I see the ^M on the end of the lines ... but i dont understand why im getting the blank lines
    in between each entry ... I printed "HHHH" just to help with debugging ... anyone have any ideas why i am getting the extra blank lines?
    thanks,
    jd

    maybe its a FileReader deal.. Im not sure, maybe try using InputStreams. This code works for me (it reads from data.txt), give it a try and see if it works:
    import java.io.*;
    public class Example {
         public Example() throws IOException {
              BufferedReader b = new BufferedReader(new InputStreamReader(new FileInputStream("data.txt")));
              String s = "";
              while ((s = b.readLine()) != null) {
                   System.out.println(s);
              b.close();
         public static void main(String[] args) {
              try {
                   new Example();
              catch (IOException e) {
                   e.printStackTrace();
    }

  • Need help with ending a game

    i'm making a game at the moment.......
    i need help with a way to check all the hashmaps of enimies in a class called room......i need to check if they all == 0...when they all equal zero the game ends......
    i know i can check the size of a hash map with size().....but i want to check if all the hashmaps within all the rooms == 0.

    First of all stop cross posting. These values in the HashMap, they are a "Collection" of values, so what is wrong with reply two and putting all these collections of values into a super collection? A collection of collections? You can have a HashMap of HashMaps. One HashMap that holds all your maps and then you can use a for loop to check if they are empty. A map is probably a bad choice for this operation as you don't need a key and an array will be much faster.
    HashMap [] allMaps = {new HashMap(),new HashMap()};

  • F4 Help with text table in WD abap

    Hi,
    i am using country related input help with check table T005 in one of table and i want to display the country text along with country id in my table, f4 for country is coming however if i select country from f4 it showing country id in the input field of table.
    i want to have country text also in one of my input fields in the table, i have seen f4 help works if we have explicit search help and using parameter assignment we can have id and text defaulted if we use same context for id and text fields,  however in this case country table t005 has check table t005 where texts are stored in text table t005t so web dynpro abap is't picking up the texts??
    please suggest how can i get the texts as soon as i select country in the f4??

    Hi Kranthi,
    You merely have to have an internal table storing list of countries, which you only need to do once, e.g. on load of application (method WDDOINIT of COMPONENTCONTROLLER). In your view, you have to declare a method for event onEnter of the input field, but this method doesn't have to have any code. Your code will be in method WDDOBEFOREACTION, where you read get country name from country key. Once you've got country name, transfer value to a context attribute to which you've already mapped as a source for attribute value of the UI element.
    Check out SAP Webdynpro component FITV_IMG_DEFHTLCATA -> view V_ITEM.

  • Help with Flex based popup windows and data population.

    Hello, I need a bit of help with Flex popups. I have a flex
    application that uses a popup window when you click on a button and
    displays information about the image above the button the user
    clicked. I have about 4 images and I need to be able to display
    information about each of them through the popup window when users
    click on the buttons below the image.
    At this time, I am trying to do this from somewhat of a
    "static" point of view because I do not believe my hosting company
    supports Flex Data services. You will find my code below.
    First File.
    <?xml version="1.0" encoding="utf-8"?>
    <!--Application Initialization -->
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute" width="850" height="750"
    cornerRadius="10" borderColor="#000000"
    backgroundGradientColors="[#1b3434, #000000]">
    <!-- Popup-->
    <mx:Script>
    <![CDATA[
    import mx.managers.PopUpManager;
    [Bindable]
    private var win:IMSAI;
    private function init():void{}
    private function createPopup():void{
    win=IMSAI(PopUpManager.createPopUp(this,IMSAI,true));
    win.title = 'IMSAI.Net';
    win.x = -500;
    win.y = 0;
    customMove.end();
    customMove.play();
    ]]>
    </mx:Script>
    <mx:Style>
    TitleWindow {
    borderStyle:solid;
    borderThickness:2;
    </mx:Style>
    <mx:Parallel id="customMove" target="{win}">
    <mx:Move duration="2000" xTo="{(stage.width - win.width)
    / 2}" yTo="{(stage.height - win.height) / 2}" />
    <mx:WipeDown duration="2000" />
    </mx:Parallel>
    This is the code to trigger the popup when a user clicks on
    the button. The code below is the code for the popup.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:TitleWindow xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="vertical" creationComplete="init()"
    close="PopUpManager.removePopUp(this)"
    showCloseButton="true" alpha=".8"
    headerColors="[#000000,#1F3F62]" color="#FFFFFF"
    minHeight="200" minWidth="300"
    backgroundColor="#000000" title="IMSAI.net" width="520"
    height="394" verticalAlign="middle" horizontalAlign="center">
    <mx:Script>
    <![CDATA[
    import mx.managers.PopUpManager;
    private function init():void{}
    ]]>
    </mx:Script>
    <mx:Canvas width="470" height="338">
    <mx:Image x="10" y="10" width="140" height="103">
    <mx:source>file:///C|/ColdFusion8/wwwroot/IMSAI/Web-App/Site_Images/IMSAI
    Final Movie.swf</mx:source>
    </mx:Image>
    <mx:Text x="10" y="121" text="Description:" width="75"
    height="25" fontWeight="bold" color="#ff0000"/>
    <mx:Text x="158" y="10" text="Client:" width="52"
    height="28" fontWeight="bold" color="#ff0000"/>
    <mx:Text x="196" y="10" text="IMSAI Microcomputers
    &amp; Fischer-Freitas Company" width="252" height="39"/>
    <mx:Text x="159" y="46" text="Industry:"
    fontWeight="bold" color="#ff0000"/>
    <mx:Text x="216" y="46" text="Computer &amp;
    Microcontroller Manufacturing." width="232" height="35"/>
    <mx:Text x="83" y="121" text="IMSAI.net is the front-end
    web application for IMSAI Computer " width="355"/>
    <mx:Text x="10" y="136" text="manufacturing, customer
    support, and order processing. Driven by a Microsoft database
    back-end, this application includes rich flash forms, site search
    capabilities, and flash content. Currently under phase II of a
    three phase development plan, the e-commerce logic and processing
    capabilities are under development. Once finished, this application
    will be able to process orders provide customers with instant order
    confirmation numbers, shipment dates, and payment processing."
    width="428"/>
    <mx:Text x="10" y="244" text="Technologies:"
    fontWeight="bold" color="#ff0000"/>
    <mx:Image x="100" y="244" width="50" height="50">
    <mx:source>file:///C|/ColdFusion8/wwwroot/Sapphire
    Development/content/cf8icon.jpg</mx:source>
    </mx:Image>
    <mx:Image x="244" y="244" width="50" height="50">
    <mx:source>file:///C|/ColdFusion8/wwwroot/Sapphire
    Development/content/flashlogo.jpg</mx:source>
    </mx:Image>
    <mx:Text x="53" y="290" text="Coldfusion 8 Enterprise"
    height="30"/>
    <mx:Text x="230" y="290" text="Adobe Flash 8"/>
    </mx:Canvas>
    What I want to do is either be able to create a popup file
    for each button and photo, or find a way to pass a name like a
    button ID that corresponds to a XML data structure and then
    provides the appropriate data for the photo. I have tried altering
    the first page of code with the "public" declaration to allow for a
    second popup file for each button and image, but the IDE won't
    allow me to do such because it creates errors stating I can only
    have one public declaration of the kind and function above per
    application. Help resolving this would be greatly appreciated.
    Thank you.

    I have an idea of what I want to do. I am just having
    difficulty articulating how to go about such. I know I want to find
    a way so that if a user clicks on button 1, button 1 will send some
    kind of variable. For example, a user clicks Btn1 under a picture.
    Btn1 sends some kind of variable or binding to a data structure
    which returns the picture's description, price, etc. and calls the
    popup to display that data in a form like manner. Then the user
    click Btn2 which does the same thing. The only purpose of the popup
    is to display the data.
    Do I create a data structure with a related name to say a
    button name so when the btn is clicked, the a variable title btn1
    will prepend itself to the data structure like
    {btn1.imagename}
    {btn1.price}
    {btn1.description}.
    I want each btn to call a different set of data about each
    picture because right now, the code I have is allowing me multiple
    buttons, but is just displays the popup. Is there a way to create a
    separate popup window for each button? Thats seems as though it
    would be easier. Thank you for your help.

  • New to After Effects - need help with text manipulation!

    Hi all, I'm new to AE and this forum and I'm looking for some advice. I've been asked by the boss at work to create a short video clip, around 10-15 seconds, where text is displayed on the screen (3 words), after the few seconds, I want a 'forging' noise to happen and the final word in the text to be changed to another word and have a metallic effect applied, similar to the effect in this tutorial:
    Create Hot Metallic Text in After Effects - After Effects - macProVideo.com Hub
    Will this be difficult to do and do you guys think a complete beginner like myself can do it? I've got a lot of experience with the likes of PS, so I'm not too shy with Adobe software.
    Thanks,
    John

    johnster1991 wrote:
    Thanks for the advice, I appreciate it. So will it be difficult to have one word of text come onto the screen and overlay on top of the existing text, as if it's crashing over it? Any ideas on the steps I would use to do this? Thanks
    As you begin your career of using AE, you will change your vocabulary. Overlay will be replaced with spatial references like in front or behind.
    Designing text with surface styles like chrome or metal is not difficult. You can even import them from Photoshop if you have some PS chops or friends who can do it quickly.
    TEXT ONE can be easily replaced with TEXT TWO in any of dozens of different ways but to drop TWO in front of ONE is easy, you're just setting position keyframes. The finesse of animation, though, lies in the illusion of motion, exaggeration, overshooting and recoil. Your TWO could fall and squish and rebound and bounce or it could raise a dust cloud as it hits or it could make the camera wiggle. These are the things that separate simple key framing from animation and motion graphics.

  • 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();
    }                  

  • Need a little help with a trivia game

    Hey guys I was wondering if I could get some help. I'm taking a class at school for java programming and its my first class. And I have to do a final assignment, which is to make a java trivia game. I have all the parts coded already pretty sure. Now be forewarned that I'm not "that" great at programming.
    But the part that I'm stuck on and cant really get any help on is this: For the game I need to have a file with all the questions and answers, which is created already and works. The file writer has the question, choice 1, choice 2, choice 3, choice 4 and the answer written to it, in that order. We needed to implement a GUI and I coded that as a message label on top where the question will go, in the middle 4 radio buttons where the choices to the answer will go and on the bottom a next question, ok and quit button.
    My question is this: How do I pull the information from the file that was written to appear in the GUI, such as the question and the choices for the answers for the question? ANY and ALL help would be appreciated

    Read the information using a BufferedReader wrapped around a FileReader. Change your GUI using setText on the component you want to display the text.
    Edit: An example that does both things
    import java.io.*;
    import javax.swing.*;
    public class FileAndSwing {
       public static void main(String[] args) throws Exception {
          BufferedReader reader = new BufferedReader(
                new FileReader("FileAndSwing.java"));
          StringBuilder builder = new StringBuilder();
          for ( String line = null; (line = reader.readLine()) != null; ) {
             builder.append(line).append("\n");
          JFrame frame = new JFrame("FileAndSwing.java");
          frame.setSize(500, 500);
          JTextArea field = new JTextArea();
          frame.add(field);
          field.setText(builder.toString());
          frame.setVisible(true);
    }This is also kind of a Quine :-).
    Edited by: endasil on 15-Dec-2009 4:00 PM

  • Need help with Connect 4 game, IndexOutOfRangeException was unhandled

    Hi! I've been struggling with this for a while now, the issue is that as soon i move a game piece to the field i get this errorats "IndexOutOfRangeException was unhandled" and i don't know why since my intention with the code was to use for loops
    look through the 2D array thats based on two constants: BOARDSIZEx = 9 and BOARDSIZEy = 6. Instead of traditional 7*6 connect 4 grid i made it 9 squares wide due to having pieces on the side to drag and drop.
    Here's the code for my checkwin:
    public bool checkWin(Piece[,] pieceArray, bool movebool)
    bool found = false;
    //Horizontal
    for (int i = 0; i < BOARDSIZEx - 3; i++)
    for (int j = 0; j < BOARDSIZEy; j++)
    if ((pieceArray[i, j] != null)
    && (pieceArray[i, j] == pieceArray[i, j + 1])
    && (pieceArray[i, j] == pieceArray[i, j + 2])
    && (pieceArray[i, j] == pieceArray[i, j + 3]))
    if (pieceArray[i, j].IsStarter != movebool)
    found = true;
    goto Done; //interesting way of getting out of nested for loop
    //for more on goto: http://stackoverflow.com/questions/324831/breaking-out-of-a-nested-loop
    //Vertikal
    for (int i = 0; i < BOARDSIZEx; i++)
    for (int j = 0; j < BOARDSIZEy - 3; j++)
    if ((pieceArray[i, j] != null)
    && (pieceArray[i, j] == pieceArray[i + 1, j]) && (pieceArray[i, j] == pieceArray[i + 2, j])
    && (pieceArray[i, j] == pieceArray[i + 3, j]))
    if (pieceArray[i, j].IsStarter != movebool)
    found = true;
    goto Done; //interesting way of getting out of nested for loop
    //for more on goto: http://stackoverflow.com/questions/324831/breaking-out-of-a-nested-loop
    //Diagonal, Lower left to upper right
    for (int i = 0; i < BOARDSIZEx - 3; i++)
    for (int j = 0; j < BOARDSIZEy - 3; j++)
    if ((pieceArray[i, j] != null)
    && (pieceArray[i, j] == pieceArray[i + 1, j +1])
    && (pieceArray[i, j] == pieceArray[i + 2, j + 2])
    && (pieceArray[i, j] == pieceArray[i + 3, j + 3]))
    if (pieceArray[i, j].IsStarter != movebool)
    found = true;
    goto Done; //interesting way of getting out of nested for loop
    //for more on goto: http://stackoverflow.com/questions/324831/breaking-out-of-a-nested-loop
    //Diagonal, upper left to lower right
    for (int i = 0; i >= BOARDSIZEx; i--)
    for (int j = 0; j < BOARDSIZEy - 3; j++)
    if ((pieceArray[i, j] != null)
    && (pieceArray[i, j] == pieceArray[i - 1, j + 1])
    && (pieceArray[i, j] == pieceArray[i - 2, j + 2])
    && (pieceArray[i, j] == pieceArray[i - 3, j +3]))
    if (pieceArray[i, j].IsStarter != movebool)
    found = true;
    goto Done; //interesting way of getting out of nested for loop
    //for more on goto: http://stackoverflow.com/questions/324831/breaking-out-of-a-nested-loop
    Done:
    return !found;
    It's at the vertical check that the error occurs and also my checkwin doesnt seem to respond to the call in the game.cs code.
    //check for win
    bool moveBool = true; //returns yes or no depending on whether both players have moved their pieces
    if (move % 2 == 0) moveBool = false;
    bool win = rules.checkWin(pieceArray, moveBool);
    //The game is won!
    if (win)
    string winningPlayerName = player1.Name; //creating a new player instance, just for shortening the code below
    if (moveBool == false) winningPlayerName = player2.Name; //if it was player 2 who won, the name changes
    message = winningPlayerName + " has won the game!\n\n"; //The name of the player
    Board.PrintMove(message); //Print the message
    if (moveBool == true) player1.Score += 1; else player2.Score += 1; //update score for the players
    //The player's labels get their update texts (score)
    Board.UpdateLabels(player1, player2);
    //Here, depending on what one wants to do, the board is reset etc.
    else
    move++; //draw is updated
    And here's a picture on how it looks like at the moment.
    Thanks in Advance!
    Student at the University of Borås, Sweden

    for (int i = 0; i < BOARDSIZEx; i++) // If BOARDSizex is the number of elements in the first dimension...
    for (int j = 0; j < BOARDSIZEy - 3; j++)
    if ((pieceArray[i, j] != null)
    && (pieceArray[i, j] == pieceArray[i + 1, j]) && (pieceArray[i, j] == pieceArray[i + 2, j])
    && (pieceArray[i, j] == pieceArray[i + 3, j])) // Then [i + anything, j] will be out of range.
    You probably meant to add the one, two, or three to the j rather than the i.

  • Help with completing sentences game code

    Hi, I`m a bit stuck, I`m making a game where you have to complete the sentences by dragging the words which are generated dinamically to its right place over some boxes, everything works fine but if you pull the words out of the boxes one all are placed it crashes.
    Unfortunately this is someone elses code (another programmer who bailed on us in the middle of the proyect) although I manage to make it work with new words, making the draggable items undraggable one you place all 4 of them in the right boxes is totally unclear to me. I`ll appreciate any help I can get.
    Here`s all the code that this part of the movie is using:
    function aleatorio(min, max)
        var _loc2 = true;
        if (usados.length <= max - min)
            while (_loc2 != false)
                var _loc1 = Math.floor(Math.random() * (max - min + 1));
                _loc2 = repetido(_loc1);
            } // end while
            usados.push(_loc1);
            return (_loc1);
        else
            return (0);
        } // end else if
    } // End of the function
    function repetido(num)
        var _loc1 = false;
        for (i = 0; i < usados.length; i++)
            if (num == usados[i])
                _loc1 = true;
            } // end if
        } // end of for
        return (_loc1);
    } // End of the function
    stop ();
    var usados = new Array();
    _root.palabras_colocadas = 0;
    palabras_correctas = 0;
    listado_x = 700;
    listado_y = 400;
    origenx = 0;
    origeny = 0;
    estaba_en = -1;
    apagar = false;
    _root.frase = 2;
    var palabras = new Array("huts", "made", "mud", "straw");
    var correctas = new Array(false, false, false, false);
    var ocupadas = new Array(-1, -1, -1, -1);
    var my_font = new TextFormat();
    my_font.font = "Arial";
    my_font.color = 0;
    my_font.size = 30;
    palabras[i].embedFonts = true;
    my_font.bold = true;
    var i = 0;
    while (i < 4)
        this["cuadro" + i].gotoAndStop(1);
        this.createEmptyMovieClip("myClip" + i, this.getNextHighestDepth());
        largo = palabras[i].length * 22;
        this["myClip" + i].createTextField("label", 1, 0, 0, largo, 40);
        this["myClip" + i].label.text = palabras[i];
        this["myClip" + i].label.setTextFormat(my_font);
        this["myClip" + i].onPress = function ()
            temp = this._name;
            temp = Number(temp.charAt(6));
            if (ocupadas[0] == temp)
                apagar = true;
                estaba_en = 0;
            } // end if
            if (ocupadas[1] == temp)
                apagar = true;
                estaba_en = 1;
            } // end if
            if (ocupadas[2] == temp)
                apagar = true;
                estaba_en = 2;
            } // end if
            if (ocupadas[3] == temp)
                apagar = true;
                estaba_en = 3;
            } // end if
            if (!apagar)
                estaba_en = -1;
            } // end if
            origenx = this._x;
            origeny = this._y;
            trace ("estaba en " + estaba_en);
            this.startDrag();
        this["myClip" + i].onRelease = this["myClip" + i].onReleaseOutside = function ()
            this.stopDrag();
            cual = this._name;
            cual = Number(cual.charAt(6));
            drop = eval(this._droptarget);
            trace (drop);
            donde = String(drop);
            cuadro = donde.substr(8, 6);
            donde = Number(donde.charAt(14));
            trace (cual + " en " + donde + " " + cuadro);
            if (cuadro == "cuadro")
                if (ocupadas[donde] >= 0 && ocupadas[donde] <= 3 || donde == estaba_en)
                    apagar = false;
                    this._x = origenx;
                    this._y = origeny;
                else
                    if (!apagar)
                        ++_root.palabras_colocadas;
                    } // end if
                    tramo = eval("tramo" + (donde + 1) + "_mc");
                    tramo.gotoAndPlay(2);
                    if (_root.palabras_colocadas >= 4)
                        startbtn.start();
                        start_mc.gotoAndPlay(2);
                    else
                        palabra_ok.start();
                    } // end else if
                    largo = palabras[cual].length * 8.500000E+000;
                    drop.gotoAndStop(2);
                    this._y = drop._y - 22;
                    this._x = drop._x - largo;
                    ocupadas[donde] = cual;
                    if (apagar)
                        apaga = eval("cuadro" + estaba_en);
                        apaga.gotoAndStop(1);
                        tramo = eval("tramo" + (estaba_en + 1) + "_mc");
                        tramo.gotoAndPlay(6);
                        ocupadas[estaba_en] = -1;
                        correctas[estaba_en] = false;
                        apagar = false;
                        trace ("hay " + _root.palabras_colocadas + " palabras");
                        if (_root.palabras_colocadas == 3)
                            trace ("apaga sin ruido");
                            start_mc.gotoAndStop(1);
                        } // end if
                    } // end if
                    trace (ocupadas[0] + " " + ocupadas[1] + " " + ocupadas[2] + " " + ocupadas[3]);
                    if (cual == donde)
                        ++palabras_correctas;
                        correctas[donde] = true;
                    } // end if
                } // end if
            } // end else if
            if (cuadro == "myClip" || cuadro == "start_")
                palabra_error.start();
                this._x = origenx;
                this._y = origeny;
            } // end if
            if (cuadro == "fondo")
                if (apagar)
                    apaga = eval("cuadro" + estaba_en);
                    apaga.gotoAndStop(1);
                    tramo = eval("tramo" + (estaba_en + 1) + "_mc");
                    tramo.gotoAndPlay(6);
                    ocupadas[estaba_en] = -1;
                    correctas[estaba_en] = false;
                    --_root.palabras_colocadas;
                    apagar = false;
                    trace ("hay " + _root.palabras_colocadas + " palabras");
                    if (_root.palabras_colocadas == 3)
                        startbtn.start();
                        start_mc.gotoAndStop(1);
                    } // end if
                } // end if
            } // end if
        ++i;
    } // end while
    var ii = 0;
    while (ii < 4)
        var numeroNuevo = aleatorio(1, 4);
        trace (numeroNuevo);
        this["myClip" + numeroNuevo]._x = listado_x;
        this["myClip" + numeroNuevo]._y = listado_y + 40 * i;
        ++ii;
    } // end while

    that's too much code to go through line by line.  i'd recommend placing some trace() functions in strategic locations to narrow the location of the problem.

Maybe you are looking for