我做了一个文字冒险,变成了一个基于我喜欢的动漫的纸牌游戏,基本上我将所有长卷曲的文字移动到私人静态空隙中,以便清理'主要方法。首先,这是最好的方法吗?其次,这是我的主要问题,在public static String 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 :(得分:0)
你的方法已经返回了值,但你只需要捕获它
name = jojiFunai();
System.out.println(name);