ultimate_tictactoe/game_manager.js

66 lines
1.4 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.local_player_a = new Player("red player", "rgb(128,0,0)");
this.local_player_b = new Player("green player", "rgb(0,128,0");
2019-03-06 12:11:43 +01:00
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");
var subgrid = this.grid.subgrids[sub_y][sub_x];
var tile = subgrid.cells[y][x];
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");
2019-03-07 13:07:51 +01:00
this.grid.deactivate_all();
this.grid.unblock_all();
2019-03-07 10:38:08 +01:00
}
end_game()
{
this.set_game_mode("none");
this.grid.block_all();
}
on_local_game_move(sub_x, sub_y, x, y)
{
//checking whether one
2019-03-06 12:11:43 +01:00
}
}