update
This commit is contained in:
parent
bf8d402aa7
commit
139266aae4
@ -19,10 +19,12 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
|
|||||||
<label id="playerPoints"></label><br>
|
<label id="playerPoints"></label><br>
|
||||||
<label id="playerCards"></label><br>
|
<label id="playerCards"></label><br>
|
||||||
<label id="cardsInPlay"></label>
|
<label id="cardsInPlay"></label>
|
||||||
|
<label id="winAnnounce"></label><br>
|
||||||
<input type="button" id="startButton" onclick="startGame()" value="Start Game">
|
<input type="button" id="startButton" onclick="startGame()" value="Start Game">
|
||||||
<input type="button" id="continueButton" onclick="draw()" value="Continue Round">
|
<input type="button" id="continueButton" onclick="draw()" value="Continue Round">
|
||||||
<input type="button" id="endButton" onclick="endRound()" value="End Round">
|
<input type="button" id="endButton" onclick="endRound()" value="End Round">
|
||||||
<script>
|
<script>
|
||||||
|
var timesLooped = 0;
|
||||||
var cpuPoints = 0, playerPoints = 0;
|
var cpuPoints = 0, playerPoints = 0;
|
||||||
var cpuCards = 0, playerCards = 0;
|
var cpuCards = 0, playerCards = 0;
|
||||||
var totalCpuPoints = 0, totalPlayerPoints = 0;
|
var totalCpuPoints = 0, totalPlayerPoints = 0;
|
||||||
@ -30,48 +32,50 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
|
|||||||
playerTimesWon = 0;
|
playerTimesWon = 0;
|
||||||
var isStarted = false;
|
var isStarted = false;
|
||||||
// Card array. This will allow us to remember if a card is in play.
|
// Card array. This will allow us to remember if a card is in play.
|
||||||
var rows = 12;
|
var rows = 13;
|
||||||
var cols = 3;
|
var cols = 3;
|
||||||
var cardArray = Array.from({length: rows}, () =>
|
var cardArray = Array.from({length: rows}, () =>
|
||||||
Array.from({length: cols}, () => false)
|
Array.from({length: cols}, () => [0, 0, false])
|
||||||
);
|
);
|
||||||
hiddenCard.hidden = true;
|
hiddenCard.hidden = true;
|
||||||
continueButton.hidden = true;
|
continueButton.hidden = true;
|
||||||
endButton.hidden = true;
|
endButton.hidden = true;
|
||||||
|
cardsInPlay.hidden = true;
|
||||||
function checkEntireArray() {
|
function checkEntireArray() {
|
||||||
var numOfBools = (cardArray.length * cardArray[0].length);
|
var numOfBools = (cardArray.length * cardArray[0].length);
|
||||||
console.log("Number of bools: " + numOfBools);
|
//console.log("Number of bools: " + numOfBools);
|
||||||
var trueCount = 0;
|
var trueCount = 0;
|
||||||
var returnBool = false;
|
var returnBool = false;
|
||||||
for (let i = 0; i < cardArray.length; i++) {
|
for (let i = 0; i < cardArray.length; i++) {
|
||||||
for (let j = 0; j < cardArray[i].length; j++) {
|
for (let j = 0; j < cardArray[i].length; j++) {
|
||||||
if (cardArray[i][j]) {
|
if (cardArray[i][j][2]) {
|
||||||
trueCount++;
|
trueCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("Number of bools set to true: " + trueCount);
|
//console.log("Number of bools set to true: " + trueCount);
|
||||||
if (trueCount == numOfBools) {
|
if (trueCount == numOfBools) {
|
||||||
returnBool = true;
|
returnBool = true;
|
||||||
}
|
}
|
||||||
return returnBool;
|
return returnBool;
|
||||||
}
|
}
|
||||||
function getCardNumber() {
|
function getCardNumber() {
|
||||||
|
console.log("Times looped " + ++timesLooped);
|
||||||
let exitLoop = false;
|
let exitLoop = false;
|
||||||
let cardNumber = 0; //prompt("Card Number:");
|
let cardNumber = 0; //prompt("Card Number:");
|
||||||
let cardType = 0; //prompt("Card Type: ");
|
let cardType = 0; //prompt("Card Type: ");
|
||||||
do {
|
do {
|
||||||
console.log(cardType + " " + cardNumber);
|
//console.log(cardType + " " + cardNumber);
|
||||||
if (checkEntireArray()) {
|
if (checkEntireArray()) {
|
||||||
console.log('Ran out of cards in deck! Breaking!');
|
console.log('Ran out of cards in deck! Breaking!');
|
||||||
alert("Cannot draw more cards!");
|
alert("Cannot draw more cards!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!cardArray[cardNumber][cardType]) {
|
if (!cardArray[cardNumber][cardType][2]) {
|
||||||
cardArray[cardNumber][cardType] = true;
|
cardArray[cardNumber][cardType] = [cardNumber, cardType, true];
|
||||||
exitLoop = true;
|
exitLoop = true;
|
||||||
} else {
|
} else {
|
||||||
cardNumber = Math.trunc((Math.random() * 12));
|
cardNumber = Math.trunc((Math.random() * 13));
|
||||||
cardType = Math.trunc((Math.random() * 3));
|
cardType = Math.trunc((Math.random() * 3));
|
||||||
console.log("Ran into existing card, generating new numbers! " + cardType + " " + cardNumber);
|
console.log("Ran into existing card, generating new numbers! " + cardType + " " + cardNumber);
|
||||||
exitLoop = false;
|
exitLoop = false;
|
||||||
@ -79,6 +83,7 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
|
|||||||
} while (!exitLoop);
|
} while (!exitLoop);
|
||||||
printArray();
|
printArray();
|
||||||
checkEntireArray();
|
checkEntireArray();
|
||||||
|
console.log(cardType + " " + cardNumber);
|
||||||
return [cardNumber, cardType];
|
return [cardNumber, cardType];
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -176,9 +181,18 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
|
|||||||
document.getElementById("cpuPoints").innerHTML = "This round: " + cpuPoints + "; ";
|
document.getElementById("cpuPoints").innerHTML = "This round: " + cpuPoints + "; ";
|
||||||
document.getElementById("cpuPoints").innerHTML += "Total Points: " + totalCpuPoints;
|
document.getElementById("cpuPoints").innerHTML += "Total Points: " + totalCpuPoints;
|
||||||
document.getElementById("cpuGamesWon").innerHTML = "Dealer cards: (times won: " + cpuTimesWon + ")";
|
document.getElementById("cpuGamesWon").innerHTML = "Dealer cards: (times won: " + cpuTimesWon + ")";
|
||||||
|
}
|
||||||
|
function resetArray() {
|
||||||
|
for (let i = 0; i < cardArray.length; i++) {
|
||||||
|
for (let j = 0; j < cardArray[i].length; j++) {
|
||||||
|
cardArray[i][j] = [0, 0, false];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function startGame() {
|
function startGame() {
|
||||||
|
resetArray();
|
||||||
// Dealer and player have two cards.
|
// Dealer and player have two cards.
|
||||||
|
document.getElementById("winAnnounce").innerHTML = "";
|
||||||
if (!isStarted) {
|
if (!isStarted) {
|
||||||
document.getElementById("playerCards").innerHTML = "";
|
document.getElementById("playerCards").innerHTML = "";
|
||||||
document.getElementById("cpuCards").innerHTML = "";
|
document.getElementById("cpuCards").innerHTML = "";
|
||||||
@ -225,9 +239,11 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
|
|||||||
if (playerPoints <= 21 & (cpuPoints < playerPoints)) {
|
if (playerPoints <= 21 & (cpuPoints < playerPoints)) {
|
||||||
totalPlayerPoints += playerPoints;
|
totalPlayerPoints += playerPoints;
|
||||||
playerTimesWon++;
|
playerTimesWon++;
|
||||||
|
document.getElementById("winAnnounce").innerHTML = "You win!";
|
||||||
} else {
|
} else {
|
||||||
totalCpuPoints += cpuPoints;
|
totalCpuPoints += cpuPoints;
|
||||||
cpuTimesWon++;
|
cpuTimesWon++;
|
||||||
|
document.getElementById("winAnnounce").innerHTML = "The dealer wins!";
|
||||||
}
|
}
|
||||||
updatePoints();
|
updatePoints();
|
||||||
|
|
||||||
|
@ -5,58 +5,110 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
|
|||||||
-->
|
-->
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Point Finder</title>
|
<title id="title"></title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<script>
|
|
||||||
// Change the dialog labels if computation changes
|
|
||||||
function onComputationSelect(computation) {
|
|
||||||
alert("Selected " + computation);
|
|
||||||
if (computation === "area") {
|
|
||||||
document.getElementById('input1Text').innerHTML = "Enter the base: ";
|
|
||||||
document.getElementById('input2Text').innerHTML = "Enter the height: ";
|
|
||||||
} else if (computation === "pointDistance") {
|
|
||||||
document.getElementById('output').innerHTML;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function onClick() {
|
|
||||||
// Determine what the user wants us to do.
|
|
||||||
if (selectComputation.value === "area") {
|
|
||||||
getArea();
|
|
||||||
} else if (selectComputation.value === "pointDistance") {
|
|
||||||
getPointDistance();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function getInput() {
|
|
||||||
var input1Val = parseFloat(input1.value);
|
|
||||||
var input2Val = parseFloat(input2.value);
|
|
||||||
return [input1Val, input2Val];
|
|
||||||
}
|
|
||||||
function getArea() {
|
|
||||||
var [baseVal, heightVal] = getInput();
|
|
||||||
var area = (.5 * baseVal) * heightVal;
|
|
||||||
document.getElementById('output').innerHTML = "The area of " + baseVal + " and " + heightVal + " is " + area;
|
|
||||||
}
|
|
||||||
function getPointDistance() {
|
|
||||||
var [baseVal, heightVal] = getInput();
|
|
||||||
|
|
||||||
}
|
|
||||||
function calculatePower() {
|
|
||||||
alert("Not implemented!");
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<label><label id="input1Text">Select a computation type to continue.</label><input type="text" id="input1" name="input1"></label><br>
|
<label id="input1Field"><label id="input1Text"></label><input type="text" id="input1" name="input1" value=""><br></label>
|
||||||
<label><label id="input2Text">Select a computation type to continue.</label><input type="text" id="input2" name="input2"></label><br>
|
<label id="input2Field"><label id="input2Text"></label><input type="text" id="input2" name="input2" value=""><br></label>
|
||||||
|
<label id="input3Field"><label id="input3Text"></label><input type="text" id="input3" name="input3" value=""><br></label>
|
||||||
|
<label id="input4Field"><label id="input4Text"></label><input type="text" id="input4" name="input4" value=""><br></label>
|
||||||
<label for="selectComputation">What do you want to do?</label>
|
<label for="selectComputation">What do you want to do?</label>
|
||||||
<select name="selectComputation" id="selectComputation"><br>
|
<select name="selectComputation" id="selectComputation"><br>
|
||||||
<option value="" selected>-- Select computation type --</option>
|
<option onclick="onComputationSelect(this.value);" value="nothingSelected" selected>-- Select computation type --</option>
|
||||||
|
<option onclick="onComputationSelect(this.value);" value="calculatePower">Get magnitude of power</option>
|
||||||
<option onclick="onComputationSelect(this.value);" value="area">Get Area</option>
|
<option onclick="onComputationSelect(this.value);" value="area">Get Area</option>
|
||||||
<option onclick="onComputationSelect(this.value);" value="pointDistance">Get Point Distance</option>
|
<option onclick="onComputationSelect(this.value);" value="pointDistance">Get Point Distance</option>
|
||||||
</select>
|
</select>
|
||||||
<br>
|
<br>
|
||||||
<label id="output"></label><br>
|
<label id="output"></label><br>
|
||||||
<input type="button" value="Compute!" onclick="onClick()">
|
<input type="button" value="Compute!" onclick="onClick()">
|
||||||
|
<script>
|
||||||
|
onComputationSelect("nothingSelected");
|
||||||
|
|
||||||
|
// Change the dialog labels if computation changes
|
||||||
|
function onComputationSelect(computation) {
|
||||||
|
//alert("Selected " + computation);
|
||||||
|
if (computation === "nothingSelected") {
|
||||||
|
console.log("Hiding text box...");
|
||||||
|
document.getElementById("input1").hidden = true;
|
||||||
|
} else {
|
||||||
|
console.log("Unhiding text box...");
|
||||||
|
document.getElementById("input1").hidden = false;
|
||||||
|
}
|
||||||
|
switch (computation) {
|
||||||
|
case "nothingSelected":
|
||||||
|
document.getElementById('title').innerHTML = "Calculator";
|
||||||
|
input1Field.hidden = false;
|
||||||
|
input2Field.hidden = true;
|
||||||
|
input3Field.hidden = true;
|
||||||
|
input4Field.hidden = true;
|
||||||
|
document.getElementById('input1Text').innerHTML = "Select a computation type to continue. ";
|
||||||
|
break;
|
||||||
|
case "area":
|
||||||
|
document.getElementById('title').innerHTML = "Calculator | Area";
|
||||||
|
input1Field.hidden = false;
|
||||||
|
input2Field.hidden = false;
|
||||||
|
input3Field.hidden = true;
|
||||||
|
input4Field.hidden = true;
|
||||||
|
document.getElementById('input1Text').innerHTML = "Enter the base: ";
|
||||||
|
document.getElementById('input2Text').innerHTML = "Enter the height: ";
|
||||||
|
break;
|
||||||
|
case "pointDistance":
|
||||||
|
document.getElementById('title').innerHTML = "Calculator | Point Distance";
|
||||||
|
input1Field.hidden = false;
|
||||||
|
input2Field.hidden = false;
|
||||||
|
input3Field.hidden = false;
|
||||||
|
input4Field.hidden = false;
|
||||||
|
document.getElementById('input1Text').innerHTML = "Enter x1: ";
|
||||||
|
document.getElementById('input2Text').innerHTML = "Enter y1: ";
|
||||||
|
document.getElementById('input3Text').innerHTML = "Enter x2: ";
|
||||||
|
document.getElementById('input4Text').innerHTML = "Enter y2: ";
|
||||||
|
break;
|
||||||
|
case "calculatePower":
|
||||||
|
document.getElementById('title').innerHTML = "Calculator | Power";
|
||||||
|
input1Field.hidden = false;
|
||||||
|
input2Field.hidden = false;
|
||||||
|
input3Field.hidden = true;
|
||||||
|
input4Field.hidden = true;
|
||||||
|
document.getElementById('input1Text').innerHTML = "Enter base: ";
|
||||||
|
document.getElementById('input2Text').innerHTML = "Enter power: ";
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function onClick() {
|
||||||
|
// Determine what the user wants us to do.
|
||||||
|
switch (selectComputation.value) {
|
||||||
|
case "area":
|
||||||
|
getArea();
|
||||||
|
break;
|
||||||
|
case "pointDistance":
|
||||||
|
getPointDistance();
|
||||||
|
break;
|
||||||
|
case "calculatePower":
|
||||||
|
calculatePower();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getArea() {
|
||||||
|
var [baseVal, heightVal] = [parseFloat(input1.value), parseFloat(input2.value)];
|
||||||
|
var area = (.5 * baseVal) * heightVal;
|
||||||
|
document.getElementById('output').innerHTML = "The area of " + baseVal + " and " + heightVal + " is " + area;
|
||||||
|
}
|
||||||
|
function getPointDistance() {
|
||||||
|
var [x1, y1, x2, y2] = [parseFloat(input1.value), parseFloat(input2.value), parseFloat(input3.value), parseFloat(input4.value)];
|
||||||
|
var a = (x2 - x1);
|
||||||
|
var b = (y2 - y1);
|
||||||
|
var distance = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
|
||||||
|
document.getElementById('output').innerHTML = "The distance of point (" + x1 + ", " + y1 + ") to point (" + x2 + ", " + y2 + ") is " + distance;
|
||||||
|
}
|
||||||
|
function calculatePower() {
|
||||||
|
var [base, power] = [parseFloat(input1.value), parseFloat(input2.value)];
|
||||||
|
var output = Math.pow(base, power);
|
||||||
|
document.getElementById('output').innerHTML = "The value of " + base + "^" + power + " is " + output;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
BIN
ZIPs/JavaScript/MP11_CalebFontenot.zip
Normal file
BIN
ZIPs/JavaScript/MP11_CalebFontenot.zip
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user