diff --git a/flask/testapp/static/javascript/beautyVote.js b/flask/testapp/static/javascript/beautyVote.js index fde1ed5..1b144cf 100644 --- a/flask/testapp/static/javascript/beautyVote.js +++ b/flask/testapp/static/javascript/beautyVote.js @@ -46,6 +46,7 @@ function mainloop(){ + timer ++; switch(scene){ case START_SCENE: @@ -59,10 +60,9 @@ checkAnswer(); break; } - else{ - timer ++; - } + + fill("silver"); setAlp(50); fRect(50, 50, 855, 100, "black"); @@ -111,33 +111,32 @@ if(50 <= tapX && tapX <= 450 && 300 <= tapY && tapY <= 550){ player.choice = A; sendChoice(); - checkAnswer(); } else if(500 <= tapX && tapX <= 900 && 300 <= tapY && tapY <= 550){ player.choice = B; sendChoice(); - checkAnswer(); } else if(50 <= tapX && tapX <= 450 && 600 <= tapY && tapY <= 850){ player.choice = C; sendChoice(); - checkAnswer(); } else if(500 <= tapX && tapX <= 900 && 600 <= tapY && tapY <= 850){ player.choice = D; sendChoice(); - checkAnswer(); } - scene = WAIT_SCENE; //nemoto追記 } break; case RESULT_SCENE: showResult(); + break; // nemoto追記 case WAIT_SCENE: WaitOthers() // 他のプレイヤーが終わるまで待機する画面(nemoto追記) - CheckOthers() // 他のプレイヤーが終わるまで待機する処理(nemoto追記) + if(timer > 30){ + timer = 0; + CheckOthers() // 他のプレイヤーが終わるまで待機する処理(nemoto追記) + } } } @@ -160,29 +159,10 @@ round ++; if(round < MAX_ROUND){ setQuestion(round); - timer = 0; } } -// 送信用 -// function postForm(value) { -// var form = document.createElement('form'); -// var request = document.createElement('input'); - -// form.method = 'POST'; -// form.action = '/form'; - -// request.type = 'hidden'; //入力フォームが表示されないように -// request.name = 'text'; -// request.value = value; - -// form.appendChild(request); -// document.body.appendChild(form); - -// form.submit(); - -// } function postForm(){ xhr.open('POST', '/form'); xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); @@ -201,6 +181,8 @@ } function sendChoice(){ + timer = 0; + scene = WAIT_SCENE; //nemoto追記 xhr.open('POST', '/form'); xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); xhr.send('choice=' + player.choice); //変更 @@ -208,7 +190,6 @@ if (xhr.readyState === 4 && xhr.status === 200) { if(xhr.responseText!="Data received successfully"){ console.log(xhr.responseText); - my_order=xhr.responseText } else{ console.log(xhr.responseText); @@ -220,11 +201,11 @@ function sendName(){ xhr.open('POST', '/form'); xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); - xhr.send('originalnme=' + player.name); //変更 + xhr.send('username=' + player.name); //変更 xhr.onreadystatechange = function() { //受信用 if (xhr.readyState === 4 && xhr.status === 200) { if(xhr.responseText!="Data received successfully"){ - console.log(xhr.responseText); + console.log("識別番号:" + xhr.responseText); player.number = xhr.responseText; } else{ @@ -244,13 +225,17 @@ if(xhr.responseText=="WAIT"){ console.log(xhr.responseText); } - else if(xhr.responseText=="END ROUNDS"){ + else{ + timer = 0; console.log(xhr.responseText); + question[round].answer = xhr.responseText; + checkAnswer(); if(round < MAX_ROUND) scene = GAME_SCENE - else + else{ scene = RESULT_SCENE postForm(); + } } } } @@ -262,7 +247,7 @@ var round = 0; //変更 -var MAX_ROUND = 10; +var MAX_ROUND = 5; var timer = 0; var TIME_LIMIT = 900; @@ -283,7 +268,7 @@ var scene = START_SCENE; -var BLOCK_SIZE = 5; + var my_order = 8; var ranking_order = ["ルフィ", "ゾロ", "ジンベエ", "サンジ", "ロビン", "ウソップ", "フランキー", "ブルック", "ナミ", "チョッパー"] var scoreing_order = [3000000000,1110000000, 1100000000, 1032000000, 930000000, 500000000, 394000000, 383000000, 366000000, 1000] diff --git a/flask/testapp/static/javascript/resultScreen.js b/flask/testapp/static/javascript/resultScreen.js index e20231a..89ed316 100644 --- a/flask/testapp/static/javascript/resultScreen.js +++ b/flask/testapp/static/javascript/resultScreen.js @@ -57,6 +57,7 @@ player.name = document.getElementById('textBox').value; document.getElementById('textBox').style.display = 'none'; scene = GAME_SCENE; + timer = 0; sendName(); } } @@ -84,10 +85,10 @@ 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(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].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 ac1bc05..da17261 100644 --- a/flask/testapp/views.py +++ b/flask/testapp/views.py @@ -7,9 +7,8 @@ # ユーザーごとの点数を格納する辞書 user_score = {} - # playerの数 -MAX_PLAYER = 2 +MAX_PLAYER = 3 # scoreを保存するデータ data = [0] * MAX_PLAYER @@ -20,46 +19,23 @@ choices = [] # ユーザーを識別するための番号(実際の初期値は0にする) -user_number = 5 +user_number = 0 +data_count = 0 + +order_table = "" @app.route("/form", methods=["GET", "POST"]) def index(): - global user_number + global user_number, data_count, order_table if request.method == "GET": return render_template("testapp/index.html") if request.method == "POST": - """ - # POSTデータを受け取る - data.append( - request.get_data(as_text=True) - ) # バイナリデータではなくテキストとして取得する - - # 全員分のデータが集まった時 - if len(data) >= players: - # リスト内の要素の出現回数をカウントする - counter = Counter(data) - # 最も多く出現する要素を取得する - most_common_element = counter.most_common(1)[0][0] - return most_common_element - """ - # ゲーム中に選択肢を取得し,集計する - 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) >= MAX_PLAYER: # nemoto変更 - print("集計...") - most_common_option = calculate_majority(choices) # nemoto追記 - return most_common_option # nemoto追記 # ゲーム開始時にユーザー数を出しておき,それぞれに識別番号を振る - if request.form.get("originalname"): - + if request.form.get("username"): # ユーザー名を取得し,ユーザー情報を登録←クラス化したほうがいいかも? - username = request.form.get("originalname") + username = request.form.get("username") user[user_number] = username print("Received name:", username, "UserNumber:", user_number) @@ -67,6 +43,28 @@ # クライアントサイドに識別番号を返す return str(user_number - 1) + # ゲーム中に選択肢を取得し,集計する + if request.form.get("choice"): + if len(choices) >= MAX_PLAYER: + choices.clear() + choices.append(request.form.get("choice")) + print("Received choice:", choices) + + if len(choices) >= MAX_PLAYER: # nemoto変更 + print("集計...") + + return "WAIT" # nemoto追記 + + # 他の人が終わるまで待機(nemoto追記) + if request.form.get("checkothers"): + if len(choices) < MAX_PLAYER: + return "WAIT" + else: + most_common_option = calculate_majority(choices) # nemoto追記 + print("Answer:", most_common_option) + return str(most_common_option) + + # ゲーム終了時,識別番号とスコアを受け取り,ランキング上位を返す(作成途中) if request.form.get("number") and request.form.get("score"): # 識別番号を取得 @@ -74,7 +72,6 @@ # スコアを取得 score = int(request.form.get("score")) # nemoto変更 data[user_number] = score - scores_order, user_number_order = calculate_order(data) # nemoto追記 print( "Received number:", user_number, @@ -83,22 +80,24 @@ "\nScore:", data[user_number], ) - # 戻り値でランキング上位を返す?(仮) - return "7" - """ - # ユーザーごとのデータに追加 - user_data[username].append(data) data_count += 1 - """ - # 他の人が終わるまで待機(nemoto追記) - if request.form.get("checkothers"): - if len(choices) < MAX_PLAYER: + if data_count >= MAX_PLAYER: + scores_order, user_number_order = calculate_order(data) # nemoto追記 + print(scores_order, user_number_order) + order_table = create_order_table(scores_order, user_number_order) + # 戻り値でランキング上位を返す?(仮) + return "WAIT" + + if request.form.get("waitResult"): + if order_table == "": return "WAIT" else: - return "END ROUNDS" + return order_table + + # 必要な処理を行う(例:データベースへの書き込みなど) - return "Data received successfully" + return "WAIT" # 多数派の計算(nemoto追記) @@ -111,9 +110,23 @@ # ランキング上位の計算(nemoto追記) 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] print("スコア:" + str(get_scores)) print("識別番号:" + str(get_labels)) return get_scores, get_labels + + +def create_order_table(scores, labels): + order_table = "" + print(user) + for i in range(MAX_PLAYER): + order_table += ( + str(i) + "位 " + user[int(labels[i])] + " " + str(scores[i]) + "pt\n" + ) + + print(order_table) + return order_table