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?

Edited 6 Years Ago by NormR1: n/a

!- 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?

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.

This article has been dead for over six months. Start a new discussion instead.