pong_bots smarter and starting with ggs.jeena.net
This commit is contained in:
parent
b7fc68a010
commit
68e97023c6
2 changed files with 14 additions and 12 deletions
|
@ -3,8 +3,8 @@
|
||||||
-export([read/2, send_command/3]).
|
-export([read/2, send_command/3]).
|
||||||
|
|
||||||
connect() ->
|
connect() ->
|
||||||
%{ok,Socket} = gen_tcp:connect("ggs.jeena.net", 9000,[{active, false}]),
|
{ok,Socket} = gen_tcp:connect("ggs.jeena.net", 9000,[{active, false}]),
|
||||||
{ok,Socket} = gen_tcp:connect("localhost", 9000,[{active, false}]),
|
%{ok,Socket} = gen_tcp:connect("localhost", 9000,[{active, false}]),
|
||||||
Socket.
|
Socket.
|
||||||
|
|
||||||
read(Socket, Ref) ->
|
read(Socket, Ref) ->
|
||||||
|
|
|
@ -61,8 +61,10 @@ ggsNetworkReceivedCommandWithArgs(Command, Args, Ref) ->
|
||||||
"game" ->
|
"game" ->
|
||||||
game(Args, Ref);
|
game(Args, Ref);
|
||||||
"player1_points" ->
|
"player1_points" ->
|
||||||
|
%io:format("Player1 win~n"),
|
||||||
new_round(Ref);
|
new_round(Ref);
|
||||||
"player2_points" ->
|
"player2_points" ->
|
||||||
|
%io:format("Player2 win~n"),
|
||||||
new_round(Ref);
|
new_round(Ref);
|
||||||
_ -> ok
|
_ -> ok
|
||||||
end.
|
end.
|
||||||
|
@ -113,16 +115,16 @@ gameTick(Ref) ->
|
||||||
|
|
||||||
case ((BallY - MeY) < 0) of
|
case ((BallY - MeY) < 0) of
|
||||||
true ->
|
true ->
|
||||||
ggs_network:send_command("up", "", Ref),
|
ggs_network:send_command("up", "", Ref);
|
||||||
io:format("Player down sent to server~n"),
|
%io:format("Player down sent to server~n"),
|
||||||
io:format("Ball: ~B~n", [BallY]),
|
%io:format("Ball: ~B~n", [BallY]),
|
||||||
io:format("Player: ~B~n", [MeY]);
|
%io:format("Player: ~B~n", [MeY]);
|
||||||
_ -> case ((BallY - MeY) > 0) of
|
_ -> case ((BallY - MeY) > 0) of
|
||||||
true ->
|
true ->
|
||||||
ggs_network:send_command("down", "", Ref),
|
ggs_network:send_command("down", "", Ref);
|
||||||
io:format("Player up sent to server~n"),
|
%io:format("Player up sent to server~n"),
|
||||||
io:format("Ball: ~B~n", [BallY]),
|
%io:format("Ball: ~B~n", [BallY]),
|
||||||
io:format("Player: ~B~n", [MeY]);
|
%io:format("Player: ~B~n", [MeY]);
|
||||||
_ -> ok
|
_ -> ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -140,12 +142,12 @@ ball(Pos_s, Ref) ->
|
||||||
|
|
||||||
player1_y(YStr, Ref) ->
|
player1_y(YStr, Ref) ->
|
||||||
Y = list_to_integer(YStr),
|
Y = list_to_integer(YStr),
|
||||||
io:format("Player1_y~n~n~n~n"),
|
%io:format("Player1_y~n~n~n~n"),
|
||||||
gen_server:cast({global, {pong_bot, Ref}}, {player1_y, Y}).
|
gen_server:cast({global, {pong_bot, Ref}}, {player1_y, Y}).
|
||||||
|
|
||||||
player2_y(YStr, Ref) ->
|
player2_y(YStr, Ref) ->
|
||||||
Y = list_to_integer(YStr),
|
Y = list_to_integer(YStr),
|
||||||
io:format("Player2_y~n~n~n~n"),
|
%io:format("Player2_y~n~n~n~n"),
|
||||||
gen_server:cast({global, {pong_bot, Ref}}, {player2_y, Y}).
|
gen_server:cast({global, {pong_bot, Ref}}, {player2_y, Y}).
|
||||||
|
|
||||||
game(WaitOrStart, Ref) ->
|
game(WaitOrStart, Ref) ->
|
||||||
|
|
Reference in a new issue