bpong-client improved incl. player ctr

This commit is contained in:
Stefan `Sec` Zehl 2011-12-27 11:56:16 +01:00
parent 1d6915538c
commit 3d9da1ec9e
2 changed files with 28 additions and 4 deletions

View File

@ -28,6 +28,14 @@ div
} }
div.score div.score
{
color: #33FF33;
background-color: transparent;
width: 640px;
font-size: 20px;
font-family: courier new;
}
div.player
{ {
color: #33FF33; color: #33FF33;
background-color: transparent; background-color: transparent;
@ -46,5 +54,7 @@ div.score
</input> </input>
<div style="font-size:14;color:black;background-color:white;" id="socket">s_data...</div> <div style="font-size:14;color:black;background-color:white;" id="socket">s_data...</div>
<div style="font-size:14;color:black;background-color:white;" id="debug">debug</div> <div style="font-size:14;color:black;background-color:white;" id="debug">debug</div>
<div class="player" style="text-align:left" id="player_left">0</div>
<div class="player" style="text-align:right" id="player_right">0</div>
</body> </body>
</html> </html>

View File

@ -1,5 +1,5 @@
// Initialisation // Initialisation
var socket = "ws://83.133.179.198:8888/data"; var socket = "ws://127.0.0.1:8888/data";
var field= { w: 320, h: 240 }; var field= { w: 320, h: 240 };
var paddle = { w: 2, h: 30 }; var paddle = { w: 2, h: 30 };
var ball = { w: 5, h: 5, s: 5 }; var ball = { w: 5, h: 5, s: 5 };
@ -12,6 +12,9 @@ function pong() {
this.score = {}; this.score = {};
this.score.left = {}; this.score.left = {};
this.score.right = {}; this.score.right = {};
this.cnt = {};
this.cnt.left = {};
this.cnt.right = {};
this.field = {}; this.field = {};
this.game = { run: 0 }; this.game = { run: 0 };
@ -40,6 +43,12 @@ function pong() {
setupavatar(this.right); setupavatar(this.right);
setupavatar(this.field); setupavatar(this.field);
this.cnt.left.avatar=$('div#player_left');
this.cnt.right.avatar=$('div#player_right');
$('div#player_left').css({top: 2*this.field.size.h-30});
$('div#player_right').css({top: 2*this.field.size.h-30});
this.field.avatar.focus(); this.field.avatar.focus();
this.score.left.pts=0; this.score.left.pts=0;
@ -209,10 +218,15 @@ pong.prototype.socketstart = function(uri){
var result=JSON.parse(data); var result=JSON.parse(data);
if (result.right){ if (result.right){
this.setright(result.right); this.setright(result.right);
} else if (result.left){ } ;
if (result.left){
this.setleft(result.left); this.setleft(result.left);
}else { };
// unknown json input if (result.cntl){
this.cnt.left.avatar.html(result.cntl);
};
if (result.cntr){
this.cnt.right.avatar.html(result.cntr);
}; };
}else{ }else{
// unknown non-json input // unknown non-json input