diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index a683e37..b1a069f 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,43 +5,49 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
+
+
+
+
-
-
+
+
+
-
+
+
+
+
+
+
+
+
@@ -54,7 +60,7 @@
-
+
com.texttwist.client.*
@@ -64,127 +70,104 @@
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
-
-
-
-
-
+
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -201,36 +184,36 @@
- s
- setWo
- setWor
- setWord
- setWords
- w
- words
- showLe
- sendW
- lett
- word
- wait
- ma
- matchModel
- matchMode
- matchMod
- matchMo
- matchM
match
- matchSer
- matchServ
- letters
- a
- addWordToWo
- addWordToW
- addWordTo
- addWordT
- addWord
- addWor
- letter
+ match.pla
+ match.play
+ match.player
+ match.players
+ .size/(
+ .size/
+ .size
+ Default
+ .size()
+ .
+ .get (
+ .get
+ .get(
+ .get
+ all pla
+ Done
+ Done I
+ Done Invi
+ Done Invit
+ Done Invite
+ Done Invite p
+ Dne
+ Done Invite pl
+ I
+ INVIT
+ INVITES
+ INVITES_A
+ INVITES_AL
+ INVITES_ALL
@@ -244,57 +227,57 @@
@@ -349,6 +332,90 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -547,6 +614,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -705,92 +794,34 @@
-
+
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
@@ -811,8 +842,12 @@
-
-
+
+
+
+
+
+
@@ -822,12 +857,8 @@
-
-
-
-
-
-
+
+
@@ -842,7 +873,7 @@
-
+
@@ -1250,15 +1281,20 @@
-
+
+
+
+
+
-
-
+
+
+
-
-
+
+
@@ -1302,12 +1338,13 @@
-
+
+
-
+
@@ -1323,7 +1360,7 @@
-
+
@@ -1336,7 +1373,7 @@
-
+
@@ -1353,15 +1390,7 @@
-
-
- file://$PROJECT_DIR$/Server/src/com/texttwist/server/components/ThreadProxy.java
- 114
-
-
-
-
-
+
@@ -1370,36 +1399,27 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
+
+
+
-
+
-
-
+
+
+
@@ -1407,398 +1427,409 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-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+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ com.texttwist.client.*
+
+
+ com.texttwist.client.*
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ match
+ match.pla
+ match.play
+ match.player
+ match.players
+ .size/(
+ .size/
+ .size
+ Default
+ .size()
+ .
+ .get (
+ .get
+ .get(
+ .get
+ all pla
+ Done
+ Done I
+ Done Invi
+ Done Invit
+ Done Invite
+ Done Invite p
+ Dne
+ Done Invite pl
+ I
+ INVIT
+ INVITES
+ INVITES_A
+ INVITES_AL
+ INVITES_ALL
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+ false
+ false
+
+
+ true
+ DEFINITION_ORDER
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Google Web Toolkit issues
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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src/com/texttwist/client/App.java
index 8846393..5cd18b8 100644
--- a/Client/src/com/texttwist/client/App.java
+++ b/Client/src/com/texttwist/client/App.java
@@ -1,13 +1,13 @@
package com.texttwist.client;
import com.texttwist.client.services.AuthService;
-import com.texttwist.client.pages.Home;
-import com.texttwist.client.services.MatchModel;
-import com.texttwist.client.services.SessionService;
+import com.texttwist.client.pages.HomePage;
+import com.texttwist.client.models.Game;
import com.texttwist.client.services.NotificationClient;
import constants.Config;
import interfaces.INotificationClient;
import interfaces.INotificationServer;
+import models.Session;
import utilities.Logger;
import javax.swing.*;
@@ -26,8 +26,8 @@ import java.rmi.server.UnicastRemoteObject;
public class App extends JFrame {
public static AuthService authService;
- public static SessionService sessionService;
- public static MatchModel match;
+ public static Session session;
+ public static Game game;
public static JFrame app;
public App() throws IOException {
@@ -58,12 +58,15 @@ public class App extends JFrame {
e.printStackTrace();
}
+ //Init models
+ game = new Game();
+
//Init services
authService = new AuthService();
- sessionService = new SessionService();
- match = new MatchModel();
+
app = this;
- Home home = new Home(this);
+
+ HomePage home = new HomePage(this);
}
public static Point getWindowsPosition(){
diff --git a/Client/src/com/texttwist/client/controllers/GameController.java b/Client/src/com/texttwist/client/controllers/GameController.java
index c1f9393..5e7dc26 100644
--- a/Client/src/com/texttwist/client/controllers/GameController.java
+++ b/Client/src/com/texttwist/client/controllers/GameController.java
@@ -1,33 +1,29 @@
package com.texttwist.client.controllers;
import com.texttwist.client.App;
-import com.texttwist.client.pages.Game;
+import com.texttwist.client.pages.GamePage;
import com.texttwist.client.tasks.SendWords;
import com.texttwist.client.tasks.StartGame;
import com.texttwist.client.tasks.WaitForPlayers;
import com.texttwist.client.tasks.WaitForScore;
import javax.swing.*;
-import java.util.concurrent.Callable;
/**
- * Game Controller
+ * GamePage Controller
*/
public class GameController {
- private Game game;
- private Timer timer;
+ private GamePage game;
- public GameController(Game game){
+ public GameController(GamePage game){
this.game = game;
- this.timer = game.timer;
-
}
public DefaultListModel getLetters(){
- return App.match.letters;
+ return App.game.letters;
}
public DefaultListModel getWords() {
- return App.match.words;
+ return App.game.words;
}
public SwingWorker waitForPlayers(SwingWorker callback) {
@@ -39,10 +35,10 @@ public class GameController {
}
public SwingWorker sendWords(SwingWorker callback){
- return new SendWords(App.match.words, waitForScore(callback));
+ return new SendWords(App.game.words, waitForScore(callback));
}
public SwingWorker startGame() {
- return new StartGame(App.match.letters, game);
+ return new StartGame(App.game.letters, game);
}
}
diff --git a/Client/src/com/texttwist/client/controllers/HighscoresController.java b/Client/src/com/texttwist/client/controllers/HighscoresController.java
index 480f54b..ee477a1 100644
--- a/Client/src/com/texttwist/client/controllers/HighscoresController.java
+++ b/Client/src/com/texttwist/client/controllers/HighscoresController.java
@@ -1,31 +1,28 @@
package com.texttwist.client.controllers;
-import com.texttwist.client.services.HighscoresService;
+import com.texttwist.client.App;
+import com.texttwist.client.pages.HighscoresPage;
+import com.texttwist.client.tasks.FetchHighscore;
+import javafx.util.Pair;
import javax.swing.*;
-import java.util.concurrent.Callable;
/**
- * Created by loke on 28/06/2017.
+ * Highscores Controller
*/
public class HighscoresController {
- HighscoresService highscoresService = new HighscoresService();
-
- public HighscoresController(){
+ private HighscoresPage highscoresPage;
+ public HighscoresController(HighscoresPage highscoresPage){
+ this.highscoresPage = highscoresPage;
}
+ public SwingWorker fetchHighscores () {
+ return new FetchHighscore(highscoresPage);
+ }
- public void fetchHighscores(JFrame window){
- highscoresService.fetchHighscores(new Callable() {
- @Override
- public String call() throws Exception {
- window.revalidate();
- window.repaint();
- System.out.println("ASDDD");
- return "";
- }
- });
+ public DefaultListModel> getRanks(Boolean isPartialRank) {
+ return isPartialRank ? App.game.ranks : App.game.globalRanks;
}
}
diff --git a/Client/src/com/texttwist/client/controllers/HomeController.java b/Client/src/com/texttwist/client/controllers/HomeController.java
index 5d05eb5..cb9a08d 100644
--- a/Client/src/com/texttwist/client/controllers/HomeController.java
+++ b/Client/src/com/texttwist/client/controllers/HomeController.java
@@ -1,6 +1,8 @@
package com.texttwist.client.controllers;
import com.texttwist.client.App;
import models.Response;
+import models.Session;
+import models.User;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
@@ -11,13 +13,11 @@ import java.rmi.RemoteException;
*/
public class HomeController {
- public HomeController(){
- }
-
public Response login(String userName, String password) throws RemoteException, NotBoundException, MalformedURLException {
Response res = App.authService.login(userName,password);
+ System.out.println(res.data);
if (res.code == 200){
- App.sessionService.create(userName, res.data.get("token").toString());
+ App.session = (new Session(new User(userName,password,0), res.data.get("token").toString()));
}
return res;
}
diff --git a/Client/src/com/texttwist/client/controllers/MatchSetupController.java b/Client/src/com/texttwist/client/controllers/MatchSetupController.java
index e119048..be68086 100644
--- a/Client/src/com/texttwist/client/controllers/MatchSetupController.java
+++ b/Client/src/com/texttwist/client/controllers/MatchSetupController.java
@@ -1,23 +1,18 @@
package com.texttwist.client.controllers;
import com.texttwist.client.App;
-import models.Response;
import javax.swing.*;
import java.io.IOException;
-import java.net.MalformedURLException;
-import java.rmi.NotBoundException;
-import java.rmi.RemoteException;
/**
* Created by loke on 18/06/2017.
*/
public class MatchSetupController {
- public MatchSetupController(){}
public Object play(DefaultListModel userNames) {
try {
- return App.match.play(userNames);
+ return App.game.play(userNames);
} catch (IOException e) {
e.printStackTrace();
}
diff --git a/Client/src/com/texttwist/client/controllers/MenuController.java b/Client/src/com/texttwist/client/controllers/MenuController.java
index 1029684..6848a77 100644
--- a/Client/src/com/texttwist/client/controllers/MenuController.java
+++ b/Client/src/com/texttwist/client/controllers/MenuController.java
@@ -12,13 +12,10 @@ import java.rmi.RemoteException;
*/
public class MenuController {
- public MenuController(){
- }
-
public Response logout(String userName) throws RemoteException, NotBoundException, MalformedURLException {
Response res = App.authService.logout(userName);
if (res.code == 200){
- App.sessionService.remove();
+ App.session = null;
}
return res;
}
diff --git a/Client/src/com/texttwist/client/controllers/RegisterController.java b/Client/src/com/texttwist/client/controllers/RegisterController.java
index d914e18..d52f066 100644
--- a/Client/src/com/texttwist/client/controllers/RegisterController.java
+++ b/Client/src/com/texttwist/client/controllers/RegisterController.java
@@ -12,9 +12,6 @@ import java.rmi.RemoteException;
*/
public class RegisterController {
- public RegisterController(){
- }
-
public Response register(String userName, String password) throws RemoteException, NotBoundException, MalformedURLException {
return App.authService.register(userName,password);
}
diff --git a/Client/src/com/texttwist/client/services/MatchModel.java b/Client/src/com/texttwist/client/models/Game.java
similarity index 82%
rename from Client/src/com/texttwist/client/services/MatchModel.java
rename to Client/src/com/texttwist/client/models/Game.java
index 2d76503..92db12a 100644
--- a/Client/src/com/texttwist/client/services/MatchModel.java
+++ b/Client/src/com/texttwist/client/models/Game.java
@@ -1,11 +1,10 @@
-package com.texttwist.client.services;
+package com.texttwist.client.models;
import com.texttwist.client.App;
-import com.texttwist.client.pages.Game;
-import com.texttwist.client.pages.Menu;
+import com.texttwist.client.pages.GamePage;
+import com.texttwist.client.pages.MenuPage;
import com.texttwist.client.pages.Page;
import com.texttwist.client.tasks.InvitePlayers;
-import com.texttwist.client.tasks.WaitForPlayers;
import com.texttwist.client.ui.TTDialog;
import constants.Config;
import javafx.util.Pair;
@@ -13,7 +12,9 @@ import models.Message;
import javax.swing.*;
import java.io.*;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.net.MulticastSocket;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.concurrent.*;
@@ -21,23 +22,25 @@ import java.util.concurrent.*;
/**
* Created by loke on 18/06/2017.
*/
-public class MatchModel {
+public class Game {
public Integer multicastId = 0 ;
public DefaultListModel pendingList = new DefaultListModel();
- ByteBuffer buffer = ByteBuffer.allocate(1024);
+ private ByteBuffer buffer = ByteBuffer.allocate(1024);
public DefaultListModel words = new DefaultListModel();
public DefaultListModel letters = new DefaultListModel();
public DefaultListModel> ranks = new DefaultListModel<>();
public DefaultListModel> globalRanks = new DefaultListModel<>();
+ public MulticastSocket multicastSocket;
public SocketChannel clientSocket = null;
- public MatchModel(){
+ public Game(){
InetSocketAddress socketAddress = new InetSocketAddress(Config.GameServerURI, Config.GameServerPort);
try {
clientSocket = SocketChannel.open(socketAddress);
clientSocket.configureBlocking(false);
+ System.out.println("Join multicast group");
} catch (IOException e) {
e.printStackTrace();
@@ -58,14 +61,14 @@ public class MatchModel {
new Callable() {
@Override
public Object call() throws Exception {
- App.match.joinMatch(userName);
+ App.game.joinMatch(userName);
return null;
}
},
new Callable() {
@Override
public Object call() throws Exception {
- return new Menu(Page.window);
+ return new MenuPage(Page.window);
}
});
}
@@ -82,19 +85,19 @@ public class MatchModel {
}
public void joinMatch(String matchName) {
- //Svuota la lista dei match pendenti e joina il match selezionato
+ //Svuota la lista dei game pendenti e joina il game selezionato
this.pendingList.clear();
try {
//Invia tcp req a server per dirgli che sto joinando
DefaultListModel matchNames = new DefaultListModel();
matchNames.addElement(matchName);
- Message message = new Message("JOIN_GAME", App.sessionService.account.userName, App.sessionService.account.token, matchNames);
+ Message message = new Message("JOIN_GAME", App.session.account.userName, App.session.token, matchNames);
byte[] byteMessage = new String(message.toString()).getBytes();
buffer = ByteBuffer.wrap(byteMessage);
clientSocket.write(buffer);
- new Game(Page.window);
+ new GamePage(Page.window);
} catch (IOException e) {
e.printStackTrace();
diff --git a/Client/src/com/texttwist/client/pages/Game.java b/Client/src/com/texttwist/client/pages/GamePage.java
similarity index 85%
rename from Client/src/com/texttwist/client/pages/Game.java
rename to Client/src/com/texttwist/client/pages/GamePage.java
index 3351a70..097c69e 100644
--- a/Client/src/com/texttwist/client/pages/Game.java
+++ b/Client/src/com/texttwist/client/pages/GamePage.java
@@ -1,136 +1,135 @@
-package com.texttwist.client.pages;
-import com.texttwist.client.controllers.GameController;
-import constants.Config;
-import constants.Palette;
-import com.texttwist.client.ui.*;
-import javax.swing.*;
-import java.awt.*;
-import java.io.IOException;
-import java.util.concurrent.*;
-
-/**
- * Game Page
- */
-public class Game extends Page {
-
- private TTContainer gameContainer;
- private TTGameBox gameBox;
- private GameController gameController;
- public Timer timer;
-
- /*Spawnig points, fixed and not modifiable*/
- private final DefaultListModel letterSpawningPoints = setLetterSpawningPoint();
-
- /*Available spawning points*/
- private DefaultListModel availableLetterSpawningPoint = new DefaultListModel<>();
-
- public Game(JFrame window) throws IOException {
-
- super(window);
- gameController = new GameController(this);
- availableLetterSpawningPoint.clear();
- availableLetterSpawningPoint = letterSpawningPoints;
- gameController.waitForPlayers(gameController.startGame()).execute();
- createUIComponents();
- window.setVisible(true);
- }
-
- private Point occupyRandomPosition(){
-
- if(availableLetterSpawningPoint.size() > 1) {
- int index = ThreadLocalRandom.current().nextInt(0, letterSpawningPoints.size() - 1);
- Point placeholder = letterSpawningPoints.get(index);
- letterSpawningPoints.remove(index);
- return placeholder;
- }
-
- return new Point(0,0);
- }
-
-
- private SwingWorker timeIsOver() {
- return gameController.sendWords(new SwingWorker() {
- @Override
- protected Object doInBackground() throws Exception {
- new Highscores(window,true);
- return null;
- }
- });
- }
-
- private DefaultListModel setLetterSpawningPoint(){
-
- DefaultListModel l = new DefaultListModel<>();
-
- //FirstRow
- l.addElement(new Point(100,30));
- l.addElement(new Point(200,15));
- l.addElement(new Point(300,30));
- l.addElement(new Point(400,15));
- l.addElement(new Point(500,25));
-
- //SecondRow
- l.addElement(new Point(15,80));
- l.addElement(new Point(65,95));
- l.addElement(new Point(440,80));
- l.addElement(new Point(500,90));
-
- //ThirdRow
- l.addElement(new Point(50,140));
- l.addElement(new Point(150,130));
- l.addElement(new Point(250,125));
- l.addElement(new Point(350,145));
- l.addElement(new Point(450,140));
- l.addElement(new Point(550,130));
-
- return l;
- }
-
- public void showLetters(){
-
- /* Place letters in a available random spawning point */
- for(int i = 0; i < gameController.getLetters().size(); i++){
- new TTLetter(
- occupyRandomPosition(),
- gameController.getLetters().get(i),
- gameContainer
- );
- }
-
- window.repaint();
- window.revalidate();
- }
-
- @Override
- public void createUIComponents() throws IOException {
-
- addLogo(root);
-
- gameContainer = new TTContainer(
- null,
- new Dimension(1150,220),
- Palette.root_backgroundColor,
- -1,
- root
- );
-
- gameBox = new TTGameBox(
- new Point(150, 90),
- new Dimension(250, 40),
- "Insert word and Press ENTER!",
- gameController.getWords(),
- gameContainer
- );
-
- addFooter(root);
-
- timer = addTimer(
- footer,
- new Font(Palette.inputBox_font.getFontName(), Font.BOLD, 40),
- null,
- "00:00",
- timeIsOver(),
- Config.timeoutGame
- );
- }
-}
+package com.texttwist.client.pages;
+import com.texttwist.client.controllers.GameController;
+import constants.Config;
+import constants.Palette;
+import com.texttwist.client.ui.*;
+import javax.swing.*;
+import java.awt.*;
+import java.io.IOException;
+import java.util.concurrent.*;
+
+/**
+ * GamePage Page
+ */
+public class GamePage extends Page {
+
+ private TTContainer gameContainer;
+ private TTGameBox gameBox;
+ private GameController gameController;
+ public Timer timer;
+
+ /*Spawnig points fixed and not modifiable*/
+ private final DefaultListModel letterSpawningPoints = setLetterSpawningPoint();
+
+ /*Available spawning points*/
+ private DefaultListModel availableLetterSpawningPoint = new DefaultListModel<>();
+
+ public GamePage(JFrame window) throws IOException {
+
+ super(window);
+ gameController = new GameController(this);
+ availableLetterSpawningPoint.clear();
+ availableLetterSpawningPoint = letterSpawningPoints;
+ gameController.waitForPlayers(gameController.startGame()).execute();
+ createUIComponents();
+ window.setVisible(true);
+ }
+
+ private Point occupyRandomPosition(){
+
+ if(availableLetterSpawningPoint.size() > 1) {
+ int index = ThreadLocalRandom.current().nextInt(0, letterSpawningPoints.size() - 1);
+ Point placeholder = letterSpawningPoints.get(index);
+ letterSpawningPoints.remove(index);
+ return placeholder;
+ }
+
+ return new Point(0,0);
+ }
+
+
+ private SwingWorker timeIsOver() {
+ return gameController.sendWords(new SwingWorker() {
+ @Override
+ protected Object doInBackground() throws Exception {
+ new HighscoresPage(window,true);
+ return null;
+ }
+ }
+ );
+ }
+
+ private DefaultListModel setLetterSpawningPoint(){
+
+ DefaultListModel l = new DefaultListModel<>();
+
+ //FirstRow
+ l.addElement(new Point(100,30));
+ l.addElement(new Point(200,15));
+ l.addElement(new Point(300,30));
+ l.addElement(new Point(400,15));
+ l.addElement(new Point(500,25));
+
+ //SecondRow
+ l.addElement(new Point(15,80));
+ l.addElement(new Point(65,95));
+ l.addElement(new Point(440,80));
+ l.addElement(new Point(500,90));
+
+ //ThirdRow
+ l.addElement(new Point(50,140));
+ l.addElement(new Point(150,130));
+ l.addElement(new Point(250,125));
+ l.addElement(new Point(350,145));
+ l.addElement(new Point(450,140));
+ l.addElement(new Point(550,130));
+
+ return l;
+ }
+
+ public void showLetters(){
+
+ /* Place letters in a available random spawning point */
+ for(int i = 0; i < gameController.getLetters().size(); i++){
+ new TTLetter(
+ occupyRandomPosition(),
+ gameController.getLetters().get(i),
+ gameContainer
+ );
+ }
+
+ window.repaint();
+ window.revalidate();
+ }
+
+ @Override
+ public void createUIComponents() throws IOException {
+
+ addLogo(root);
+
+ gameContainer = new TTContainer(
+ null,
+ new Dimension(1150,220),
+ Palette.root_backgroundColor,
+ -1,
+ root
+ );
+
+ gameBox = new TTGameBox(
+ new Point(150, 90),
+ new Dimension(250, 40),
+ "Insert word and Press ENTER!",
+ gameController.getWords(),
+ gameContainer
+ );
+
+ addFooter(root);
+
+ timer = addTimer(
+ footer,
+ new Font(Palette.inputBox_font.getFontName(), Font.BOLD, 40),
+ timeIsOver(),
+ Config.timeoutGame
+ );
+ }
+}
diff --git a/Client/src/com/texttwist/client/pages/Highscores.java b/Client/src/com/texttwist/client/pages/Highscores.java
deleted file mode 100644
index 4f5998e..0000000
--- a/Client/src/com/texttwist/client/pages/Highscores.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package com.texttwist.client.pages;
-
-import com.texttwist.client.App;
-import com.texttwist.client.controllers.HighscoresController;
-import constants.Palette;
-import com.texttwist.client.ui.*;
-import javafx.util.Pair;
-
-import javax.swing.*;
-import java.awt.*;
-import java.io.IOException;
-import java.util.concurrent.Callable;
-
-/**
- * Created by loke on 14/06/2017.
- */
-public class Highscores extends Page{
-
- public TTContainer highscoreContainer;
- public Boolean isPartialScore;
- public HighscoresController highscoreController;
- public DefaultListModel> ranks = new DefaultListModel<>();
-
- public Highscores(JFrame window, Boolean isPartialScore) throws IOException {
- super(window);
- this.isPartialScore = isPartialScore;
-
- highscoreController = new HighscoresController();
- System.out.println("SHSHSHSHs");
- System.out.println(App.match.ranks);
- System.out.println(App.match.globalRanks);
-
- System.out.println(ranks);
- System.out.println("SHSHSHSssssssHs");
-
- if(this.isPartialScore){
- this.ranks = App.match.ranks;
- } else {
- this.highscoreController.fetchHighscores(window);
- this.ranks = App.match.globalRanks;
- }
- createUIComponents();
-
- window.setVisible(true);
- }
-
- @Override
- public void createUIComponents() throws IOException {
- addLogo(root);
- highscoreContainer = new TTContainer(
- null,
- new Dimension(1150,220),
- Palette.root_backgroundColor,
- -1,
- root);
-
- TTLabel title = new TTLabel(
- new Point(200,0),
- new Dimension(350,50),
- this.isPartialScore ? "Scores of the match" : "Highscores",
- new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 38),
- null,
- highscoreContainer);
-
- TTScrollList highscoreList = new TTScrollList(
- new Point(20, 60),
- new Dimension(515, 142),
- this.ranks,
- highscoreContainer);
- addFooter(root);
-
- addBack(footer,
- new Callable