나는 재미있는/텍스트 연습을위한 간단한 텍스트 기반의 카드 게임을 만들고 있습니다. 카드에 대한 모든 사양이 포함 된 일반 텍스트 파일이 있습니다. 내 카드는 "#########"로 나뉩니다. 그것들은 여러 줄로 묶여있다. 당분간 나는 원할 때마다 하나의 카드 전체를 끌어낼 수 있기를 원할뿐입니다. 예를 들어 플레이어가 캐릭터 1을 골라서 카드 1 만 가져옵니다. 어떻게? 실제로 SPLIT 카드 I은 단지 어떤 카드를 사용자에게 요청할 수있다 수 있도록 HOW문자열 토크 나이저 및 일반 텍스트 구문 분석 JAVA
EXAMPLE:
##########
CARD 1
Character Name:
Something Else:
##########
CARD 2
Character Name:
Something Else:
##########
Character Name:
Something Else:
##########
. 줄을 읽고 내가했던 것처럼 인쇄하고 싶지 않습니다. 오히려 성가시다. 내 새로운 시도 : ArrayList listForCard1 = new ArrayList(); 정수 selected_card = 1;
try {
String line;
FileReader fR = new FileReader("MyText.txt");
BufferedReader br = new BufferedReader(fR);
int x = 0;
Integer card = 1;
while ((line = br.readLine()) != null) {
ALines[x] = line;
x++;
if (line.contains("##########")) {
if (card == selected_card) {
listForCard1.add(br.readLine());
// System.out.println(br.readLine());
break;
} else {
card++;
}
}
}
System.out.println("Done");
System.out.println(ALines[0]);
System.out.println(ALines[1]);
System.out.println(ALines[2]);
System.out.println(ALines[3]);
System.out.println(ALines[4]);
System.out.println(ALines[5]);
System.out.println(ALines[6]);
} catch (IOException e) {
e.printStackTrace();
}
}
왜 downvote? – StreamingBits
환영합니다. 코드를 덤핑하는 대신 조금 더 설명을 시도하십시오. 그것은 매우 간단했다 - 그래서 나는 어쨌든 – clancer
@ clancer 충분히 공정하게 upvoted. 나는 그것을 더 많이 할 것이다. 고맙습니다! – StreamingBits