Game going, pads moving up.
This commit is contained in:
parent
1ec145efa8
commit
f827795dd8
2 changed files with 25 additions and 16 deletions
|
@ -53,9 +53,7 @@ received_command(Headers, Data) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
make_message(ServerOrGame, Command, Args) ->
|
make_message(ServerOrGame, Command, Args) ->
|
||||||
io:format("Before fetch gametoken~n"),
|
|
||||||
GameToken = pong_bot:get_game_token(),
|
GameToken = pong_bot:get_game_token(),
|
||||||
io:format("After fetch gametoken~n"),
|
|
||||||
StrGameToken = string:concat("Token: ", GameToken),
|
StrGameToken = string:concat("Token: ", GameToken),
|
||||||
StrGameTokenln = string:concat(StrGameToken, "\n"),
|
StrGameTokenln = string:concat(StrGameToken, "\n"),
|
||||||
StrCommand = string:concat("-Command: ", Command),
|
StrCommand = string:concat("-Command: ", Command),
|
||||||
|
|
|
@ -17,11 +17,6 @@ communication_loop(Socket) ->
|
||||||
communication_loop(Socket).
|
communication_loop(Socket).
|
||||||
|
|
||||||
|
|
||||||
% A = gen_tcp:recv(Socket, 0),
|
|
||||||
% ggs_network:read(A),
|
|
||||||
%communication_loop(Socket).
|
|
||||||
|
|
||||||
|
|
||||||
peek_socket() ->
|
peek_socket() ->
|
||||||
gen_server:call({global, pong_bot}, socket).
|
gen_server:call({global, pong_bot}, socket).
|
||||||
|
|
||||||
|
@ -69,9 +64,11 @@ welcome(Who_am_I) ->
|
||||||
io:format("I am player: ~s~n", [Who_am_I]),
|
io:format("I am player: ~s~n", [Who_am_I]),
|
||||||
case Who_am_I of
|
case Who_am_I of
|
||||||
"1" ->
|
"1" ->
|
||||||
|
io:format("I made myself into player 1~n"),
|
||||||
Me = gen_server:call({global, pong_bot}, player1),
|
Me = gen_server:call({global, pong_bot}, player1),
|
||||||
gen_server:cast({global, pong_bot}, {me, Me});
|
gen_server:cast({global, pong_bot}, {me, Me});
|
||||||
"2" ->
|
"2" ->
|
||||||
|
io:format("I made myself into player 2~n"),
|
||||||
Me = gen_server:call({global, pong_bot}, player2),
|
Me = gen_server:call({global, pong_bot}, player2),
|
||||||
gen_server:cast({global, pong_bot}, {me, Me})
|
gen_server:cast({global, pong_bot}, {me, Me})
|
||||||
end.
|
end.
|
||||||
|
@ -91,6 +88,7 @@ gameTick() ->
|
||||||
true ->
|
true ->
|
||||||
case SendStart of
|
case SendStart of
|
||||||
false ->
|
false ->
|
||||||
|
io:format("Command start sent~n"),
|
||||||
ggs_network:send_command("start", ""),
|
ggs_network:send_command("start", ""),
|
||||||
gen_server:cast({global, pong_bot}, {start, true});
|
gen_server:cast({global, pong_bot}, {start, true});
|
||||||
true ->
|
true ->
|
||||||
|
@ -114,20 +112,25 @@ gameTick() ->
|
||||||
|
|
||||||
|
|
||||||
ball(Pos_s) ->
|
ball(Pos_s) ->
|
||||||
|
io:format("Ball~n"),
|
||||||
PosList = string:tokens(Pos_s, ","),
|
PosList = string:tokens(Pos_s, ","),
|
||||||
XStr = lists:nth(1,PosList),
|
XStr = lists:nth(1,PosList),
|
||||||
YStr = lists:nth(1,PosList),
|
YStr = lists:nth(2,PosList),
|
||||||
X = string:to_integer(XStr),
|
X = list_to_integer(XStr),
|
||||||
Y = string:to_integer(YStr),
|
Y = list_to_integer(YStr),
|
||||||
|
io:format("X~B~n", [X]),
|
||||||
|
io:format("Y~B~n", [Y]),
|
||||||
Pos = {X, Y},
|
Pos = {X, Y},
|
||||||
gen_server:cast({global, pong_bot}, {ball, Pos}).
|
gen_server:cast({global, pong_bot}, {ball, Pos}).
|
||||||
|
|
||||||
player1_y(YStr) ->
|
player1_y(YStr) ->
|
||||||
Y = string:to_integer(YStr),
|
Y = list_to_integer(YStr),
|
||||||
|
io:format("Y in integer: ~B~n", [Y]),
|
||||||
gen_server:cast({global, pong_bot}, {player1_y, Y}).
|
gen_server:cast({global, pong_bot}, {player1_y, Y}).
|
||||||
|
|
||||||
player2_y(YStr) ->
|
player2_y(YStr) ->
|
||||||
Y = string:to_integer(YStr),
|
Y = list_to_integer(YStr),
|
||||||
|
io:format("Y in integer: ~B~n", [Y]),
|
||||||
gen_server:cast({global, pong_bot}, {player2_y, Y}).
|
gen_server:cast({global, pong_bot}, {player2_y, Y}).
|
||||||
|
|
||||||
game(WaitOrStart) ->
|
game(WaitOrStart) ->
|
||||||
|
@ -172,6 +175,14 @@ handle_call(player2_y, _From, State) ->
|
||||||
{_,Y} = dict:fetch(player2, State),
|
{_,Y} = dict:fetch(player2, State),
|
||||||
{reply, Y, State};
|
{reply, Y, State};
|
||||||
|
|
||||||
|
handle_call(ball, _From, State) ->
|
||||||
|
Ball = dict:fetch(ball, State),
|
||||||
|
{reply, Ball, State};
|
||||||
|
|
||||||
|
handle_call(me, _From, State) ->
|
||||||
|
Me = dict:fetch(me, State),
|
||||||
|
{reply, Me, State};
|
||||||
|
|
||||||
handle_call(game_token, _From, State) ->
|
handle_call(game_token, _From, State) ->
|
||||||
GameToken = dict:fetch(game_token, State),
|
GameToken = dict:fetch(game_token, State),
|
||||||
{reply, GameToken, State};
|
{reply, GameToken, State};
|
||||||
|
|
Reference in a new issue