2 * Copyright (c) 2012, Intel Corporation.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 function queryObj(obj) {
12 this.isNull = this.q?false:true;
14 this.html = function (val) {
15 this.q.innerHTML = val;
19 this.hasClass = function (c_name) {
22 return this.q.classList.contains(c_name);
25 this.addClass = function (c_name) {
28 var list = this.q.classList;
33 this.removeClass = function (c_name) {
36 var list = this.q.classList;
41 this.click = function (fun) {
48 this.attr = function (attr, val) {
51 this.q.setAttribute(attr, val);
56 function $(selector) {
58 if (typeof selector == "string") {
59 res = document.querySelector(selector);
63 return new queryObj(res);
66 function gamesound(src, loop) {
68 this.soundobj = new Audio(src);
69 this.soundobj.preload = 'auto';
72 this.loop = (loop == undefined)?false:loop;
73 this.focus = function focus() {
77 if(me.enable&&me.loop)
81 this.blur = function blur() {
85 if(me.enable&&me.loop)
89 window.addEventListener('focus', me.focus, false);
90 window.addEventListener('blur', me.blur, false);
92 this.play = function play() {
97 this.pause = function pause() {
99 this.soundobj.pause();
105 'black':'images/GO_BlackPiece_010612_a.png',
106 'black1':'images/GO_BlackPiece_010612_b.png',
107 'black2':'images/GO_BlackPiece_010612_c.png',
108 'white':'images/GO_WhitePiece_010612_a-2.png',
109 'white1': 'images/GO_WhitePiece_010612_b.png',
110 'white2': 'images/GO_WhitePiece_010612_c.png',
111 'uncheck':'images/GO_Checkbox_010612_a.png',
112 'checked':'images/GO_CheckboxChecked_010612_a.png',
113 'board':'images/Go_Board.png',
118 playButton:'play_button',
119 winMessage:'win_panel',
120 settingPanel:'setting_panel',
121 helpPanel:'help_panel',
123 directs: [[1,0],[0,1],[0,-1],[-1,0],],
137 Go.init = function(){
139 'black':[[1,3],[1,4],[2,2],[3,2],
140 [4,2],[5,2],[5,4],[5,5],
141 [6,2],[6,5],[7,2],[7,5],[8,3],
144 'white':[[1,8],[1,9],[2,7],[2,10],
145 [3,7],[3,10],[4,7],[4,10],
146 [5,7],[5,10],[6,7],[6,10],
147 [7,7],[7,10],[8,8],[8,9],],
149 for (var i=0; i<this.bounder; i++){
150 var line=new Array();
151 for (var j=0; j<this.bounder; j++){
154 this.board[i] = line;
156 for (var color in welcome){
157 var matrix = welcome[color];
158 for (var p in matrix) {
159 this.board[matrix[p][0]][matrix[p][1]] = color;
164 'end': 'sounds/GameEndChimes.wav',
165 'setStone': 'sounds/Pieces_SinglePlaced.wav',
166 'dropStone': 'sounds/PiecesFillPocket.wav',
167 'positive': 'sounds/PositiveSound.wav',
168 'settingbtn': 'sounds/SettingsButton.wav',
169 'settingck': 'sounds/SettingsButtonCheck.wav',
170 'settingon': 'sounds/SettingsAppearWoodSlide.wav',
171 'dida': 'sounds/ClockTicking_Loop.wav',
176 this.disable('.'+this.winMessage);
177 this.enable('.'+this.playButton);
181 Go.start = function(){
182 for (var i=0; i<this.bounder; i++){
183 for (var j=0; j<this.bounder; j++){
184 this.board[i][j] = 'board';
187 this.player['black'] = new player('black');
188 this.player['white'] = new player('white');
189 this.current = this.player['white'];
193 this.isSetting =false;
194 this.isRestart = false;
196 this.isEndMsg = true;
199 this.disable('.'+this.playButton);
200 this.disable('.'+this.winMessage);
201 this.disable('.'+this.settingPanel);
202 this.disable('.'+this.helpPanel);
203 this.playSound('settingbtn');
204 // this.startTimer();
206 $('.setting_restart img').attr('src', this.texture['uncheck'])
207 .removeClass('setting_restart_checked')
208 .addClass('setting_restart_check');
211 Go.getSoundSource = function(snd) {
212 var ret = this.sounds[snd];
213 if (typeof ret == 'undefined') {
214 var src = this.soundSource[snd];
216 ret = new gamesound(src);
218 ret = new Audio(src);
220 this.sounds[snd] = ret;
225 Go.playSound = function(snd){
227 var audio = this.getSoundSource(snd);
228 if (audio.paused == false) {
230 audio.currentTime = 0;
236 Go.stop = function(){
237 this.isStart = false;
240 var blackScore = this.player['black'].getScore();
241 var whiteScore = this.player['white'].getScore();
242 this.initWinMessage();
243 if (blackScore > whiteScore){
244 $('#win_player').html(' '+getMessage('one', 'One'));
245 $('#win_result').html(getMessage('win', 'Wins'));
246 } else if (blackScore < whiteScore) {
247 $('#win_player').html(' '+getMessage('two', 'Two'));
248 $('#win_result').html(getMessage('win', 'Wins'));
250 $('#win_player').html('');
251 $('#win_result').html(getMessage('draw', 'Draw'));
254 this.playSound('end');
255 this.enable('.'+this.winMessage);
256 this.isEndMsg = false;
260 Go.initWinMessage = function() {
261 if (!this.hasWinMessage) {
262 var winmsg = $('.'+this.winMessage);
263 winmsg.html('<a onClick="javascript:Go.disable('+"'.win_panel');"+'" class="win_exit">X</a> <div class="win_arrow" align="center"> <span style="font-size:55pt;"><span name="player"></span><span id="win_player"></span></span><br> <span style="font-size:70pt;" id="win_result"></span> <img class="win_arrow_img" src="images/GO_WinArrow_012012_a.png" /> </div> <a onClick="javascript:Go.start();" class="replay"> </a>');
264 $('.replay').html(getMessage('newGame', 'New Game'));
265 $('span[name="player"]').html(getMessage('player', 'Player'));
266 this.hasWinMessage = true;
271 Go.exit = function(){
277 Go.restart = function(){
287 Go.startTimer = function(){
288 if (this.isTimer && this.isStart) {
289 this.timer = setTimeout('Go.startTimer()',1000);
290 this.current.timeDida();
291 this.playSound('dida');
292 if (this.current.restTime <= 0) {
294 } else if (this.current.restTime == 5) {
295 this.playSound('positive');
300 Go.stopTimer = function(){
302 clearTimeout(this.timer);
303 // this.sounds['dida'].pause();
307 Go.disable = function(which) {
308 $(which).addClass('display_none');
311 Go.enable = function(which) {
312 $(which).removeClass('display_none');
315 Go.toggleSetting = function(){
316 if ($('.'+this.winMessage).hasClass('display_none')) {
322 this.playSound('settingbtn');
326 Go.initSettingPanel = function() {
327 if (!this.hasSettingPanel) {
328 var panel = $('.setting_panel');
329 panel.html('<a onClick="javascript:Go.toggleHelp();" class="setting_help">?</a> <a onClick="javascript:Go.toggleSetting();" class="setting_exit">X</a> <div id="licensebtnl" style="top: 490px; left: 405px;"> i </div> <div class="setting_arrow" align="center"> <span></span> <img class="setting_arrow_img" src="images/GO_SettingsArrow_010612_a.png" /> </div> <div class="setting_sound"> <span></span> <a onClick="javascript:Go.toggleSound();"><img class="setting_sound_check" src="images/GO_Checkbox_010612_a.png" /></a> </div> <div class="setting_timer"> <span></span> <a onClick="javascript:Go.toggleTimer();"><img class="setting_timer_check" src="images/GO_Checkbox_010612_a.png" /></a> </div> <div class="setting_restart"> <span></span> <a onClick="javascript:Go.toggleRestart();"><img class="setting_restart_check" src="images/GO_Checkbox_010612_a.png" /></a> </div> <div class="setting_quit"> <span class="setting_quit_text"></span> <a onClick="javascript:Go.toggleQuit();"><img class="setting_quit_check" src="images/GO_Checkbox_010612_a.png" /></a> </div> <a onClick="javascript:Go.toggleSetting();" class="setting_resume setting_resume_inactive" align="center"> </a>');
330 $('.setting_arrow span').html(getMessage('settings', 'Settings'));
331 $('.setting_sound span').html(getMessage('sound_setting', 'Sound FX....'));
332 $('.setting_timer span').html(getMessage('timer_setting', 'Timer...........'));
333 $('.setting_restart span').html(getMessage('restart', 'Restart'));
334 $('.setting_quit span').html(getMessage('quit', 'Quit'));
335 $('.setting_resume').html(getMessage('resume', 'Submit'));
336 $('#licensebtnl').click(function(){
337 Go.showLicense("license", "theworld");
340 this.hasSettingPanel = true;
344 Go.showSetting = function(){
345 this.initSettingPanel();
346 this.enable('.setting_panel');
347 setTimeout("$('.setting_panel').addClass('setting_panel_in')", 100);
348 this.isSetting = true;
350 this.playSound('settingon');
353 Go.exitSetting = function(){
354 this.disable('.setting_panel');
355 $('.'+this.helpPanel).addClass('display_none');
356 $('.setting_panel').removeClass('setting_panel_in');
357 this.isSetting = false;
363 Go.toggleSound = function(){
364 var img = $('.setting_sound img');
366 img.attr('src', this.texture['uncheck']);
367 img.removeClass('setting_sound_checked');
368 img.addClass('setting_sound_check');
369 this.isSound = false;
371 img.attr('src', this.texture['checked']);
372 img.addClass('setting_sound_checked');
373 img.removeClass('setting_sound_check');
376 this.playSound('settingck');
379 Go.toggleTimer = function(){
380 var img = $('.setting_timer img');
382 img.attr('src', this.texture['uncheck']);
383 img.removeClass('setting_timer_checked');
384 img.addClass('setting_timer_check');
385 this.isTimer = false;
387 img.attr('src', this.texture['checked']);
388 img.addClass('setting_timer_checked');
389 img.removeClass('setting_timer_check');
392 this.playSound('settingck');
395 Go.toggleRestart = function(){
396 if (this.isStart || this.isStop) {
397 var conflict = false;
398 var img = $('.setting_restart img');
399 if (this.isRestart) {
400 img.attr('src', this.texture['uncheck']);
401 img.removeClass('setting_restart_checked');
402 img.addClass('setting_restart_check');
403 this.isRestart = false;
405 img.attr('src', this.texture['checked']);
406 img.addClass('setting_restart_checked');
407 img.removeClass('setting_restart_check');
408 this.isRestart = true;
415 this.playSound('settingck');
420 Go.toggleQuit = function(){
421 var img = $('.setting_quit img');
422 var conflict = false;
424 img.attr('src', this.texture['uncheck']);
425 img.removeClass('setting_quit_checked');
426 img.addClass('setting_quit_check');
429 img.attr('src', this.texture['checked']);
430 img.addClass('setting_quit_checked');
431 img.removeClass('setting_quit_check');
437 this.toggleRestart();
439 this.playSound('settingck');
443 Go.toggleHelp = function() {
444 var help = $('.'+this.helpPanel);
446 help.html('<a onClick="javascript:Go.toggleHelp();" class="help_exit text_shadow">X</a> <div class="help_title text_shadow" ></div> <div class="help_text" > Take turns placing a stone on a vacant intersections (points) of the grid on a Go board. Black moves first. Once placed, a stone may not be moved, and can be removed only if captured. If a player believes he has no useful moves, he may skip his move (pass).<br> Vertically and horizontally adjacent stones of the same color form a chain (also called a string, or group) that shares liberties (adjacent, empty spaces) in common. These chains cannot be divided, and in effect becomes a single larger stone. Chains may be expanded by placing additional stones on adjacent points, and can be connected by placing a stone on a points adjacent to two or more chains of the same color.<br> A chain of stones must have at least one liberty to remain on the board. When a chain is surrounded by opposing stones so that it has no liberties, it is captured and removed from the board.<br> The game ends when both players have passed (clicked Skip) consecutively. The player who scores more points (the number of empty points, or intersections, surrounded by their pieces, plus the number of stones they'+"'" + 've captured) wins.<br> For more information on how to play Go, see the Wikipedia article on the game: <span><a style="opacity: 0.6; color: #0000FF" href="http://en.wikipedia.org/wiki/Go_(game)">http://en.wikipedia.org/wiki/Go_(game)</a></span>. </div>');
447 $('.help_title').html(getMessage('rules', 'Rules'));
448 var help_text = getMessage('help');
449 if (help_text.length > 0) {
450 $('.help_text').html(help_text);
454 if (help.hasClass('display_none')) {
455 help.removeClass('display_none');
457 help.addClass('display_none');
459 //$('.'+this.helpPanel).toggleClass('display_none');
462 Go.drawBoard = function(){
464 var style=['margin:1px 0px 9px 0px;','margin:0px 10px 9px 0px;','margin:0px 9px 10px 0px;'];
465 for (var i=0; i<this.bounder; i++){
467 if (i<6) margin = style[0];
468 str += '<div style="width:595px;height:36px;'+margin+'">';
469 for (var j=0; j<this.bounder; j++){
471 if (j<6) margin = style[1];
472 if (i>8) margin += 'position:relative;top:-5px;';
473 str += '<span style="float:left;width:36px;height:36px;'+margin
474 +'"><a onClick="javascript:Go.click('+i+','+j+');" class="img_style" ><img src="'
475 +this.texture[this.board[i][j]]+'" id="a'+i+j+'" class="board_img" /></a></span>';
479 $('.'+this.boardview).html(str);
482 Go.click = function(i, j){
483 if (this.board[i][j]==='board' && !this.isSetting && this.isStart) {
484 var revColor = (this.current.color=='black'?'white':'black');
485 var p = this.player[revColor];
487 this.board[i][j] = this.current.color;
488 var takes = this.getTake([i, j]);
489 if (takes.length == 1 && p.takes.length == 1
490 && p.takes[0][0] == i && p.takes[0][1] == j
491 && takes[0][0] == p.place[0] && takes[0][1] == p.place[1]) {
493 this.board[i][j] = 'board';
496 for (var n in takes) {
497 this.board[takes[n][0]][takes[n][1]] = 'board';
501 if (takes.length == 0 && this.isContained(i, j, this.current.color)) {
502 this.board[i][j] = 'board';
504 var status = {'color':this.current.color,};
505 this.playSound('setStone');
506 if (takes.length > 0)
507 this.playSound('dropStone');
508 status.setPlace = [i, j];
509 status.place = this.place;
511 this.current.score++;
512 status.userPlace = this.current.place;
513 this.current.place = this.place;
514 this.current.takes = takes;
515 status.takes = takes;
516 this.current.pickStone();
517 status.isPass = this.isPass;
521 var liberty = this.getLiberty();
523 status.liberty['black'] = this.player['black'].liberty;
524 status.liberty['white'] = this.player['white'].liberty;
525 this.player['black'].liberty = liberty['black'];
526 this.player['white'].liberty = liberty['white'];
528 status.restTime = {};
529 status.restTime['black'] = this.player['black'].restTime;
530 status.restTime['white'] = this.player['white'].restTime;
531 this.manual.push(status);
538 Go.undue = function(color_) {
539 if (!this.isSetting && this.isStart && color_ != this.current.color) {
540 var status = this.manual.pop();
542 var color = status.color;
543 var revColor = (color == 'black'?'white':'black');
544 var player = this.player[color];
545 if (status.setPlace.length > 0) {
546 this.place = status.place;
549 this.board[status.setPlace[0]][status.setPlace[1]] = 'board';
550 for (var p in status.takes) {
551 var take = status.takes[p];
552 this.player[revColor].pickStone();
553 this.board[take[0]][take[1]] = revColor;
554 this.player[revColor].score++;
556 if (status.liberty) {
557 var liberty = status.liberty;
558 this.player['black'].liberty = liberty['black'];
559 this.player['white'].liberty = liberty['white'];
561 this.player['black'].liberty = [];
562 this.player['white'].liberty = [];
564 player.place = status.userPlace;
567 this.isPass = status.isPass;
569 // this.player['black'].restTime = status.restTime['black'];
570 // this.player['white'].restTime = status.restTime['white'];
576 Go.getTake = function(place_) {
577 var p = place_ || this.place;
578 var checkColor = (this.current.color=='black'?'white':'black');
580 for (var d in this.directs) {
581 var i = parseInt(p[0])+parseInt(this.directs[d][0]);
582 var j = parseInt(p[1])+parseInt(this.directs[d][1]);
583 if (i>=0 && j>= 0 && i<this.bounder && j<this.bounder
584 && this.board[i][j] === checkColor) {
586 if (this.isContained(i, j, checkColor, t)) {
588 if (!this.isContain(t[n], takes)) {
595 //console.log(takes);
599 Go.isContained = function(i_, j_, color_, contains_, except_) {
600 var color = color_ || (this.current.color == 'black'?'white':'black');
601 var except = except_ || [];
602 var contains = contains_ || [];
604 except.push([parseInt(i_),parseInt(j_)]);
606 for (var d in this.directs) {
609 var i = parseInt(i_)+parseInt(this.directs[d][0]);
610 var j = parseInt(j_)+parseInt(this.directs[d][1]);
611 if ( i>=0 && j>= 0 && i<this.bounder && j<this.bounder
612 && !this.isContain([i,j], except)) {
613 if (this.board[i][j] == 'board') {
615 } else if (this.board[i][j] == color) {
616 if (!this.isContained(i, j, color, contains, except)) {
623 contains.push([i_, j_]);
627 Go.getLiberty = function(){
633 for (var i=0; i<this.bounder; i++){
634 for (var j=0; j<this.bounder; j++){
635 if (this.board[i][j] == 'board' && !this.isContain([i,j], except)) {
637 var liberty = this.countLiberty(i,j,except_);
638 if (!liberty.hasOwnProperty('none')) {
640 if (liberty.hasOwnProperty('black')) {
642 } else if (liberty.hasOwnProperty('white')) {
645 if (color != 'none') {
646 var needpush = liberty[color];
647 for (var n in needpush){
648 if (!this.isContain(needpush[n], contain[color])) {
649 contain[color].push(needpush[n]);
654 for (var n in except_) {
655 if (!this.isContain(except_[n], except)) {
656 except.push(except_[n]);
666 Go.countLiberty = function(i_,j_,except){
668 except.push([i_,j_]);
669 for (var d in this.directs) {
670 if (ret.hasOwnProperty('none'))
672 var i = parseInt(i_)+parseInt(this.directs[d][0]);
673 var j = parseInt(j_)+parseInt(this.directs[d][1]);
674 if (i>=0 && j>= 0 && i<this.bounder && j<this.bounder && !this.isContain([i,j], except)) {
675 if (this.board[i][j] == 'board') {
676 var liberty = this.countLiberty(i,j,except);
677 if (liberty.hasOwnProperty('none')) {
680 } else if (liberty.hasOwnProperty('black')){
681 if (ret.hasOwnProperty('white')) {
685 if (!ret.hasOwnProperty('black'))
687 for (var n in liberty['black']){
688 if (!this.isContain(liberty['black'][n], ret['black'])) {
689 ret['black'].push(liberty['black'][n]);
693 } else if (liberty.hasOwnProperty('white')) {
694 if (ret.hasOwnProperty('black')) {
698 if (!ret.hasOwnProperty('white'))
700 for (var n in liberty['white']){
701 if (!this.isContain(liberty['white'][n], ret['white'])) {
702 ret['white'].push(liberty['white'][n]);
706 } else if (liberty.hasOwnProperty('neutral')) {
707 if (!ret.hasOwnProperty('neutral'))
709 for (var n in liberty['neutral']){
710 if (!this.isContain(liberty['neutral'][n], ret['neutral'])) {
711 ret['neutral'].push(liberty['neutral'][n]);
715 } else if (this.board[i][j] == 'black') {
716 if (ret.hasOwnProperty('white')) {
719 } else if (!ret.hasOwnProperty('black')) {
722 } else if (this.board[i][j] == 'white') {
723 if (ret.hasOwnProperty('black')) {
726 } else if (!ret.hasOwnProperty('white')) {
732 if (!ret.hasOwnProperty('none')) {
733 if (ret.hasOwnProperty('black')) {
734 if (!this.isContain([i_,j_], ret['black']))
735 ret['black'].push([i_,j_]);
736 if (ret.hasOwnProperty('neutral')){
737 for (var p = ret['neutral'].shift(); typeof p != 'undefined'; p = ret['neutral'].shift()) {
738 if (!this.isContain(p, ret['black'])) {
739 ret['black'].push(p);
743 } else if (ret.hasOwnProperty('white')) {
744 if (!this.isContain([i_,j_], ret['white']))
745 ret['white'].push([i_,j_]);
746 if (ret.hasOwnProperty('neutral')){
747 for (var p = ret['neutral'].shift(); typeof p != 'undefined'; p = ret['neutral'].shift()) {
748 if (!this.isContain(p, ret['white'])) {
749 ret['white'].push(p);
754 if (!ret.hasOwnProperty('neutral'))
756 if (!this.isContain([i_,j_], ret['neutral']))
757 ret['neutral'].push([i_,j_]);
763 Go.isContain = function(place, _array) {
764 var heat = _array || [];
766 if (heat[i][0] == place[0] && heat[i][1] == place[1]) {
773 Go.drawMessage = function(){
775 this.current = this.player[(this.current.color=='black'?'white':'black')];
776 this.current.start();
779 Go.skip = function(color_){
780 var color = color_ || this.current.color;
781 if (this.current.color == color && !this.isSetting && this.isStart) {
782 this.playSound('settingbtn');
786 var status = {'color': this.current.color,
789 status.restTime = {};
790 status.restTime['black'] = this.player['black'].restTime;
791 status.restTime['white'] = this.player['white'].restTime;
792 this.manual.push(status);
799 function player(color_) {
801 var side = (color_ == 'black'?'left':'right');
802 this.restTime = 20*60;
804 this.place = [-1,-1];
805 this.stoneNum = Math.floor(Go.bounder*Go.bounder);
810 'arrow':side+'_arrow',
811 'timer':side+'_timer',
812 'score':side+'_score',
813 'stone':Go.texture[this.color],
814 'stone1':Go.texture[this.color+'1'],
815 'stone2':Go.texture[this.color+'2'],
819 $('.'+this.resource['pit']).html(str);
820 for (var i=0; i<this.stoneNum; i++){
821 var x = Math.floor(Math.random()*76)+20;
822 var y = Math.floor(Math.random()*296)+20;
823 var ext = Math.floor(Math.random()*16);
824 if (ext != 1 && ext != 2) ext = '';
825 str += '<img class="stone_in_pit" id="'+this.color+'stone'+i+'" style="top:'+y+'px;left:'+x+'px;" src="'+this.resource['stone'+ext]+'" />';
827 $('.'+this.resource['pit']).html(str);
829 $('.'+this.resource['timer']+' span').html('20:00');
831 this.currentStone = this.stoneNum-1;
833 this.dropStone = function() {
834 var x = Math.floor(Math.random()*76)+20;
835 var y = Math.floor(Math.random()*296)+20;
836 // var id = Math.floor(Math.random()*this.stoneNum);
837 var id = this.currentStone++;
838 var ext = Math.floor(Math.random()*16);
839 if (ext != 1 && ext != 2) ext = '';
840 $('#'+this.color+'stone'+id).attr('style', 'top:'+y+'px;left:'+x+'px;').attr('src', this.resource['stone'+ext]).removeClass('display_none');
843 this.pickStone = function(){
844 // var id = Math.floor(Math.random()*this.stoneNum);
845 var id = this.currentStone--;
846 $('#'+this.color+'stone'+id).addClass('display_none');
849 this.start = function(){
850 $('.'+this.resource['arrow']+' img').attr('src', this.texture['hi_arrow']);
857 this.stop = function(){
858 $('.'+this.resource['arrow']+' img').attr('src', this.texture['arrow']);
864 this.timeDida = function(){
869 this.updateTimer = function() {
870 if (this.restTime >= 0){
871 var s = this.restTime%60;
872 var m = Math.floor(this.restTime/60);
874 var s2 = Math.floor(s/10);
876 var m2 = Math.floor(m/10);
877 var t = ''+m2+m1+':'+s2+s1;
878 //console.log(this.color+'['+t+']');
879 $('.'+this.resource['timer']+' span').html(t);
883 this.getScore = function() {
888 return (this.score+this.liberty.length);
892 this.updateScore = function(){
894 var s = this.getScore();
895 for (var i=0; i<4; i++){
897 s = Math.floor(s/10);
899 $('#'+this.resource['score']).html(str);
903 player.prototype.texture = {
904 'arrow':'images/GO_PlayerArrow_010612_a.png',
905 'hi_arrow':'images/GO_PlayerArrow_012012_b.png',
908 Go.showLicense = function(id, hpageid) {
909 var lbtn = document.getElementById(id+"btnl");
911 var lpage = document.getElementById(id+"page");
912 var hpage = document.getElementById(hpageid);
917 if (!this.hasLicense) {
918 $('#licensepage').html('<div id="licensetext"><div id="licensescroll"></div></div> <div id="licensebtnq" class="licensebtn">Back</div>');
919 lscroll = document.getElementById(id+"scroll");
920 var request = new XMLHttpRequest();
921 request.open("GET", "README.txt", false);
922 request.onload = function(e) {
923 var text = this.responseText;
924 text = text.replace("<","<");
925 text = text.replace(">",">");
926 var lines = text.split("\n");
927 lines[0] = "<br><br>"+lines[0];
930 if(lines[i].match(/--------------------/))
939 lscroll.innerHTML = lines.join("\n");
942 this.hasLicense = true;
945 var btnq = document.getElementById(id+"btnq");
946 lscroll = document.getElementById(id+"scroll");
947 ltext = document.getElementById(id+"text");
948 /* initialize scroll rate */
953 /* set the scroller to the top position */
954 lscroll.style.top = "0px";
956 /* display the license page, hide its parent */
957 hpage.style.display="none";
958 lpage.style.display="block";
960 /* calculate the scroll length when the window is shown */
961 var maxY = lscroll.clientHeight - ltext.clientHeight;
963 /* start the autoscroll interval */
964 timer = setInterval(function() {
965 /* get the actual interval, in case performance slows us down */
966 var t1 = (new Date()).getTime();
967 var dT = (t0 == 0)?20:(t1-t0);
970 /* delay specific number of milliseconds */
975 /* calculate the new top position using dY and dT */
976 var newY = Math.abs(parseInt(lscroll.style.top)) + ((dT/40)*dY);
978 lscroll.style.top = (-1 * newY) + "px";
980 lscroll.style.top = "0px";
982 /* if the lscroll has hit the limit, delay and swing */
996 btnq.onclick = function() {
997 hpage.style.display="block";
998 lpage.style.display="none";
999 clearInterval(timer);
1005 function getMessage(key, alter) {
1006 var ret = alter || '';
1007 if (locale && locale == 'en' && ret.length>0) {
1010 if (window.chrome && window.chrome.i18n && window.chrome.i18n.getMessage) {
1011 ret = chrome.i18n.getMessage(key);
1013 if (typeof messages == 'undefined') {
1015 var request = new XMLHttpRequest();
1016 request.open("GET", "_locales/en/messages.json", false);
1018 var res = request.responseText;
1019 messages = window.eval(res);
1024 if (messages && (messages.hasOwnProperty(key)) && (messages[key].hasOwnProperty('message'))) {
1025 ret = messages[key].message;
1033 window.onload = function(){
1034 locale = getMessage('locale', 'en');
1035 if (locale != 'en') {
1036 var head = $('head').q;
1037 var link = document.createElement('link');
1038 link.rel = 'stylesheet';
1039 link.type = 'text/css';
1040 link.href = 'css/i18n.css';
1041 head.appendChild(link);
1044 $('title').html(getMessage('name', 'Go'));
1045 $('#playerone').html(getMessage('player', 'Player')+' '+getMessage('one', 'One'));
1046 $('#playertwo').html(getMessage('player', 'Player')+' '+getMessage('two', 'Two'));
1047 $('.left_arrow span[name="score"]').html(getMessage('score', 'Score'));
1048 $('.right_arrow span[name="score"]').html(getMessage('score', 'Score'));
1049 $('.left_skip').html(getMessage('skip', 'Skip'));
1050 $('.right_skip').html(getMessage('skip', 'Skip'));
1051 $('.play_button_text').html(getMessage('play', 'Play'));
1053 //Pass game, continue pass cause the end
1054 $('.left_skip').click(function(){
1058 $('.right_skip').click(function(){