Removed command queue, command is changed via set method, removed time measurement, edited chance to write letter,

This commit is contained in:
WickedJack99
2022-05-23 00:32:05 +02:00
parent 798f32e2a7
commit 0b9b861f22
4 changed files with 35 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
package Controller;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.Scanner;
import Model.ModelData;
import Model.MyModel;
@@ -9,7 +10,6 @@ import View.MyView;
public class Main {
public static void main(String[] args) {
ConcurrentLinkedQueue<Integer> qCommands = new ConcurrentLinkedQueue<Integer>();
ConcurrentLinkedQueue<ModelData> qDataFromModel = new ConcurrentLinkedQueue<ModelData>();
Object oThreadLock = new Object();
@@ -20,16 +20,29 @@ public class Main {
MyView oView = new MyView(oModelData);
int iCommand = 2;
oModel.start();
while (true) {
while (iCommand != 0) {
Scanner oScanner = new Scanner(System.in);
System.out.print("Enter command: ");
iCommand = oScanner.nextInt(); //TODO remove statement if gui finished
oModel.setModelCommand(iCommand);
//Wake up model thread if new task to execute.
synchronized(oThreadLock) {
oThreadLock.notifyAll();
}
while (qDataFromModel.isEmpty() && (iCommand == 1)) {
//Wait for model to finish TODO remove loop if gui is finished
}
if (!qDataFromModel.isEmpty()) {
oModelData = qDataFromModel.poll();
System.out.println("Data received from Model:\n" + oModelData.getModelString());
}
}
System.out.println("Main-Thread stopped.");
}
}