gpt4 book ai didi

javascript - 垄断资金追踪器

转载 作者:行者123 更新时间:2023-12-02 21:18:05 25 4
gpt4 key购买 nike

我已经下载了《大富翁》资金追踪器,因此我和几个 friend 可以通过 Skype 玩游戏,并且所有人都能够看到游戏资金的实际情况。

我从这里得到的https://github.com/brentvollebregt/monopoly-money

如果可以选择设置每个玩家的平衡,但它不起作用。它只是设置作为庄家玩的玩家的平衡,无论您选择哪个玩家。如果您尝试发送免费 parking 广场的内容,它也会执行此操作。

这是处理交易的 JavaScript

var background_check_delay = 4000

switch_balance_format = function(obj){
var MK = obj.text.slice(-1);
if (MK == "M"){
obj.text = String(Number(obj.text.slice(0,-1)) * 1000) + "K"
} else {
obj.text = String(Number(obj.text.slice(0,-1)) / 1000) + "M"
}
};

switch_char = function(obj){
var MK = obj.text
if (MK == "M"){
obj.text = "K"
} else {
obj.text = "M"
}
}

flash_red = function() {
$("#pin").css("background", "rgba(224, 31, 31,0.35)");
$('#pin').fadeTo('slow', 0.3, function()
{
$(this).css('background', 'rgba(255,255,255,0.05)');
}).delay(1000).fadeTo('slow', 1);
}

play_refresh = function(){
$.getJSON($SCRIPT_ROOT + '/play_data/', function(data) {

if (jQuery.isEmptyObject(data)){
window.location.reload(true);
return;
}

if ($('#balance').text().slice(-1) == "K"){
$('#balance').text(String(data['balance']) + "K");
} else {
$('#balance').text(String(data['balance']/1000) + "M");
}

var current_names = [];
for (var i = 0; i < $('#send_money_player').children().length; i++) {
current_names.push($('#send_money_player').children()[i].text);
}
for (var i = 0; i < data['users'].length; i++) {
if (!(current_names.indexOf(data['users'][i]) >= 0)){
$('#send_money_player').append('<option value="' + data['users'][i] + '">' + data['users'][i] + '</option>')
}
}
for (var i = 0; i < $('#send_money_player').children().length; i++) {
if (["Bank", "Free Parking", "Player"].indexOf($('#send_money_player').children()[i].text) !== -1){
continue;
}
if (data['users'].indexOf($('#send_money_player').children()[i].text) == -1){
$('#send_money_player').children()[i].remove();
}
}

if ($('#free_parking').text().slice(-1) == "K"){
$('#free_parking').text(String(data['free_parking']) + "K");
} else {
$('#free_parking').text(String(data['free_parking']/1000) + "M");
}

var current_logs = [];
for (var i = 0; i < $('#logs').children().length; i++) {
current_logs.push($('#logs').children()[i].textContent );
}
data['logs'] = data['logs'];
for (var i = 0; i < data['logs'].length; i++) {
if (!(current_logs.indexOf(data['logs'][i]) >= 0)){
$('#logs').prepend('<div class="play_scroll_log">' + data['logs'][i] + '</div>');
}
}
});
}

