Skip to content
Browse files

Merge branch 'turn'

  • Loading branch information...
2 parents dbfdc62 + c70378f commit 9489649e4f8b14b3a06e80b62fd10a443fe8cca0 @polettix committed
View
30 environments/local.yml
@@ -0,0 +1,30 @@
+# configuration file for development environment
+
+# the logger engine to use
+# console: log messages to STDOUT (your console where you started the
+# application server)
+# file: log message to a file in log/
+logger: "console"
+
+# the log level for this environement
+# core is the lowest, it shows Dancer's core log messages as well as yours
+# (debug, warning and error)
+log: "core"
+
+# should Dancer consider warnings as critical errors?
+warnings: 1
+
+# should Dancer show a stacktrace when an error is caught?
+show_errors: 1
+
+# auto_reload is a development and experimental feature
+# you should enable it by yourself if you want it
+# Module::Refresh is needed
+#
+# Be aware it's unstable and may cause a memory leak.
+# DO NOT EVER USE THAT FEATURE IN PRODUCTION
+# OR TINY KITTENS SHALL DIE WITH LOTS OF SUFFERING
+auto_reload: 0
+
+# all local
+'narsil-ws': 'http://localhost:3000/'
View
7 lib/Narsil/Frontend.pm
@@ -9,7 +9,7 @@ use Try::Tiny;
use Storable qw< dclone >;
BEGIN {
- unshift @INC, qw< /home/poletti/sviluppo/perl/narsil/narsil-core/lib >
+ unshift @INC, qw< /home/poletti/sviluppo/perl/narsil/core/lib >
unless exists $ENV{DOTCLOUD_ENVIRONMENT};
}
@@ -88,6 +88,7 @@ get '/' => sub {
return template 'index',
{
matches => $matches,
+ string => to_json($matches),
availables => $availables,
waiting => $waiting,
games => $games,
@@ -157,10 +158,11 @@ sub get_matches_for {
my ($user, $phase) = @_;
return {} unless defined $user;
my $userid = $user->{username};
+ $phase //= 'active';
my $stuff = rest_call(
get => "/user/matches/$userid",
{
- phase => $phase // 'active',
+ phase => $phase,
user => $userid,
}
);
@@ -168,6 +170,7 @@ sub get_matches_for {
($match->{id} = $match->{uri}) =~ s{.*/}{}mxs;
$match->{opponents} =
[grep { $_->[0] ne $userid } @{$match->{participants}}];
+ $match->{movers} = [map { $_->[0] } @{$match->{movers}}];
}
return $stuff;
} ## end sub get_matches_for
View
10 lib/Narsil/Frontend/battleship.pm
@@ -9,10 +9,12 @@ use Narsil::Game::BattleShip::Status;
sub adapt {
my ($package, $match, $user) = @_;
my $status = Narsil::Game::BattleShip::Status->new($match->{status});
+
$status->field_size_y();
my %retval = (%$status, match => $match, user => $user);
+
($retval{matchid} = $match->{uri}) =~ s{.*/}{}mxs;
- my @players = @{$status->{players}};
+ my @players = map { $_->[0] } @{$match->{participants}};
push @players, '*undef' while scalar(@players) < 2;
if (grep { $_ eq $user } @players) { # user participates
($retval{upper}) = grep { $_ ne $user } @players;
@@ -22,8 +24,10 @@ sub adapt {
@retval{qw< upper lower >} = @players;
}
- $retval{active_player} =
- $status->{players}[$status->{current_player_id}];
+ my @movers = map { $_->[0] } @{$match->{movers}};
+ $retval{movers} = \@movers;
+ $retval{active_player} = $movers[0] if @movers == 1;
+ $retval{player_is_active} = grep { $_ eq $user } @movers;
delete $retval{active_player} if $match->{phase} eq 'terminated';
$retval{maxx} = $retval{field_size_x} - 1;
View
2 public/css/style.css
@@ -171,8 +171,8 @@ form.logout button {
}
table.battleboat td {
- border: 1px solid #ddd;
border: 0;
+ border: 1px solid #777;
padding: 2px;
padding: 0;
}
View
8 views/_matches.tt
@@ -11,6 +11,12 @@
IF match.phase == 'gathering' && ! match.is_participant;
id = match.id;
uri = request.uri_for("/match/joins/$id");
- %>(<form style="display:inline" action="<% uri %>" method="POST"><button class="aslink">join</button></form>)<% END %></li>
+ %>(<form style="display:inline" action="<% uri %>" method="POST"><button class="aslink">join</button></form>)<%
+ END;
+
+ IF match.movers && match.movers.size > 0;
+ %>(<% match.movers.join(", ") %> moving)<%
+ END
+ %></li>
<% END %>
</ul>
View
11 views/games/battleship/setup.tt
@@ -1,7 +1,14 @@
<h1>Battleship</h1>
-<p>It's <% active_player %>'s turn</p>
-<% IF active_player == user %>
+Match is in setup phase. The following users are setting up:
+
+<ul>
+<% FOR mover = movers %>
+ <li><% mover %></li>
+<% END %>
+</ul>
+
+<% IF player_is_active %>
Setup it here...
View
6 views/layouts/main.tt
@@ -7,12 +7,6 @@
<link rel="stylesheet" href="<% request.uri_for('/css/style.css') %>" />
<link rel="shortcut icon" href="<% request.uri_for('/images/favicon.ico') %>" />
-<!-- Grab Google CDN's jQuery. fall back to local if necessary -->
-<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
-<script type="text/javascript">/* <![CDATA[ */
- !window.jQuery && document.write('<script type="text/javascript" src="<% request.uri_base %>/javascripts/jquery.js"><\/script>')
-/* ]]> */</script>
-
</head>
<body>
<div id="container">

0 comments on commit 9489649

Please sign in to comment.
Something went wrong with that request. Please try again.