diff --git a/flask/testapp/static/javascript/beautyVote.js b/flask/testapp/static/javascript/beautyVote.js index 58990db..fde1ed5 100644 --- a/flask/testapp/static/javascript/beautyVote.js +++ b/flask/testapp/static/javascript/beautyVote.js @@ -128,10 +128,17 @@ sendChoice(); checkAnswer(); } - } - break; + scene = WAIT_SCENE; //nemoto追記 + } + break; case RESULT_SCENE: showResult(); + + // nemoto追記 + case WAIT_SCENE: + WaitOthers() // 他のプレイヤーが終わるまで待機する画面(nemoto追記) + CheckOthers() // 他のプレイヤーが終わるまで待機する処理(nemoto追記) + } } @@ -155,10 +162,6 @@ setQuestion(round); timer = 0; } - else{ - scene = RESULT_SCENE; - postForm(); - } } // 送信用 @@ -231,10 +234,33 @@ } } +// 追記(nemoto) +function CheckOthers(){ + xhr.open('POST', '/form'); + xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); + xhr.send('checkothers=' + "check"); //変更 + xhr.onreadystatechange = function() { //受信用 + if (xhr.readyState === 4 && xhr.status === 200) { + if(xhr.responseText=="WAIT"){ + console.log(xhr.responseText); + } + else if(xhr.responseText=="END ROUNDS"){ + console.log(xhr.responseText); + if(round < MAX_ROUND) + scene = GAME_SCENE + else + scene = RESULT_SCENE + postForm(); + } + } + } +} + var xhr = new XMLHttpRequest(); + var round = 0; //変更 var MAX_ROUND = 10; @@ -253,6 +279,7 @@ var START_SCENE = 1; var GAME_SCENE = 2; var RESULT_SCENE = 3; +var WAIT_SCENE = 4; // nemoto追記 var scene = START_SCENE; diff --git a/flask/testapp/static/javascript/resultScreen.js b/flask/testapp/static/javascript/resultScreen.js index 4db6382..e20231a 100644 --- a/flask/testapp/static/javascript/resultScreen.js +++ b/flask/testapp/static/javascript/resultScreen.js @@ -63,31 +63,31 @@ } -// 他のプレイヤーの終わりを待つとき(nemoto変更) +// 他のプレイヤーの終わりを待つ画面(nemoto変更) function WaitOthers(){ fill("silver"); - setAlp(50); - fRect(50, 50, 855, 100, "black"); - fText("Q.", 110, 100, 50, "white"); - fRect(45, 295, 865, 560, "white"); - fRect(50, 300, 400, 250, "black"); - fRect(500, 300, 400, 250, "black"); - fRect(50, 600, 400, 250, "black"); - fRect(500, 600, 400, 250, "black"); + setAlp(50); + fRect(50, 50, 855, 100, "black"); + fText("Q.", 110, 100, 50, "white"); + fRect(45, 295, 865, 560, "white"); + fRect(50, 300, 400, 250, "black"); + fRect(500, 300, 400, 250, "black"); + fRect(50, 600, 400, 250, "black"); + fRect(500, 600, 400, 250, "black"); - sRect(45, 880, 865, 40, "black"); - fRect(45, 880, (timer/900)*865, 40, "red"); - setAlp(100); + sRect(45, 880, 865, 40, "black"); + fRect(45, 880, (timer/900)*865, 40, "red"); + setAlp(100); - fText("A.", 100, 425, 40, "white"); - fText("B.", 550, 425, 40, "white"); - fText("C.", 100, 725, 40, "white"); - fText("D.", 550, 725, 40, "white"); + fText("A.", 100, 425, 40, "white"); + fText("B.", 550, 425, 40, "white"); + fText("C.", 100, 725, 40, "white"); + fText("D.", 550, 725, 40, "white"); - fText(question[round].question, 480, 100, 30, "white"); - fText(question[round].choiceA, 275, 425, 25, "white"); - fText(question[round].choiceB, 725, 425, 25, "white"); - fText("集計中...", 500, 500, 25, "black"); - fText(question[round].choiceC, 275, 725, 25, "white"); - fText(question[round].choiceD, 725, 725, 25, "white"); + fText(question[round].question, 480, 100, 30, "white"); + fText(question[round].choiceA, 275, 425, 25, "white"); + fText(question[round].choiceB, 725, 425, 25, "white"); + fText("集計中...", 500, 500, 25, "black"); + fText(question[round].choiceC, 275, 725, 25, "white"); + fText(question[round].choiceD, 725, 725, 25, "white"); } \ No newline at end of file diff --git a/flask/testapp/views.py b/flask/testapp/views.py index 2d07cb3..ac1bc05 100644 --- a/flask/testapp/views.py +++ b/flask/testapp/views.py @@ -2,13 +2,14 @@ from testapp import app from collections import Counter import random +import time # ユーザーごとの点数を格納する辞書 user_score = {} # playerの数 -MAX_PLAYER = 1 +MAX_PLAYER = 2 # scoreを保存するデータ data = [0] * MAX_PLAYER @@ -44,12 +45,14 @@ """ # ゲーム中に選択肢を取得し,集計する if request.form.get("choice"): + if len(choices) >= MAX_PLAYER: + print("AAAAAAAAAAAAAAAAAA") + choices.clear() # nemoto追記(始めに初期化) choices.append(request.form.get("choice")) print("Received choice:", choices) - if len(choices) >= user_number: + if len(choices) >= MAX_PLAYER: # nemoto変更 print("集計...") most_common_option = calculate_majority(choices) # nemoto追記 - choices.clear() return most_common_option # nemoto追記 # ゲーム開始時にユーザー数を出しておき,それぞれに識別番号を振る @@ -87,8 +90,12 @@ user_data[username].append(data) data_count += 1 """ - # 受け取ったデータを印刷する - # print("Received data:", user_data[username]) + # 他の人が終わるまで待機(nemoto追記) + if request.form.get("checkothers"): + if len(choices) < MAX_PLAYER: + return "WAIT" + else: + return "END ROUNDS" # 必要な処理を行う(例:データベースへの書き込みなど) return "Data received successfully"