bank_refresh = function(){
$.get($SCRIPT_ROOT + '/bank_data/', function(data) {

if (jQuery.isEmptyObject(data)){
window.location.reload(true);
return;
}

if ($('#free_parking').text().slice(-1) == "K"){
$('#free_parking').text("Amount: " + String(data['free_parking']) + "K");
} else {
$('#free_parking').text("Amount: " + String(data['free_parking']/1000) + "M");
}

var current_names = [];
for (var i = 0; i < $('#send_money_player').children().length; i++) {
current_names.push($('#send_money_player').children()[i].text);
}
for (var i = 0; i < data['users'].length; i++) {
if (!(current_names.indexOf(data['users'][i]) >= 0)){
$('#send_money_player').append('<option value="' + data['users'][i] + '">' + data['users'][i] + '</option>')
$('#send_free_parking_player').append('<option value="' + data['users'][i] + '">' + data['users'][i] + '</option>')
$('#set_player_bal_player').append('<option value="' + data['users'][i] + '">' + data['users'][i] + '</option>')
$('#active_players').append('<div style="width: 100%; height: 30%; display: block;"><div style="width: 50%; height: 100%; margin-left: 15%; margin-right: 0px; float: left;"><div class="outer_rel"><div class="middle"><div class="inner"><a class="white_text" style="font-size: 350%; float: left;">' + data['users'][i] + '</a></div></div></div></div><div style="width: 10%; height: 100%; float: right; margin-right: 15%;"><img onclick="javascript:remove_player(this);" value="' + data['users'][i] + '" src="' + close_png_src +'" style="height: 100%;"></div><div style="width: 10%; height: 100%; float: right;"><img onclick="javascript:edit_player_name(this);" value="' + data['users'][i] + '" src="' + edit_png_src +'" class="banker_switch"></div></div>')
}
}
for (var i = 0; i < $('#send_money_player').children().length; i++) {
if (["Bank", "Free Parking", "Player"].indexOf($('#send_money_player').children()[i].text) !== -1){
continue;
}
var name = $('#send_money_player').children()[i].text
if (data['users'].indexOf(name) == -1){
$('#send_money_player').children()[i].remove();
for (var i = 0; i < $('#send_free_parking_player').children().length; i++){
if ($('#send_free_parking_player').children()[i].text == name){
$('#send_free_parking_player').children()[i].remove()
}
}
for (var i = 0; i < $('#set_player_bal_player').children().length; i++){
if ($('#set_player_bal_player').children()[i].text == name){
$('#set_player_bal_player').children()[i].remove()
}
}
for (var i = 0; i < $('#active_players').children().length; i++){
if ($($('#active_players').children()[i]).find('a').text() == name){
$('#active_players').children()[i].remove()
}
}
}
}

if (data['open']){
if($('#lock_button').text() == "Closed"){
$('#lock_button').text("Open");
}
} else {
if($('#lock_button').text() == "Open"){
$('#lock_button').text("Closed");
}
}
});
}

leave = function(){
window.location.href = $SCRIPT_ROOT + '/clear';
}

leave_prep = function(context){
if (window.confirm("Are you sure you want to " + context)){
leave();
}
}

check_pin_response = function(data){
if (data['response'] == 1) {
window.location.href = $SCRIPT_ROOT + '/game/';
} else if (data['response'] == 3) {
$('#pin').val('');
flash_red();
} else if (data['response'] == 4) {
$('#pin').val('');
alert("Game is currently locked");
flash_red();
} else if (data['response'] == 5) {
$('#pin').val('');
alert("Name is already taken");
flash_red();
}
}

who_starts_first = function(){
$.get($SCRIPT_ROOT + '/who_starts/', function(data) {
alert(data['user'] + " starts");
});
}

play_background_checks = function(){
setInterval(function() {
play_refresh();
}, background_check_delay);
}

bank_background_checks = function(){
setInterval(function() {
bank_refresh();
}, background_check_delay);
}

edit_player_name = function(obj){
var new_name = prompt("New name for " + $(obj).attr('value') + "?");
if (!(new_name == "" || new_name == null)){
$.post($SCRIPT_ROOT + '/edit_player_name/', {
player_name_to_change: $(obj).attr('value'),
new_name: new_name
});
}

bank_refresh();
}

remove_player = function(obj){
if (window.confirm("Are you sure you want to remove " + $(obj).attr('value') + "?")){
$.post($SCRIPT_ROOT + '/remove_player/', {
player_name_to_remove: $(obj).attr('value')
});
}

bank_refresh();
}

send_money = function(isBank){
if($('#send_money_amount').val() == ""){
alert("No amount entered");
return;
}
if($('#send_money_player').val() == null){
alert("No player selected");
return;
}

if ($('#send_money_MK').text() == "K"){
var amount = Number($('#send_money_amount').val())
} else {
var amount = Number($('#send_money_amount').val()*1000)
}
var player = $('#send_money_player').val()

var success = true;
$.post($SCRIPT_ROOT + '/send_money/', {
transfer_amount: amount,
player_receiving: player,
banker: isBank
}, function(data){
var response = jQuery.parseJSON(data);
if (!(response['success'])){
alert(response['reason']);
success = false;
}
});

if (!success){
return;
}

$('#send_money_player').val("")
$('#send_money_amount').val("")

if (window.location['pathname'] == "/bank/"){
bank_refresh();
} else {
play_refresh();
}
}

send_free_parking = function(){
$.post($SCRIPT_ROOT + '/send_free_parking/', {
player: $('#send_free_parking_player').val()
});

$('#send_free_parking_player').val("")

bank_refresh();
}

set_balance = function(){
if($('#set_player_bal_amount').val() == ""){
alert("No amount entered");
return;
}
if($('#set_player_bal_player').val() == null){
alert("No player selected");
return;
}

if ($('#set_player_bal_MK').text() == "K"){
var amount = Number($('#set_player_bal_amount').val())
} else {
var amount = Number($('#set_player_bal_amount').val())*1000
}
var player = $('#set_player_bal_player').val()

$.post($SCRIPT_ROOT + '/set_balance/', {
set_amount: amount,
player_to_set: player,
});

$('#set_player_bal_player').val("")
$('#set_player_bal_amount').val("")

bank_refresh();
}

switch_lock = function(){
$.post($SCRIPT_ROOT + '/switch_lock/');

bank_refresh();
}

以及银行家使用的前端的HTML

{% extends "SKELETON.html" %}
{% block content %}

<script>
var $SCRIPT_ROOT = {{ request.script_root|tojson|safe }};


var close_png_src = "{{ url_for('static', filename='./icons/close.png') }}"
var edit_png_src = "{{ url_for('static', filename='./icons/edit.png') }}"

$(document).ready(function(){
bank_refresh();
bank_background_checks();
});
</script>

<!--Top Display-->
<div class="green_top">
<div style="width: 20%; height; 100%; float: left;">
<a href="/play/">
<img src="{{ url_for('static', filename='./icons/play.png') }}" class="banker_switch">
</a>
</div>
<div class="outer_rel" style="width: 80%; float: right;">
<div class="middle">
<div class="inner">
<a class="play_name_title">Bank {{ game_pin }}</a>
</div>
</div>
</div>
</div>

<!--Body-->
<div style="width: 100%; height: 90%;">
<!--Transfer Money-->
<div style="height: 28%; width: 100%;" class="section_divider">
<div style="height: 100%; width: 30%; float: right;">
<button id="send_money" class="green_btn play_go" onclick="javascript:send_money(true);">Go</button>
</div>
<div style="height: 50%; width: 70%; float: left;">
<select id="send_money_player" class="user_select white_text">
<option value="" disabled selected>Player</option>
</select>
</div>
<div style="height: 50%; width: 70%; float: left;">
<input id="send_money_amount" type="number" class="play_amount_entry" placeholder="Amount">
<a id="send_money_MK" class="white_text" style="height; 100%; width: 20%; font-size: 650%;" onclick="switch_char(this)">K</a>
</div>
</div>

<!--Send Free Parking-->
<div style="height: 15%; width: 100%;" class="section_divider">
<div class="outer_rel" style="width: 30%; float: left;">
<div class="middle">
<div class="inner">
<a id="free_parking" class="white_text" style="font-size: 300%; height: 100%; width: 100%; display: block; text-align: center;">Amount: 0K</a>
</div>
</div>
</div>
<div style="height; 100%; width: 70%; float: right;">
<div style="height: 100%; width: 57%; float: left;">
<select id="send_free_parking_player" class="user_select white_text" style="font-size: 300%;">
<option value="" disabled selected>Player</option>
</select>
</div>
<button id="send_free_parking" class="green_btn play_go" style="width: 43%; float: right;" onclick="javascript:send_free_parking();">Go</button>
</div>
</div>

