Commits

Anonymous committed 92912a7

POSTした結果が反映するようにした

  • Participants
  • Parent commits b10851f
  • Branches work

Comments (0)

Files changed (2)

-<!DOCTYPE html>
+<!DOCTYPE html>
 <html>
 <head>
   <title>第30回開発オフゲーム</title>
   <meta charset="utf-8" />
-  <script type="text/javascript" src="/script/jquery-1.7.2.js"></script>
+  <script type="text/javascript" src="./script/jquery-1.7.2.js"></script>
   <script type="text/javascript" src="./script/main.js"></script>
 </head>
 <body>
+var palyerlist = {
+	1: 'player2.rb',
+	2: 'player2.rb'
+};
 
 function run() {
 	$('#result').html('Start');
 
-	var palyerlist = {
-		1: 'player1.py',
-		2: 'player2.rb'
-	};
+	var start_player = 1;
+	var default_remaing_flag = 10;
 
-	var player_no = 1;
-	var remaing_flag = 10;
+	play(start_player, default_remaing_flag);
 
-	while(remaing_flag > 0){
-		var player = palyerlist[player_no];
-		setTimeout(function(){},300);
-
-		var result = exec(player, remaing_flag);
-		remaing_flag -= result;
-		console.log('result:' + result + ', remaing_flag:' + remaing_flag);
-
-		player_no = get_nextplayer(player_no);
-	}
-
-	$('#result').html('End');
 }
 
-function get_nextplayer(player_no) {
+function play(player_no, remaing_flag){
+  var player = palyerlist[player_no];
+	exec(player, remaing_flag, function(result){
+    remaing_flag -= result;
+    console.log('result:' + result + ', remaing_flag:' + remaing_flag);
+    if(remaing_flag <= 0){
+      $('#result').html('player_no:'+ player_no + 'Lose. Game End.');
+      return;
+    }
+    play(get_next_player_no(player_no), remaing_flag);
+  });
+}
+
+function get_next_player_no(player_no) {
 	next_no = 0;
 	if (player_no == 1) {
 		next_no = 2;
 	return next_no;
 }
 
-function exec(player, remaing_flag) {
-	var ret = 0;
-	$.post('/cgi-bin/' + player,
+function exec(player, remaing_flag, func) {
+	$.post('./cgi-bin/' + player,
 			{
 				'remaing_flag': remaing_flag
 			},
 			function(data){
-				ret = data;
+				func(data);
 			}
-			);
-	return ret;
+	);
 }