diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 6027cfe..e8fbf0a 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,20 +5,21 @@
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
@@ -31,7 +32,7 @@
-
+
com.texttwist.client.*
@@ -41,47 +42,15 @@
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -90,8 +59,28 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -99,11 +88,51 @@
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -111,28 +140,12 @@
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
@@ -148,36 +161,36 @@
- Joi
- Join
- Joine
- Joined
- new
- Buffer
- MatchTim
- clientSocket
- .c
- socketChannel
- .
- .clo
- .clos
- .close
- .close(
- .close()
- star
- starti
- starting
- starting ca
- starting cal
- starting call
+ GAME_STARTED
+ G
+ GAME:
+ GAME
+ GAME_ST
+ GAME_STA
W
- WAIT
- WAIT
- WAIT f
- socket
- WAIT fri
- fi
- final
+ Wa
+ Wai
+ Wait
+ WaitF
+ WaitFor
+ HE
+ HEY
+ F
+ Futur
+ Future
+ f
+ future
+ a
+ addT
+ addTi
+ addTim
+ addTime
+ addTimer
+ TIME
+ TIMEO
+ TIMEOU
+ TIMEOUT
+ fetc
@@ -191,14 +204,6 @@
@@ -257,7 +270,7 @@
-
+
@@ -290,6 +303,90 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1580,60 +1543,176 @@
-
+
-
-
-
-
-
+
+
+
-
+
-
-
-
-
-
-
-
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
diff --git a/Client/src/com/texttwist/client/pages/Game.java b/Client/src/com/texttwist/client/pages/Game.java
index 4de11f8..c2c5493 100644
--- a/Client/src/com/texttwist/client/pages/Game.java
+++ b/Client/src/com/texttwist/client/pages/Game.java
@@ -1,35 +1,61 @@
package com.texttwist.client.pages;
-import com.texttwist.client.App;
+import com.texttwist.client.tasks.StartGame;
import constants.Palette;
import com.texttwist.client.ui.*;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.*;
/**
* Created by loke on 14/06/2017.
*/
public class Game extends Page {
- private TTContainer gamecontainer;
- private DefaultListModel letters = new DefaultListModel();
- private DefaultListModel words = new DefaultListModel();
- private DefaultListModel letterSpawningPoint = new DefaultListModel();
+ private TTContainer gameContainer;
+ public GameController gameController;
+ public DefaultListModel letterSpawningPoint = new DefaultListModel();
+
+ public Timer timer = null;
+
+ public Point getRandomPosition(){
+ if(letterSpawningPoint.size()>1) {
+ int index = ThreadLocalRandom.current().nextInt(0, letterSpawningPoint.size() - 1);
+ Point placeholder = letterSpawningPoint.get(index);
+ letterSpawningPoint.remove(index);
+ return placeholder;
+ }
+ return new Point(0,0);
+ }
+
+ public Thread startGame(){
+ Thread t = new Thread(new StartGame(this));
+ t.start();
+ return t;
+ }
+
+
+ public void showLetters(){
+ for(int i = 0; i< this.gameController.letters.size(); i++){
+ TTLetter letter = new TTLetter(
+ getRandomPosition(),
+ this.gameController.letters.get(i),
+ gameContainer);
+ }
+
+ window.repaint();
+ window.revalidate();
+ }
public Game(JFrame window) throws IOException {
super(window);
createUIComponents();
- letters = fetchLetters();
+ gameController = new GameController();
letterSpawningPoint = setLetterSpawningPoint();
- if(letters.size() > 0) {
- showLetters();
- } else {
- joiningPhase();
- }
+ this.gameController.waitForPlayers();
+ startGame();
window.setVisible(true);
}
@@ -59,61 +85,15 @@ public class Game extends Page {
return l;
}
- private DefaultListModel fetchLetters(){
- DefaultListModel l = new DefaultListModel();/*
- l.addElement("C");
- l.addElement("A");
- l.addElement("E");
- l.addElement("P");
- l.addElement("C");
- l.addElement("I");
- l.addElement("L");
- l.addElement("S");*/
-
- return l;
- }
-
private Callable