Some changes to Structure of VoteHandler and related classes
This commit is contained in:
parent
2ad0b03cd5
commit
19c31356c2
@ -17,7 +17,7 @@ public class GameFunctions {
|
|||||||
int nrOfGhosts; // sets how many Ghosts we start witch
|
int nrOfGhosts; // sets how many Ghosts we start witch
|
||||||
int nrOfUsers; // safes how many clients are active in this Game
|
int nrOfUsers; // safes how many clients are active in this Game
|
||||||
Train train; // safes who sits where
|
Train train; // safes who sits where
|
||||||
Passenger[] passengerTrain;
|
public Passenger[] passengerTrain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a GameFunctions instance where nrOfPlayers >= nrOfUsers. Fills passengerTrain with
|
* Constructs a GameFunctions instance where nrOfPlayers >= nrOfUsers. Fills passengerTrain with
|
||||||
|
|||||||
@ -12,15 +12,16 @@ public class GhostifyHandler {
|
|||||||
*/
|
*/
|
||||||
private static int ghostifyCallCounter = -1;
|
private static int ghostifyCallCounter = -1;
|
||||||
|
|
||||||
public GhostPlayer ghost(Passenger p) {
|
public GhostPlayer ghost(Passenger p, Game game) {
|
||||||
p.setGhost();
|
p.setGhost();
|
||||||
|
GhostPlayer g;
|
||||||
ghostifyCallCounter++;
|
ghostifyCallCounter++;
|
||||||
if (ghostifyCallCounter == 0) {
|
if (ghostifyCallCounter == 0) {
|
||||||
GhostPlayer g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), true);
|
g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), true);
|
||||||
return g;
|
|
||||||
} else {
|
} else {
|
||||||
GhostPlayer g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false);
|
g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false);
|
||||||
return g;
|
|
||||||
}
|
}
|
||||||
|
game.gameFunctions.passengerTrain[g.getPosition()] = g;
|
||||||
|
return g;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
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.gamelogic.klassenstruktur.Ghost;
|
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;
|
||||||
@ -22,11 +23,13 @@ public class VoteHandler {
|
|||||||
public static final Logger LOGGER = LogManager.getLogger();
|
public static final Logger LOGGER = LogManager.getLogger();
|
||||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO(Alex): Documentation
|
* TODO(Alex): Documentation
|
||||||
* @param passengers
|
* @param passengers
|
||||||
*/
|
*/
|
||||||
public void ghostVote(Passenger[] passengers) {
|
public void ghostVote(Passenger[] passengers, Game game) {
|
||||||
|
|
||||||
|
|
||||||
// array to collect votes for all players during voting, i.e. votes for player 1 (passengers[0]) are saved in
|
// array to collect votes for all players during voting, i.e. votes for player 1 (passengers[0]) are saved in
|
||||||
// votesForPlayers[0]
|
// votesForPlayers[0]
|
||||||
@ -69,15 +72,19 @@ public class VoteHandler {
|
|||||||
LOGGER.info("Most votes" + currentMax);
|
LOGGER.info("Most votes" + currentMax);
|
||||||
|
|
||||||
// ghostify the player with most votes
|
// ghostify the player with most votes
|
||||||
|
int ghostPosition = 0;
|
||||||
for (int i = 0; i < votesForPlayers.length; i++) {
|
for (int i = 0; i < votesForPlayers.length; i++) {
|
||||||
if (votesForPlayers[i] == currentMax) { // if player has most votes
|
if (votesForPlayers[i] == currentMax) { // if player has most votes
|
||||||
|
ghostPosition = i;
|
||||||
LOGGER.info("Most votes for Passenger" + i);
|
LOGGER.info("Most votes for Passenger" + i);
|
||||||
GhostifyHandler gh = new GhostifyHandler();
|
|
||||||
Ghost g = gh.ghost(passengers[i]);
|
|
||||||
passengers[i].send(
|
|
||||||
"You are now a ghost!"); // TODO: ServerGameInfoHandler might deal with this one
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
GhostifyHandler gh = new GhostifyHandler();
|
||||||
|
Ghost g = gh.ghost(passengers[ghostPosition],game);
|
||||||
|
passengers[ghostPosition] = g;
|
||||||
|
passengers[ghostPosition].send(
|
||||||
|
"You are now a ghost!"); // TODO: ServerGameInfoHandler might deal with this one
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,18 +129,21 @@ public class VoteHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// deal with voting results
|
// deal with voting results
|
||||||
|
int voteIndex = 0;
|
||||||
for (int i = 0; i < votesForPlayers.length; i++) {
|
for (int i = 0; i < votesForPlayers.length; i++) {
|
||||||
if (votesForPlayers[i] == currentMax) { // if player has most votes
|
if (votesForPlayers[i] == currentMax) { // if player has most votes
|
||||||
if (!passengers[i].getIsGhost()) { // if player with most votes is human, notify everyone about it
|
voteIndex = i;
|
||||||
for (Passenger passenger : passengers) {
|
|
||||||
passenger.send(
|
|
||||||
"You voted for a human!"); // TODO: ServerGameInfoHandler might be better to use here
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (passengers[i].getIsGhost()) { // if player is a ghost
|
|
||||||
if (
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!passengers[voteIndex].getIsGhost()) { // if player with most votes is human, notify everyone about it
|
||||||
|
for (Passenger passenger : passengers) {
|
||||||
|
passenger.send(
|
||||||
|
"You voted for a human!"); // TODO: ServerGameInfoHandler might be better to use here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (passengers[voteIndex].getIsGhost()) { // if player is a ghost
|
||||||
|
if (passengers[voteIndex].i
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ public class Ghost extends Passenger {
|
|||||||
public static final Logger LOGGER = LogManager.getLogger();
|
public static final Logger LOGGER = LogManager.getLogger();
|
||||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||||
|
|
||||||
protected boolean isOG; //true if the Ghost is the original ghost.
|
protected boolean isOG = false; //true if the Ghost is the original ghost false by default.
|
||||||
|
|
||||||
public boolean getIsOG() {
|
public boolean getIsOG() {
|
||||||
return isOG;
|
return isOG;
|
||||||
|
|||||||
Reference in New Issue
Block a user