up
This commit is contained in:
parent
429eb1cb02
commit
5512f1a358
52 changed files with 5537 additions and 1557 deletions
|
|
@ -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(){
|
||||
|
|
|
|||
|
|
@ -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<String> getLetters(){
|
||||
return App.match.letters;
|
||||
return App.game.letters;
|
||||
}
|
||||
|
||||
public DefaultListModel<String> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
window.revalidate();
|
||||
window.repaint();
|
||||
System.out.println("ASDDD");
|
||||
return "";
|
||||
}
|
||||
});
|
||||
public DefaultListModel<Pair<String,Integer>> getRanks(Boolean isPartialRank) {
|
||||
return isPartialRank ? App.game.ranks : App.game.globalRanks;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String> userNames) {
|
||||
try {
|
||||
return App.match.play(userNames);
|
||||
return App.game.play(userNames);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String> pendingList = new DefaultListModel<String>();
|
||||
ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
private ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
public DefaultListModel<String> words = new DefaultListModel<String>();
|
||||
public DefaultListModel<String> letters = new DefaultListModel<String>();
|
||||
public DefaultListModel<Pair<String,Integer>> ranks = new DefaultListModel<>();
|
||||
public DefaultListModel<Pair<String,Integer>> 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<String> matchNames = new DefaultListModel<String>();
|
||||
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();
|
||||
|
|
@ -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<Point> letterSpawningPoints = setLetterSpawningPoint();
|
||||
|
||||
/*Available spawning points*/
|
||||
private DefaultListModel<Point> 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<Point> setLetterSpawningPoint(){
|
||||
|
||||
DefaultListModel<Point> 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<Point> letterSpawningPoints = setLetterSpawningPoint();
|
||||
|
||||
/*Available spawning points*/
|
||||
private DefaultListModel<Point> 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<Point> setLetterSpawningPoint(){
|
||||
|
||||
DefaultListModel<Point> 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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Pair<String, Integer>> 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<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new Menu(Page.window);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
75
Client/src/com/texttwist/client/pages/HighscoresPage.java
Normal file
75
Client/src/com/texttwist/client/pages/HighscoresPage.java
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.controllers.HighscoresController;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Highscores Page
|
||||
*/
|
||||
public class HighscoresPage extends Page{
|
||||
|
||||
private TTContainer highscoreContainer;
|
||||
private Boolean isPartialScore;
|
||||
private TTScrollList highscoreList;
|
||||
public JFrame window;
|
||||
private HighscoresController highscoreController;
|
||||
|
||||
public HighscoresPage(JFrame window, Boolean isPartialScore) throws IOException {
|
||||
super(window);
|
||||
this.window = window;
|
||||
this.isPartialScore = isPartialScore;
|
||||
highscoreController = new HighscoresController(this);
|
||||
highscoreController.fetchHighscores().execute();
|
||||
createUIComponents();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
public void showHighscoreList(){
|
||||
highscoreList = new TTScrollList(
|
||||
new Point(20, 60),
|
||||
new Dimension(515, 142),
|
||||
highscoreController.getRanks(isPartialScore),
|
||||
highscoreContainer
|
||||
);
|
||||
window.revalidate();
|
||||
window.repaint();
|
||||
}
|
||||
|
||||
@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(
|
||||
this.isPartialScore ? new Point(150,0) : 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
|
||||
);
|
||||
|
||||
addFooter(root);
|
||||
|
||||
addBack(footer,
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new MenuPage(Page.window);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
package com.texttwist.client.pages;
|
||||
import com.texttwist.client.controllers.HomeController;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
import com.texttwist.client.ui.TTDialog;
|
||||
import models.Response;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class Home extends Page {
|
||||
|
||||
private TTContainer loginDataContainer;
|
||||
private HomeController homeController;
|
||||
private TTContainer logoContainer;
|
||||
|
||||
public Home(JFrame window) {
|
||||
super(window);
|
||||
homeController = new HomeController();
|
||||
createUIComponents();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUIComponents(){
|
||||
addLogo(root);
|
||||
loginDataContainer = new TTContainer(
|
||||
null,
|
||||
new Dimension(1150,250),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
root);
|
||||
|
||||
TTInputField usernameField = new TTInputField(
|
||||
new Point(50,60),
|
||||
new Dimension(220,50),
|
||||
"Username",
|
||||
loginDataContainer);
|
||||
|
||||
TTPasswordField passwordField = new TTPasswordField(
|
||||
new Point(280,60),
|
||||
new Dimension(220,50),
|
||||
loginDataContainer);
|
||||
|
||||
TTButton loginBtn = new TTButton(
|
||||
new Point(50,120),
|
||||
new Dimension(450,50),
|
||||
"Go!",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
//TODO CHIAMA API PER LOGIN E SE TUTTO OKEY MANDA A PAGINA DEL MENU
|
||||
Response res = homeController.login(usernameField.getText(), String.valueOf(passwordField.getPassword()));
|
||||
if (res.code == 200){
|
||||
//OK, go to next page and show popup
|
||||
return new Menu(window);
|
||||
} else {
|
||||
return new TTDialog("alert", res.message,
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new Home(window);
|
||||
}
|
||||
},null);
|
||||
}
|
||||
}
|
||||
},
|
||||
loginDataContainer);
|
||||
|
||||
TTLabel registerText = new TTLabel(
|
||||
new Point(70,200),
|
||||
new Dimension(350,50),
|
||||
"Don't have an account?",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 24),
|
||||
null,
|
||||
loginDataContainer);
|
||||
|
||||
TTLabelBtn registerField = new TTLabelBtn(
|
||||
new Point(360, 200),
|
||||
new Dimension(210, 50),
|
||||
"Register!",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.BOLD, 34),
|
||||
null,
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new Register(Page.window);
|
||||
}
|
||||
},
|
||||
loginDataContainer);
|
||||
|
||||
}
|
||||
}
|
||||
96
Client/src/com/texttwist/client/pages/HomePage.java
Normal file
96
Client/src/com/texttwist/client/pages/HomePage.java
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
package com.texttwist.client.pages;
|
||||
import com.texttwist.client.controllers.HomeController;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
import com.texttwist.client.ui.TTDialog;
|
||||
import models.Response;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class HomePage extends Page {
|
||||
|
||||
private HomeController homeController;
|
||||
|
||||
public HomePage(JFrame window) {
|
||||
super(window);
|
||||
homeController = new HomeController();
|
||||
|
||||
createUIComponents();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUIComponents(){
|
||||
addLogo(root);
|
||||
|
||||
TTContainer loginDataContainer = new TTContainer(
|
||||
null,
|
||||
new Dimension(1150,250),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
root
|
||||
);
|
||||
|
||||
TTInputField usernameField = new TTInputField(
|
||||
new Point(50,60),
|
||||
new Dimension(220,50),
|
||||
"Username",
|
||||
loginDataContainer
|
||||
);
|
||||
|
||||
TTPasswordField passwordField = new TTPasswordField(
|
||||
new Point(280,60),
|
||||
new Dimension(220,50),
|
||||
loginDataContainer
|
||||
);
|
||||
|
||||
new TTButton(
|
||||
new Point(50,120),
|
||||
new Dimension(450,50),
|
||||
"Go!",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
Response res = homeController.login(usernameField.getText(), String.valueOf(passwordField.getPassword()));
|
||||
if (res.code == 200){
|
||||
return new MenuPage(window);
|
||||
} else {
|
||||
return new TTDialog("alert", res.message,
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new HomePage(window);
|
||||
}
|
||||
},null);
|
||||
}
|
||||
}
|
||||
},
|
||||
loginDataContainer
|
||||
);
|
||||
|
||||
new TTLabel(
|
||||
new Point(70,200),
|
||||
new Dimension(350,50),
|
||||
"Don't have an account?",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 24),
|
||||
null,
|
||||
loginDataContainer
|
||||
);
|
||||
|
||||
new TTLabelBtn(
|
||||
new Point(360, 200),
|
||||
new Dimension(210, 50),
|
||||
"RegisterPage!",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.BOLD, 34),
|
||||
null,
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new RegisterPage(Page.window);
|
||||
}
|
||||
},
|
||||
loginDataContainer
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,74 +1,77 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 14/06/2017.
|
||||
*/
|
||||
public class MatchRequests extends Page{
|
||||
|
||||
public TTContainer matchsContainer;
|
||||
MatchRequests(JFrame window) throws IOException {
|
||||
super(window);
|
||||
createUIComponents();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void createUIComponents() throws IOException {
|
||||
addLogo(root);
|
||||
matchsContainer = new TTContainer(
|
||||
null,
|
||||
new Dimension(1150,220),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
root);
|
||||
|
||||
TTLabel title = new TTLabel(
|
||||
new Point(150,0),
|
||||
new Dimension(350,50),
|
||||
"Pending matches",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 38),
|
||||
null,
|
||||
matchsContainer);
|
||||
|
||||
TTScrollList pendingMatches = new TTScrollList(
|
||||
new Point(20, 60),
|
||||
new Dimension(520, 142),
|
||||
App.match.pendingList,
|
||||
matchsContainer);
|
||||
|
||||
pendingMatches.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
super.mouseClicked(evt);
|
||||
JList thisList = (JList)evt.getSource();
|
||||
if (evt.getClickCount() == 2) {
|
||||
// Double-click detected
|
||||
int index = thisList.locationToIndex(evt.getPoint());
|
||||
App.match.joinMatch(App.match.pendingList.get(index));
|
||||
}
|
||||
}
|
||||
});
|
||||
addFooter(root);
|
||||
|
||||
addBack(footer,
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new Menu(Page.window);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* MatchRequest Page
|
||||
*/
|
||||
public class MatchRequestsPage extends Page{
|
||||
|
||||
public TTContainer matchsContainer;
|
||||
MatchRequestsPage(JFrame window) throws IOException {
|
||||
super(window);
|
||||
createUIComponents();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void createUIComponents() throws IOException {
|
||||
addLogo(root);
|
||||
matchsContainer = new TTContainer(
|
||||
null,
|
||||
new Dimension(1150,220),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
root
|
||||
);
|
||||
|
||||
new TTLabel(
|
||||
new Point(150,0),
|
||||
new Dimension(350,50),
|
||||
"Pending matches",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 38),
|
||||
null,
|
||||
matchsContainer
|
||||
);
|
||||
|
||||
TTScrollList pendingMatches = new TTScrollList(
|
||||
new Point(20, 60),
|
||||
new Dimension(520, 142),
|
||||
App.game.pendingList,
|
||||
matchsContainer
|
||||
);
|
||||
|
||||
pendingMatches.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
super.mouseClicked(evt);
|
||||
JList thisList = (JList)evt.getSource();
|
||||
if (evt.getClickCount() == 2) {
|
||||
// Double-click detected
|
||||
int index = thisList.locationToIndex(evt.getPoint());
|
||||
App.game.joinMatch(App.game.pendingList.get(index));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
addFooter(root);
|
||||
|
||||
addBack(footer,
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new MenuPage(Page.window);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.controllers.MatchSetupController;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 14/06/2017.
|
||||
*/
|
||||
public class MatchSetup extends Page{
|
||||
|
||||
public TTContainer matchSetupContainer;
|
||||
public MatchSetupController matchSetupController;
|
||||
|
||||
MatchSetup(JFrame window) throws Exception {
|
||||
super(window);
|
||||
matchSetupController = new MatchSetupController();
|
||||
createUIComponents();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUIComponents() throws Exception {
|
||||
addLogo(root);
|
||||
|
||||
matchSetupContainer = new TTContainer(
|
||||
null,
|
||||
new Dimension(1150,220),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
root);
|
||||
|
||||
TTLabel title = new TTLabel(
|
||||
new Point(170,0),
|
||||
new Dimension(350,50),
|
||||
"Invite players",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 38),
|
||||
null,
|
||||
matchSetupContainer);
|
||||
|
||||
TTSearchBar searchUserBar = new TTSearchBar(
|
||||
new Point(20, 80),
|
||||
new Dimension(250, 40),
|
||||
"Username",
|
||||
matchSetupContainer);
|
||||
|
||||
addFooter(root);
|
||||
addNext(footer,
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.BOLD, 40),
|
||||
null,
|
||||
"Play!",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
//If server response ok, start play, else error
|
||||
return matchSetupController.play(searchUserBar.list);
|
||||
}
|
||||
});
|
||||
|
||||
addBack(footer,
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new Menu(Page.window);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
75
Client/src/com/texttwist/client/pages/MatchSetupPage.java
Normal file
75
Client/src/com/texttwist/client/pages/MatchSetupPage.java
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.controllers.MatchSetupController;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* MatchSetup Page
|
||||
*/
|
||||
public class MatchSetupPage extends Page{
|
||||
|
||||
private MatchSetupController matchSetupController;
|
||||
|
||||
MatchSetupPage(JFrame window) throws Exception {
|
||||
super(window);
|
||||
matchSetupController = new MatchSetupController();
|
||||
createUIComponents();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUIComponents() throws Exception {
|
||||
addLogo(root);
|
||||
|
||||
TTContainer matchSetupContainer = new TTContainer(
|
||||
null,
|
||||
new Dimension(1150,220),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
root
|
||||
);
|
||||
|
||||
new TTLabel(
|
||||
new Point(170,0),
|
||||
new Dimension(350,50),
|
||||
"Invite players",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 38),
|
||||
null,
|
||||
matchSetupContainer
|
||||
);
|
||||
|
||||
TTSearchBar searchUserBar = new TTSearchBar(
|
||||
new Point(20, 80),
|
||||
new Dimension(250, 40),
|
||||
"Username",
|
||||
matchSetupContainer
|
||||
);
|
||||
|
||||
addFooter(root);
|
||||
|
||||
addNext(
|
||||
footer,
|
||||
"Play!",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
//If server response ok, start play, else error
|
||||
return matchSetupController.play(searchUserBar.list);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
addBack(footer,
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new MenuPage(Page.window);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
package com.texttwist.client.pages;
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.controllers.MenuController;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 14/06/2017.
|
||||
*/
|
||||
public class Menu extends Page{
|
||||
|
||||
private TTContainer menuBar;
|
||||
private MenuController menuController;
|
||||
|
||||
public Menu(JFrame window) throws IOException {
|
||||
super(window);
|
||||
createUIComponents();
|
||||
menuController = new MenuController();
|
||||
window.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUIComponents() throws IOException {
|
||||
addLogo(root);
|
||||
|
||||
menuBar = new TTContainer(
|
||||
null,
|
||||
new Dimension(1150,280),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
root);
|
||||
|
||||
TTLabel playerToSendInvite_flavourText = new TTLabel(
|
||||
new Point(25,15),
|
||||
new Dimension(350,20),
|
||||
"Welcome back, " + App.sessionService.account.userName + "!",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 24),
|
||||
null,
|
||||
menuBar);
|
||||
|
||||
TTButton newMatch = new TTButton(
|
||||
new Point(25,70),
|
||||
new Dimension(250,75),
|
||||
"New Match!",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
//TODO CHIAMA API PER REGISTRAZIONE E SE TUTTO OKEY MANDA A PAGINA LOGIN
|
||||
return new MatchSetup(window);
|
||||
}
|
||||
},
|
||||
menuBar);
|
||||
TTButton matchRequests = new TTButton(
|
||||
new Point(290,70),
|
||||
new Dimension(250,75),
|
||||
"In pending",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
//TODO CHIAMA API PER REGISTRAZIONE E SE TUTTO OKEY MANDA A PAGINA LOGIN
|
||||
return new MatchRequests(window);
|
||||
}
|
||||
},
|
||||
menuBar);
|
||||
TTCircleCounter circleCounter = new TTCircleCounter(
|
||||
new Point(290,70),
|
||||
new Dimension(25,25),
|
||||
menuBar.getGraphics(),
|
||||
menuBar);
|
||||
|
||||
TTButton highscores = new TTButton(
|
||||
new Point(25, 155),
|
||||
new Dimension(250, 75),
|
||||
"Highscores",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new Highscores(Page.window, false);
|
||||
}
|
||||
},
|
||||
menuBar);
|
||||
|
||||
TTButton logout = new TTButton(
|
||||
new Point(290, 155),
|
||||
new Dimension(250, 75),
|
||||
"Logout",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
menuController.logout(App.sessionService.account.userName);
|
||||
return new Home(Page.window);
|
||||
}
|
||||
},
|
||||
menuBar);
|
||||
|
||||
}
|
||||
}
|
||||
111
Client/src/com/texttwist/client/pages/MenuPage.java
Normal file
111
Client/src/com/texttwist/client/pages/MenuPage.java
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
package com.texttwist.client.pages;
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.controllers.MenuController;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 14/06/2017.
|
||||
*/
|
||||
public class MenuPage extends Page{
|
||||
|
||||
private TTContainer menuBar;
|
||||
private MenuController menuController;
|
||||
|
||||
public MenuPage(JFrame window) throws IOException {
|
||||
super(window);
|
||||
createUIComponents();
|
||||
menuController = new MenuController();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUIComponents() throws IOException {
|
||||
addLogo(root);
|
||||
|
||||
menuBar = new TTContainer(
|
||||
null,
|
||||
new Dimension(1150,280),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
root
|
||||
);
|
||||
|
||||
TTLabel playerToSendInvite_flavourText = new TTLabel(
|
||||
new Point(25,15),
|
||||
new Dimension(350,20),
|
||||
"Welcome back, " + App.session.account.userName + "!",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 24),
|
||||
null,
|
||||
menuBar
|
||||
);
|
||||
|
||||
TTButton newMatch = new TTButton(
|
||||
new Point(25,70),
|
||||
new Dimension(250,75),
|
||||
"New Game!",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
//TODO CHIAMA API PER REGISTRAZIONE E SE TUTTO OKEY MANDA A PAGINA LOGIN
|
||||
return new MatchSetupPage(window);
|
||||
}
|
||||
},
|
||||
menuBar
|
||||
);
|
||||
|
||||
TTButton matchRequests = new TTButton(
|
||||
new Point(290,70),
|
||||
new Dimension(250,75),
|
||||
"In pending",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
//TODO CHIAMA API PER REGISTRAZIONE E SE TUTTO OKEY MANDA A PAGINA LOGIN
|
||||
return new MatchRequestsPage(window);
|
||||
}
|
||||
},
|
||||
menuBar
|
||||
);
|
||||
|
||||
TTCircleCounter circleCounter = new TTCircleCounter(
|
||||
new Point(290,70),
|
||||
new Dimension(25,25),
|
||||
menuBar.getGraphics(),
|
||||
menuBar
|
||||
);
|
||||
|
||||
TTButton highscores = new TTButton(
|
||||
new Point(25, 155),
|
||||
new Dimension(250, 75),
|
||||
"Highscores",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new HighscoresPage(Page.window, false);
|
||||
}
|
||||
},
|
||||
menuBar
|
||||
);
|
||||
|
||||
TTButton logout = new TTButton(
|
||||
new Point(290, 155),
|
||||
new Dimension(250, 75),
|
||||
"Logout",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
menuController.logout(App.session.account.userName);
|
||||
return new HomePage(Page.window);
|
||||
}
|
||||
},
|
||||
menuBar
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +1,16 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
* Base Page
|
||||
*/
|
||||
public class Page {
|
||||
|
||||
|
|
@ -24,18 +19,18 @@ public class Page {
|
|||
public static JFrame window;
|
||||
|
||||
public Page(JFrame window){
|
||||
this.window = window;
|
||||
Page.window = window;
|
||||
|
||||
window.getContentPane().removeAll();
|
||||
window.repaint();
|
||||
window.revalidate();
|
||||
|
||||
root = new TTContainer(
|
||||
new Point(40,20),
|
||||
new Dimension(0,0),
|
||||
Palette.root_backgroundColor,
|
||||
BoxLayout.Y_AXIS,
|
||||
null);
|
||||
new Point(40,20),
|
||||
new Dimension(0,0),
|
||||
Palette.root_backgroundColor,
|
||||
BoxLayout.Y_AXIS,
|
||||
null);
|
||||
window.add(root);
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +77,7 @@ public class Page {
|
|||
root);
|
||||
}
|
||||
|
||||
public void addNext(TTContainer parent, Font font, Color fontColor, String caption, Callable<Object> clickHandler) {
|
||||
public void addNext(TTContainer parent, String caption, Callable<Object> clickHandler) {
|
||||
TTLabelBtn next = new TTLabelBtn(
|
||||
new Point(500, 0),
|
||||
new Dimension(150, 50),
|
||||
|
|
@ -93,16 +88,17 @@ public class Page {
|
|||
parent);
|
||||
}
|
||||
|
||||
public Timer addTimer(TTContainer parent, Font font, Color fontColor, String caption, SwingWorker timerEndHandler, Integer value) {
|
||||
public Timer addTimer(TTContainer parent, Font font, SwingWorker timerEndHandler, Integer value) {
|
||||
TTLabel lblTimer = new TTLabel(
|
||||
new Point(0, 0),
|
||||
new Dimension(150, 50),
|
||||
caption,
|
||||
font,
|
||||
fontColor,
|
||||
parent);
|
||||
new Point(0, 0),
|
||||
new Dimension(150, 50),
|
||||
"00:00",
|
||||
font,
|
||||
null,
|
||||
parent
|
||||
);
|
||||
|
||||
Timer timer = new Timer(1000, new ActionListener() {
|
||||
return new Timer(1000, new ActionListener() {
|
||||
private int count = value;
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
|
@ -120,11 +116,8 @@ public class Page {
|
|||
String str = String.format("%d:%02d", minutes, seconds);
|
||||
lblTimer.setText(str);
|
||||
count--;
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
return timer;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,90 +0,0 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.controllers.RegisterController;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
import models.Response;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
*/
|
||||
public class Register extends Page {
|
||||
|
||||
private TTContainer registerDataContainer;
|
||||
private RegisterController registerController;
|
||||
public Register(JFrame window) {
|
||||
super(window);
|
||||
createUIComponents();
|
||||
registerController = new RegisterController();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUIComponents() {
|
||||
addLogo(root);
|
||||
registerDataContainer = new TTContainer(
|
||||
null,
|
||||
new Dimension(1150,220),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
root);
|
||||
TTLabel registerText = new TTLabel(
|
||||
new Point(70,35),
|
||||
new Dimension(400,40),
|
||||
"<html><h2>Insert your datas and press Register!</h2></html>",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 12),
|
||||
null,
|
||||
registerDataContainer);
|
||||
TTInputField usernameField = new TTInputField(
|
||||
new Point(70,90),
|
||||
new Dimension(210,50),
|
||||
"Username",
|
||||
registerDataContainer);
|
||||
TTPasswordField passwordField = new TTPasswordField(
|
||||
new Point(290,90),
|
||||
new Dimension(210,50),
|
||||
registerDataContainer);
|
||||
TTButton register = new TTButton(
|
||||
new Point(70,150),
|
||||
new Dimension(430,50),
|
||||
"Register!",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
//TODO CHIAMA API PER LOGIN E SE TUTTO OKEY MANDA A PAGINA DEL MENU
|
||||
Response res = registerController.register(usernameField.getText(), String.valueOf(passwordField.getPassword()));
|
||||
if (res.code == 200){
|
||||
return new TTDialog("success", res.message,
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new Home(window);
|
||||
}
|
||||
},null);
|
||||
} else {
|
||||
return new TTDialog("alert", res.message,
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return null;
|
||||
}
|
||||
},null);
|
||||
}
|
||||
}
|
||||
},
|
||||
registerDataContainer);
|
||||
addFooter(root);
|
||||
addBack(footer,
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new Home(Page.window);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
101
Client/src/com/texttwist/client/pages/RegisterPage.java
Normal file
101
Client/src/com/texttwist/client/pages/RegisterPage.java
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.controllers.RegisterController;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
import models.Response;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
*/
|
||||
public class RegisterPage extends Page {
|
||||
|
||||
private TTContainer registerDataContainer;
|
||||
private RegisterController registerController;
|
||||
public RegisterPage(JFrame window) {
|
||||
super(window);
|
||||
createUIComponents();
|
||||
registerController = new RegisterController();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUIComponents() {
|
||||
addLogo(root);
|
||||
registerDataContainer = new TTContainer(
|
||||
null,
|
||||
new Dimension(1150,220),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
root
|
||||
);
|
||||
TTLabel registerText = new TTLabel(
|
||||
new Point(70,35),
|
||||
new Dimension(400,40),
|
||||
"<html><h2>Insert your datas and press RegisterPage!</h2></html>",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 12),
|
||||
null,
|
||||
registerDataContainer
|
||||
);
|
||||
|
||||
TTInputField usernameField = new TTInputField(
|
||||
new Point(70,90),
|
||||
new Dimension(210,50),
|
||||
"Username",
|
||||
registerDataContainer
|
||||
);
|
||||
|
||||
TTPasswordField passwordField = new TTPasswordField(
|
||||
new Point(290,90),
|
||||
new Dimension(210,50),
|
||||
registerDataContainer
|
||||
);
|
||||
|
||||
TTButton register = new TTButton(
|
||||
new Point(70,150),
|
||||
new Dimension(430,50),
|
||||
"RegisterPage!",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
//TODO CHIAMA API PER LOGIN E SE TUTTO OKEY MANDA A PAGINA DEL MENU
|
||||
Response res = registerController.register(usernameField.getText(), String.valueOf(passwordField.getPassword()));
|
||||
if (res.code == 200){
|
||||
return new TTDialog("success", res.message,
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new HomePage(window);
|
||||
}
|
||||
},null);
|
||||
} else {
|
||||
return new TTDialog("alert", res.message,
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return null;
|
||||
}
|
||||
},null);
|
||||
}
|
||||
}
|
||||
},
|
||||
registerDataContainer
|
||||
);
|
||||
|
||||
addFooter(root);
|
||||
|
||||
addBack(footer,
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new HomePage(Page.window);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -27,6 +27,6 @@ public class AuthService {
|
|||
|
||||
public Response logout(String userName) throws RemoteException, NotBoundException, MalformedURLException {
|
||||
IAuth auth = (IAuth) Naming.lookup(baseUrl);
|
||||
return auth.logout(userName, App.sessionService.account.token);
|
||||
return auth.logout(userName, App.session.token);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,10 +35,5 @@ public class HighscoresService {
|
|||
}
|
||||
}
|
||||
|
||||
public void fetchHighscores(Callable<String> callback){
|
||||
SwingWorker worker = new FetchHighscore(callback, clientSocket);
|
||||
worker.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,11 @@
|
|||
package com.texttwist.client.services;
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.pages.Game;
|
||||
import com.texttwist.client.pages.Home;
|
||||
import com.texttwist.client.pages.Menu;
|
||||
import com.texttwist.client.pages.Page;
|
||||
import com.texttwist.client.ui.TTDialog;
|
||||
import interfaces.INotificationClient;
|
||||
import models.Response;
|
||||
import utilities.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 15/06/2017.
|
||||
|
|
@ -27,9 +20,9 @@ public class NotificationClient implements INotificationClient {
|
|||
public Response sendInvite(String userName, DefaultListModel<String> users) throws RemoteException {
|
||||
Logger.write("Invoked invitation with username=" + userName + "|" + users.toString() );
|
||||
|
||||
if(users.contains(App.sessionService.account.userName)){
|
||||
if(users.contains(App.session.account.userName)){
|
||||
Logger.write(userName+" ti ha sfidato!");
|
||||
App.match.newMatch(userName);
|
||||
App.game.newMatch(userName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
package com.texttwist.client.services;
|
||||
|
||||
import models.Session;
|
||||
|
||||
/**
|
||||
* Created by loke on 17/06/2017.
|
||||
*/
|
||||
public class SessionService {
|
||||
|
||||
public Session account;
|
||||
public SessionService(){}
|
||||
|
||||
public void create(String userName, String token) {
|
||||
account = new Session(userName, token);
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
account = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +1,36 @@
|
|||
package com.texttwist.client.tasks;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import constants.Config;
|
||||
import com.texttwist.client.pages.HighscoresPage;
|
||||
import javafx.util.Pair;
|
||||
import models.Message;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.MulticastSocket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 28/06/2017.
|
||||
* Job: FetchHighscore
|
||||
*/
|
||||
public class FetchHighscore extends SwingWorker<Void,Void> {
|
||||
|
||||
DefaultListModel<Pair<String,Integer>> globalRanks = new DefaultListModel<Pair<String,Integer>>();
|
||||
Callable<String> callback;
|
||||
SocketChannel socketChannel;
|
||||
ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
private DefaultListModel<Pair<String,Integer>> globalRanks = new DefaultListModel<>();
|
||||
private SocketChannel socketChannel;
|
||||
private ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
HighscoresPage highscoresPage;
|
||||
|
||||
//TODO PASSARE LA CALLBACK ALLO SWING WORKER ED ESEGUIRLA AL DONE
|
||||
public FetchHighscore(Callable<String> callback, SocketChannel socketChannel){
|
||||
this.socketChannel = socketChannel;
|
||||
this.callback = callback;
|
||||
public FetchHighscore(HighscoresPage highscoresPage){
|
||||
this.socketChannel = App.game.clientSocket;
|
||||
this.highscoresPage = highscoresPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void doInBackground() {
|
||||
Message message = new Message("FETCH_HIGHSCORES", App.sessionService.account.userName, App.sessionService.account.token, new DefaultListModel<>());
|
||||
buffer.flip();
|
||||
buffer.clear();
|
||||
byte[] byteMessage = new String(message.toString()).getBytes();
|
||||
Message message = new Message("FETCH_HIGHSCORES", App.session.account.userName, App.session.token, new DefaultListModel<>());
|
||||
buffer = ByteBuffer.allocate(1024);
|
||||
System.out.println("SENDDDDD MESSAGE");
|
||||
byte[] byteMessage = message.toString().getBytes();
|
||||
buffer = ByteBuffer.wrap(byteMessage);
|
||||
try {
|
||||
socketChannel.write(buffer);
|
||||
|
|
@ -56,24 +50,13 @@ public class FetchHighscore extends SwingWorker<Void,Void> {
|
|||
if (line.startsWith("MESSAGE")) {
|
||||
Message msg = Message.toMessage(line);
|
||||
System.out.println(line);
|
||||
if (msg.message.equals("HIGHSCORES")) {
|
||||
if (msg.message.equals("HIGHSCORES") && msg.data != null) {
|
||||
|
||||
for(int i = 0; i< msg.data.size()-1; i++){
|
||||
String[] splitted = msg.data.get(i).split(":");
|
||||
System.out.println(splitted.toString());
|
||||
globalRanks.addElement(new Pair<String, Integer>(splitted[0],new Integer(splitted[1])));
|
||||
globalRanks.addElement(new Pair<>(splitted[0],new Integer(splitted[1])));
|
||||
}
|
||||
|
||||
App.match.globalRanks = globalRanks;
|
||||
|
||||
System.out.println(globalRanks);
|
||||
/*new TTDialog("alert", "Users not online!",
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return null;
|
||||
}
|
||||
}, null);*/
|
||||
return null;
|
||||
|
||||
}
|
||||
|
|
@ -86,14 +69,10 @@ public class FetchHighscore extends SwingWorker<Void,Void> {
|
|||
}
|
||||
|
||||
public void done(){
|
||||
System.out.println("Done");
|
||||
App.match.globalRanks = globalRanks;
|
||||
try {
|
||||
this.callback.call();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("Done Highscores");
|
||||
App.game.globalRanks = globalRanks;
|
||||
this.highscoresPage.showHighscoreList();
|
||||
System.out.println("DODODO");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
package com.texttwist.client.tasks;
|
||||
|
||||
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.Page;
|
||||
import com.texttwist.client.ui.TTDialog;
|
||||
import models.Message;
|
||||
|
|
@ -29,7 +28,7 @@ public class InvitePlayers extends SwingWorker<Boolean,Void> {
|
|||
}
|
||||
@Override
|
||||
public Boolean doInBackground() {
|
||||
Message message = new Message("START_GAME", App.sessionService.account.userName, App.sessionService.account.token, userNames);
|
||||
Message message = new Message("START_GAME", App.session.account.userName, App.session.token, userNames);
|
||||
|
||||
byte[] byteMessage = new String(message.toString()).getBytes();
|
||||
buffer = ByteBuffer.wrap(byteMessage);
|
||||
|
|
@ -66,7 +65,7 @@ public class InvitePlayers extends SwingWorker<Boolean,Void> {
|
|||
@Override
|
||||
public Object call() throws Exception {
|
||||
//In attesa dei giocatori
|
||||
new Game(Page.window);
|
||||
new GamePage(Page.window);
|
||||
return null;
|
||||
}
|
||||
}, null);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.texttwist.client.tasks;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.pages.Highscores;
|
||||
import constants.Config;
|
||||
import javafx.util.Pair;
|
||||
import models.Message;
|
||||
|
|
@ -9,10 +8,6 @@ import models.Message;
|
|||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.RunnableFuture;
|
||||
|
||||
import static com.texttwist.client.pages.Page.window;
|
||||
|
||||
/**
|
||||
* Created by loke on 29/06/2017.
|
||||
|
|
@ -39,12 +34,12 @@ public class SendWords extends SwingWorker<Void,Void> {
|
|||
InetAddress IPAddress = InetAddress.getByName(Config.WordsReceiverServerURI);
|
||||
byte[] sendData = new byte[1024];
|
||||
byte[] receiveData = new byte[1024];
|
||||
Message msg = new Message("WORDS", App.sessionService.account.userName, "", words);
|
||||
Message msg = new Message("WORDS", App.session.account.userName, "", words);
|
||||
String sentence = msg.toString();
|
||||
sendData = sentence.getBytes();
|
||||
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, Config.WordsReceiverServerPort);
|
||||
clientSocket.send(sendPacket);
|
||||
clientSocket.close();
|
||||
//clientSocket.close();
|
||||
|
||||
return null;
|
||||
} catch (UnknownHostException e) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.texttwist.client.tasks;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.pages.Game;
|
||||
import com.texttwist.client.pages.GamePage;
|
||||
import com.texttwist.client.ui.TTDialog;
|
||||
|
||||
import javax.swing.*;
|
||||
|
|
@ -15,24 +14,24 @@ public class StartGame extends SwingWorker<Void,Void> {
|
|||
|
||||
/*Words inserted from user*/
|
||||
private DefaultListModel<String> letters = new DefaultListModel<>();
|
||||
private Game game;
|
||||
private GamePage gamePage;
|
||||
|
||||
public StartGame(DefaultListModel<String> letters, Game game){
|
||||
public StartGame(DefaultListModel<String> letters, GamePage game){
|
||||
this.letters = letters;
|
||||
this.game = game;
|
||||
this.gamePage = game;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void doInBackground(){
|
||||
|
||||
//Mostra pannello di conferma che le lettere sono tutte arrivate
|
||||
new TTDialog("success", "Game is ready. Press OK to start!",
|
||||
new TTDialog("success", "GamePage is ready. Press OK to start!",
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
game.showLetters();
|
||||
gamePage.showLetters();
|
||||
System.out.println(letters);
|
||||
game.timer.start();
|
||||
gamePage.timer.start();
|
||||
return null;
|
||||
}
|
||||
}, null);
|
||||
|
|
@ -41,6 +40,6 @@ public class StartGame extends SwingWorker<Void,Void> {
|
|||
|
||||
@Override
|
||||
public void done(){
|
||||
System.out.println("Done start game");
|
||||
System.out.println("Done start gamePage");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,19 @@
|
|||
package com.texttwist.client.tasks;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.pages.Menu;
|
||||
import com.texttwist.client.pages.MenuPage;
|
||||
import com.texttwist.client.pages.Page;
|
||||
import com.texttwist.client.ui.TTDialog;
|
||||
import constants.Config;
|
||||
import models.Message;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutput;
|
||||
import java.nio.Buffer;
|
||||
import java.net.InetAddress;
|
||||
import java.net.MulticastSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.RunnableFuture;
|
||||
|
||||
/**
|
||||
* Created by loke on 25/06/2017.
|
||||
|
|
@ -31,7 +30,7 @@ public class WaitForPlayers extends SwingWorker<DefaultListModel<String>,Default
|
|||
public WaitForPlayers(SwingWorker callback) {
|
||||
this.callback = callback;
|
||||
this.words = words;
|
||||
this.socketChannel = App.match.clientSocket;
|
||||
this.socketChannel = App.game.clientSocket;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -55,7 +54,7 @@ public class WaitForPlayers extends SwingWorker<DefaultListModel<String>,Default
|
|||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new Menu(Page.window);
|
||||
return new MenuPage(Page.window);
|
||||
|
||||
}
|
||||
}, null);
|
||||
|
|
@ -64,17 +63,25 @@ public class WaitForPlayers extends SwingWorker<DefaultListModel<String>,Default
|
|||
|
||||
if (msg.message.equals("GAME_STARTED")) {
|
||||
loading.dispose();
|
||||
DefaultListModel<String> data = msg.data;
|
||||
|
||||
System.out.println("HERE");
|
||||
System.out.println(msg.data);
|
||||
Integer multicastId = Integer.valueOf(data.remove(data.size()-2));
|
||||
System.out.println(multicastId);
|
||||
App.match.setMulticastId(multicastId);
|
||||
letters = msg.data;
|
||||
DefaultListModel<String> data;
|
||||
if(msg.data !=null ) {
|
||||
data= msg.data;
|
||||
|
||||
System.out.println("HERE");
|
||||
Integer multicastId = Integer.valueOf(data.remove(data.size()-2));
|
||||
System.out.println(multicastId);
|
||||
App.game.setMulticastId(multicastId);
|
||||
|
||||
App.game.multicastSocket = new MulticastSocket(App.game.multicastId);
|
||||
InetAddress ia = InetAddress.getByName(Config.ScoreMulticastServerURI);
|
||||
App.game.multicastSocket.joinGroup(ia);
|
||||
letters = msg.data;
|
||||
|
||||
//socketChannel.close();
|
||||
return words;
|
||||
}
|
||||
|
||||
//socketChannel.close();
|
||||
return words;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -89,7 +96,7 @@ public class WaitForPlayers extends SwingWorker<DefaultListModel<String>,Default
|
|||
System.out.println("Done wait for players");
|
||||
try {
|
||||
System.out.println(letters);
|
||||
App.match.setLetters(letters);
|
||||
App.game.setLetters(letters);
|
||||
System.out.println("PAROLE IN INVIO");
|
||||
this.callback.execute();
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.texttwist.client.tasks;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.operations.Bool;
|
||||
import com.texttwist.client.App;
|
||||
import constants.Config;
|
||||
import javafx.util.Pair;
|
||||
|
|
@ -12,8 +11,6 @@ import java.net.DatagramPacket;
|
|||
import java.net.InetAddress;
|
||||
import java.net.MulticastSocket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.RunnableFuture;
|
||||
|
||||
/**
|
||||
* Created by loke on 27/06/2017.
|
||||
|
|
@ -34,28 +31,23 @@ public class WaitForScore extends SwingWorker<Void,Void> {
|
|||
InetAddress group = null;
|
||||
try {
|
||||
|
||||
MulticastSocket ms = new MulticastSocket(App.match.multicastId);
|
||||
InetAddress ia = InetAddress.getByName(Config.ScoreMulticastServerURI);
|
||||
ms.joinGroup(ia);
|
||||
System.out.println("Join multicast group");
|
||||
|
||||
byte[] buf = new byte[1024];
|
||||
DatagramPacket recv = new DatagramPacket(buf, buf.length);
|
||||
ms.receive(recv);
|
||||
App.game.multicastSocket.receive(recv);
|
||||
String s = new String(recv.getData());
|
||||
System.out.println("HSHSHSHS");
|
||||
System.out.println(s);
|
||||
Message msg = Message.toMessage(s);
|
||||
System.out.println(msg.data);
|
||||
|
||||
for(int i = 0; i< msg.data.size()-1; i++){
|
||||
String[] splitted = msg.data.get(i).split(":");
|
||||
System.out.println(splitted.toString());
|
||||
ranks.addElement(new Pair<String, Integer>(splitted[0],new Integer(splitted[1])));
|
||||
if(msg.data != null) {
|
||||
for (int i = 0; i < msg.data.size() - 1; i++) {
|
||||
String[] splitted = msg.data.get(i).split(":");
|
||||
System.out.println(splitted.toString());
|
||||
ranks.addElement(new Pair<String, Integer>(splitted[0], new Integer(splitted[1])));
|
||||
}
|
||||
}
|
||||
|
||||
App.match.ranks = ranks;
|
||||
System.out.println(App.match.ranks);
|
||||
App.game.ranks = ranks;
|
||||
System.out.println(App.game.ranks);
|
||||
System.out.println("ENDDDDd");
|
||||
|
||||
} catch (UnknownHostException e) {
|
||||
|
|
@ -68,8 +60,11 @@ public class WaitForScore extends SwingWorker<Void,Void> {
|
|||
|
||||
@Override
|
||||
public void done(){
|
||||
System.out.println("Done");
|
||||
App.match.ranks = ranks;
|
||||
System.out.println("Done ranks");
|
||||
App.game.ranks = ranks;
|
||||
App.game.multicastSocket.close();
|
||||
//App.game.clientSocket.close();
|
||||
|
||||
try {
|
||||
this.callback.execute();
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class TTSearchBar extends TTContainer{
|
|||
@Override
|
||||
public Object call() throws Exception {
|
||||
String username = ctx.getText();
|
||||
if(!username.equals("") && !username.equals(App.sessionService.account.userName)) {
|
||||
if(!username.equals("") && !username.equals(App.session.account.userName)) {
|
||||
ctx.setText("");
|
||||
list.addElement(username);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue