← Multiton lesson
Lab

Multiton

Sign in to run your code

Read the brief and the starter here. With a free account you can edit it, run the sample, step through it and check your work, and your progress is kept.

// One live game. Every player in it holds this same object.
type Room = { game: string; code: string; id: number; moves: number };

// The game server: every player who joins asks it for a room.
class GameServer {
  private created = 0;

  // Makes one new room. Room numbers count this server's creations.
  private create(game: string, code: string): Room {
    this.created++;
    return { game, code, id: this.created, moves: 0 };
  }

  // A player joins a game by its code. Today every join makes a new room.
  join(game: string, code: string): Room {
    return this.create(game, code);
  }

  // How many rooms the server keeps open.
  openRooms(): number {
    return 0;
  }
}