mirror of
https://github.com/Vale54321/schafkopf-bot.git
synced 2025-12-16 11:49:33 +01:00
edited a lot of stuff (#52)
This commit is contained in:
committed by
GitHub
parent
539e29dc56
commit
ea5df95228
@@ -0,0 +1,51 @@
|
||||
package org.schafkopf;
|
||||
|
||||
import java.util.List;
|
||||
import org.schafkopf.SchafkopfException.NotEnoughPlayersException;
|
||||
import org.schafkopf.SchafkopfMessage.SchafkopfBaseMessage;
|
||||
import org.schafkopf.SchafkopfMessage.SchafkopfMessageType;
|
||||
import org.schafkopf.player.BotPlayer;
|
||||
import org.schafkopf.player.Player;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* The main entrypoint of the Application.
|
||||
*/
|
||||
public abstract class BaseGameSession implements MessageSender {
|
||||
|
||||
protected static final Logger logger = LoggerFactory.getLogger(BaseGameSession.class);
|
||||
protected Thread spielThread;
|
||||
protected Schafkopf schafkopf;
|
||||
protected List<Player> players;
|
||||
|
||||
void startGame(List<Player> players) {
|
||||
logger.info("Starting game");
|
||||
for (int i = players.size(); i < 4; i++) {
|
||||
players.add(new BotPlayer("Bot " + i));
|
||||
}
|
||||
|
||||
sendMessage(new SchafkopfBaseMessage(SchafkopfMessageType.GAME_START_READY));
|
||||
|
||||
//wait for 5 seconds
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
spielThread = new Thread(() -> {
|
||||
try {
|
||||
schafkopf = new Schafkopf(players.toArray(Player[]::new), this);
|
||||
schafkopf.startGame();
|
||||
} catch (NotEnoughPlayersException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
spielThread.start();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user