Make our multiplayer experience easy

doing multiplayer game is a lot of fun just bugs what rune it when you spend ours without a clue ,so i tried to write my own engine to test my code but doing so for every game is a lot of tremendous work
my hope is that for every game there is downloadable class/s that will do the engine work then i just pass my code to this engine so i can debug my code with ease

why is it that hard also current solution available are confusing and i didn’t have a clue how they work their has to be official help on this regard

my current work is simple a abstract class that represent the game data engine and a player inter face the represent the player

public interface CodinGameTeam {

    void initializeTeam(Scanner in);

    String playTurn(Scanner in);

}
class MyTeam implements CodinGameTeam {
      //impelementation go there
}

all i have to do is to implement this interface and in the body of void initializeTeam(Scanner in) i write the code the handle initial game data pass in variable in

then on String playTurn(Scanner in) i write the code the handle one turn game data pass in variable in “this replace the game loop”

after implementing it i just create object of it pass it to engine class

class JoinThePacEngine extends CodinGameEngine {
}
public abstract class CodinGameEngine {

    protected int turn = 0;
    protected final List<CodinGameTeam> teams = new LinkedList<>() ;

    public CodinGameEngine(List<CodinGameTeam> teams) {
        this.teams.addAll(Collections.unmodifiableList(teams));
    }
    
    public final void playGame() {
        setupGameData();
        
        if (teams == null || teams.isEmpty()) {
            throw new ErrorInMethod("playGame() CodinGameEngine", "team list are null or empty");
        }
        for (CodinGameTeam a : teams) {
            a.initializeTeam(getInitializationGameData(a));
        }
        int canPlayCount = teams.size();
        while (!gameEnds() && canPlayCount > 0 && turn <= getMaxTurnCount()) {
            HashMap<CodinGameTeam, String> playerMessages = new HashMap<>();
            for (CodinGameTeam a : teams) {
                if (canPlay(a)) {
                String msg = a.playTurn(getGameData(a));
                playerMessages.put(a, msg);
            }
        }
        for (Map.Entry<CodinGameTeam, String> msgEntry : playerMessages.entrySet()) {
            String errMsg = updateGameData(msgEntry.getValue(), msgEntry.getKey());
            if (!errMsg.isEmpty()) {
                setCanNotPlay(msgEntry.getKey());
                canPlayCount--;
                System.out.println(errMsg);
            }
        }
        resolveGameTrun();
        turn++;
    }
}

protected abstract void setupGameData();

protected abstract Scanner getInitializationGameData(CodinGameTeam t);

protected abstract Scanner getGameData(CodinGameTeam t);

/**
 * this method update game data and should return error message if occurred
 * or "" if no error
 *
 * @param outputMsg
 * @param t
 * @return this method should return error message if occurred or "" if no
 * error
 */
protected abstract String updateGameData(String outputMsg, CodinGameTeam t);

protected abstract void resolveGameTrun();

protected abstract boolean gameEnds();

protected abstract int getMaxTurnCount();

protected abstract boolean canPlay(CodinGameTeam t);

protected abstract void setCanNotPlay(CodinGameTeam t);

}
then using it as follow

public static void main(String[] args) {
        List<CodinGameTeam> temp = new ArrayList<>();
        temp.add(new JoinThePacTeam());
        temp.add(new JoinThePacTeam());
        JoinThePacEngine g = new JoinThePacEngine(temp);
        g.playGame();
    }

not the best work there but manged to get some code running but make engine for every game is very exhausting so i think if their is a way to make me just download the engine write my solution run and test :grin: