Added Handler skeletons concerning game logic and instructions on how to implement them

This commit is contained in:
Seraina 2022-04-01 12:20:08 +02:00
parent 5010b66d4c
commit 401b3bec52
6 changed files with 59 additions and 11 deletions

View File

@ -0,0 +1,11 @@
package ch.unibas.dmi.dbis.cs108.gamelogic;
/**
* Handles all communication Client to Server concerning games tate updates i.e. client a has voted
* Maybe unnecessary, everything that is needed might already be implemented in ClientHandler.
* We might only need to extend the protocol and its parser.
*/
public class ClientGameInfoHandler {
}

View File

@ -15,6 +15,7 @@ public class Game {
protected int nrOfGhosts; // sets how many Ghosts we start witch protected int nrOfGhosts; // sets how many Ghosts we start witch
protected int nrOfUsers; // safes how many clients are active in this Game protected int nrOfUsers; // safes how many clients are active in this Game
protected GameFunctions gameFunctions; protected GameFunctions gameFunctions;
//TODO: Figure out where Day/Night game state is saved maybe think about a game state class or smt.
/** /**
* Constructs a Game instance where: * Constructs a Game instance where:
* *

View File

@ -0,0 +1,10 @@
package ch.unibas.dmi.dbis.cs108.gamelogic;
/**
* Determines who heard something (via Passenger Array currently in GameFunctions 'passengerTrain')
* and broadcasts noise message to them (via ServerGameInfoHandler)
*/
public class NoiseHandler {
}

View File

@ -0,0 +1,12 @@
package ch.unibas.dmi.dbis.cs108.gamelogic;
/**
* Handles all communications Server to Client concerning game state or game state related requests
* - Needs a possibility to only send to Ghosts
* - and only humans
* TODO: Figure out what format the messages have, consider protocol add what is needed dont forget about parsing
*/
public class ServerGameInfoHandler {
}

View File

@ -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.BudaLogConfig;
import java.util.Arrays;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -43,7 +44,7 @@ public class Train {
} }
} }
LOGGER.debug("A bug"); LOGGER.info("The userTrain order is: " + Arrays.toString(userTrain));
this.orderOfTrain = userTrain; this.orderOfTrain = userTrain;
this.positionOfGhost = nrOfPlayers / 2; this.positionOfGhost = nrOfPlayers / 2;
} }
@ -63,23 +64,14 @@ public class Train {
} }
i++; i++;
} }
LOGGER.info("An information");
return false; return false;
} }
public static void main(String[] args) { public static void main(String[] args) {
int[] a = {1, 2, 3, 4, 5};
System.out.println(isInArray(a, 0));
//Test
try { try {
Train t = new Train(6, 1); Train t = new Train(6, 1);
for (int i = 0; i < 6; i++) {
System.out.print("|" + t.orderOfTrain[i] + "|");
}
System.out.println(" Ghost:" + t.positionOfGhost);
} catch (TrainOverflow e) { } catch (TrainOverflow e) {
System.out.println(e.getMessage()); LOGGER.error(e.getMessage());
} }
} }

View File

@ -0,0 +1,22 @@
package ch.unibas.dmi.dbis.cs108.gamelogic;
/**
* Handles the Event of Voting for Humans and Ghosts. Differentiates between day and night (human Ghost) and handles votes accordingly.
* - Sends voting request to passengers that need to be concerned
* - collects voting results
* - calculates who was voted for
* - decides consequence of vote:
* - Is Og Ghost: Humans win
* - Is last Human: Ghosts win
* - Is just a human: Message "x is a human"
* - Is a peasant Ghost -> kickoff
*
* (All messages going to Clients are handled via ServerGameInfoHandler)
*
* TODO: Think about if the timer needs to be implemented here or in the Game class
*/
public class VoteHandler {
}