java - How to retrieve variable from a method -


i made text adventure turns card game based on anime enjoy, moved long winded text private static voids in order 'clean up' main method. firstly best way go it? second, , main question, in public static string jojifunai ask user name. want use variable throughout rest of code, how can go this? sorry mouthful, don't know go.

    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 deck player chooses         // boolean emperor= false, slave= false;          int deckchoice;          wakeup();         jojifunai();          system.out.println(name);         gamerules();         deckchoice(); //this portion turned class deck //      random computer = new random(); // //      while (emperor = true && emperorplayer1 != 0) { //          system.out.println("what card 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 emperor card down."); //              if (deckchoice == computerchoice) { //                  system.out.println("it looks lost,hahaha");                 }             }         }          // talk rules of each deck , deck has         //         // 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 @ sound of alarm clock,"                 + " go turn off alarm? y/n");         scanner keyboard = new scanner(system.in);         string alarm = keyboard.nextline();         if (alarm.equalsignorecase("y")) {             system.out.println("as hit awake button hear the"                     + " sound of knocking @ front door.");         } else if (alarm.equalsignorecase("n")) {             system.out.println("you hit snooze button"                     + " , fall deep sleep,"                     + " avoiding 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 reach door, hit behind......");         system.out                 .println("you hear faint words coming figure 'we have him, talking him boat', darkness 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 you! name?'");         string name = keyboard.nextline();         system.out                 .println("'nice meet "                         + name                         + ". name joji funai , people told me,"                         + " looks opponent card game playing.'");         system.out.println("options:");         system.out.println("1. i?");         system.out.println("2. refuse.");         system.out.println("3. accept.");         int funaiquestion = intkeyboard.nextint();         switch (funaiquestion) {         case 1:             system.out                     .println("your in ship, seems signed contract in failed uphold, way can pay through gambling.. lets started.");             break;         case 2:             system.out                     .println("i wish didnt that' joji instantly pulls out pistol ending life before knew happened");             system.exit(0);         case 3:             system.out                     .println("without asking questions? has confidence, that! let me explain rules....");             break;          }         return name;      }      private static void gamerules() {         system.out.println("///////////////////////////////game"                 + " rules//////////////////////////////////////////////////");          system.out.println("'this game called e-card, each player"                 + " takes turns playing 3 rounds"                 + " on 'emperor' side , 'slave' side.'");         system.out.println("the game starts each player holding"                 + " 5 cards, 4 of citizens"                 + " , last being either slave or emperor."                 + " holds card decided beforehand,"                 + " , played 3 turns before switching.");         system.out.println("the game lasts total of twelve turns,"                 + " meaning each side gets play emperor twice. ");         system.out.println("the players choose 1 card hand"                 + " , place them face-down on table."                 + " flipped on reveal winner "                 + "of match.the 3 card types citizen,"                 + " emperor , slave.");         system.out.println("the citizen card represents common man,"                 + " , cannot defeat emperor sits at"                 + " top. can, however, defeat slave,"                 + " resides @ bottom of system."                 + " 2 citizen against each other results in tie.");         system.out.println("the emperor represents 1 @ top of"                 + " society. card can defeat citizen,"                 + " lose slave.");         system.out.println("the slave presented 1 @ very"                 + " bottom of society. seeing how has nothing"                 + " lose, can overthrow emperor in 1 last"                 + " attempt @ revenge. card lose citizen,"                 + " win against emperor card.");         system.out.println("//////////////////////////////////////////////"                 + "game rules///////////////////////////////////");          system.out.println("sorry being long winded, anyways, ill let"                 + " choose first, \n 1.emperor"                 + " deck or \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 chose risky deck "                     + " that!");             boolean emperor = true;         } else if (deckchoice == 2) {             system.out.println("i can tell frightened"                     + ". dont blame ya, haha");             boolean slave = true;         }         system.out.println("funai slams deck on table.");      } 

you method returning value, need capture it

    name = jojifunai();     system.out.println(name); 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -