- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我的代码运行时,我进入 2 人模式并调用函数 rounda 和 roundb,但由于某种原因它们没有响应。其他一切都正常,但我不知道出了什么问题。预先感谢您提供任何可能的建议。我的代码如下。我调用函数的地方位于底部。
var a = Math.floor(Math.random() * 7) + 1;
var da = null;
var ga = null;
if (a === 1) {
da = "Monday";
} else if (a === 2) {
da = "Tuesday";
} else if (a === 3) {
da = "Wednesday";
} else if (a === 4) {
da = "Thursday";
} else if (a === 5) {
da = "Friday";
} else if (a === 6) {
da = "Saturday";
} else if (a === 7) {
da = "Sunday";
}
var play = prompt("Please select either 1 or 2 players! Have at least 5000 credits at the end to win!");
if (play === "1") {
var wel = confirm("On a stormy " + da + " night, lightning lurks the skies. Will you risk your business for a chance to make millions?");
} else if (play === "2") {
confirm("On a stormy " + da + " night, lightning lurks the skies. Two electricity distributors compete head to head for dominance over the electric market. Who will reign supreme?");
} else {
ga = 1;
}
var ezR1 = Math.floor((Math.random() * 2560) + 500);
var ezR2 = Math.floor((Math.random() * 6650) + 500);
var ezR3 = Math.floor((Math.random() * 6670) + 600);
var ezR4 = Math.floor((Math.random() * 7780) + 600);
var ezR5 = Math.floor((Math.random() * 8120) + 700);
var ezR6 = Math.floor((Math.random() * 9540) + 700);
var ezR7 = Math.floor((Math.random() * 1230) + 800);
var ezR8 = Math.floor((Math.random() * 1134) + 800);
var ezR9 = Math.floor((Math.random() * 1223) + 900);
var ezR10 = Math.floor((Math.random() * 1510) + 1000);
var ezR1a = Math.floor((Math.random() * 2560) + 500);
var ezR2a = Math.floor((Math.random() * 6650) + 500);
var ezR3a = Math.floor((Math.random() * 6670) + 600);
var ezR4a = Math.floor((Math.random() * 7780) + 600);
var ezR5a = Math.floor((Math.random() * 8120) + 700);
var ezR6a = Math.floor((Math.random() * 9540) + 700);
var ezR7a = Math.floor((Math.random() * 1230) + 800);
var ezR8a = Math.floor((Math.random() * 1134) + 800);
var ezR9a = Math.floor((Math.random() * 1223) + 900);
var ezR10a = Math.floor((Math.random() * 1510) + 1000);
var ezR1b = Math.floor((Math.random() * 2560) + 500);
var ezR2b = Math.floor((Math.random() * 6650) + 500);
var ezR3b = Math.floor((Math.random() * 6670) + 600);
var ezR4b = Math.floor((Math.random() * 7780) + 600);
var ezR5b = Math.floor((Math.random() * 8120) + 700);
var ezR6b = Math.floor((Math.random() * 9540) + 700);
var ezR7b = Math.floor((Math.random() * 1230) + 800);
var ezR8b = Math.floor((Math.random() * 1134) + 800);
var ezR9b = Math.floor((Math.random() * 1223) + 900);
var ezR10b = Math.floor((Math.random() * 1510) + 1000);
var choozMany = Math.floor((Math.random() * 4) + 1);
var chooz = Math.random();
var amountOfPower = null;
var money = null;
var moneya = null;
var moneyb = null;
var cabels = 5;
var clients = 2;
var bacout = 1;
var one = 1;
var d = 0;
var da = 0;
var db = 0;
var vas = true;
var vasa = true;
var vasb = true;
var cabelsTake = 500 * cabels;
var bacoutTake = 2000 * bacout;
var valu = "a";
var valua = "a";
var valub = "a";
var gunka = true;
var gunkb = true;
var cabelsa = 5;
var clientsa = 2;
var bacouta = 1;
var cabelsb = 5;
var clientsb = 2;
var bacoutb = 1;
function Round(x) {
alert("Round " + x + " has begun!");
}
function s() {
console.log(" ");
}
function Tell(a, b, c, d, z, e) {
s();
console.log("***********************************");
if(e === n1 || e === n2){
console.log("ROUND " + z + "(" + e + ")");
} else {
console.log("ROUND " + z);
}
console.log("-----------------------------------");
console.log("Credits: " + a);
console.log("Power Cabels: " + b);
console.log("Back Outputters: " + c);
console.log("Clients: " + d);
console.log("-----------------------------------");
}
function Strike(x) {
console.log("⚡ KABOOM! ⚡");
console.log("Lightning strike power: " + x + " Volts");
}
function blowCable() {
console.log("Oh No! Some of your cables have blown up! You have " + cabels + " left!");
}
function blowBacout() {
console.log("Oh No! Some of your backup outputters have blown up! You have " + bacout + " left!");
}
// Logic(cabelsTake, bacoutTake, clients, cabels, ezRX,);
function Logic(a, b, c, d, e) {
var total = e - a;
var out = total - b;
var yon = a - e;
var cab = 500 * d;
if (yon > 0) {
var moneyEarned = e / 2 * c + cab;
var result = Math.round(moneyEarned);
money += result;
console.log("-----------------------------------");
console.log("Credits Earned: " + result);
console.log("Cables/Backup Outputters Overridden: None");
console.log("***********************************");
s();
} else {
console.log(" ");
console.log("ALERT! ALERT! Too much power!");
console.log(" ");
console.log("Attempting to send power to Backup Outputter... ");
console.log("⚠️BREACH! BREACH! OUTPUTTER INVALID! ATTEMPTING TO RESEND...⚠️");
console.log("***********************************");
s();
if (out < 0) {
var pen = 3000 + cab;
money += pen;
console.log("***********************************");
console.log("Success! Power diverted.");
console.log("Credits Earned: " + pen);
console.log("***********************************");
s();
} else {
console.log("WARNING! Input to large!");
if (chooz < 0.75 && cabels > 0) {
cabels -= choozMany;
blowCable();
console.log("Cables/Backup Outputters Overridden: " + choozMany);
console.log("***********************************");
} else if (chooz > 0.75 && bacout > 0) {
bacout -= choozMany;
blowBacout();
console.log("Cables/Backup Outputters Overridden: " + choozMany);
console.log("***********************************");
s();
}
}
}
}
//round('round number', 'ezRX' )
function round(x, y) {
if (d < 1 && valu === "a") {} else if (valu === "a" && vas === true) {
alert("Press 'ok' to move on to the next round");
}
if (valu === "a" && money > 3000) {
var shop = prompt("Shop Round " + x + ": 1.Power cable-$3000 2.Backup Outputter-$5000 3. Extra client-$30,000 Credits: " + "$" + money);
if (shop === "1" && money >= 3000) {
//cabels += one; works, money -= 1000; works
cabels += one;
money -= 3000;
cabelsTake = 500 * cabels;
bacoutTake = 2000 * bacout;
//Round x
Round(x);
Tell(money, cabels, bacout, clients, x);
Strike(y);
Logic(cabelsTake, bacoutTake, clients, cabels, y);
d++;
} else if (shop === "2" && money >= 5000) {
money -= 5000;
cabelsTake = 500 * cabels;
bacoutTake = 2000 * bacout;
bacout += one;
//Round x
Round(x);
Tell(money, cabels, bacout, clients, x);
Strike(y);
Logic(cabelsTake, bacoutTake, clients, cabels, y);
d++;
} else if (shop === "3" && money >= 30000) {
money -= 30000;
cabelsTake = 500 * cabels;
bacoutTake = 2000 * bacout;
clients += one;
//Round x
Round(x);
Tell(money, cabels, bacout, clients, x);
Strike(y);
Logic(cabelsTake, bacoutTake, clients, cabels, y);
d++;
} else {
var g = money / 2;
if (money < 3000) {
valu = "b";
} else {
money -= g;
console.log("You lost " + g + " credits for skipping a turn.");
if (money < 3000) {
console.log("------------------");
console.log("GAME OVER! Thanks for playing.");
valu = "b";
vas = false;
}
}
}
if (bacout <= 0 || cabels <= 0) {
valu = "b";
}
}
if (valu === "b" && vas === true) {
console.log("------------------");
console.log("GAME OVER! Thanks for playing.");
valu = "b";
vas = false;
}
if (d === 10) {
if (money > 5000 && valu === "a") {
console.log("Congratulations! You have made it through the storm. Your business continues to make millions!");
} else {
console.log("Oh No! You don't have enough money! Your business crumbles into chaos!");
}
valu = "b";
vas = false;
}
}
// Logic(cabelsTake, bacoutTake, clients, cabels, ezRX,);
//-------------------------------------------
function Logica(a, b, c, d, e) {
var total = e - a;
var out = total - b;
var yon = a - e;
var cab = 500 * d;
if (yon > 0) {
var moneyEarned = e / 2 * c + cab;
var result = Math.round(moneyEarned);
moneya += result;
console.log("-----------------------------------");
console.log("Credits Earned: " + result);
console.log("Cables/Backup Outputters Overridden: None");
console.log("***********************************");
s();
} else {
console.log(" ");
console.log("ALERT! ALERT! Too much power!");
console.log(" ");
console.log("Attempting to send power to Backup Outputter... ");
console.log("⚠️BREACH! BREACH! OUTPUTTER INVALID! ATTEMPTING TO RESEND...⚠️");
console.log("***********************************");
s();
if (out < 0) {
var pen = 3000 + cab;
moneya += pen;
console.log("***********************************");
console.log("Success! Power diverted.");
console.log("Credits Earned: " + pen);
console.log("***********************************");
s();
} else {
console.log("WARNING! Input to large!");
if (chooz < 0.75 && cabels > 0) {
cabels -= choozMany;
blowCable();
console.log("Cables/Backup Outputters Overridden: " + choozMany);
console.log("***********************************");
s();
} else if (chooz > 0.75 && bacout > 0) {
bacout -= choozMany;
blowBacout();
console.log("Cables/Backup Outputters Overridden: " + choozMany);
console.log("***********************************");
s();
}
}
}
}
//round('round number', 'ezRX' )
function rounda(x, y) {
if (da < 1 && valua === "a") {} else if (valua === "a" && vasa === true && valub === true) {
alert("Press 'ok' to move on to the next round");
}
if (valua === "a" && moneya > 3000 && valub === "a") {
nexd(n1);
var shopa = prompt("Shop Round " + x + ": 1.Power cable-$3000 2.Backup Outputter-$5000 3. Extra client-$30,000 Credits: " + "$" + moneya);
if (shopa === "1" && moneya >= 3000) {
//cabels += one; works, money -= 1000; works
cabelsa += one;
moneya -= 3000;
cabelsTake = 500 * cabelsa;
bacoutTake = 2000 * bacouta;
//Round x
Round(x);
Tell(moneya, cabelsa, bacouta, clientsa, x, n1);
Strike(y);
Logica(cabelsTake, bacoutTake, clientsa, cabelsa, y);
da++;
} else if (shopa === "2" && moneya >= 5000) {
moneya -= 5000;
cabelsTake = 500 * cabelsa;
bacoutTake = 2000 * bacouta;
bacouta += one;
//Round x
Round(x);
Tell(moneya, cabelsa, bacouta, clientsa, x, n1);
Strike(y);
Logica(cabelsTake, bacoutTake, clientsa, cabelsa, y);
da++;
} else if (shopa === "3" && moneya >= 30000) {
moneya -= 30000;
cabelsTake = 500 * cabelsa;
bacoutTake = 2000 * bacouta;
clientsa += one;
//Round x
Round(x);
Tell(moneya, cabelsa, bacouta, clientsa, x, n1);
Strike(y);
Logica(cabelsTake, bacoutTake, clientsa, cabelsa, y);
da++;
} else {
var g = moneya / 2;
if (g < 3000 && gunka === true && gunkb === true) {
console.log(n1 + " Eliminated!");
console.log(n2 + " wins!");
gunka = false;
gunkb = false;
valua = "b";
valub = "b";
} else {
moneya -= g;
console.log("You lost " + g + " credits for skipping a turn!");
}
}
} else {}
//Prototype
var tosta = moneya + cabelsTake + bacoutTake + clientsa * 100;
var tostb = moneyb + cabelsTake + bacoutTake + clientsb * 100;
if (bacouta <= 0 || cabelsa <= 0 && gunka === true) {
console.log(n1 + " Eliminated!");
console.log(n2 + " wins with a total of " + tostb + " Points!");
gunka = false;
gunkb = false;
valua = "b";
valub = "b";
}
if (bacoutb <= 0 || cabelsb <= 0 && gunkb === true) {
console.log(n2 + " Eliminated!");
console.log(n1 + " wins with a total of " + tosta + " Points!");
gunka = false;
gunkb = false;
valua = "b";
valub = "b";
}
}
//round('round number', 'ezRX' )
function roundb(x, y) {
if (db < 1 && valub === "a") {} else if (valua === "a" && vasb === true && valub === true) {
alert("Press 'ok' to move on to the next round");
}
if (valua === "a" && moneyb > 3000 && valub === "a") {
nexd(n2);
var shopb = prompt("Shop Round " + x + ": 1.Power cable-$3000 2.Backup Outputter-$5000 3. Extra client-$30,000 Credits: " + "$" + moneya);
if (shopb === "1" && moneyb >= 3000) {
//cabels += one; works, money -= 1000; works
cabelsb += one;
moneyb -= 3000;
cabelsTake = 500 * cabelsb;
bacoutTake = 2000 * bacoutb;
//Round x
Round(x);
Tell(moneyb, cabelb, bacoutb, clientsb, x, n2);
Strike(y);
Logica(cabelsTake, bacoutTake, clientsb, cabelsb, y);
db++;
} else if (shopb === "2" && moneyb >= 5000) {
moneyb -= 5000;
cabelsTake = 500 * cabelsb;
bacoutTake = 2000 * bacoutb;
bacoutb += one;
//Round x
Round(x);
Tell(moneyb, cabelb, bacoutb, clientsb, x, n2);
Strike(y);
Logica(cabelsTake, bacoutTake, clientsb, cabelsb, y);
db++;
} else if (shopb === "3" && moneyb >= 30000) {
moneyb -= 30000;
cabelsTake = 500 * cabelsb;
bacoutTake = 2000 * bacoutb;
clientsb += one;
//Round x
Round(x);
Tell(moneyb, cabelb, bacoutb, clientsb, x, n2);
Strike(y);
Logica(cabelsTake, bacoutTake, clientsb, cabelsb, y);
db++;
} else {
var g = moneyb / 2;
if (g < 3000 && gunka === true && gunkb === true) {
console.log(n2 + " Eliminated!");
console.log(n1 + " wins!");
gunka = false;
gunkb = false;
valua = "b";
valub = "b";
} else {
moneyab -= g;
console.log("You lost " + g + " credits for skipping a turn!");
}
}
} else {}
//Prototype
var tosta = moneya + cabelsTake + bacoutTake + clientsa * 100;
var tostb = moneyb + cabelsTake + bacoutTake + clientsb * 100;
if (bacoutb <= 0 || cabelsb <= 0 && gunkb === true) {
console.log(n2 + " Eliminated!");
console.log(n1 + " wins with a total of " + tosta + " Points!");
gunka = false;
gunkb = false;
valua = "b";
valub = "b";
}
if (bacouta <= 0 || cabelsa <= 0 && gunka === true) {
console.log(n1 + " Eliminated!");
console.log(n2 + " wins with a total of " + tostb + " Points!");
gunka = false;
gunkb = false;
valua = "b";
valub = "b";
}
if (db === 10) {
if (valua === "a" && valub === "a") {
compare(tosta, tostb, n1, n2);
} else {}
}
}
if (play === "1") {
//Start rounds
money = 15000;
round(1, ezR1);
round(2, ezR2);
round(3, ezR3);
round(4, ezR4);
round(5, ezR5);
round(6, ezR6);
round(7, ezR7);
round(8, ezR8);
round(9, ezR9);
round(10, ezR10);
} else if (play === "2") {
var check = alert("Welcome to 2 player mode!");
var n1 = prompt("Input Player 1's username.");
var n2 = prompt("Input Player 2's username.");
rounda(1, ezR1a );
roundb(1, ezR1b );
rounda(2, ezR2a );
roundb(2, ezR2b );
rounda(3, ezR3a );
roundb(3, ezR3b );
rounda(4, ezR4a );
roundb(4, ezR4b );
rounda(5, ezR5a );
roundb(5, ezR5b );
rounda(6, ezR6a );
roundb(6, ezR6b );
rounda(7, ezR7a );
roundb(7, ezR7b );
rounda(8, ezR8a );
roundb(8, ezR8b );
rounda(9, ezR9a );
roundb(9, ezR9b );
rounda(10, ezR10a );
roundb(10, ezR10b );
} else {
console.log("You didn't select a valid amount of players.");
}
最佳答案
您有 2 个错误
首先,您没有设置 Moneya 和 Moneyb 的值,因此第二个如果您比较 Money 总是返回 false。然后还有一个问题是没有定义nexd()(第485、609行)。
这段代码有太多的 if,而且变量的命名也不太好。我清理了顶部一点,给你一些想法
https://jsfiddle.net/ujn6uq5r/
var dayOfWeek = Math.floor(Math.random() * 7) + 1,
dateLookup = {
1: "Monday",
2: "Tuesday",
3: "Wednesday",
4: "Thursday",
5: "Friday",
6: "Saturday",
7: "Sunday"
},
da = dateLookup[dayOfWeek],
ga = null;
关于javascript - 当我在 2 人模式下运行代码时,功能 round 和 round 没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37691954/
对此感到疯狂,真的缺少一些东西。 我有webpack 4.6.0,webpack-cli ^ 2.1.2,所以是最新的。 在文档(https://webpack.js.org/concepts/mod
object Host "os.google.com" { import "windows" address = "linux.google.com" groups = ["linux"] } obj
每当我安装我的应用程序时,我都可以将数据库从 Assets 文件夹复制到 /data/data/packagename/databases/ .到此为止,应用程序工作得很好。 但 10 或 15 秒后
我在 cc 模式缓冲区中使用 hideshow.el 来折叠我不查看的文件部分。 如果能够在 XML 文档中做到这一点就好了。我使用 emacs 22.2.1 和内置的 sgml-mode 进行 xm
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 我们不允许提出有关书籍、工具、软件库等方面的建议的问题。您可以编辑问题,以便用事实和引用来回答它。 关闭
根据java: public Scanner useDelimiter(String pattern) Sets this scanner's delimiting pattern to a patt
我读过一些关于 PRG 模式以及它如何防止用户重新提交表单的文章。比如this post有一张不错的图: 我能理解为什么在收到 2xx 后用户刷新页面时不会发生表单提交。但我仍然想知道: (1) 如果
看看下面的图片,您可能会清楚地看到这一点。 那么如何在带有其他一些 View 的简单屏幕中实现没有任何弹出/对话框/模式的微调器日期选择器? 我在整个网络上进行了谷歌搜索,但没有找到与之相关的任何合适
我不知道该怎么做,我一直遇到问题。 以下是代码: rows = int(input()) for i in range(1,rows): for j in range(1,i+1):
我想为重写创建一个正则表达式。 将所有请求重写为 index.php(不需要匹配),它不是以/api 开头,或者不是以('.html',或'.js'或'.css'或'.png'结束) 我的例子还是这样
MVC模式代表 Model-View-Controller(模型-视图-控制器) 模式 MVC模式用于应用程序的分层开发 Model(模型) - 模型代表一个存取数据的对象或 JAVA PO
我想为组织模式创建一个 RDF 模式世界。您可能知道,组织模式文档基于层次结构大纲,其中标题是主要的分组实体。 * March auxiliary :PROPERTIES: :HLEVEL: 1 :E
我正在编写一个可以从文件中读取 JSON 数据的软件。该文件包含“person”——一个值为对象数组的对象。我打算使用 JSON 模式验证库来验证内容,而不是自己编写代码。符合代表以下数据的 JSON
假设我有 4 张 table 人 公司 团体 和 账单 现在bills/persons和bills/companys和bills/groups之间是多对多的关系。 我看到了 4 种可能的 sql 模式
假设您有这样的文档: doc1: id:1 text: ... references: Journal1, 2013, pag 123 references: Journal2, 2014,
我有这个架构。它检查评论,目前工作正常。 var schema = { id: '', type: 'object', additionalProperties: false, pro
这可能很简单,但有人可以解释为什么以下模式匹配不明智吗?它说其他规则,例如1, 0, _ 永远不会匹配。 let matchTest(n : int) = let ran = new Rand
我有以下选择序列作为 XML 模式的一部分。理想情况下,我想要一个序列: 来自 my:namespace 的元素必须严格解析。 来自任何其他命名空间的元素,不包括 ##targetNamespace和
我希望编写一个 json 模式来涵盖这个(简化的)示例 { "errorMessage": "", "nbRunningQueries": 0, "isError": Fals
首先,我是 f# 的新手,所以也许答案很明显,但我没有看到。所以我有一些带有 id 和值的元组。我知道我正在寻找的 id,我想从我传入的三个元组中选择正确的元组。我打算用两个 match 语句来做到这
我是一名优秀的程序员,十分优秀!