added log, fixed checkIfWon()
This commit is contained in:
parent
3ffe26f9ae
commit
f07bceb019
3 changed files with 8 additions and 9 deletions
|
@ -15,7 +15,6 @@ function hi(player_id) {
|
||||||
var p2_id = GGS.localStorage.getItem("p2_id");
|
var p2_id = GGS.localStorage.getItem("p2_id");
|
||||||
if (!p1_id) {
|
if (!p1_id) {
|
||||||
GGS.localStorage.setItem("p1_id", player_id);
|
GGS.localStorage.setItem("p1_id", player_id);
|
||||||
GGS.localStorage.setItem("next_player", 1);
|
|
||||||
GGS.sendCommand(player_id, "welcome", "1");
|
GGS.sendCommand(player_id, "welcome", "1");
|
||||||
} else if (!p2_id) {
|
} else if (!p2_id) {
|
||||||
GGS.localStorage.setItem("p2_id", player_id);
|
GGS.localStorage.setItem("p2_id", player_id);
|
||||||
|
@ -48,8 +47,8 @@ function move(player_id, args) {
|
||||||
gameBoard[props.x][props.y] = p;
|
gameBoard[props.x][props.y] = p;
|
||||||
GGS.localStorage.setItem("game_board", JSON.stringify(gameBoard));
|
GGS.localStorage.setItem("game_board", JSON.stringify(gameBoard));
|
||||||
GGS.sendCommandToAll("game_board", boardAsString(gameBoard));
|
GGS.sendCommandToAll("game_board", boardAsString(gameBoard));
|
||||||
|
GGS.log(this.checkIfWon(gameBoard))
|
||||||
if (this.checkIfWon()) {
|
if (this.checkIfWon(gameBoard)) {
|
||||||
if (p == 1) {
|
if (p == 1) {
|
||||||
GGS.sendCommand(p1_id, "winner", "You win!");
|
GGS.sendCommand(p1_id, "winner", "You win!");
|
||||||
GGS.sendCommand(p2_id, "loser", "You lose!");
|
GGS.sendCommand(p2_id, "loser", "You lose!");
|
||||||
|
@ -75,9 +74,9 @@ function move(player_id, args) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkIfWon() {
|
function checkIfWon(gameBoard) {
|
||||||
|
|
||||||
var gameBoard = JSON.parse(GGS.localStorage.getItem("game_board"));
|
//var gameBoard = JSON.parse(GGS.localStorage.getItem("game_board"));
|
||||||
|
|
||||||
for (i = 0; i < ROWS; ++i) {
|
for (i = 0; i < ROWS; ++i) {
|
||||||
for (j = 0; j < ROWS; ++j) {
|
for (j = 0; j < ROWS; ++j) {
|
||||||
|
@ -133,8 +132,9 @@ function newGame() {
|
||||||
}
|
}
|
||||||
|
|
||||||
GGS.localStorage.setItem("game_board", JSON.stringify(gameBoard));
|
GGS.localStorage.setItem("game_board", JSON.stringify(gameBoard));
|
||||||
GGS.sendCommandToAll("new_game", "");
|
GGS.sendCommandToAll("new_game", "");
|
||||||
GGS.sendCommandToAll("game_board", boardAsString(gameBoard));
|
GGS.sendCommandToAll("game_board", boardAsString(gameBoard));
|
||||||
|
GGS.localStorage.setItem("next_player", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function boardAsString(gameBoard) {
|
function boardAsString(gameBoard) {
|
||||||
|
|
|
@ -95,8 +95,8 @@ expose(Global, Table) ->
|
||||||
{"serverInfo", fun(#erlv8_fun_invocation{}, []) ->
|
{"serverInfo", fun(#erlv8_fun_invocation{}, []) ->
|
||||||
PlayerList = ggs_coordinator:get_all_players(),
|
PlayerList = ggs_coordinator:get_all_players(),
|
||||||
integer_to_list(length(PlayerList))
|
integer_to_list(length(PlayerList))
|
||||||
end}
|
end},
|
||||||
%{"log", fun(#erlv8_fun_invocation{}, [Arg]) -> erlang:display(Arg) end }
|
{"log", fun(#erlv8_fun_invocation{}, [Arg]) -> erlang:display(Arg) end }
|
||||||
%{"setTimeout", fund(#erlv8_fun_invocation{}, [Time, FunctionName])-> setTimeout(Time, FunctionName) end}
|
%{"setTimeout", fund(#erlv8_fun_invocation{}, [Time, FunctionName])-> setTimeout(Time, FunctionName) end}
|
||||||
])).
|
])).
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,6 @@ handle_cast({srv_cmd, "hello", _Headers, TableToken}, State) ->
|
||||||
{noreply, State#state{ table = TPid } }
|
{noreply, State#state{ table = TPid } }
|
||||||
end;
|
end;
|
||||||
handle_cast({srv_cmd, "define", _Headers, Data}, #state { table = Table } = State) ->
|
handle_cast({srv_cmd, "define", _Headers, Data}, #state { table = Table } = State) ->
|
||||||
erl:display(Data),
|
|
||||||
ggs_table:notify(Table, self(), {server, define, Data}),
|
ggs_table:notify(Table, self(), {server, define, Data}),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_cast({game_cmd, Command, _Headers, Data}, #state { table = Table } = State) ->
|
handle_cast({game_cmd, Command, _Headers, Data}, #state { table = Table } = State) ->
|
||||||
|
|
Reference in a new issue