ultimate_tictactoe/game_manager.js

55 lines
1.0 KiB
JavaScript
Raw Normal View History

2019-03-06 12:11:43 +01:00
class GameManager
{
2019-03-07 13:07:51 +01:00
constructor(grid, n)
2019-03-06 12:11:43 +01:00
{
this.grid = grid;
2019-03-07 13:07:51 +01:00
this.n = n;
2019-03-06 12:11:43 +01:00
this.dummy_player = new Player("test_player", "rgb(0,128,0)");
this.grid.player_change_listener(this.dummy_player);
2019-03-07 10:38:08 +01:00
// possible modes:
// -- none
// -- local
// -- remote //TODO
this.game_mode = "none";
2019-03-07 13:07:51 +01:00
this.grid.register_click_callback((i,j,k,l) => this.click_listener(i,j,k,l));
}
click_listener(sub_x, sub_y, x,y)
{
// TODO: dummy
console.log("click");
2019-03-07 10:38:08 +01:00
}
register_game_mode_change_listener(func)
{
this.game_mode_change_listener = func;
}
set_game_mode(mode)
{
this.game_mode = mode;
this.game_mode_change_listener(mode);
console.log("changed gamemode to " + mode);
}
start_local_game()
{
this.set_game_mode("local");
this.grid.unblock_all();
2019-03-07 13:07:51 +01:00
this.grid.deactivate_all();
2019-03-07 10:38:08 +01:00
}
end_game()
{
this.set_game_mode("none");
2019-03-07 13:07:51 +01:00
this.grid.unblock_all();
2019-03-06 12:11:43 +01:00
}
}