Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding player-list update

  • Loading branch information...
commit fd95b3af9c683b1564ab8176510494681e45caf3 1 parent 466bf39
@getify getify authored
Showing with 25 additions and 27 deletions.
  1. +11 −24 public/gameboard.html
  2. +14 −3 public/js/socket.js
View
35 public/gameboard.html
@@ -40,29 +40,16 @@
</section>
<section class="mod scoreboard">
- <h3>Scoreboard</h3>
- <table border="1" summary="Current game score between you and your wily opponent">
- <caption>
- Current Scoreboard
- </caption>
- <tr>
- <th scope="col">Player</th>
- <th scope="col">Ships Left</th>
- <th scope="col">Hits</th>
- <th scope="col">Sunk</th>
- </tr>
- <tr>
- <td>Your Name</td>
- <td>5</td>
- <td>13</td>
- <td>2</td>
- </tr>
- <tr>
- <td>Opponent Name</td>
- <td>4</td>
- <td>10</td>
- <td>0</td>
- </tr>
+ <h3>Players</h3>
+ <table id="players_list" border="1" summary="Current game score between you and your wily opponent">
+ <thead>
+ <tr>
+ <th scope="col">#</th>
+ <th scope="col">Player</th>
+ </tr>
+ </thead>
+ <tbody>
+ </tbody>
</table>
</section>
@@ -109,6 +96,6 @@
<p>
<a href="http://nodeknockout.com/teams/hms-dreadnode" title="Vote Dreadnode" target="_blank"><img width="126" height="63" src="http://nodeknockout.com/images/voteko.png" border="0" alt="Vote Node Knockout" /></a>
</p>
-
+
</body>
</html>
View
17 public/js/socket.js
@@ -92,8 +92,19 @@
userlist : function(message) {
var userlist = message.msg || [];
console.log(JSON.stringify(userlist));
- alert(JSON.stringify(userlist));
- // TODO: Update player listing.
+
+ var $player_list = $("#players_list"), $tr, $td;
+ if ($player_list.length) {
+ $player_list.find("tbody").empty();
+ for (var count=0; count<userlist.length; count++) {
+ $tr = $("<tr></tr>");
+ $td = $("<td></td>").text((count+1));
+ $tr.append($td);
+ $td = $("<td></td>").text(userlist[count]);
+ $tr.append($td);
+ $player_list.find("tbody").append($tr);
+ }
+ }
},
yourturn : function(message) {
var msg = message.msg || "";
@@ -154,5 +165,5 @@
dread.fire = function(shot) {
$.socket.send(JSON.stringify(new dread.Message("shot", shot)));
};
-
+
})(window,jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.