Fixed some bugs now the VoteHanlder does what it is supposed to
This commit is contained in:
parent
5cfa6809a2
commit
4337583de6
@ -38,7 +38,7 @@ public class GameFunctions {
|
|||||||
for (int i = 0; i < nrOfPlayers; i++) {
|
for (int i = 0; i < nrOfPlayers; i++) {
|
||||||
Human h = new Human();
|
Human h = new Human();
|
||||||
h.setPosition(train.orderOfTrain[i]);
|
h.setPosition(train.orderOfTrain[i]);
|
||||||
passengerTrain[i] = h;
|
passengerTrain[train.orderOfTrain[i]] = h;
|
||||||
}
|
}
|
||||||
this.passengerTrain = passengerTrain;
|
this.passengerTrain = passengerTrain;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.gamelogic;
|
package ch.unibas.dmi.dbis.cs108.gamelogic;
|
||||||
|
|
||||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Ghost;
|
||||||
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.GhostPlayer;
|
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.GhostPlayer;
|
||||||
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
|
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@ -16,10 +17,13 @@ public class GhostifyHandler {
|
|||||||
* @param p Passenger to be ghostified
|
* @param p Passenger to be ghostified
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public GhostPlayer ghost(Passenger p, Game game) {
|
public Ghost ghost(Passenger p, Game game) { //TODO: Adjust for not only players but also npcs
|
||||||
|
LOGGER.debug("Passenger Position " + p.getPosition());
|
||||||
p.setGhost();
|
p.setGhost();
|
||||||
GhostPlayer g;
|
Ghost g;
|
||||||
g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false);
|
g = new Ghost();
|
||||||
|
g.setGhost();
|
||||||
|
g.setPosition(p.getPosition());
|
||||||
game.gameFunctions.passengerTrain[g.getPosition()] = g;
|
game.gameFunctions.passengerTrain[g.getPosition()] = g;
|
||||||
LOGGER.info("Passenger at position " + p.getPosition() + "has been ghostified");
|
LOGGER.info("Passenger at position " + p.getPosition() + "has been ghostified");
|
||||||
return g;
|
return g;
|
||||||
|
|||||||
@ -83,8 +83,10 @@ public class VoteHandler {
|
|||||||
if (votesForPlayers[i] == currentMax) { // if player at position i has most votes
|
if (votesForPlayers[i] == currentMax) { // if player at position i has most votes
|
||||||
ghostPosition = i;
|
ghostPosition = i;
|
||||||
LOGGER.info("Most votes for Passenger " + i);
|
LOGGER.info("Most votes for Passenger " + i);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LOGGER.debug("ghostPosition: " + ghostPosition);
|
||||||
GhostifyHandler gh = new GhostifyHandler();
|
GhostifyHandler gh = new GhostifyHandler();
|
||||||
Ghost g = gh.ghost(passengers[ghostPosition], game);
|
Ghost g = gh.ghost(passengers[ghostPosition], game);
|
||||||
passengers[ghostPosition] = g;
|
passengers[ghostPosition] = g;
|
||||||
@ -170,10 +172,10 @@ public class VoteHandler {
|
|||||||
if (!passenger.getIsGhost()) {
|
if (!passenger.getIsGhost()) {
|
||||||
humans++;
|
humans++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (humans == 1) {
|
if (humans == 1) {
|
||||||
System.out.println("Game over: ghosts win!");
|
System.out.println("Game over: ghosts win!");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Usual case: there is more than one human left and a normal ghost has been voted for -->
|
// Usual case: there is more than one human left and a normal ghost has been voted for -->
|
||||||
// kick this ghost off
|
// kick this ghost off
|
||||||
passengers[voteIndex].setKickedOff(true);
|
passengers[voteIndex].setKickedOff(true);
|
||||||
@ -192,10 +194,14 @@ public class VoteHandler {
|
|||||||
System.out.println();
|
System.out.println();
|
||||||
String[] print = new String[6];
|
String[] print = new String[6];
|
||||||
for (int i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
if(array[i].getIsGhost()) {
|
if (array[i].getKickedOff()) {
|
||||||
print[i] = "| ghost |";
|
print[i] = "| kicked off " + array[i].getPosition() + "|";
|
||||||
} else {
|
} else {
|
||||||
print[i] = "| human |";
|
if (array[i].getIsGhost()) {
|
||||||
|
print[i] = "| ghost " + array[i].getPosition() + "|";
|
||||||
|
} else {
|
||||||
|
print[i] = "| human " + array[i].getPosition() + "|";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,6 +221,7 @@ public class VoteHandler {
|
|||||||
testArray[3] = ghost;
|
testArray[3] = ghost;
|
||||||
testArray[3].setGhost();
|
testArray[3].setGhost();
|
||||||
testArray[3].setIsOg();
|
testArray[3].setIsOg();
|
||||||
|
testArray[3].setPosition(3);
|
||||||
print(testArray);
|
print(testArray);
|
||||||
LOGGER.info("NIGHT");
|
LOGGER.info("NIGHT");
|
||||||
ghostVote(testArray,game);
|
ghostVote(testArray,game);
|
||||||
@ -224,6 +231,13 @@ public class VoteHandler {
|
|||||||
humanVote(testArray, game);
|
humanVote(testArray, game);
|
||||||
print(testArray);
|
print(testArray);
|
||||||
|
|
||||||
|
LOGGER.info("NIGHT");
|
||||||
|
ghostVote(testArray,game);
|
||||||
|
print(testArray);
|
||||||
|
|
||||||
|
LOGGER.info("Day");
|
||||||
|
humanVote(testArray, game);
|
||||||
|
print(testArray);
|
||||||
} catch (TrainOverflow e) {
|
} catch (TrainOverflow e) {
|
||||||
LOGGER.warn(e.getMessage());
|
LOGGER.warn(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,17 +19,23 @@ public class Passenger {
|
|||||||
protected ClientHandler clientHandler;//the socket for the client associated with this Passenger, for NPCs, this can be null.
|
protected ClientHandler clientHandler;//the socket for the client associated with this Passenger, for NPCs, this can be null.
|
||||||
protected boolean hasVoted; //true if the player gave his vote during voting time
|
protected boolean hasVoted; //true if the player gave his vote during voting time
|
||||||
protected int vote; //saves the number of the player this passenger voted for during voting (0-5)
|
protected int vote; //saves the number of the player this passenger voted for during voting (0-5)
|
||||||
|
int sendcounter = 0;
|
||||||
/**
|
/**
|
||||||
* Sends a protocol message to the respective player or NPC.
|
* Sends a protocol message to the respective player or NPC.
|
||||||
* @param msg the message that is sent to this player.
|
* @param msg the message that is sent to this player.
|
||||||
**/
|
**/
|
||||||
public void send(String msg) {
|
public void send(String msg) {
|
||||||
if (msg.equals("Vote on who to ghostify!") || msg.equals("Vote for a ghost to kick off!")) {
|
sendcounter++;
|
||||||
vote = 1;
|
if (msg.equals("Vote on who to ghostify!")) {
|
||||||
|
vote = 1*sendcounter;
|
||||||
|
hasVoted = true; // for testing, when is it set to false again?
|
||||||
|
LOGGER.info("Voted for Position " + vote);
|
||||||
|
} else if(msg.equals("Vote for a ghost to kick off!")) {
|
||||||
|
vote = (int) (0.5*sendcounter);
|
||||||
hasVoted = true; // for testing, when is it set to false again?
|
hasVoted = true; // for testing, when is it set to false again?
|
||||||
LOGGER.info("Voted for Position " + vote);
|
LOGGER.info("Voted for Position " + vote);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
LOGGER.debug(msg);
|
LOGGER.debug(msg);
|
||||||
}
|
}
|
||||||
/*if (isPlayer) {
|
/*if (isPlayer) {
|
||||||
|
|||||||
Reference in New Issue
Block a user