ggs_server changes(not finished)
Conflicts: src/ggs_server.erl
This commit is contained in:
commit
02b72e5445
10 changed files with 45 additions and 27 deletions
|
@ -1,12 +1,6 @@
|
||||||
- background image
|
- background
|
||||||
- subimages for game_area:s
|
|
||||||
- subimages for game markers (X or 0)
|
|
||||||
- rectangle collision on game_area:s
|
|
||||||
- redraw background then all game_area:s
|
- redraw background then all game_area:s
|
||||||
- board_state: a hashtable where key is game_area_index
|
|
||||||
and value is either'x' 'o' or ' '
|
|
||||||
|
|
||||||
board contains nr_of_squares = 9
|
|
||||||
board contains array of squares with nr_of_squares elements
|
board contains array of squares with nr_of_squares elements
|
||||||
board contains x, y, width and height
|
board contains x, y, width and height
|
||||||
board contains a frame
|
board contains a frame
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 187 B |
|
@ -4,6 +4,7 @@ from point import Point
|
||||||
from pygame.image import load
|
from pygame.image import load
|
||||||
from pygame.rect import Rect
|
from pygame.rect import Rect
|
||||||
from pygame import Surface
|
from pygame import Surface
|
||||||
|
from data import greatest_sequence
|
||||||
|
|
||||||
#inherits Board.
|
#inherits Board.
|
||||||
#Used for displaying the board on the screen and interact with it
|
#Used for displaying the board on the screen and interact with it
|
||||||
|
@ -47,4 +48,14 @@ class TicTacToeBoard(Board):
|
||||||
game_rectangle.state = 'o'
|
game_rectangle.state = 'o'
|
||||||
self.players_turn = (self.players_turn + 1) % 2
|
self.players_turn = (self.players_turn + 1) % 2
|
||||||
|
|
||||||
|
"""
|
||||||
|
def turn(self, mouse_point):
|
||||||
|
if player.id != players_turn:
|
||||||
|
print "Other players turn"
|
||||||
|
|
||||||
|
else:
|
||||||
|
for game_rectangle in self.game_rectangles:
|
||||||
|
if (mouse_point.inside(game_rectangle) and
|
||||||
|
game_rectangle.state == ' '):
|
||||||
|
server.turn(player.id, game_rectangle.index)
|
||||||
|
"""
|
||||||
|
|
Binary file not shown.
BIN
mnesia/.gamedb.erl.swp
Normal file
BIN
mnesia/.gamedb.erl.swp
Normal file
Binary file not shown.
|
@ -1,26 +1,45 @@
|
||||||
%Test Mnesia
|
%%%%----------------------------------------------------
|
||||||
|
%%% @author Mattias Pettersson <mattiaspgames@gmail.com>
|
||||||
|
%%% @copyright 2011 Mattias Pettersson
|
||||||
|
%%% @doc Database for runtime game variable storage.
|
||||||
|
%%% @end
|
||||||
|
|
||||||
|
Test Mnesia
|
||||||
-module(gamedb).
|
-module(gamedb).
|
||||||
-import(mnesia).
|
-import(mnesia).
|
||||||
-export([init/0,insert_player/1,example_player/0,read_player/1,test_player/0]).
|
-export([init/0,insert_player/1,example_player/0,read_player/1,test_player/0]).
|
||||||
-include("gamedb.hrl").
|
-include("gamedb.hrl").
|
||||||
|
|
||||||
|
%%-----------------------------------------------------
|
||||||
|
%% Creation
|
||||||
|
%%-----------------------------------------------------
|
||||||
init() ->
|
init() ->
|
||||||
mnesia:create_table(player, [{attributes, record_info(fields, player)}]).
|
mnesia:create_table(player, [{attributes, record_info(fields, player)}]).
|
||||||
|
|
||||||
|
%%-----------------------------------------------------
|
||||||
|
%% Test
|
||||||
|
%%-----------------------------------------------------
|
||||||
test_player() ->
|
test_player() ->
|
||||||
insert_player(example_player()),
|
insert_player(example_player()),
|
||||||
read_player(0001).
|
read_player(0001).
|
||||||
|
|
||||||
|
example_player() ->
|
||||||
|
#player{id = 0001,
|
||||||
|
name = "Tux"}.
|
||||||
|
|
||||||
|
%%-----------------------------------------------------
|
||||||
|
%% Insertions
|
||||||
|
%%-----------------------------------------------------
|
||||||
insert_player(Player) ->
|
insert_player(Player) ->
|
||||||
Fun = fun() ->
|
Fun = fun() ->
|
||||||
mnesia:write(Player)
|
mnesia:write(Player)
|
||||||
end,
|
end,
|
||||||
mnesia:transaction(Fun).
|
mnesia:transaction(Fun).
|
||||||
|
|
||||||
example_player() ->
|
|
||||||
#player{id = 0001,
|
|
||||||
name = "Tux"}.
|
|
||||||
|
|
||||||
|
%%-----------------------------------------------------
|
||||||
|
%% Querries
|
||||||
|
%%-----------------------------------------------------
|
||||||
read_player(Player_Key) ->
|
read_player(Player_Key) ->
|
||||||
Fun = fun() ->
|
Fun = fun() ->
|
||||||
[P] = mnesia:read(player, Player_Key),
|
[P] = mnesia:read(player, Player_Key),
|
|
@ -1,13 +1,15 @@
|
||||||
%%%----------------------------------------------------
|
%%%----------------------------------------------------
|
||||||
%%% @author Jonatan Pålsson <Jonatan.p@gmail.com>
|
%%% @author Jonatan Pålsson <Jonatan.p@gmail.com>
|
||||||
%%% @copyright 2010 Jonatan Pålsson
|
%%% @copyright 2010 Jonatan Pålsson
|
||||||
%%% @doc RPC over TCP server
|
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%----------------------------------------------------
|
%%%----------------------------------------------------
|
||||||
|
|
||||||
-module(ggs_server).
|
-module(ggs_server).
|
||||||
-behaviour(gen_server).
|
-behaviour(gen_server).
|
||||||
|
|
||||||
|
% import
|
||||||
|
-import(ggs_connection).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/1,
|
-export([start_link/1,
|
||||||
start_link/0,
|
start_link/0,
|
||||||
|
@ -16,8 +18,7 @@
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
-export([init/1, handle_call/3, handle_cast/2,
|
-export([terminate/2, code_change/3]).
|
||||||
handle_info/2, terminate/2, code_change/3]).
|
|
||||||
|
|
||||||
|
|
||||||
-define(SERVER, ?MODULE).
|
-define(SERVER, ?MODULE).
|
||||||
|
@ -115,7 +116,6 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
%%-----------------------------------------------------
|
%%-----------------------------------------------------
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%%-----------------------------------------------------
|
%%-----------------------------------------------------
|
||||||
|
|
||||||
do_JSCall(Socket, Data, State) ->
|
do_JSCall(Socket, Data, State) ->
|
||||||
JSVM = js_runner:boot(),
|
JSVM = js_runner:boot(),
|
||||||
js_runner:define(JSVM, "function userCommand(cmd, par) {return cmd+' '+ par}"),
|
js_runner:define(JSVM, "function userCommand(cmd, par) {return cmd+' '+ par}"),
|
||||||
|
@ -126,23 +126,23 @@ do_JSCall(Socket, Data, State) ->
|
||||||
Ret = js_runner:call(JSVM, "userCommand",
|
Ret = js_runner:call(JSVM, "userCommand",
|
||||||
[list_to_binary(Command),
|
[list_to_binary(Command),
|
||||||
list_to_binary(Parameter)]),
|
list_to_binary(Parameter)]),
|
||||||
send(Socket, "RefID", "JS says: ", Ret),
|
connection:send(Socket, "RefID", "JS says: ", Ret),
|
||||||
[];
|
[];
|
||||||
% Set the new state to the reference generated, and JSVM associated
|
% Set the new state to the reference generated, and JSVM associated
|
||||||
{hello} ->
|
{hello} ->
|
||||||
Client = getRef(),
|
Client = getRef(),
|
||||||
send(Socket, Client, "__ok_hello"),
|
connection:send(Socket, Client, "__ok_hello"),
|
||||||
{Client, JSVM};
|
{Client, JSVM};
|
||||||
{echo, RefID, _, MSG} ->
|
{echo, RefID, _, MSG} ->
|
||||||
send(Socket, RefID, "Your VM is ", getJSVM(RefID, State)),
|
connection:send(Socket, RefID, "Your VM is ", getJSVM(RefID, State)),
|
||||||
[];
|
[];
|
||||||
{crash, Zero} ->
|
{crash, Zero} ->
|
||||||
10/Zero;
|
10/Zero;
|
||||||
{vms} ->
|
{vms} ->
|
||||||
send(Socket, "RefID", State);
|
connection:send(Socket, "RefID", State);
|
||||||
% Set the new state to []
|
% Set the new state to []
|
||||||
Other ->
|
Other ->
|
||||||
send(Socket, "RefID", "__error"),
|
ggs_connection:send(Socket, "RefID", "__error"),
|
||||||
[]
|
[]
|
||||||
end,
|
end,
|
||||||
% Return the new state
|
% Return the new state
|
||||||
|
@ -159,9 +159,3 @@ getJSVM(RefID, State) ->
|
||||||
VMs = State#state.client_vm_map,
|
VMs = State#state.client_vm_map,
|
||||||
{value, {_,VM}} = lists:keysearch(RefID, 1, VMs),
|
{value, {_,VM}} = lists:keysearch(RefID, 1, VMs),
|
||||||
VM.
|
VM.
|
||||||
|
|
||||||
send(Socket, RefID, String) ->
|
|
||||||
gen_tcp:send(Socket, io_lib:fwrite("~p ~p~n", [RefID,String])).
|
|
||||||
|
|
||||||
send(Socket, RefID, String1, String2) ->
|
|
||||||
gen_tcp:send(Socket, io_lib:fwrite("~p ~p ~p~n", [RefID, String1, String2])).
|
|
||||||
|
|
Reference in a new issue