mirror of
https://github.com/Soccera1/agg.git
synced 2025-11-04 10:27:33 +01:00
update html
This commit is contained in:
parent
8d1c88ec5b
commit
4377d8b31e
1 changed files with 44 additions and 19 deletions
63
src/agg.html
Executable file → Normal file
63
src/agg.html
Executable file → Normal file
|
|
@ -64,7 +64,6 @@
|
||||||
let questioncount = 0;
|
let questioncount = 0;
|
||||||
let currentResult = 0;
|
let currentResult = 0;
|
||||||
let gameRunning = false;
|
let gameRunning = false;
|
||||||
let gameInterval;
|
|
||||||
|
|
||||||
function print(text) {
|
function print(text) {
|
||||||
document.getElementById('output').innerHTML += text + '\n';
|
document.getElementById('output').innerHTML += text + '\n';
|
||||||
|
|
@ -102,6 +101,32 @@
|
||||||
return Math.floor(Date.now() / 1000);
|
return Math.floor(Date.now() / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isvalidnumber(entered) {
|
||||||
|
let valid = 1;
|
||||||
|
for (let i = 0; i < entered.length; i++) {
|
||||||
|
const char = entered[i];
|
||||||
|
switch (char) {
|
||||||
|
case '0':
|
||||||
|
case '1':
|
||||||
|
case '2':
|
||||||
|
case '3':
|
||||||
|
case '4':
|
||||||
|
case '5':
|
||||||
|
case '6':
|
||||||
|
case '7':
|
||||||
|
case '8':
|
||||||
|
case '9':
|
||||||
|
case '.':
|
||||||
|
case '-':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
function startGame() {
|
function startGame() {
|
||||||
const username = getUsername();
|
const username = getUsername();
|
||||||
print(`Hello ${username}!`);
|
print(`Hello ${username}!`);
|
||||||
|
|
@ -110,9 +135,12 @@
|
||||||
print("Type 1 for no, or 0 for yes.");
|
print("Type 1 for no, or 0 for yes.");
|
||||||
|
|
||||||
createInput("Enter 0 or 1", function(input) {
|
createInput("Enter 0 or 1", function(input) {
|
||||||
const tempInput = parseInt(input);
|
if (isvalidnumber(input)) {
|
||||||
if (!isNaN(tempInput)) {
|
const tempInput = parseInt(input);
|
||||||
tutorial = tempInput;
|
tutorial = tempInput;
|
||||||
|
} else {
|
||||||
|
print("Error! An invalid character was entered.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearInput();
|
clearInput();
|
||||||
|
|
@ -130,7 +158,12 @@
|
||||||
function askAccuracyType() {
|
function askAccuracyType() {
|
||||||
print("Would you like your accuracy as a float or as an int? Type 0 for float or 1 for int.");
|
print("Would you like your accuracy as a float or as an int? Type 0 for float or 1 for int.");
|
||||||
createInput("Enter 0 or 1", function(input) {
|
createInput("Enter 0 or 1", function(input) {
|
||||||
accuracytype = parseInt(input);
|
if (isvalidnumber(input)) {
|
||||||
|
accuracytype = parseInt(input);
|
||||||
|
} else {
|
||||||
|
print("Error! An invalid character was entered.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
clearInput();
|
clearInput();
|
||||||
askPlaytime();
|
askPlaytime();
|
||||||
});
|
});
|
||||||
|
|
@ -165,7 +198,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function nextQuestion() {
|
function nextQuestion() {
|
||||||
const unix_time = time();
|
let unix_time = time();
|
||||||
|
|
||||||
if (unix_time >= end_time) {
|
if (unix_time >= end_time) {
|
||||||
endGame();
|
endGame();
|
||||||
|
|
@ -184,27 +217,20 @@
|
||||||
print(`Divide ${num1} by ${num2}`);
|
print(`Divide ${num1} by ${num2}`);
|
||||||
result = num1 / num2;
|
result = num1 / num2;
|
||||||
} else if (type == 3) {
|
} else if (type == 3) {
|
||||||
print(`Subtract ${num1} from ${num2}`);
|
print(`Subtract ${num2} from ${num1}`);
|
||||||
result = num2 - num1;
|
result = num1 - num2;
|
||||||
} else if (type == 4) {
|
} else if (type == 4) {
|
||||||
print(`Multiply ${num1} by ${num2}`);
|
print(`Multiply ${num1} by ${num2}`);
|
||||||
result = num1 * num2;
|
result = num1 * num2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update time after generating question (like C version)
|
||||||
|
unix_time = time();
|
||||||
currentResult = result;
|
currentResult = result;
|
||||||
questioncount++;
|
questioncount++;
|
||||||
|
|
||||||
createInput("Enter your answer", function(entered) {
|
createInput("Enter your answer", function(entered) {
|
||||||
let valid = 1;
|
if (isvalidnumber(entered)) {
|
||||||
for (let i = 0; i < entered.length; i++) {
|
|
||||||
const char = entered[i];
|
|
||||||
if (!'0123456789.'.includes(char)) {
|
|
||||||
valid = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (valid == 1) {
|
|
||||||
const answer = parseFloat(entered);
|
const answer = parseFloat(entered);
|
||||||
|
|
||||||
if (currentResult == answer) {
|
if (currentResult == answer) {
|
||||||
|
|
@ -215,12 +241,11 @@
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print("Error! An invalid character was entered.");
|
print("Error! An invalid character was entered.");
|
||||||
endGame();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearInput();
|
clearInput();
|
||||||
setTimeout(nextQuestion, 100); // Small delay to prevent blocking
|
setTimeout(nextQuestion, 10); // Small delay to prevent blocking
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue