Hello! guys,
I am developing a java game, "the rabbit, turtle, bird," I have a small problem, I do not know how to put attributes to the objects created, for example, a goal of 60 feet, the turtle walks " shift "of 4-8 meters, 6-12 rabbit, but has a 60% chance falling asleep from lack of energy and lose two turns. and the bird moves from 9 to 16 spaces per shift but has a 45% chance to rest and lose three turns and 25% of feeding and losing four shifts., 60% falling asleep from lack of energy and lose two turns. Finally you have obtáculos for the rabbit and the bird, they will lose a turn, and the tortoise is not affected by OBSTACLES,

What do you recommend to make this work? How I can work the thread objects, the attributes of each object?

I'm working on this example.

public class Ejemplo21 {

    static Animal tortuga;

    static Animal liebre;

    static Animal pajaro;

    public static void main(String argv[])

        throws InterruptedException {

            tortuga = new Animal(2, "TORTUGA  ");

            liebre = new Animal(4, "LIEBRE  ");

            pajaro = new Animal(10, "PAJARO  ");


            tortuga.start();

            liebre.start();

            pajaro.start();



            
            
}

}

class Animal extends Thread {

        String nombre;

        public Animal(int prioridad, String nombre) {

        this.nombre = nombre;

        setPriority(prioridad);

        }

            @Override
        public void run() {

        for (int x = 0; x < 30; x++) {

      

        yield();

        }

        System.out.println("\nLlega a meta "+nombre );

        }


        }

thanks a lot, for the people than showl be helme!!!

How is the game played? Does each animal take a turn until one of them reaches the goal?
Is there any user interaction with the program or does it run by itself?
Would the percentages be part of the computation for an animal's move?

!- How is the game played? Does each animal take a turn until one of them reaches the goal?

yes, the user selects an animal, and each turn, will be a kind wheel that tells the animal as moving spaces, of course! magic dice, maybe, but only the chosen animal, you can spin the wheel, the other makes automatic

Would the percentages be part of the computation for an animal's move?

i think so, like a random, because, do you not know if the animal are tired o whitg hungri, in bird case,
for that reason is the percentage!

Your code shows that all the animals are started at one time.
Is the right? They all start together and run until one wins?
Where does the user interact with the animals?

I'm not sure how your threads with the loop and the yield() are supposed to work.
I would think that the model would be for each animal to do its moving for a fixed amount of time and then plot where each animal was after that time had passed. Then do it again and again until done. Say every 5 seconds plot where each animal is. Then again and again. Using threads means that some animals might not get any time to move while others get all they want. That doesn't sound like a normal race where all the contestants start at the same time and move at the same time.

the user interacts only when the turn of the selected animal (on the part of throwing the dice or roulette, only), but only the turtle not affected by fatigue, hunger, or the obstacles, in short, all move in turn, once the user turned her wheel movements, but the case of the rabbit and the bird, which affects their abstaculos are random, and hunger and fatigue. shifts lost

you understand me?

you can read in spanih?

Sorry, I only know a few words of Spanish. You'll have to use English.
Have you tried the Google Translator. It does a pretty good job.

see the document, the format is .doc

i am read manuals and turorials, but the information is not clear, if can help. thanks a lot!!

You are provided with two examples named threadRunExample and Example2 including
the basic functionality of threads creation and manipulation. You are encouraged to

understand it and then try to modify it by implementing following up-gradation:
 Turtle covers 2m in 1sec and rabbit covers 5m in 1sec.
 Declare a variable distanceCovered in thread class (where function run is defined). This
variable would denote the total distance covered by instances of thread class (in your case
the turtle and the rabbit).
 Modify the code and make rabbit fall asleep after covering 15m of distance as rabbit is fast
and proudy.  Meanwhile, turtle would cross rabbit and reach finish line. When the rabbit wakes up, it
would see turtle crossed the finish line.
wh

[BONUS]

 To get extra credit, also share a common variable between these two instances of thread
class which would be the distance till finish line. Get value of this variable from user and see
who wins in that case. You may also ask user to decide distance covered by either turtle or
rabbit and after how many distance, the rabbit should be fallen asleep. This is all for bonus
marks. But the basic functionality asked above must be achieved.

commented: Why 10 years later? -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.