2013-09-29 2 views
-4

и мне нужна помощь по этому проекту Я занимаюсь в классе. Вот, что у меня есть!Создание оружия Игра вещь

public class Game { 

public static void main(String[] args) { 
     // TODO Auto-generated method stub 
     int Naruto = 0; 
     int DragonBallZ = 1; 
     int Batman = 0; 
     int Freedom = 0; 
     int righthand = 1; 
     int lefthand = 1; 

     if (Naruto == 0) { 
      if (lefthand == 0) { 
       System.out.println("The command 0 has been used..."); 
       System.out.println("Processing..."); 
       System.out.println("Accessing Game Server..."); 
       System.out.println("Success!"); 
       System.out.println("You have been given the 'Kunai'"); 
      } else if (righthand == 1) { 
       System.out.println("The command 1 has been used..."); 
       System.out.println("Processing..."); 
       System.out.println("Accessing Game Server..."); 
       System.out.println("Success!"); 
       System.out.println("You have been given the 'Shurikan'"); 
      } 
      if (DragonBallZ == 1) { 
       if (lefthand == 0) { 
        System.out.println("The command 2 has been used..."); 
        System.out.println("Processing..."); 
        System.out.println("Accessing Game Server..."); 
        System.out.println("Success!"); 
        System.out.println("You have been given the 'Kaioken' Ability"); 
       } else if (righthand == 1) { 
        System.out.println("The command 3 has been used..."); 
        System.out.println("Processing..."); 
        System.out.println("Accessing Game Server..."); 
        System.out.println("Success!"); 
        System.out.println("You have been given the 'Super Saiyan 4'  Ability"); 
       } 
       if (Batman == 2) { 
        if (lefthand == 0) { 
         System.out.println("The command 4 has been used..."); 
         System.out.println("Processing..."); 
         System.out.println("Accessing Game Server..."); 
         System.out.println("Success!"); 
         System.out.println(" You have been given the 'Batarang' "); 
        } else if (righthand == 1) { 
         System.out.println("The command 5 has been used..."); 
         System.out.println("Processing..."); 
         System.out.println("Accessing Game Server..."); 
         System.out.println("Success!"); 
         System.out.println(" You have been given the 'Keen Eyes'  Ability"); 
        } 
        if (Freedom == 3) { 
         if (lefthand == 0) { 
          System.out.println("The command 6 has been used..."); 
          System.out.println("Processing..."); 
          System.out.println("Accessing Game Server..."); 
          System.out.println("Success!"); 
          System.out.println(" You have been given the 'Rope' "); 
         } else if (righthand == 1) { 
          System.out.println("The command 7 has been used..."); 
          System.out.println("Processing..."); 
          System.out.println("Accessing Game Server..."); 
          System.out.println("Success!"); 
          System.out.println(" You have been given the 'Knife' "); 
         } 
        } 
       } 
      } 
     } 
    } 
} 

Так что, если кто-нибудь может мне помочь, я пытаюсь сделать 4 игры, и каждая игра имеет 2 оружия. Когда я запускаю программу, мне нужно 1 оружие для этой игры. Я продолжаю получать результат всех игр этого номера оружия. Поэтому, если кто-то может помочь, это было бы потрясающе! Благодаря!

  • Редактировать - Я также использую Eclipse для java-программы!
+0

Ваш дизайн действительно плохой. Код становится длинным и неудобным (как вы можете видеть). Также этот вопрос не удовлетворяет требованиям stackcoverflow, поэтому он будет закрыт, вероятно, (если вы не отредактируете его в форме соответствующего вопроса). – Kayaman

+0

Что это означает ** если ** DragonBallZ'''''? Это выбор? Что это означает **, если «Бэтмен» - «2»? Что было бы иначе, если бы там, где «1» или «-1»? Помимо других проблем (* массивное дублирование кода является одним), это, по-видимому, представляет собой концептуальную сложность, которая у вас есть. Я даже не могу дать вам подсказки о том, как это должно выглядеть так, потому что я не понимаю, что означают эти переменные. –

+0

Мне жаль, Кайаман, если он длинный, но мой учитель хочет, чтобы я сделал его как настоящую игру, если она есть. – HexDust

ответ

0

Даже если ваш вопрос не так ясно, я полагаю, что вы ожидаете, что ваш код возврата

Команда 1 была использована ...

Processing ...

Доступ к игровому серверу ...

Успех!

Вы дали «» Shurikan

Это не происходит, потому что вы вложенности ваши различные виды игры.

Вы должны использовать заявление else-if при переходе от «Наруто» к «DragonballZ».

Вот фиксированный код, надеясь, что я понял ваш вопрос.

public class Game { 

    public static void main(String[] args) { 
     // TODO Auto-generated method stub 
     int Naruto = 0; 
     int DragonBallZ = 1; 
     int Batman = 0; 
     int Freedom = 0; 
     int righthand = 1; 
     int lefthand = 1; 

     if (Naruto == 0) { 
      if (lefthand == 0) { 
       System.out.println("The command 0 has been used..."); 
       System.out.println("Processing..."); 
       System.out.println("Accessing Game Server..."); 
       System.out.println("Success!"); 
       System.out.println("You have been given the 'Kunai'"); 
      } else if (righthand == 1) { 
       System.out.println("The command 1 has been used..."); 
       System.out.println("Processing..."); 
       System.out.println("Accessing Game Server..."); 
       System.out.println("Success!"); 
       System.out.println("You have been given the 'Shurikan'"); 
      } 
     } else if (DragonBallZ == 1) { //Changed if to else if 
      if (lefthand == 0) { 
       System.out.println("The command 2 has been used..."); 
       System.out.println("Processing..."); 
       System.out.println("Accessing Game Server..."); 
       System.out.println("Success!"); 
       System.out.println("You have been given the 'Kaioken' Ability"); 
      } else if (righthand == 1) { 
       System.out.println("The command 3 has been used..."); 
       System.out.println("Processing..."); 
       System.out.println("Accessing Game Server..."); 
       System.out.println("Success!"); 
       System.out.println("You have been given the 'Super Saiyan 4'  Ability"); 
      } 
     } else if (Batman == 2) { //Changed if to else if 
      if (lefthand == 0) { 
       System.out.println("The command 4 has been used..."); 
       System.out.println("Processing..."); 
       System.out.println("Accessing Game Server..."); 
       System.out.println("Success!"); 
       System.out.println(" You have been given the 'Batarang' "); 
      } else if (righthand == 1) { 
       System.out.println("The command 5 has been used..."); 
       System.out.println("Processing..."); 
       System.out.println("Accessing Game Server..."); 
       System.out.println("Success!"); 
       System.out.println(" You have been given the 'Keen Eyes'  Ability"); 
      } 
     } else if (Freedom == 3) { //Changed if to else if 
      if (lefthand == 0) { 
       System.out.println("The command 6 has been used..."); 
       System.out.println("Processing..."); 
       System.out.println("Accessing Game Server..."); 
       System.out.println("Success!"); 
       System.out.println(" You have been given the 'Rope' "); 
      } else if (righthand == 1) { 
       System.out.println("The command 7 has been used..."); 
       System.out.println("Processing..."); 
       System.out.println("Accessing Game Server..."); 
       System.out.println("Success!"); 
       System.out.println(" You have been given the 'Knife' "); 
      } 
     } 
    } 
} 

Пожалуйста, имейте в виду, что даже если я отвечаю, это не правильный способ использования этого сайта!

+0

Спасибо! это помогло И нормально – HexDust

Смежные вопросы