<!--Manage Players (edit names and remove-->
<div style="height: 19%; width: 100%;" class="section_divider">
<div id="active_players" class="in_scroll">
<!--Individuals-->
<!--<div style="width: 100%; height: 30%; display: block;">-->
<!--<div style="width: 50%; height: 100%; margin-left: 15%; margin-right: 0px; float: left;">-->
<!--<div class="outer_rel">-->
<!--<div class="middle">-->
<!--<div class="inner">-->
<!--<a class="white_text" style="font-size: 350%; float: left;">Brent</a>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!--<div style="width: 10%; height: 100%; float: right; margin-right: 15%;">-->
<!--<img src="{{ url_for('static', filename='./icons/close.png') }}" style="height: 100%;">-->
<!--</div>-->
<!--<div style="width: 10%; height: 100%; float: right;">-->
<!--<img src="{{ url_for('static', filename='./icons/edit.png') }}" class="banker_switch">-->
<!--</div>-->
<!--</div>-->

</div>
</div>

<!--Edit Balance Of Player-->
<div style="height: 18%; width: 100%;" class="section_divider">
<div style="height: 100%; width: 30%; float: right;">
<button id="set_player_bal" class="green_btn" style="height: 100%; width: 100%; font-size: 700%; font-family: Quicksand; border: none;" onclick="javascript:set_balance();">Go</button>
</div>
<div style="height: 50%; width: 70%; float: left;">
<select id="set_player_bal_player" class="user_select white_text" style="font-size: 300%;">
<option value="" disabled selected>Player</option>
</select>
</div>
<div style="height: 50%; width: 70%; float: left;">
<input id="set_player_bal_amount" type="number" class="play_amount_entry" style="font-size: 300%;" placeholder="Amount">
<a id="set_player_bal_MK" class="white_text" style="height; 100%; width: 20%; font-size: 400%;" onclick="switch_char(this)">K</a>
</div>
</div>

<!--Who Starts First-->
<div style="height: 8%; width: 100%;" class="section_divider">
<div class="outer_rel">
<div class="middle">
<div class="inner">
<a class="white_text" style="font-size: 300%; text-align: center; display: block;" onclick="javascript:who_starts_first();">Who starts first?</a>
</div>
</div>
</div>
</div>

<!--Lock and End-->
<div style="height: 12%; width: 100%;" class="section_divider">
<div class="green_btn" style="width: 50%; height: 100%; float: left;">
<div class="outer_rel">
<div class="middle">
<div class="inner">
<a id="lock_button" class="play_bottom_btns" onclick="javascript:switch_lock();">Open</a>
</div>
</div>
</div>
</div>
<div class="red_btn" style="width: 50%; height: 100%; float: right;">
<div class="outer_rel">
<div class="middle">
<div class="inner">
<a class="play_bottom_btns" onclick="javascript:leave_prep('end the game?');">End</a>
</div>
</div>
</div>
</div>
</div>
</div>

{% endblock %}

谁能看出是什么原因造成的以及如何解决它?

开发者已经近 3 年没有更新了,所以我猜他已经停止使用了

最佳答案

第 427-438 行 ( https://github.com/brentvollebregt/monopoly-money/blob/9fc8f631746a6fdfb627b5b22f37f270113b48b8/run_server.py )

game = data['users'][request.cookies['id']]['game']
name = data['users'][request.cookies['id']]['name']

# Check if banker
if data['users'][request.cookies['id']]['type'] != "banker":
return jsonify()

player_name = request.form['player_to_set']
balance = int(request.form['set_amount'])

data['games'][game]['players'][name]['bal'] = balance
data['games'][game]['logs'].append("Bank set balance of " + name + " to " + str(balance) + "K")

请注意,目标玩家名称(表单参数)存储在 player_name 中,执行玩家(cookie 参数)存储在 name 中,但代码随后使用变量 name 代替。这将始终设置执行请求的玩家(即银行家)的余额。

编辑:看来这个错误现已修复:https://github.com/brentvollebregt/monopoly-money/commit/7136b61f90e497d5ff5e0763a2f135941ad7ad79

关于javascript - 垄断资金追踪器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60916855/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com