Commit 888d6a4c authored by Jonathan Michalon's avatar Jonathan Michalon
Browse files

Bot plays!

The bot now places tiles (locally, and if alone).
Server don't assign players to game anymore, it's done by signal.
Bot don't quit (?!) and message receiving is badly stopped (should use
the cancel parameter?). Ban?
parent 1ec4a362
......@@ -49,8 +49,6 @@ public class Bot
}
debug ("Joined");
/* start listening to the server */
client.start_listening ();
/* react on game state changes */
client.game.notify["state"].connect ((s, p) => {
......@@ -60,11 +58,11 @@ public class Bot
debug ("Game started!");
break;
case OVCC.GameState.FINISHED:
loop.quit ();
leave ();
debug ("We're done, bye!");
break;
case OVCC.GameState.ABORTED:
loop.quit ();
leave ();
debug ("Abnormal game termination!");
break;
}
......
......@@ -127,9 +127,11 @@ namespace OVCC
if (state == GameState.STARTED) {
throw new GameError.STARTED ("Game already started");
}
state = GameState.STARTED;
/* set starting player as the first in the list */
current_player = _players.nth_data(0);
state = GameState.STARTED;
return true;
}
......
......@@ -69,7 +69,12 @@ namespace OVCC.Network
send_to_peer (SignalType.PLAYER_REMOVED, "s", p.nick);
});
game_object.notify["state"].connect ((s, p) => {
send_to_peer (SignalType.GAME_STATE, "i", ((OVCC.Game)s).state);
OVCC.GameState state = ((OVCC.Game)s).state;
/* other states should be automatic (useful until full communication) */
// if (state == OVCC.GameState.STARTED ||
// state == OVCC.GameState.ABORTED ) {
send_to_peer (SignalType.GAME_STATE, "i", state);
// }
});
}
......
......@@ -11,7 +11,7 @@ namespace OVCCClient
public class Client : Object
{
public Server server {get; private set; default = null;}
public Player player {get; set;}
public Player player {get; private set;}
public Game game {get; private set; default = null;}
public signal void place_tile (Tile t);
......@@ -53,24 +53,34 @@ namespace OVCCClient
public bool login (string nick)
throws ServerError
{
server.login_to (nick, "patate");
player = new Player (nick);
server.login_to (player);
return true;
}
/* start listening to the server */
public void start_listening ()
{
server.start_listening (game, player);
}
public Game join_table (int index)
throws ServerError
{
game = server.join_table (index);
game = server.join_table (index, player);
player.joined (game);
game.notify["current-player"].connect (() => {
debug ("Current player changed");
if (game.current_player == player) {
this.place_tile (game.current_tile);
}
});
game.board.tile_added.connect ((t, p) => {
if (game.current_player == player) {
// this.place_pawn (t);
}
});
return game;
}
}
......
......@@ -78,12 +78,12 @@ namespace OVCCClient
return true;
}
public /*async*/ bool login_to (Player player)
public /*async*/ bool login_to (string login, string password)
throws ServerError
{
Message msg;
send_message (new LoginMessage (player.nick, "patate"));
send_message (new LoginMessage (login, password));
try {
msg = Message.receive (input);
} catch (Error e) {
......@@ -116,9 +116,10 @@ namespace OVCCClient
} catch {
/* FIXME ? */
}
connection = null;
input = null;
output = null;
signal_handle = null;
connection = null;
input = null;
output = null;
}
public bool is_connected ()
......@@ -146,7 +147,7 @@ namespace OVCCClient
/* join a table, index -1 means any open table
* The index is typically within the list returned by enumerate_tables() */
public Game join_table (int index)
public Game join_table (int index, Player player)
throws ServerError
requires (connection != null)
{
......@@ -157,9 +158,14 @@ namespace OVCCClient
tileset.load (tiles, File.new_for_path (TILESET_FILE));
Game game = new Game.from_tileset(tileset);
return game;
/* start communication NOW: we have the game and the player and must
* send the PLAYER_ADDED triggered by next instruction... */
start_communication (game, player);
game.add_player (player);
throw new ServerError.NO_OPEN_TABLE ("Not implemented");
return game;
}
private void listen_loop ()
......@@ -191,7 +197,7 @@ namespace OVCCClient
signal_handle = null;
}
public void start_listening (Game game, Player player)
public void start_communication (Game game, Player player)
{
signal_handle = new SignalHandle (game, player, input, output);
Thread.create<void> (listen_loop, false);
......
......@@ -82,7 +82,8 @@ public class Client: Object
game = game_p;
signal_handle = new SignalHandle (game, player, input, output);
game.add_player (player);
/* the client adds itselves */
// game.add_player (player);
return true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment