diff --git a/flask/testapp/static/javascript/beautyVote.js b/flask/testapp/static/javascript/beautyVote.js index 9c0e218..9c8e239 100644 --- a/flask/testapp/static/javascript/beautyVote.js +++ b/flask/testapp/static/javascript/beautyVote.js @@ -56,7 +56,7 @@ case WAIT_START: WaitStart(); - if(timer > 5){ + if(timer > 30){ timer = 0; CheckStart();// 他のプレイヤーが名前を書き終わるのを待機 } @@ -100,7 +100,15 @@ WaitOthers() // 他のプレイヤーが終わるまで待機する画面 if(timer > 30){ timer = 0; - CheckOthers() // 他のプレイヤーが終わるまで待機する処理 + CheckOthers(); // 他のプレイヤーが終わるまで待機する処理 + } + break; + + case ROUND_RESULT: + showOtherResult(round-1); + if(timer > 30){ + timer = 0; + scene = GAME_SCENE; } break; @@ -111,6 +119,7 @@ timer = 0; CheckResult(); //順位表を受け取るための処理 } + //結果表示 case RESULT_SCENE: showResult(); @@ -182,22 +191,7 @@ break; } } -/* - if(player.choice == question[round].answer[0]){ - player.points[round] = "4"; - } - else if(player.choice == question[round].answer[1]){ - player.points[round] = "3"; - } - else if(player.choice == question[round].answer[2]){ - player.points[round] = "2"; - } - else if(player.choice == question[round].answer[3]){ - player.points[round] = "1"; - } - else{ - player.points[round] = "0"; - }*/ + round ++; console.log(player.points[round]) if(round < MAX_ROUND){ @@ -211,12 +205,6 @@ xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); //識別番号とスコアを送信 xhr.send('number='+player.number + '&score=' + player.calcScore()); //変更 - //WAITコードを受信 - xhr.onreadystatechange = function() { - if (xhr.readyState === 4 && xhr.status === 200) { - console.log(xhr.responseText); - } - } } //選択をサーバーに送信する処理 @@ -241,11 +229,18 @@ xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); //ユーザーネームを送信 xhr.send('username=' + player.name); + timer = 0; //識別番号を受信 xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { - console.log("識別番号:" + xhr.responseText); - player.number = xhr.responseText; + if(xhr.responseText == "Capasity ERROR"){ + scene = RESULT_SCENE; + } + else{ + console.log("識別番号:" + xhr.responseText); + player.number = xhr.responseText; + scene = WAIT_START; + } } } } @@ -298,32 +293,17 @@ question[round].answer[i] = arr_answer[0]; question[round].people[i] = arr_answer[1]; } - /* - // 1番目に多かった答えと人数 - let arr_answer1 = splitAnswer[0].split(" "); - question[round].answer1 = arr_answer1[0]; - question[round].people1 = arr_answer1[1]; - // 2番目に多かった答えと人数 - let arr_answer2 = splitAnswer[1].split(" "); - question[round].answer2 = arr_answer2[0]; - question[round].people2 = arr_answer2[1]; - // 3番目に多かった答えと人数 - let arr_answer3 = splitAnswer[2].split(" "); - question[round].answer3 = arr_answer3[0]; - question[round].people3 = arr_answer3[1]; - // 4番目に多かった答えと人数 - let arr_answer4 = splitAnswer[3].split(" "); - question[round].answer4 = arr_answer4[0]; - question[round].people4 = arr_answer4[1]; - console.log(question[round].answer4) - console.log(question[round].people4)*/ + //正解判定 checkAnswer(); - if(round < MAX_ROUND) - scene = GAME_SCENE + timer = 0; + if(round < MAX_ROUND){ + scene = ROUND_RESULT; + //scene = GAME_SCENE; + } //最終ラウンド終了時 else{ - scene = WAIT_RESULT + scene = WAIT_RESULT; postForm(); } } @@ -356,7 +336,7 @@ var round = 0; //変更 -var MAX_ROUND = 5; +var MAX_ROUND = 3; var CHOICE_NUMBER = 4; var max_player = 0; // 最大のplayer数(変更不要) var current_player = 0; @@ -381,6 +361,7 @@ var WAIT_RESULT = 5; var WAIT_START = 6; // nemoto追記 var CHECK_RESULT = 7; +var ROUND_RESULT = 8; var scene = START_SCENE; diff --git a/flask/testapp/static/javascript/resultScreen.js b/flask/testapp/static/javascript/resultScreen.js index d7035f7..bf48971 100644 --- a/flask/testapp/static/javascript/resultScreen.js +++ b/flask/testapp/static/javascript/resultScreen.js @@ -69,8 +69,6 @@ if(200 <= tapX && tapX <= 760 && 500 <= tapY && tapY <= 700){ player.name = document.getElementById('textBox').value; document.getElementById('textBox').style.display = 'none'; - scene = WAIT_START; - timer = 0; sendName(); } } diff --git a/flask/testapp/views.py b/flask/testapp/views.py index 028b5ef..d21ecfe 100644 --- a/flask/testapp/views.py +++ b/flask/testapp/views.py @@ -1,12 +1,15 @@ from flask import render_template, request from testapp import app from collections import Counter +import time # ユーザーごとの点数を格納する辞書 user_score = {} # playerの数 -MAX_PLAYER = 3 +MAX_PLAYER = 2 + +WAIT_TIME = 35 # 何位まで表示するか(nemoto) max_order = 5 @@ -33,10 +36,12 @@ most_common_option = 0 +start, end = 0, 0 + @app.route("/form", methods=["GET", "POST"]) def index(): - global frequent_table, user_number, data_count, order_table, most_common_option, max_order + global frequent_table, user_number, data_count, order_table, most_common_option, max_order, current_player, start, end if request.method == "GET": return render_template("testapp/index.html") @@ -53,6 +58,8 @@ print("Received name:", username, "UserNumber:", user_number) user_number += 1 + current_player = user_number + print(f"現在の参加人数: {current_player}") # クライアントサイドに識別番号を返す return str(user_number - 1) @@ -62,26 +69,35 @@ return str(MAX_PLAYER) + " " + str(user_number) # 全員のデータが集まった場合は,ゲーム開始 else: + start = time.time() + # print(f"START: {start}") return "START" # ゲーム中に選択肢を取得し,集計する if request.form.get("choice"): - if len(choices) >= MAX_PLAYER: + if len(choices) >= current_player: choices.clear() choices.append(request.form.get("choice")) print("Received choice:", choices) - - if len(choices) >= MAX_PLAYER: + """ + if len(choices) >= current_player: frequent_table = calculate_majority(choices) - return "WAIT" + return "WAIT + """ # 他の人が終わるまで待機 if request.form.get("checkothers"): - if len(choices) < MAX_PLAYER: - return "WAIT" - # 全員のデータが集まった場合は,多数派を計算 + end = time.time() + # print(f"END: {end}") + print(f"TIME: {end-start}") + if len(choices) >= current_player or end - start > WAIT_TIME: + start = time.time() + current_player = len(choices) + # print(f"START: {start}") + print(f"現在の参加人数:{current_player}") + return calculate_majority(choices) else: - return frequent_table + return "WAIT" # ゲーム終了時,識別番号とスコアを受け取る if request.form.get("number") and request.form.get("score"): @@ -101,10 +117,12 @@ data_count += 1 # すべてのデータが集まった場合,順位表を作成 otaki - if data_count >= MAX_PLAYER: + if data_count >= current_player: scores_order, user_number_order = calculate_order(data) print(scores_order, user_number_order) - order_table = create_order_table(scores_order, user_number_order, max_order) + order_table = create_order_table( + scores_order, user_number_order, max_order + ) return "WAIT" @@ -124,30 +142,52 @@ counter = Counter(get_data) get_frequent_table = "" # 最も多く出現する要素を取得する - most_common = counter.most_common() # 出現回数が多い順に要素とその出現回数のリストを取得 + most_common = ( + counter.most_common() + ) # 出現回数が多い順に要素とその出現回数のリストを取得 # 最も多く出現する要素 get_most_common_option = str(most_common[0][0]) get_most_common_count = str(most_common[0][1]) get_frequent_table += get_most_common_option + " " + get_most_common_count + "\n" # 2番目に多い要素 - get_second_most_common_option = str(most_common[1][0]) if len(most_common) > 1 else str(4) - get_second_most_common_count = str(most_common[1][1]) if len(most_common) > 1 else str(0) - get_frequent_table += get_second_most_common_option + " " + get_second_most_common_count + "\n" + get_second_most_common_option = ( + str(most_common[1][0]) if len(most_common) > 1 else str(4) + ) + get_second_most_common_count = ( + str(most_common[1][1]) if len(most_common) > 1 else str(0) + ) + get_frequent_table += ( + get_second_most_common_option + " " + get_second_most_common_count + "\n" + ) # 3番目に多い要素 - get_third_most_common_option = str(most_common[2][0]) if len(most_common) > 2 else str(4) - get_third_most_common_count = str(most_common[2][1]) if len(most_common) > 2 else str(0) - get_frequent_table += get_third_most_common_option + " " + get_third_most_common_count + "\n" + get_third_most_common_option = ( + str(most_common[2][0]) if len(most_common) > 2 else str(4) + ) + get_third_most_common_count = ( + str(most_common[2][1]) if len(most_common) > 2 else str(0) + ) + get_frequent_table += ( + get_third_most_common_option + " " + get_third_most_common_count + "\n" + ) # 4番目に多い要素 - get_fourth_most_common_option = str(most_common[3][0]) if len(most_common) > 3 else str(4) - get_fourth_most_common_count = str(most_common[3][1]) if len(most_common) > 3 else str(0) - get_frequent_table += get_fourth_most_common_option + " " + get_fourth_most_common_count + get_fourth_most_common_option = ( + str(most_common[3][0]) if len(most_common) > 3 else str(4) + ) + get_fourth_most_common_count = ( + str(most_common[3][1]) if len(most_common) > 3 else str(0) + ) + get_frequent_table += ( + get_fourth_most_common_option + " " + get_fourth_most_common_count + ) return get_frequent_table # ランキング上位の計算 def calculate_order(get_data): - get_sorted_numbers_with_indices = sorted(enumerate(get_data), key=lambda x: x[1], reverse=True) + get_sorted_numbers_with_indices = sorted( + enumerate(get_data), key=lambda x: x[1], reverse=True + ) get_scores = [item[1] for item in get_sorted_numbers_with_indices] get_labels = [item[0] for item in get_sorted_numbers_with_indices] @@ -160,13 +200,22 @@ j = 0 # 同率順位の考慮 # 最高"max位"までを表示する - if max >= MAX_PLAYER: - max = MAX_PLAYER + if max >= current_player: + max = current_player for i in range(max): if i + j >= max: # 参照する配列がこれ以上ない時 break - order_table += str(i + 1 + j) + "位" + " " + user[int(labels[i + j])] + " " + str(scores[i + j]) + "pt" + "\n" + order_table += ( + str(i + 1 + j) + + "位" + + " " + + user[int(labels[i + j])] + + " " + + str(scores[i + j]) + + "pt" + + "\n" + ) now_order = i + 1 + j # 今の順位 if i + j + 1 == max: # 先ほどorder_tableに挿入した配列が,最後であった時 break @@ -174,7 +223,14 @@ while str(scores[i + j]) == str(scores[i + 1 + j]): j += 1 order_table += ( - str(now_order) + "位" + " " + user[int(labels[i + j])] + " " + str(scores[i + j]) + "pt" + "\n" + str(now_order) + + "位" + + " " + + user[int(labels[i + j])] + + " " + + str(scores[i + j]) + + "pt" + + "\n" ) if i + j + 1 >= max: # (i+j)と比較する配列(i+j+1)がない時 break