【发布时间】:2020-06-07 02:44:51
【问题描述】:
我正在尝试将函数 dealIt() 插入到函数 dealFlop() 中,这样我就可以在 dealIt() 函数中访问 shuffle 函数。当我尝试在
的 dealFlop() 函数中使用 shuffle 时,我目前收到错误未定义让 freshDeck_04 = shuffle(loadedDeck_03)
;任何帮助都会很棒,谢谢。
注意:点击:点击按钮发牌,然后翻牌
function begin() {
document.querySelector(".introScreen").style = "transition: transform 3s;transform:matrix3d(1,0,0,0,-1.8,1,0,0,0,0,1,0,3000,3000,0,1)"
}
let p1Pot = 5+5;
let p2Pot = 6+6;
let p3Pot = 7+7;
let p4Pot = 8+8;
let playerone = document.querySelector(".dealItP1");
let playertwo = document.querySelector(".dealItP2");
let playerthree = document.querySelector(".dealItP3");
let playerfour = document.querySelector(".dealItP4");
let getP1Pot = document.querySelector(".P1").children[0];
let getP2Pot = document.querySelector(".P2").children[1];
let getP3Pot = document.querySelector(".P3").children[0];
let getP4Pot = document.querySelector(".P4").children[0];
let getFlopInterface = document.querySelector(".flopIt");
let getTurnInterface = document.querySelector(".turnIt");
let getRiverInterface = document.querySelector(".riverIt");
//for loop for bet loop
//let a = for(i=0; thisFunction(); i++){};
let deck = ["2 Club", "2 Spade", "2 Diamond", "2 Heart", "3 Club", "3 Spade", "3 Diamond", "3 Heart", "4 Club", "4 Spade", "4 Diamond", "4 Heart", "5 Club", "5 Spade", "5 Diamond", "5 Heart", "6 Club", "6 Spade", "6 Diamond", "6 Heart", "7 Club", "7 Spade", "7 Diamond", "7 Heart", "8 Club", "8 Spade", "8 Diamond", "8 Heart", "9 Club", "9 Spade", "9 Diamond", "9 Heart", "10 Club", "10 Spade", "10 Diamond", "10 Heart", "Jack Club", "Jack Spade", "Jack Diamond", "Jack Heart", "Queen Club", "Queen Spade", "Queen Diamond", "Queen Heart", "King Club", "King Spade", "King Diamond", "King Heart", "Ace Club", "Ace Spade", "Ace Diamond", "Ace Heart"];
function dealIt() {
function shuffle(array) {
var m = array.length,
t, i;
// While there remain elements to shuffle…
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
// And swap it with the current element.
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array
}
//Player One
var arr = deck;
let freshDeck_00 = shuffle(arr); //length = 52 *Working* shuffled//
let p1Deal = freshDeck_00.filter(function (value, index, arr) {
return index < 2;
}); //length=2 *Working* PlayerOne delt cards//
let loadedDeck_00 = p1Deal.filter(x => !freshDeck_00.includes(x)).concat(freshDeck_00.filter(x => !p1Deal.includes(x)));
playerone.innerHTML = p1Deal;
//Player Two
let freshDeck_01 = shuffle(loadedDeck_00);
let p2Deal = freshDeck_01.filter(function (value, index, arr) {
return index < 2;
});
let loadedDeck_01 = p2Deal.filter(x => !freshDeck_01.includes(x)).concat(freshDeck_01.filter(x => !p2Deal.includes(x)));
playertwo.innerHTML = p2Deal;
//Player Three
let freshDeck_02 = shuffle(loadedDeck_01);
let p3Deal = freshDeck_02.filter(function (value, index, arr) {
return index < 2;
});
let loadedDeck_02 = p3Deal.filter(x => !freshDeck_02.includes(x)).concat(freshDeck_02.filter(x => !p3Deal.includes(x)));
playerthree.innerHTML = p3Deal;
//Player Four
let freshDeck_03 = shuffle(loadedDeck_02);
let p4Deal = freshDeck_03.filter(function (value, index, arr) {
return index < 2;
});
let loadedDeck_03 = p4Deal.filter(x => !freshDeck_03.includes(x)).concat(freshDeck_03.filter(x => !p4Deal.includes(x)));
playerfour.innerHTML = p4Deal;
//Deal Player One Through Four
getP1Pot.innerHTML = 'User Pot:' + p1Pot;
getP2Pot.innerHTML = 'P2 Pot:' + p2Pot;
getP3Pot.innerHTML = 'P3 Pot:' + p3Pot;
getP4Pot.innerHTML = 'P4 Pot:' + p4Pot;
}
function dealFlop(dealIt){
//The Flop
let freshDeck_04 = shuffle(loadedDeck_03);
let theFlop = freshDeck_04.filter(function (value, index, arr) {
return index < 3;
});
let loadedDeck_04 = theFlop.filter(x => !freshDeck_04.includes(x)).concat(freshDeck_04.filter(x => !theFlop.includes(x)));
getFlopInterface.innerHTML = theFlop;
}
function pingThisIn01() {
let fold = [false];
let call = [true];
let raise_01 = [true, 20];
let raise_02 = [true, 50];
let dealBets = {
fold: fold.valueOf(),
call: call.valueOf(),
raiseFifty: raise_02.valueOf(),
raiseTwenty: raise_01.valueOf()
};
document.querySelector(".P2").innerHTML = dealBets.call + dealBets.raiseTwenty;
document.querySelector(".P3").innerHTML = dealBets.fold;
document.querySelector(".P4").innerHTML = dealBets.raiseFifty;
}
.elTorro{
box-sizing: border-box; border: 3px solid green; background-image: url("../images(1)/bullface.png");height: 45%;width: 45%;position: absolute; top: 45%;left: 45%;background-repeat: no-repeat;
}
.main{
z-index: -1;
box-sizing: border-box;
border: 3px solid green;
height: 1000px;
width: 1000px;
position: absolute;
background-color: black;
opacity: 90%;
}
.introScreen{box-sizing: border-box;
border: 3px solid green;
height: 200px;
width: 200px;
background-color: yellow;}
.title{
box-sizing: border-box;
border: 3px green solid;
height: 100px;
width: 200px;
position: absolute;
top: 10%;
left: 50%;
background-color: green;
opacity:10%0;
font-family: coniferous, sans-serif;
font-style: normal;
font-weight: 300;
}
.P1{
box-sizing: border-box;
border: 3px green solid;
height: 100px;
width: 100px;
position: absolute;
top: 30%;
left: 45%;
background-color: green;
opacity: 100%;
font-size: 1.5em;
color: red;
z-index: 1;
}
.p1BetForm{
box-sizing: border-box;
border: 3px green solid;
height: 100px;
width: 200px;
position: absolute;
top: 30%;
left: 65%;
background-color: green;
opacity: 100%;
font-size: 1.5em;
color: red;
}
.playersBetForm{box-sizing: border-box;
border: 3px green solid;
height: 100px;
width: 200px;
position: absolute;
top: 45%;
left: 45%;
background-color: green;
opacity: 100%;
font-size: 1.5em;
color: red;}
.P2{
box-sizing: border-box;
border: 3px green solid;
height: 100px;
width: 100px;
position: absolute;
top: 45%;
left: 10%;
background-color: green;
opacity:100%;
font-size: 1.5em;
color: red;
z-index: 1;
}
.P3{
box-sizing: border-box;
border: 3px green solid;
height: 100px;
width: 100px;
position: absolute;
top: 60%;
left: 45%;
background-color: green;
opacity: 100%;
font-size:1.5em;
color: red;
z-index: 1;
}
.P4{
box-sizing: border-box;
border: 3px green solid;
height: 100px;
width: 100px;
position: absolute;
top: 45%;
left: 80%;
background-color: green;
opacity: 100%;
font-size: 1.5em;
color: red;
z-index: 1;
}
.dealBet{box-sizing: border-box;
border: 3px green solid;
height: 100px;
width: 100px;
position: absolute;
top: 75%;
left: 5%;
background-color: green;
opacity: 100%;
font-size: 1.5em;
color: red;}
.flopIt{box-sizing: border-box;
border: 3px green solid;
height: 300px;
width: 100px;
position: absolute;
top: 55%;
left: 20%;
background-color: green;
opacity: 100%;
font-size: 1.5em;
color: red;}
.flopBet{box-sizing: border-box;
border: 3px green solid;
height: 100px;
width: 100px;
position: absolute;
top: 75%;
left: 35%;
background-color: green;
opacity: 100%;
font-size: 1.5em;
color: red;}
.turnIt{box-sizing: border-box;
border: 3px green solid;
height: 300px;
width: 100px;
position: absolute;
top: 55%;
left: 35%;
background-color: green;
opacity: 100%;
font-size: 1.5em;
color: red;}
.turnBet{box-sizing: border-box;
border: 3px green solid;
height: 100px;
width: 100px;
position: absolute;
top: 75%;
left: 50%;
background-color: green;
opacity: 100%;
font-size: 1.5em;
color: red;}
.riverIt{box-sizing: border-box;
border: 3px green solid;
height: 300px;
width: 100px;
position: absolute;
top: 55%;
left: 65%;
background-color: green;
opacity: 100%;
font-size: 1.5em;
color: red;}
.riverBet{box-sizing: border-box;
border: 3px green solid;
height: 100px;
width: 100px;
position: absolute;
top: 75%;
left: 80%;
background-color: green;
opacity: 100%;
font-size: 1.5em;
color: red;}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<link href="../CSS/pokerTryOne.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="main"><div class="elTorro"></div>
<!--<div class="output02" style="z-index: 1; box-sizing: border-box; border: 7px dashed orange;height: 200px; width: 225px; position: absolute; top: 35%; left: 35%;font-size: 5em;color:darkred;background-color: white;"></div>
<div class="output" style="z-index: 1; box-sizing: border-box; border: 7px dashed orange;height: 200px; width: 225px; position: absolute; top: 75%; left: 35%;font-size: 5em;color:darkred;background-color: white;"></div>
<input style="box-sizing: border-box; 4px solid green;height: 50px; width: 600px; position: absolute; top:10%; left:10%; z-index: 1; background-color: white; color: darkred;" type="range" min="1" max="100" value="50" id="slider01">-->
<div class="introScreen" >
<button onClick="begin()"> Hello Please Begin</button><p>Here is my video:</p>
<div style="position: absolute; box-sizing: border-box; border: 7px solid green; height: 2000px; width: 2000px; top: 10%; left: 90%;"><img SRC="../images(1)/PortalHuman01Gif.gif"></div>
</div>
<header><h1 class="title">Buttons:<button onClick="dealIt()">Click Button to Deal</button></h1>
<h1> <button onClick="dealFlop()">Flop</button></h1>
<h1> <button onClick="dealTurn()">Turn</button></h1>
<h1> <button onClick="dealRiver()">River</button></h1>
</header>
<div class="P1"><p>Pot:</p><div class="dealItP1">User</div>
<form id="playerOneForm" action="pokerTryOne.php" method="post">
<label>label:01</label>
<input id="label01" name="label01" type="range" value="#" max="#" min="#">
</form>
</div>
<div class="P2"><button onClick="pingThisIn01()">onclick</button><p>Pot:</p><div class="dealItP2">P2</div></div><div class="playersBetForm">Plaayers Bet form</div>
<div class="P3"><p>Pot:</p><div class="dealItP3">P3</div></div>
<div class="P4"><p>Pot:</p><div class="dealItP4">P4</div></div>
<div class="dealBet">deal Bet</div>
<div class="flopIt">flop It</div>
<div class="flopBet">flop bet</div>
<div class="turnIt">turn It</div>
<div class="turnBet">turn Bet</div>
<div class="riverIt">river It</div>
<div class="riverBet">river Bet</div>
</div>
<script type="text/javascript" src="../JavaScript/pokerTryOne.js"></script>
</script>
</body>
</html>
【问题讨论】:
标签: javascript parameters