boxQuery and added default basic card boxes
This commit is contained in:
@@ -1,54 +1,62 @@
|
|||||||
package main;
|
package main;
|
||||||
|
|
||||||
|
import com.asecave.Console;
|
||||||
import com.asecave.Console.Color;
|
import com.asecave.Console.Color;
|
||||||
|
|
||||||
public class BoxMaker {
|
public class BoxMaker extends StringInput {
|
||||||
|
|
||||||
public CardBox createBox() {
|
public CardBox createBox() {
|
||||||
Trainer.con.setBGColor(Color.BLACK);
|
Console con = Trainer.con;
|
||||||
Trainer.con.fill(' ');
|
con.setBGColor(Color.BLACK);
|
||||||
|
con.fill(' ');
|
||||||
|
|
||||||
Trainer.con.setCursor(5, 3);
|
con.setCursor(5, 3);
|
||||||
Trainer.con.setFGColor(Color.WHITE);
|
con.setFGColor(Color.WHITE);
|
||||||
Trainer.con.print("Boxname:");
|
con.print("Boxname:");
|
||||||
CardBox box = new CardBox(requestString(5, 5));
|
CardBox box = new CardBox(requestString(5, 5));
|
||||||
|
con.fill(' ');
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String requestString(int x, int y) {
|
int cardCounter = 0;
|
||||||
String in = "";
|
|
||||||
boolean writing = true;
|
while (true) {
|
||||||
while (writing) {
|
|
||||||
char inputChar = Trainer.con.getInputChar();
|
con.setCursor(5, 3);
|
||||||
switch (inputChar) {
|
con.print("#######################");
|
||||||
case 13:
|
con.setCursor(5, 4);
|
||||||
writing = false;
|
con.print("# #");
|
||||||
break;
|
con.setCursor(6, 4);
|
||||||
case 0:
|
con.setFGColor(Color.GRAY);
|
||||||
break;
|
con.print(cardCounter + 1);
|
||||||
case 8:
|
con.setFGColor(Color.WHITE);
|
||||||
if (in.length() > 0) {
|
con.setCursor(5, 5);
|
||||||
Trainer.con.setCursor(x, y);
|
con.print("# #");
|
||||||
Trainer.con.print(" ");
|
con.setCursor(5, 6);
|
||||||
in = in.substring(0, in.length() - 1);
|
con.print("# #");
|
||||||
}
|
con.setCursor(5, 7);
|
||||||
break;
|
con.print("#######################");
|
||||||
default:
|
con.setCursor(5, 8);
|
||||||
in += inputChar;
|
con.print("# #");
|
||||||
|
con.setCursor(5, 9);
|
||||||
|
con.print("# #");
|
||||||
|
con.setCursor(5, 10);
|
||||||
|
con.print("# #");
|
||||||
|
con.setCursor(5, 11);
|
||||||
|
con.print("#######################");
|
||||||
|
|
||||||
|
String word = requestString(7, 5);
|
||||||
|
if (word == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (inputChar != 0) {
|
String translation = requestString(7, 9);
|
||||||
Trainer.con.setCursor(x, y);
|
if (translation == null) {
|
||||||
Trainer.con.print(in);
|
break;
|
||||||
}
|
|
||||||
try {
|
|
||||||
Thread.sleep(16);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
Card card = new Card(word, translation);
|
||||||
|
box.addCard(card);
|
||||||
|
cardCounter++;
|
||||||
}
|
}
|
||||||
return in;
|
|
||||||
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,84 @@
|
|||||||
package main;
|
package main;
|
||||||
|
|
||||||
public class BoxQuery {
|
import com.asecave.Console;
|
||||||
|
import com.asecave.Console.Color;
|
||||||
|
|
||||||
|
public class BoxQuery extends StringInput {
|
||||||
|
|
||||||
|
private Console con;
|
||||||
|
|
||||||
public BoxQuery(List<Card> vocabulary) {
|
public BoxQuery(List<Card> vocabulary) {
|
||||||
|
con = Trainer.con;
|
||||||
|
|
||||||
|
con.setBGColor(Color.BLACK);
|
||||||
|
con.setFGColor(Color.WHITE);
|
||||||
|
con.fill(' ');
|
||||||
|
|
||||||
|
vocabulary.toFirst();
|
||||||
while (!vocabulary.isEmpty()) {
|
while (!vocabulary.isEmpty()) {
|
||||||
|
if (!vocabulary.hasAccess()) {
|
||||||
|
vocabulary.toFirst();
|
||||||
|
}
|
||||||
|
int offsetX = con.getConsoleWidth() / 2 - (vocabulary.getContent().getWidth() + 4) / 2;
|
||||||
|
int offsetY = con.getConsoleHeight() / 2 - 4;
|
||||||
|
|
||||||
|
con.setFGColor(Color.WHITE);
|
||||||
|
printCard(vocabulary.getContent(), offsetX, offsetY);
|
||||||
|
|
||||||
|
int test = vocabulary.getContent().isCorrect(requestString(offsetX + 2, offsetY + 6));
|
||||||
|
if (test == 1) {
|
||||||
|
con.setFGColor(Color.GREEN);
|
||||||
|
printCard(vocabulary.getContent(), offsetX, offsetY);
|
||||||
|
vocabulary.remove();
|
||||||
|
try {
|
||||||
|
Thread.sleep(3000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else if (test == 2) {
|
||||||
|
con.setFGColor(Color.YELLOW);
|
||||||
|
printCard(vocabulary.getContent(), offsetX, offsetY);
|
||||||
|
con.setCursor(offsetX + 2, offsetY + 7);
|
||||||
|
con.setFGColor(Color.GREEN);
|
||||||
|
con.print(vocabulary.getContent().getTranslation());
|
||||||
|
vocabulary.remove();
|
||||||
|
try {
|
||||||
|
Thread.sleep(3000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
do {
|
||||||
|
con.fill(' ');
|
||||||
|
con.setFGColor(Color.RED);
|
||||||
|
printCard(vocabulary.getContent(), offsetX, offsetY);
|
||||||
|
con.setCursor(offsetX + 2, offsetY + 7);
|
||||||
|
con.setFGColor(Color.GREEN);
|
||||||
|
con.print(vocabulary.getContent().getTranslation());
|
||||||
|
con.setFGColor(Color.WHITE);
|
||||||
|
} while (vocabulary.getContent().isCorrect(requestString(offsetX + 2, offsetY + 6)) == 0);
|
||||||
|
vocabulary.next();
|
||||||
|
}
|
||||||
|
con.fill(' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void printCard(Card card, int offsetX, int offsetY) {
|
||||||
|
int width = card.getWidth() + 4;
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
con.setCursor(offsetX, offsetY + i * 4);
|
||||||
|
for (int j = 0; j < width; j++) {
|
||||||
|
con.print('#');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 1; i < 8; i++) {
|
||||||
|
con.setCursor(offsetX, offsetY + i);
|
||||||
|
con.print('#');
|
||||||
|
con.setCursor(offsetX + width - 1, offsetY + i);
|
||||||
|
con.print('#');
|
||||||
|
}
|
||||||
|
con.setCursor(offsetX + 2, offsetY + 2);
|
||||||
|
con.print(card.getWord());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ public class Card {
|
|||||||
|
|
||||||
private String translation;
|
private String translation;
|
||||||
private String word;
|
private String word;
|
||||||
|
private int width;
|
||||||
|
|
||||||
public Card(String word, String translation) {
|
public Card(String word, String translation) {
|
||||||
this.word = word;
|
this.word = word;
|
||||||
this.translation = translation;
|
this.translation = translation;
|
||||||
|
width = Math.max(word.length(), translation.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWord() {
|
public String getWord() {
|
||||||
@@ -23,4 +25,12 @@ public class Card {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTranslation() {
|
||||||
|
return translation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
56
Vokabeltrainer/src/main/SavedBoxes.java
Normal file
56
Vokabeltrainer/src/main/SavedBoxes.java
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package main;
|
||||||
|
|
||||||
|
public class SavedBoxes {
|
||||||
|
|
||||||
|
private static String[][] germanToEnglish = {
|
||||||
|
|
||||||
|
{ "Hallo", "Hello " }, { "Danke", "Thank You " }, { "Nein", "No " },
|
||||||
|
{ "Ja", "Yes " }, { "Lecker", "Delicious " }, { "Woche", "week " },
|
||||||
|
{ "Heute", "today " }, { "Morgen", "tomorrow " }, { "Gestern", "yesterday " },
|
||||||
|
{ "Machen", "do " }, { "Gehen", "go " }, { "Kommen", "come " },
|
||||||
|
{ "Lachen", "laugh " }, { "Good", "gut " }, { "Schön", "beautiful " },
|
||||||
|
{ "Kaffee", "coffee " }, { "Bier", "beer " }, { "Tee", "tea " },
|
||||||
|
{ "Wein", "wine " }, { "Wasser", "water " }, { "Lamm", " lamb " },
|
||||||
|
{ "Fisch", "fish " }, { "Nett", "nice " }, { "Sauber", "clean " },
|
||||||
|
{ "Fein", "fine " }, { "Lieb", "dear " }, { "Liebe", "love " },
|
||||||
|
{ "Komisch", "funny " }, { "Klasse", "great " }, { "Hoch", "high " },
|
||||||
|
{ "Prima", "fantastic " }, { "Stark", "Strong " }, { "Lang", "long " },
|
||||||
|
{ "Hell", "bright " }, { "Fähig", "capable " }, { "Kurz", "short " },
|
||||||
|
{ "Klein", "small " }, { "Groß", "Big " }, { "Wunderbar", "wonderful" },
|
||||||
|
{ "Ratte", "rat " }, { "Dunkel", "dark " }, { "Bye", "Tschüss " }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
private static String[][] englishToGerman = {
|
||||||
|
|
||||||
|
{ "Hello", "Hallo " }, { "Thank You", "Danke " }, { "No", "Nein " },
|
||||||
|
{ "Yes", "Ja " }, { "Delicious", "Lecker " }, { "week", "Woche " },
|
||||||
|
{ "today", "Heute " }, { "tomorrow", "Morgen " }, { "yesterday", "Gestern " },
|
||||||
|
{ "do", "Machen " }, { "go", "Gehen " }, { "come", "Kommen " },
|
||||||
|
{ "laugh", "Lachen " }, { "gut", "Good " }, { "beautiful", "Schön " },
|
||||||
|
{ "coffee", "Kaffee " }, { "beer", "Bier " }, { "tea", "Tee " },
|
||||||
|
{ "wine", "Wein " }, { "water", "Wasser " }, { "lamb", " Lamm " },
|
||||||
|
{ "fish", "Fisch " }, { "nice", "Nett " }, { "clean", "Sauber " },
|
||||||
|
{ "fine", "Fein " }, { "dear", "Lieb " }, { "love", "Liebe " },
|
||||||
|
{ "funny", "Komisch " }, { "great", "Klasse " }, { "high", "Hoch " },
|
||||||
|
{ "fantastic", "Prima " }, { "Strong", "Stark " }, { "long", "Lang " },
|
||||||
|
{ "bright", "Hell " }, { "capable", "Fähig " }, { "short", "Kurz " },
|
||||||
|
{ "small", "Klein " }, { "Big", "Groß " }, { "wonderful", "Wunderbar" },
|
||||||
|
{ "rat", "Ratte " }, { "dark", "Dunkel " }, { "Tschüss", "Bye " }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void addTo(List<CardBox> boxes) {
|
||||||
|
CardBox box1 = new CardBox("Basics: D > E");
|
||||||
|
CardBox box2 = new CardBox("Basics: E > D");
|
||||||
|
for (String[] card : germanToEnglish) {
|
||||||
|
box1.addCard(new Card(card[0].trim(), card[1].trim()));
|
||||||
|
}
|
||||||
|
for (String[] card : englishToGerman) {
|
||||||
|
box2.addCard(new Card(card[0].trim(), card[1].trim()));
|
||||||
|
}
|
||||||
|
boxes.append(box1);
|
||||||
|
boxes.append(box2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
41
Vokabeltrainer/src/main/StringInput.java
Normal file
41
Vokabeltrainer/src/main/StringInput.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package main;
|
||||||
|
|
||||||
|
public class StringInput {
|
||||||
|
|
||||||
|
protected String requestString(int x, int y) {
|
||||||
|
String in = "";
|
||||||
|
boolean writing = true;
|
||||||
|
while (writing) {
|
||||||
|
char inputChar = Trainer.con.getInputChar();
|
||||||
|
switch (inputChar) {
|
||||||
|
case 13:
|
||||||
|
writing = false;
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case 27:
|
||||||
|
return null;
|
||||||
|
case 8:
|
||||||
|
if (in.length() > 0) {
|
||||||
|
Trainer.con.setCursor(x + in.length() - 1, y);
|
||||||
|
Trainer.con.print(' ');
|
||||||
|
in = in.substring(0, in.length() - 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
in += inputChar;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (inputChar != 0) {
|
||||||
|
Trainer.con.setCursor(x, y);
|
||||||
|
Trainer.con.print(in);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(16);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,9 +15,10 @@ public class Trainer {
|
|||||||
|
|
||||||
public Trainer() {
|
public Trainer() {
|
||||||
boxes = new List<>();
|
boxes = new List<>();
|
||||||
|
SavedBoxes.addTo(boxes);
|
||||||
|
|
||||||
maker = new BoxMaker();
|
maker = new BoxMaker();
|
||||||
|
|
||||||
con = new Console();
|
con = new Console();
|
||||||
con.setTitle("Vokabeltrainer");
|
con.setTitle("Vokabeltrainer");
|
||||||
con.setFontSize(FontSize.NORMAL);
|
con.setFontSize(FontSize.NORMAL);
|
||||||
@@ -25,7 +26,7 @@ public class Trainer {
|
|||||||
con.setBGColor(Color.BLACK);
|
con.setBGColor(Color.BLACK);
|
||||||
con.fill(' ');
|
con.fill(' ');
|
||||||
print();
|
print();
|
||||||
|
|
||||||
running = true;
|
running = true;
|
||||||
while (running) {
|
while (running) {
|
||||||
loop();
|
loop();
|
||||||
@@ -50,6 +51,13 @@ public class Trainer {
|
|||||||
case 13: // Enter
|
case 13: // Enter
|
||||||
if (cursor == 0) {
|
if (cursor == 0) {
|
||||||
boxes.append(maker.createBox());
|
boxes.append(maker.createBox());
|
||||||
|
con.fill(' ');
|
||||||
|
} else {
|
||||||
|
boxes.toFirst();
|
||||||
|
for (int i = 0; i < cursor - 1; i++) {
|
||||||
|
boxes.next();
|
||||||
|
}
|
||||||
|
new BoxQuery(boxes.getContent().getCopy());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user