fix calcolo punteggi + notifiche non permesse quando in gioco + ordinamento degli highscores per ordine crescente
This commit is contained in:
parent
dc206c0bb0
commit
4a29569052
16 changed files with 839 additions and 428 deletions
|
|
@ -42,7 +42,7 @@ public class Game {
|
|||
public DefaultListModel<Pair<String,Integer>> globalRanks = new DefaultListModel<>();
|
||||
public MulticastSocket multicastSocket;
|
||||
public INotificationServer server;
|
||||
|
||||
public Boolean isStarted = false;
|
||||
public SocketChannel clientSocket = null;
|
||||
|
||||
public Game(){
|
||||
|
|
@ -78,21 +78,23 @@ public class Game {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//Visualizza popup
|
||||
new TTDialog("success", "New invitation from: " + userName + "!",
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
App.game.joinMatch(userName);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new MenuPage(Page.window);
|
||||
}
|
||||
});
|
||||
if(!App.game.isStarted) {
|
||||
//Visualizza popup
|
||||
new TTDialog("success", "New invitation from: " + userName + "!",
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
App.game.joinMatch(userName);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new MenuPage(Page.window);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -100,29 +102,29 @@ public class Game {
|
|||
this.words = words;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setLetters(DefaultListModel<String> letters){
|
||||
this.letters = letters;
|
||||
}
|
||||
|
||||
public void joinMatch(String matchName) {
|
||||
//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.session.account.userName, App.session.token, matchNames);
|
||||
if(!isStarted) {
|
||||
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.session.account.userName, App.session.token, matchNames);
|
||||
|
||||
byte[] byteMessage = new String(message.toString()).getBytes();
|
||||
buffer = ByteBuffer.wrap(byteMessage);
|
||||
clientSocket.write(buffer);
|
||||
byte[] byteMessage = new String(message.toString()).getBytes();
|
||||
buffer = ByteBuffer.wrap(byteMessage);
|
||||
clientSocket.write(buffer);
|
||||
|
||||
new GamePage(Page.window);
|
||||
new GamePage(Page.window);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public class GamePage extends Page {
|
|||
public void showLetters(){
|
||||
|
||||
/* Place letters in a available random spawning point */
|
||||
for(int i = 0; i < gameController.getLetters().size(); i++){
|
||||
for(int i = 0; i < gameController.getLetters().size()-1; i++){
|
||||
new TTLetter(
|
||||
occupyRandomPosition(),
|
||||
gameController.getLetters().get(i),
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import javax.swing.*;
|
|||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Job: FetchHighscore
|
||||
|
|
@ -46,14 +47,11 @@ public class FetchHighscore extends SwingWorker<Void,Void> {
|
|||
|
||||
if (line.startsWith("MESSAGE")) {
|
||||
Message msg = Message.toMessage(line);
|
||||
//MODIFICARE QUI. IL BUG SI VERIFICA ANCHE CON 2 CLIENT, INVIANDO IL GIOCO A UN CLIENT CHE STA SULLA PAGNA DI 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(":");
|
||||
globalRanks.addElement(new Pair<>(splitted[0],new Integer(splitted[1])));
|
||||
}
|
||||
buffer.clear();
|
||||
|
||||
return null;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.texttwist.client.tasks;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.pages.GamePage;
|
||||
import com.texttwist.client.ui.TTDialog;
|
||||
|
||||
|
|
@ -19,11 +20,12 @@ public class StartGame extends SwingWorker<Void,Void> {
|
|||
public StartGame(DefaultListModel<String> letters, GamePage game){
|
||||
this.letters = letters;
|
||||
this.gamePage = game;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void doInBackground(){
|
||||
|
||||
App.game.isStarted=true;
|
||||
//Mostra pannello di conferma che le lettere sono tutte arrivate
|
||||
new TTDialog("success", "GamePage is ready. Press OK to start!",
|
||||
new Callable() {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ public class WaitForPlayers extends SwingWorker<DefaultListModel<String>,Default
|
|||
try {
|
||||
buffer = ByteBuffer.allocate(1024);
|
||||
String line1 = new String(buffer.array(), buffer.position(), buffer.remaining());
|
||||
System.out.println("Questo è il buffer prima: " + line1);
|
||||
TTDialog loading = new TTDialog("alert", "Waiting for users joins",null,null);
|
||||
buffer.flip();
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public class WaitForScore extends SwingWorker<Void,Void> {
|
|||
e.printStackTrace();
|
||||
}
|
||||
App.game.multicastSocket.close();
|
||||
|
||||
App.game.isStarted=false;
|
||||
try {
|
||||
this.callback.execute();
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class TTLetter extends TTLabel{
|
|||
super(position,
|
||||
new Dimension(50,50),
|
||||
caption,
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 40),
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 20),
|
||||
Palette.fontColor,
|
||||
parent);
|
||||
parent.add(this);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue