/** (C) Game Page Network, Inc., Confidential, All Rights Reserved */
// StartCommand.java
// --paul@gamepage.net, 14aug97

import java.io.*;
import java.util.*;

public class StartCommand extends Command {
  StartCommand() {
    super("start", 1, "TABLE",
          "Start the game at TABLE.\n"+
          "Example: start 4\n"+
          "See also: tables, timer, open, join, observe, reset, resign.");
  }
  public void process(StringTokenizer args, Client c) {
    Member current = c.getMember();  
    OutputStreamWriter out = c.getWriter();
    String name = args.nextToken();
    Table table = Table.findIt(name);
    String error = "! start "+name+": ";
    if (table==null) {
      c.send("No such table.");
      return;
    }
    Game game = table.getGame();
    if (game==null) {
      c.send(error+"No game.");
    } else if (game.isActive()) {
      c.send(error+"Game already started.");
    } else if (!game.canStart(current)) {
      c.send(error+"Only blue player can start game.");
    } else if (!game.hasPlayers()) {
      c.send(error+"Not yet enough players.");
    } else if (!current.isPlayer(table)) {
      c.send(error+"You are not a player.");
    } else {
      table.start(c);
    }
  }
}

