Help with War game in Java

Asked

Viewed 80 times

-1

I am trying to make a game of War in java where the game map is a simple vector of 1 to 16 each number being a country, I made a Random to draw the player the country he will start, but how to assign it to the Player without I have to do 16 if’s?

   public class Mundo {



    int sensalia = 1;
    int kemia = 2;
    int sema = 3;
    int kardia = 4;
    int torkuha = 5;
    int ohistet = 6;
    int baselia = 7;
    int dottinia = 8;
    int zellzach = 9;
    int freusen = 10;
    int sinusia = 11;
    int kuclasia = 12;
    int phlius = 13;
    int plasisia = 14;
    int dorumia = 15;
    int cresonia = 16;


    public int nacaoMae(){
     Random rand = new Random(16 + 1);

     int result = rand.nextInt();


  }
}
  • Why, instead of creating a variable for a country, you don’t create a string array and assign the vector index?

  • What is the player limit? What is the limit for each country?

1 answer

0


Place all Countries in a String vector, after generating a random number, you take the index of the vector as if it were the number you set for each Country..

For example:

your result gave 3; then: EXEMPLO

The country awarded to the player would be KARDIA.

jogador = vetor[result];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.