boxQuery and added default basic card boxes

This commit is contained in:
Asecave 2020-10-03 13:34:13 +02:00
parent b9c1a5f612
commit 8625353352
6 changed files with 239 additions and 42 deletions

View File

@ -1,54 +1,62 @@
package main;
import com.asecave.Console;
import com.asecave.Console.Color;
public class BoxMaker {
public class BoxMaker extends StringInput {
public CardBox createBox() {
Trainer.con.setBGColor(Color.BLACK);
Trainer.con.fill(' ');
Console con = Trainer.con;
con.setBGColor(Color.BLACK);
con.fill(' ');
Trainer.con.setCursor(5, 3);
Trainer.con.setFGColor(Color.WHITE);
Trainer.con.print("Boxname:");
con.setCursor(5, 3);
con.setFGColor(Color.WHITE);
con.print("Boxname:");
CardBox box = new CardBox(requestString(5, 5));
return null;
}
con.fill(' ');
private 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 8:
if (in.length() > 0) {
Trainer.con.setCursor(x, y);
Trainer.con.print(" ");
in = in.substring(0, in.length() - 1);
}
break;
default:
in += inputChar;
int cardCounter = 0;
while (true) {
con.setCursor(5, 3);
con.print("#######################");
con.setCursor(5, 4);
con.print("# #");
con.setCursor(6, 4);
con.setFGColor(Color.GRAY);
con.print(cardCounter + 1);
con.setFGColor(Color.WHITE);
con.setCursor(5, 5);
con.print("# #");
con.setCursor(5, 6);
con.print("# #");
con.setCursor(5, 7);
con.print("#######################");
con.setCursor(5, 8);
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;
}
if (inputChar != 0) {
Trainer.con.setCursor(x, y);
Trainer.con.print(in);
}
try {
Thread.sleep(16);
} catch (InterruptedException e) {
e.printStackTrace();
String translation = requestString(7, 9);
if (translation == null) {
break;
}
Card card = new Card(word, translation);
box.addCard(card);
cardCounter++;
}
return in;
return box;
}
}

View File

@ -1,10 +1,84 @@
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) {
con = Trainer.con;
con.setBGColor(Color.BLACK);
con.setFGColor(Color.WHITE);
con.fill(' ');
vocabulary.toFirst();
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());
}
}

View File

@ -4,10 +4,12 @@ public class Card {
private String translation;
private String word;
private int width;
public Card(String word, String translation) {
this.word = word;
this.translation = translation;
width = Math.max(word.length(), translation.length());
}
public String getWord() {
@ -23,4 +25,12 @@ public class Card {
}
return 0;
}
public int getWidth() {
return width;
}
public String getTranslation() {
return translation;
}
}

View 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);
}
}

View 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;
}
}

View File

@ -15,9 +15,10 @@ public class Trainer {
public Trainer() {
boxes = new List<>();
SavedBoxes.addTo(boxes);
maker = new BoxMaker();
con = new Console();
con.setTitle("Vokabeltrainer");
con.setFontSize(FontSize.NORMAL);
@ -25,7 +26,7 @@ public class Trainer {
con.setBGColor(Color.BLACK);
con.fill(' ');
print();
running = true;
while (running) {
loop();
@ -50,6 +51,13 @@ public class Trainer {
case 13: // Enter
if (cursor == 0) {
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;
}