up
This commit is contained in:
parent
44a9e43cd4
commit
8eab4d97c1
23 changed files with 714 additions and 11795 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package com.texttwist.client.controllers;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.tasks.JoinMatch;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
|
|
@ -14,6 +16,6 @@ public class MatchRequestController {
|
|||
}
|
||||
|
||||
public void joinMatch(String matchName){
|
||||
App.gameService.joinMatch(matchName);
|
||||
new JoinMatch(matchName).execute();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.texttwist.client.controllers;
|
||||
|
||||
import com.texttwist.client.tasks.InvitePlayers;
|
||||
|
||||
import javax.swing.*;
|
||||
import static com.texttwist.client.App.gameService;
|
||||
|
||||
|
|
@ -10,6 +12,7 @@ import static com.texttwist.client.App.gameService;
|
|||
public class MatchSetupController {
|
||||
|
||||
public void play(DefaultListModel<String> userNames) {
|
||||
gameService.beginMatch(userNames);
|
||||
new InvitePlayers(userNames).execute();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class MatchSetupPage extends Page{
|
|||
new Callable<Object>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
//If notificationServer response ok, start beginMatch, else error
|
||||
//If notificationServer response ok, start newMatch, else error
|
||||
matchSetupController.play(searchUserBar.list);
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ 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.JoinMatch;
|
||||
import com.texttwist.client.ui.TTDialog;
|
||||
import javafx.util.Pair;
|
||||
import models.Message;
|
||||
|
|
@ -26,10 +27,10 @@ public class GameService {
|
|||
public DefaultListModel<String> letters = new DefaultListModel<>();
|
||||
public DefaultListModel<Pair<String,Integer>> globalRanks = new DefaultListModel<>();
|
||||
public DefaultListModel<Pair<String,Integer>> ranks = new DefaultListModel<>();
|
||||
private Boolean gameIsStarted = false;
|
||||
public Boolean gameIsStarted = false;
|
||||
public Boolean isWaiting = false;
|
||||
|
||||
private void addToPendingList(String username) throws IOException {
|
||||
public void addToPendingList(String username) throws IOException {
|
||||
pendingList.addElement(username);
|
||||
}
|
||||
|
||||
|
|
@ -37,33 +38,6 @@ public class GameService {
|
|||
App.openClientTCPSocket();
|
||||
}
|
||||
|
||||
public void newMatch(String userName) {
|
||||
//Add to pending invites list
|
||||
try {
|
||||
this.addToPendingList(userName);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(!App.gameService.gameIsStarted && !App.gameService.isWaiting) {
|
||||
//Show invite popup
|
||||
new TTDialog("success", "New invite from: " + userName + "!",
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
App.gameService.joinMatch(userName);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new MenuPage(Page.window);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public DefaultListModel<String> getLetters(){
|
||||
return App.gameService.letters;
|
||||
}
|
||||
|
|
@ -76,32 +50,6 @@ public class GameService {
|
|||
this.letters = letters;
|
||||
}
|
||||
|
||||
public void joinMatch(String matchName) {
|
||||
|
||||
//Clear pending invitation list and join selected match
|
||||
if(!gameIsStarted) {
|
||||
this.pendingList.clear();
|
||||
try {
|
||||
DefaultListModel<String> matchNames = new DefaultListModel<>();
|
||||
matchNames.addElement(matchName);
|
||||
Message message = new Message("JOIN_GAME", App.session.account.userName, App.session.token, matchNames);
|
||||
|
||||
byte[] byteMessage = message.toString().getBytes();
|
||||
ByteBuffer buffer = ByteBuffer.wrap(byteMessage);
|
||||
App.clientTCP.write(buffer);
|
||||
new GamePage(Page.window);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Start game and wait for other players
|
||||
public void beginMatch(DefaultListModel<String> userNames) {
|
||||
new InvitePlayers(userNames).execute();
|
||||
}
|
||||
|
||||
public void start(){
|
||||
gameIsStarted = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.texttwist.client.services;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.tasks.BeginMatch;
|
||||
import interfaces.INotificationClient;
|
||||
import javax.swing.*;
|
||||
import java.rmi.RemoteException;
|
||||
|
|
@ -18,7 +19,7 @@ public class NotificationClientService implements INotificationClient {
|
|||
if(App.session != null) {
|
||||
if (users.contains(App.session.account.userName)) {
|
||||
App.logger.write(userName + " send a invitation!");
|
||||
App.gameService.newMatch(userName);
|
||||
new BeginMatch(userName).execute();
|
||||
} else {
|
||||
App.logger.write("User " + userName + " is slogged");
|
||||
}
|
||||
|
|
|
|||
52
Client/src/com/texttwist/client/tasks/BeginMatch.java
Normal file
52
Client/src/com/texttwist/client/tasks/BeginMatch.java
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package com.texttwist.client.tasks;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.pages.MenuPage;
|
||||
import com.texttwist.client.pages.Page;
|
||||
import com.texttwist.client.ui.TTDialog;
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Author: Lorenzo Iovino on 15/07/2017.
|
||||
* Description: Task: BeginMatch
|
||||
*
|
||||
*/
|
||||
public class BeginMatch extends SwingWorker<Void,Void> {
|
||||
|
||||
private String userName;
|
||||
|
||||
public BeginMatch(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void doInBackground() {
|
||||
//Add to pending invites list
|
||||
try {
|
||||
App.gameService.addToPendingList(userName);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(!App.gameService.gameIsStarted && !App.gameService.isWaiting) {
|
||||
//Show invite popup
|
||||
new TTDialog("success", "New invite from: " + userName + "!",
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
new JoinMatch(userName).execute();
|
||||
return null;
|
||||
}
|
||||
},
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new MenuPage(Page.window);
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
47
Client/src/com/texttwist/client/tasks/JoinMatch.java
Normal file
47
Client/src/com/texttwist/client/tasks/JoinMatch.java
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package com.texttwist.client.tasks;
|
||||
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.pages.GamePage;
|
||||
import com.texttwist.client.pages.Page;
|
||||
import models.Message;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Author: Lorenzo Iovino on 25/06/2017.
|
||||
* Description: Task: JoinMatch
|
||||
*
|
||||
*/
|
||||
public class JoinMatch extends SwingWorker<Void,Void> {
|
||||
|
||||
private String matchName;
|
||||
|
||||
public JoinMatch(String matchName) {
|
||||
this.matchName = matchName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void doInBackground() {
|
||||
//Clear pending invitation list and join selected match
|
||||
if(!App.gameService.gameIsStarted) {
|
||||
App.gameService.pendingList.clear();
|
||||
try {
|
||||
DefaultListModel<String> matchNames = new DefaultListModel<>();
|
||||
matchNames.addElement(matchName);
|
||||
Message message = new Message("JOIN_GAME", App.session.account.userName, App.session.token, matchNames);
|
||||
|
||||
byte[] byteMessage = message.toString().getBytes();
|
||||
ByteBuffer buffer = ByteBuffer.wrap(byteMessage);
|
||||
App.clientTCP.write(buffer);
|
||||
new GamePage(Page.window);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -79,6 +79,7 @@ public class WaitForPlayers extends SwingWorker<Void,Void> {
|
|||
|
||||
if(msg.data !=null ) {
|
||||
DefaultListModel<String> data = msg.data;
|
||||
|
||||
App.openClientMulticastSocket(Integer.valueOf(data.remove(data.size()-2)));
|
||||
App.gameService.setLetters(msg.data);
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue