2016-09-13 3 views
0

私は楽しんでいるアニメに基づいてカードゲームに変身するテキストアドベンチャーを作りました。基本的には、私の長年にわたる長いテキストをプライベート静的ボイドに移動して、メインメソッドをクリーンアップしました。まず最初に、これは最善の方法ですか?第二に、それは私の主な質問です、私は彼の名前のためにユーザーに尋ねる公的な静的な文字列jojiFunaiで。しかし、私はこの変数をコードの残りの部分で使いたいのですが、どうすればよいでしょうか?申し訳ありませんが、これは一口です、私はちょうどどこに行くのか分かりません。メソッドから変数を取り出す方法

import java.util.Scanner; 
    import java.util.Random; 

    public class Ecard { 

    public static void main(String[] args) { 
     Scanner intKeyboard = new Scanner(System.in); 
     boolean emperor = false; 
     boolean slave = false; 

     // Player 1 Deck 
     int emperorPlayer1 = 1; 
     final int citizenPlayer1 = 4; 
     // Player 2 Deck 

     // opening options 

     // activates which deck player chooses 
     // boolean emperor= false, slave= false; 

     int deckChoice; 

     wakeUp(); 
     jojiFunai(); 

     System.out.println(name); 
     gameRules(); 
     deckChoice(); 
//This portion will be turned into a class Deck 
//  Random computer = new Random(); 
// 
//  while (emperor = true && emperorPlayer1 != 0) { 
//   System.out.println("What card will you put down ?"); 
//   System.out.println("Options: \n 1. emperor card(" + emperorPlayer1 
//     + ")"); 
//   System.out.println("2. citizen card(" + citizenPlayer1 + ")"); 
//   int computerChoice = computer.nextInt(2) + 1; 
//   deckChoice = intKeyboard.nextInt(); 
//   if (deckChoice == 1) { 
//    emperorPlayer1--; 
//    System.out.println("You have placed a emperor card down."); 
//    if (deckChoice == computerChoice) { 
//     System.out.println("It looks like you just lost,HAHAHA"); 
       } 
      } 
     } 

     // This will talk about the rules of each deck and what deck has 
     // what 
     // final int emperorPlayer1 = 1; 
     // final int citizenPlayer1 = 4; 
     // Player 2 Deck 
     // final int slavePlayer2 = 1; 
     // final int citizenPlayer2 = 4; 
     // 

    } 

    private static void wakeUp() { 
     System.out.println("You awaken at the sound of your alarm clock," 
       + " do you go turn off the alarm? Y/N"); 
     Scanner keyboard = new Scanner(System.in); 
     String alarm = keyboard.nextLine(); 
     if (alarm.equalsIgnoreCase("y")) { 
      System.out.println("As you hit the awake button you hear the" 
        + " sound of knocking at your front door."); 
     } else if (alarm.equalsIgnoreCase("n")) { 
      System.out.println("You hit the snooze button" 
        + " and fall back into a deep sleep," 
        + " avoiding what would have happened next. END"); 
      System.exit(0); 

     } 

    } 

    public static String jojiFunai() { 
     Scanner keyboard = new Scanner(System.in); 
     Scanner intKeyboard = new Scanner(System.in); 
     System.out`enter code here` 
       .println("As you reach for the door, you are suddenly hit from behind......"); 
     System.out 
       .println("You hear the faint words coming from the figure 'We have him, we are talking him to the boat', darkness however surrounds you. "); 
     System.out 
       .println("................................................................"); 
     System.out 
       .println("................................................................"); 
     System.out 
       .println("................................................................"); 
     System.out 
       .println("................................................................"); 
     System.out.println("'Hey buddy, wake up!!!!'"); 
     System.out.println("'Hey im talking to you! What is your name?'"); 
     String name = keyboard.nextLine(); 
     System.out 
       .println("'Nice to meet you " 
         + name 
         + ". My name is Joji Funai and from what those people told me," 
         + " looks like your my opponent for the card game we will be playing.'"); 
     System.out.println("OPTIONS:"); 
     System.out.println("1. Where am I?"); 
     System.out.println("2. Refuse."); 
     System.out.println("3. Accept."); 
     int funaiQuestion = intKeyboard.nextInt(); 
     switch (funaiQuestion) { 
     case 1: 
      System.out 
        .println("Your in a ship, seems that you signed a contract in which you failed to uphold, the only way you can pay up is through gambling.. so lets get started."); 
      break; 
     case 2: 
      System.out 
        .println("I wish you didnt say that' Joji instantly pulls out a pistol ending your life before you knew what happened"); 
      System.exit(0); 
     case 3: 
      System.out 
        .println("Without asking any questions? Someone has some confidence, I like that! now let me explain the rules...."); 
      break; 

     } 
     return name; 

    } 

    private static void gameRules() { 
     System.out.println("///////////////////////////////GAME" 
       + " RULES//////////////////////////////////////////////////"); 

     System.out.println("'This game is called E-Card, each player" 
       + " takes turns playing three rounds" 
       + " on the 'emperor' side and the 'slave' side.'"); 
     System.out.println("The game is starts with each player holding" 
       + " five cards, four of which are Citizens" 
       + " and the last being either a Slave or an Emperor." 
       + " Who holds which card is decided beforehand," 
       + " and is played like that for three turns before switching."); 
     System.out.println("The game lasts for a total of twelve turns," 
       + " meaning each side gets to play Emperor twice. "); 
     System.out.println("The players choose one card from their hand" 
       + " and place them face-down on the table." 
       + " They are then flipped over to reveal the winner " 
       + "of the match.The three card types are Citizen," 
       + " Emperor and Slave."); 
     System.out.println("The Citizen card represents the common man," 
       + " and cannot defeat the Emperor who sits at" 
       + " the top. It can, however, defeat the Slave," 
       + " who resides at the very bottom of the system." 
       + " Two citizen against each other results in a tie."); 
     System.out.println("The Emperor represents the one at the top of" 
       + " society. This card can defeat the citizen," 
       + " but will lose to the Slave."); 
     System.out.println("The Slave is presented as the one at the very" 
       + " bottom of society. Seeing as how it has nothing" 
       + " to lose, it can overthrow the Emperor in one last" 
       + " attempt at revenge. This card will lose to a Citizen," 
       + " but will win against the Emperor card."); 
     System.out.println("//////////////////////////////////////////////" 
       + "GAME RULES///////////////////////////////////"); 

     System.out.println("Sorry for being so long winded, anyways, ill let" 
       + " you choose first, would you like the \n 1.emperor" 
       + " deck or the \n 2.slave deck?"); 

    } 

    private static void deckChoice() { 
     Scanner intKeyboard = new Scanner(System.in); 
     int deckChoice = intKeyboard.nextInt(); 

     if (deckChoice == 1) { 
      System.out.println("It looks like you chose the risky deck " 
        + " I like that!"); 
      boolean emperor = true; 
     } else if (deckChoice == 2) { 
      System.out.println("I can tell your frightened" 
        + ". Well i dont blame ya, HAHA"); 
      boolean slave = true; 
     } 
     System.out.println("Funai slams the deck on the table."); 

    } 

答えて

0

あなたの方法は、すでに値を返すされていますが、ちょうどそれに

name = jojiFunai(); 
    System.out.println(name); 
+0

をキャプチャする必要があり、それが今、再びjojiFunaiをループするように思えるが、それはそれはあり – twokdavey

+0

をループ二回オフの名前を印刷しませんコード内にループがなく、jojiFunalメソッドは一度だけ呼び出されます。私がやる主なことの1つは、複数のScanner Objectを作成することではなく、一度やり直してメソッド内で変数を再利用することです。Scannerオブジェクトをフィールドとして持つか、Scanner Objectをパラメータとしてメソッドに渡します。 –

+0

私はjojiFunai()にString nameを割り当てたと思います。それはもう一度ループしました、なぜ私はそれを行うのだろうかと思います。 – twokdavey

関連する問題