-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTextReader
169 lines (127 loc) · 3.78 KB
/
TextReader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package com.brainfusion.eldarfin.brainfusion;
/**
* Created by Can on 8.5.2015.
*/
import java.io.*;
/**
* Created by Eldarfin on 26.04.2015.
*/
public class TextReader{
//Properties
int qNum;
String question, answer;
File questionFile, playerData, answerFile;
TextReader(){
question = "";
answer = "";
qNum = 1;
questionFile = new File("questions.txt");
answerFile = new File("answers.txt");
playerData = new File("player_data.txt");
}
public void readQuestion() throws IOException{
StringBuilder text = new StringBuilder();
try {
InputStream in = new FileInputStream("txtfiles/questions.txt");
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
String line = null;
int count = 0;
do {
line = br.readLine();
count++;
if(count == qNum){
text.append(line).append(File.pathSeparatorChar);
}
} while (line != null);
question = text.toString();
question = question.substring(2, question.length()-1);
}catch (IOException e){
e.printStackTrace();
}
}
public void readAnswer() throws IOException{
StringBuilder text = new StringBuilder();
try {
InputStream in = new FileInputStream(answerFile);
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
String line = null;
int count = 0;
do {
line = br.readLine();
count++;
if(count == qNum){
text.append(line).append(File.pathSeparatorChar);
}
} while (line != null);
answer = text.toString();
answer = answer.substring(2, question.length()-1);
}catch (IOException e){
e.printStackTrace();
}
}
public String[][] fillBoard(String[][] board){
int count = 0;
String[] pieces = new String[32];
String temp = "";
for(int i = 0; i < question.length(); i++){
if(question.charAt(i) != '/'){
temp = temp + question.charAt(i);
}
else if(question.charAt(i) == '/' ){
pieces[count] = temp;
temp = "";
count++;
}
}
for (int j = 0 ; j < count ; j++){
int rowNo=Integer.parseInt(pieces[j].charAt(1)+"")-1;
int colNo=getColNo(pieces[j]);
board[rowNo][colNo]=pieces[j].substring(3);
}
return board;
}
public int getqNum() {
return qNum;
}
public void setqNum(int qNum) {
this.qNum = qNum;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) { this.question = question; }
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
private int getColNo(String string) {
if(string.charAt(0)=='a'){
return 0;
}
else if(string.charAt(0)=='b'){
return 1;
}
else if(string.charAt(0)=='c'){
return 2;
}
else if(string.charAt(0)=='d'){
return 3;
}
else if(string.charAt(0)=='e'){
return 4;
}
else if(string.charAt(0)=='f'){
return 5;
}
else if(string.charAt(0)=='g'){
return 6;
}
else {
return 7;
}
}
}