Created box selection

This commit is contained in:
Asecave 2020-10-02 17:54:08 +02:00
parent 7b89d5f705
commit b9c1a5f612
8 changed files with 561 additions and 0 deletions

View File

@ -2,5 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/CppConsole.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,54 @@
package main;
import com.asecave.Console.Color;
public class BoxMaker {
public CardBox createBox() {
Trainer.con.setBGColor(Color.BLACK);
Trainer.con.fill(' ');
Trainer.con.setCursor(5, 3);
Trainer.con.setFGColor(Color.WHITE);
Trainer.con.print("Boxname:");
CardBox box = new CardBox(requestString(5, 5));
return null;
}
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;
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

@ -0,0 +1,10 @@
package main;
public class BoxQuery {
public BoxQuery(List<Card> vocabulary) {
while (!vocabulary.isEmpty()) {
}
}
}

View File

@ -0,0 +1,26 @@
package main;
public class Card {
private String translation;
private String word;
public Card(String word, String translation) {
this.word = word;
this.translation = translation;
}
public String getWord() {
return word;
}
public int isCorrect(String input) {
if (input.equals(translation)) {
return 1;
}
if (input.toLowerCase().equals(translation.toLowerCase())) {
return 2;
}
return 0;
}
}

View File

@ -0,0 +1,31 @@
package main;
public class CardBox {
private List<Card> cards;
private String name;
public CardBox(String name) {
this.name = name;
cards = new List<>();
}
public void addCard(Card card) {
cards.append(card);
}
public List<Card> getCopy() {
List<Card> copy = new List<>();
cards.toFirst();
while(cards.hasAccess()) {
copy.append(cards.getContent());
cards.next();
}
return copy;
}
public String getName() {
return name;
}
}

View File

@ -0,0 +1,22 @@
package main;
public class Launcher {
public static void main(String[] args) {
try {
new Trainer();
} catch (Exception e) {
Trainer.con.print("An Exception occured.\n");
Trainer.con.print(e + ": " + e.getMessage() + "\n");
for (StackTraceElement ste : e.getStackTrace()) {
Trainer.con.print(ste.toString() + "\n");
}
Trainer.con.print("Exiting in 10 seconds...");
try {
Thread.sleep(10000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}

View File

@ -0,0 +1,317 @@
package main;
public class List<ContentType> {
/* --------- Anfang der privaten inneren Klasse -------------- */
private class ListNode {
private ContentType contentObject;
private ListNode next;
/**
* Ein neues Objekt wird erschaffen. Der Verweis ist leer.
*
* @param pContent das Inhaltsobjekt vom Typ ContentType
*/
private ListNode(ContentType pContent) {
contentObject = pContent;
next = null;
}
/**
* Der Inhalt des Knotens wird zurueckgeliefert.
*
* @return das Inhaltsobjekt des Knotens
*/
public ContentType getContentObject() {
return contentObject;
}
/**
* Der Inhalt dieses Kontens wird gesetzt.
*
* @param pContent das Inhaltsobjekt vom Typ ContentType
*/
public void setContentObject(ContentType pContent) {
contentObject = pContent;
}
/**
* Der Nachfolgeknoten wird zurueckgeliefert.
*
* @return das Objekt, auf das der aktuelle Verweis zeigt
*/
public ListNode getNextNode() {
return this.next;
}
/**
* Der Verweis wird auf das Objekt, das als Parameter uebergeben wird, gesetzt.
*
* @param pNext der Nachfolger des Knotens
*/
public void setNextNode(ListNode pNext) {
this.next = pNext;
}
}
/* ----------- Ende der privaten inneren Klasse -------------- */
// erstes Element der Liste
ListNode first;
// letztes Element der Liste
ListNode last;
// aktuelles Element der Liste
ListNode current;
/**
* Eine leere Liste wird erzeugt.
*/
public List() {
first = null;
last = null;
current = null;
}
/**
* Die Anfrage liefert den Wert true, wenn die Liste keine Objekte enthaelt,
* sonst liefert sie den Wert false.
*
* @return true, wenn die Liste leer ist, sonst false
*/
public boolean isEmpty() {
// Die Liste ist leer, wenn es kein erstes Element gibt.
return first == null;
}
/**
* Die Anfrage liefert den Wert true, wenn es ein aktuelles Objekt gibt, sonst
* liefert sie den Wert false.
*
* @return true, falls Zugriff moeglich, sonst false
*/
public boolean hasAccess() {
// Es gibt keinen Zugriff, wenn current auf kein Element verweist.
return current != null;
}
/**
* Falls die Liste nicht leer ist, es ein aktuelles Objekt gibt und dieses nicht
* das letzte Objekt der Liste ist, wird das dem aktuellen Objekt in der Liste
* folgende Objekt zum aktuellen Objekt, andernfalls gibt es nach Ausfuehrung
* des Auftrags kein aktuelles Objekt, d.h. hasAccess() liefert den Wert false.
*/
public void next() {
if (this.hasAccess()) {
current = current.getNextNode();
}
}
/**
* Falls die Liste nicht leer ist, wird das erste Objekt der Liste aktuelles
* Objekt. Ist die Liste leer, geschieht nichts.
*/
public void toFirst() {
if (!isEmpty()) {
current = first;
}
}
/**
* Falls die Liste nicht leer ist, wird das letzte Objekt der Liste aktuelles
* Objekt. Ist die Liste leer, geschieht nichts.
*/
public void toLast() {
if (!isEmpty()) {
current = last;
}
}
/**
* Falls es ein aktuelles Objekt gibt (hasAccess() == true), wird das aktuelle
* Objekt zurueckgegeben, andernfalls (hasAccess() == false) gibt die Anfrage
* den Wert null zurueck.
*
* @return das aktuelle Objekt (vom Typ ContentType) oder null, wenn es kein
* aktuelles Objekt gibt
*/
public ContentType getContent() {
if (this.hasAccess()) {
return current.getContentObject();
} else {
return null;
}
}
/**
* Falls es ein aktuelles Objekt gibt (hasAccess() == true) und pContent
* ungleich null ist, wird das aktuelle Objekt durch pContent ersetzt. Sonst
* geschieht nichts.
*
* @param pContent das zu schreibende Objekt vom Typ ContentType
*/
public void setContent(ContentType pContent) {
// Nichts tun, wenn es keinen Inhalt oder kein aktuelles Element gibt.
if (pContent != null && this.hasAccess()) {
current.setContentObject(pContent);
}
}
/**
* Falls es ein aktuelles Objekt gibt (hasAccess() == true), wird ein neues
* Objekt vor dem aktuellen Objekt in die Liste eingefuegt. Das aktuelle Objekt
* bleibt unveraendert. <br />
* Wenn die Liste leer ist, wird pContent in die Liste eingefuegt und es gibt
* weiterhin kein aktuelles Objekt (hasAccess() == false). <br />
* Falls es kein aktuelles Objekt gibt (hasAccess() == false) und die Liste
* nicht leer ist oder pContent gleich null ist, geschieht nichts.
*
* @param pContent das einzufuegende Objekt vom Typ ContentType
*/
public void insert(ContentType pContent) {
if (pContent != null) { // Nichts tun, wenn es keinen Inhalt gibt.
if (this.hasAccess()) { // Fall: Es gibt ein aktuelles Element.
// Neuen Knoten erstellen.
ListNode newNode = new ListNode(pContent);
if (current != first) { // Fall: Nicht an erster Stelle einfuegen.
ListNode previous = this.getPrevious(current);
newNode.setNextNode(previous.getNextNode());
previous.setNextNode(newNode);
} else { // Fall: An erster Stelle einfuegen.
newNode.setNextNode(first);
first = newNode;
}
} else { // Fall: Es gibt kein aktuelles Element.
if (this.isEmpty()) { // Fall: In leere Liste einfuegen.
// Neuen Knoten erstellen.
ListNode newNode = new ListNode(pContent);
first = newNode;
last = newNode;
}
}
}
}
/**
* Falls pContent gleich null ist, geschieht nichts.<br />
* Ansonsten wird ein neues Objekt pContent am Ende der Liste eingefuegt. Das
* aktuelle Objekt bleibt unveraendert. <br />
* Wenn die Liste leer ist, wird das Objekt pContent in die Liste eingefuegt und
* es gibt weiterhin kein aktuelles Objekt (hasAccess() == false).
*
* @param pContent das anzuhaengende Objekt vom Typ ContentType
*/
public void append(ContentType pContent) {
if (pContent != null) { // Nichts tun, wenn es keine Inhalt gibt.
if (this.isEmpty()) { // Fall: An leere Liste anfuegen.
this.insert(pContent);
} else { // Fall: An nicht-leere Liste anfuegen.
// Neuen Knoten erstellen.
ListNode newNode = new ListNode(pContent);
last.setNextNode(newNode);
last = newNode; // Letzten Knoten aktualisieren.
}
}
}
/**
* Falls es sich bei der Liste und pList um dasselbe Objekt handelt, pList null
* oder eine leere Liste ist, geschieht nichts.<br />
* Ansonsten wird die Liste pList an die aktuelle Liste angehaengt.
* Anschliessend wird pList eine leere Liste. Das aktuelle Objekt bleibt
* unveraendert. Insbesondere bleibt hasAccess identisch.
*
* @param pList die am Ende anzuhaengende Liste vom Typ List<ContentType>
*/
public void concat(List<ContentType> pList) {
if (pList != this && pList != null && !pList.isEmpty()) { // Nichts tun,
// wenn pList und this identisch, pList leer oder nicht existent.
if (this.isEmpty()) { // Fall: An leere Liste anfuegen.
this.first = pList.first;
this.last = pList.last;
} else { // Fall: An nicht-leere Liste anfuegen.
this.last.setNextNode(pList.first);
this.last = pList.last;
}
// Liste pList loeschen.
pList.first = null;
pList.last = null;
pList.current = null;
}
}
/**
* Wenn die Liste leer ist oder es kein aktuelles Objekt gibt (hasAccess() ==
* false), geschieht nichts.<br />
* Falls es ein aktuelles Objekt gibt (hasAccess() == true), wird das aktuelle
* Objekt geloescht und das Objekt hinter dem geloeschten Objekt wird zum
* aktuellen Objekt. <br />
* Wird das Objekt, das am Ende der Liste steht, geloescht, gibt es kein
* aktuelles Objekt mehr.
*/
public void remove() {
// Nichts tun, wenn es kein aktuelle Element gibt oder die Liste leer ist.
if (this.hasAccess() && !this.isEmpty()) {
if (current == first) {
first = first.getNextNode();
} else {
ListNode previous = this.getPrevious(current);
if (current == last) {
last = previous;
}
previous.setNextNode(current.getNextNode());
}
ListNode temp = current.getNextNode();
current.setContentObject(null);
current.setNextNode(null);
current = temp;
// Beim loeschen des letzten Elements last auf null setzen.
if (this.isEmpty()) {
last = null;
}
}
}
/**
* Liefert den Vorgaengerknoten des Knotens pNode. Ist die Liste leer, pNode ==
* null, pNode nicht in der Liste oder pNode der erste Knoten der Liste, wird
* null zurueckgegeben.
*
* @param pNode der Knoten, dessen Vorgaenger zurueckgegeben werden soll
* @return der Vorgaenger des Knotens pNode oder null, falls die Liste leer ist,
* pNode == null ist, pNode nicht in der Liste ist oder pNode der erste
* Knoten der Liste ist
*/
private ListNode getPrevious(ListNode pNode) {
if (pNode != null && pNode != first && !this.isEmpty()) {
ListNode temp = first;
while (temp != null && temp.getNextNode() != pNode) {
temp = temp.getNextNode();
}
return temp;
} else {
return null;
}
}
}

View File

@ -0,0 +1,100 @@
package main;
import com.asecave.Console;
import com.asecave.Console.Color;
import com.asecave.Console.FontSize;
public class Trainer {
private List<CardBox> boxes;
static Console con;
private boolean running;
private int cursor = 0;
private int boxCount = 0;
private BoxMaker maker;
public Trainer() {
boxes = new List<>();
maker = new BoxMaker();
con = new Console();
con.setTitle("Vokabeltrainer");
con.setFontSize(FontSize.NORMAL);
con.setBGColor(Color.BLACK);
con.fill(' ');
print();
running = true;
while (running) {
loop();
}
}
private void loop() {
char in = con.getInputChar();
if (in != 0) {
switch (in) {
case 'H': // Arrow up
if (cursor > 0) {
cursor--;
}
break;
case 'P': // Arrow down
if (cursor < boxCount) {
cursor++;
}
break;
case 13: // Enter
if (cursor == 0) {
boxes.append(maker.createBox());
}
break;
}
print();
}
try {
Thread.sleep(16);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void print() {
con.setCursor(5, 2);
con.setFGColor(Color.GOLD);
con.setBGColor(Color.BLACK);
con.print("--== V O K A B E L T R A I N E R ==--");
con.setCursor(5, 4);
if (cursor == 0) {
con.setFGColor(Color.BLACK);
con.setBGColor(Color.GREEN);
} else {
con.setFGColor(Color.WHITE);
con.setBGColor(Color.BLACK);
}
con.print("<neue Vokabelbox erstellen>");
boxCount = 0;
int y = 0;
boxes.toFirst();
while (boxes.hasAccess()) {
con.setCursor(5, 5 + y);
y++;
if (cursor == y) {
con.setFGColor(Color.BLACK);
con.setBGColor(Color.GREEN);
} else {
con.setFGColor(Color.WHITE);
con.setBGColor(Color.BLACK);
}
con.print(boxes.getContent().getName());
boxCount++;
boxes.next();
}
con.setCursorVisible(false);
}
}