fix calcolo punteggi + notifiche non permesse quando in gioco + ordinamento degli highscores per ordine crescente

This commit is contained in:
Lorenzo Iovino 2017-07-11 01:25:20 +02:00
parent dc206c0bb0
commit 4a29569052
16 changed files with 839 additions and 428 deletions

View file

@ -4,13 +4,11 @@ import interfaces.INotificationClient;
import interfaces.INotificationServer;
import javax.swing.*;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import static com.texttwist.client.App.session;
/**
* Created by loke on 19/06/2017.

View file

@ -140,7 +140,6 @@ public class ThreadProxy implements Callable<Boolean> {
} catch (IOException e) {
e.printStackTrace();
}
return false;
} catch (InterruptedException e) {
e.printStackTrace();

View file

@ -1,8 +1,12 @@
package com.texttwist.server.tasks;
import com.texttwist.server.components.AccountsManager;
import models.User;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.Callable;
/**
@ -15,6 +19,13 @@ public class ComputeHighscores implements Callable<DefaultListModel<String>> {
@Override
public DefaultListModel<String> call() throws Exception {
DefaultListModel<String> l = new DefaultListModel<>();
AccountsManager.getInstance().users.sort(new Comparator<User>() {
@Override
public int compare(User o1, User o2) {
return o2.score.compareTo(o1.score);
}
});
for(int i =0; i< AccountsManager.getInstance().users.size(); i++){
l.addElement(AccountsManager.getInstance().users.get(i).userName+":"+AccountsManager.getInstance().users.get(i).score);
}

View file

@ -23,6 +23,7 @@ public class ComputeScore implements Callable<Integer> {
public DefaultListModel<String> words;
public final String sender;
public Match match;
public DefaultListModel<String> wordsValid;
public ComputeScore(String sender, DefaultListModel<String> words, Match match){
this.words = words;
@ -32,21 +33,20 @@ public class ComputeScore implements Callable<Integer> {
@Override
public Integer call() throws Exception {
System.out.println("COMPUTE SCORE STARTED");
System.out.println(match);
System.out.println("COMPUTE SCORE STAsssssRTED");
System.out.print("CALCOLO LO SCORE PER " + match.matchCreator);
wordsValid = new DefaultListModel<>();
Integer score = 0;
for (int i = 0; i < words.size(); i++) {
if (isValid(words.get(i), match.letters)) {
score += words.get(i).length();
System.out.println(words.get(i) + " is valid!" + " : " + score );
wordsValid.addElement(words.get(i));
}
}
System.out.println("SOODDISDIS");
System.out.println(sender +" totalize SCORE = " + score);
match.setScore(sender, score);
System.out.println(score);
User u = AccountsManager.getInstance().findUser(sender);
u.addScore(score);
@ -55,12 +55,8 @@ public class ComputeScore implements Callable<Integer> {
match.matchTimeout = false;
System.out.println("MATCH TIMEOUT CANCELLATO");
//channel.close();
//Start receive words: tempo masimo 5 minuti per completare l'invio delle lettere.
match.setUndefinedScorePlayersToZero();
System.out.println("SEND BROADCAST");
match.sendScores();
}
@ -82,7 +78,7 @@ public class ComputeScore implements Callable<Integer> {
return true;
}
if(!isCharacterPresent){
if(!isCharacterPresent || wordsValid.indexOf(word)!=-1){
return false;
}
}