diff --git a/Mnesia/gamedb.erl b/Mnesia/gamedb.erl deleted file mode 100644 index 9d6bbbe..0000000 --- a/Mnesia/gamedb.erl +++ /dev/null @@ -1,31 +0,0 @@ -%Test Mnesia --module(gamedb). --import(mnesia). --export([init/0,insert_player/1,example_player/0,read_player/1,test_player/0]). --include("gamedb.hrl"). - -init() -> - mnesia:create_table(player, [{attributes, record_info(fields, player)}]). - -test_player() -> - insert_player(example_player()), - read_player(0001). - -insert_player(Player) -> - Fun = fun() -> - mnesia:write(Player) - end, - mnesia:transaction(Fun). - -example_player() -> - #player{id = 0001, - name = "Tux"}. - -read_player(Player_Key) -> - Fun = fun() -> - [P] = mnesia:read(player, Player_Key), - Name = P#player.name, - io:format("Player name: ~s~n",[Name]) - end, - mnesia:transaction(Fun). - diff --git a/Mnesia/gamedb.hrl b/Mnesia/gamedb.hrl deleted file mode 100644 index 1ae9c8f..0000000 --- a/Mnesia/gamedb.hrl +++ /dev/null @@ -1,6 +0,0 @@ -%% gamedb.hrl - --record(player, {id, name}). - - - diff --git a/Mnesia/gamedb_usage.txt b/Mnesia/gamedb_usage.txt deleted file mode 100644 index b3a07a0..0000000 --- a/Mnesia/gamedb_usage.txt +++ /dev/null @@ -1,12 +0,0 @@ -1. From terminal: erl -mnesia dir '"/home/user/dir/to/GGS/GameDB.Player"' -2. mnesia:create_schema([node()]). -3. mnesia:start(). -4. c(gamedb). -5. gamedb:init(). -6. mnesia:info(). -7. gamedb:test_player(). - -Last output should be: - Player name: Tux - {atomic,ok} - diff --git a/games/tic-tac-toe-js/js/TicTacToeClient.js b/games/tic-tac-toe-js/js/TicTacToeClient.js index 80f8ef1..79e4064 100644 --- a/games/tic-tac-toe-js/js/TicTacToeClient.js +++ b/games/tic-tac-toe-js/js/TicTacToeClient.js @@ -90,4 +90,4 @@ TicTacToeClient.prototype.updateBoard = function(gameBoardData) { this.spots[k++].innerHTML = t; } } -} \ No newline at end of file +} diff --git a/games/tic-tac-toe/TODO b/games/tic-tac-toe/TODO index 07c0710..a957a1f 100644 --- a/games/tic-tac-toe/TODO +++ b/games/tic-tac-toe/TODO @@ -1,12 +1,6 @@ -- background image -- subimages for game_area:s -- subimages for game markers (X or 0) -- rectangle collision on game_area:s +- background - 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 x, y, width and height board contains a frame diff --git a/games/tic-tac-toe/e.png b/games/tic-tac-toe/e.png index 4cbf977..1b1d7f7 100644 Binary files a/games/tic-tac-toe/e.png and b/games/tic-tac-toe/e.png differ diff --git a/games/tic-tac-toe/tictactoeboard.py b/games/tic-tac-toe/tictactoeboard.py index ee1c057..10562dd 100644 --- a/games/tic-tac-toe/tictactoeboard.py +++ b/games/tic-tac-toe/tictactoeboard.py @@ -4,6 +4,7 @@ from point import Point from pygame.image import load from pygame.rect import Rect from pygame import Surface +from data import greatest_sequence #inherits Board. #Used for displaying the board on the screen and interact with it @@ -47,4 +48,14 @@ class TicTacToeBoard(Board): game_rectangle.state = 'o' 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) + """ diff --git a/games/tic-tac-toe/tictactoeboard.pyc b/games/tic-tac-toe/tictactoeboard.pyc index 1243dc1..8913f16 100644 Binary files a/games/tic-tac-toe/tictactoeboard.pyc and b/games/tic-tac-toe/tictactoeboard.pyc differ diff --git a/src/ggs_server.erl b/src/ggs_server.erl index d7be36e..f440cde 100644 --- a/src/ggs_server.erl +++ b/src/ggs_server.erl @@ -1,13 +1,15 @@ %%%---------------------------------------------------- %%% @author Jonatan Pålsson %%% @copyright 2010 Jonatan Pålsson -%%% @doc RPC over TCP server %%% @end %%%---------------------------------------------------- -module(ggs_server). -behaviour(gen_server). +% import +-import(ggs_connection). + %% API -export([start_link/1, start_link/0, @@ -16,8 +18,7 @@ ]). %% gen_server callbacks --export([init/1, handle_call/3, handle_cast/2, - handle_info/2, terminate/2, code_change/3]). +-export([terminate/2, code_change/3]). -define(SERVER, ?MODULE). @@ -61,28 +62,6 @@ stop() -> %%----------------------------------------------------- %% gen_server callbacks %%----------------------------------------------------- - -init([Port]) -> - {ok, LSock} = gen_tcp:listen(Port, [{active, true}, - {reuseaddr, true}]), - {ok, #state{port = Port, lsock = LSock}, 0}. - -handle_call(get_count, _From, State) -> - {reply, {ok, State#state.client_vm_map}, State}. - -handle_cast(stop, State) -> - {stop, normal, State}. - -handle_info({tcp, Socket, RawData}, State) -> - NewState = do_JSCall(Socket, RawData, State), - OldMap = State#state.client_vm_map, - io:format("Old map: ~p NewState: ~p~n", [OldMap, NewState]), - {noreply, State#state{client_vm_map = OldMap ++ [NewState]}}; - -handle_info(timeout, #state{lsock = LSock} = State) -> - {ok, _Sock} = gen_tcp:accept(LSock), - {noreply, State}. - terminate(_Reason, _State) -> ok. @@ -92,7 +71,6 @@ code_change(_OldVsn, State, _Extra) -> %%----------------------------------------------------- %% Internal functions %%----------------------------------------------------- - do_JSCall(Socket, Data, State) -> JSVM = js_runner:boot(), js_runner:define(JSVM, "function userCommand(cmd, par) {return cmd+' '+ par}"), @@ -103,23 +81,23 @@ do_JSCall(Socket, Data, State) -> Ret = js_runner:call(JSVM, "userCommand", [list_to_binary(Command), 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 {hello} -> Client = getRef(), - send(Socket, Client, "__ok_hello"), + connection:send(Socket, Client, "__ok_hello"), {Client, JSVM}; {echo, RefID, _, MSG} -> - send(Socket, RefID, "Your VM is ", getJSVM(RefID, State)), + connection:send(Socket, RefID, "Your VM is ", getJSVM(RefID, State)), []; {crash, Zero} -> 10/Zero; {vms} -> - send(Socket, "RefID", State); + connection:send(Socket, "RefID", State); % Set the new state to [] Other -> - send(Socket, "RefID", "__error"), + ggs_connection:send(Socket, "RefID", "__error"), [] end, % Return the new state @@ -136,9 +114,3 @@ getJSVM(RefID, State) -> VMs = State#state.client_vm_map, {value, {_,VM}} = lists:keysearch(RefID, 1, VMs), 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])).