mirror of
https://github.com/Soccera1/agg.git
synced 2026-03-22 06:39:17 +01:00
Compare commits
No commits in common. "34169274f4abebdb19c3a9990412c27160f8a219" and "51e72669112fe69e9e2c42cb42dc13af80efb35a" have entirely different histories.
34169274f4
...
51e7266911
5 changed files with 288 additions and 8 deletions
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
|
|
@ -19,7 +19,7 @@ jobs:
|
||||||
run: sudo apt-get update && sudo apt-get install -y build-essential
|
run: sudo apt-get update && sudo apt-get install -y build-essential
|
||||||
|
|
||||||
- name: Build project for Linux
|
- name: Build project for Linux
|
||||||
run: LDFLAGS="-static" make all
|
run: make all
|
||||||
working-directory: ${{ github.workspace }}
|
working-directory: ${{ github.workspace }}
|
||||||
|
|
||||||
- name: Upload Linux artifact
|
- name: Upload Linux artifact
|
||||||
|
|
|
||||||
6
Makefile
6
Makefile
|
|
@ -1,8 +1,6 @@
|
||||||
# Compiler and flags
|
# Compiler and flags
|
||||||
CC = gcc
|
CC = gcc
|
||||||
EXTRA_CFLAGS ?=
|
CFLAGS = -Wall -Wextra -std=c99 -O3 -flto
|
||||||
CFLAGS ?= -Wall -Wextra -std=c99 -pedantic -O3 -flto $(EXTRA_CFLAGS)
|
|
||||||
LDFLAGS ?=
|
|
||||||
DEBUG_FLAGS = -g -DDEBUG
|
DEBUG_FLAGS = -g -DDEBUG
|
||||||
|
|
||||||
# Directories
|
# Directories
|
||||||
|
|
@ -31,7 +29,7 @@ $(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
|
||||||
|
|
||||||
# Link executable
|
# Link executable
|
||||||
$(TARGET): $(OBJECTS) | $(BINDIR)
|
$(TARGET): $(OBJECTS) | $(BINDIR)
|
||||||
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
|
$(CC) $(OBJECTS) -o $@
|
||||||
|
|
||||||
# Debug build
|
# Debug build
|
||||||
debug: CFLAGS += $(DEBUG_FLAGS)
|
debug: CFLAGS += $(DEBUG_FLAGS)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
Hi! This is a game designed for AgnoxGD.
|
Hi! This is a game designed for AgnoxGD.
|
||||||
|
|
||||||
This game is licensed under the GNU Affero Public License v3.
|
This game is licensed under the GNU Affero Public License v3.
|
||||||
|
|
||||||
|
also I probably won't update the html version like ever unless claude can 1 shot it 🥀
|
||||||
|
|
||||||
|
because I don't know html lmao
|
||||||
|
|
|
||||||
|
|
@ -152,12 +152,12 @@ int main(void) {
|
||||||
if (score >= 1) {
|
if (score >= 1) {
|
||||||
printf ("Great job, %s!\n", username);
|
printf ("Great job, %s!\n", username);
|
||||||
} else {
|
} else {
|
||||||
printf ("Try again!, %s.\n", username);
|
printf ("try again!, %s.\n", username);
|
||||||
}
|
}
|
||||||
if (accuracytype == 1) {
|
if (accuracytype == 1) {
|
||||||
printf ("You got an accuracy of %d%%!\n", (int)accuracy);
|
printf ("you got an accuracy of %d%%!\n", (int)accuracy);
|
||||||
} else {
|
} else {
|
||||||
printf ("You got an accuracy of %g%%!\n", accuracy);
|
printf ("you got an accuracy of %g%%!\n", accuracy);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
278
src/agg.html
Normal file
278
src/agg.html
Normal file
|
|
@ -0,0 +1,278 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Agg Math Game</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: monospace;
|
||||||
|
background: #000;
|
||||||
|
color: #0f0;
|
||||||
|
padding: 20px;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
input {
|
||||||
|
background: #000;
|
||||||
|
color: #0f0;
|
||||||
|
border: 1px solid #0f0;
|
||||||
|
padding: 5px;
|
||||||
|
font-family: monospace;
|
||||||
|
margin: 5px 0;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
background: #000;
|
||||||
|
color: #0f0;
|
||||||
|
border: 1px solid #0f0;
|
||||||
|
padding: 10px 20px;
|
||||||
|
font-family: monospace;
|
||||||
|
cursor: pointer;
|
||||||
|
margin: 5px;
|
||||||
|
}
|
||||||
|
button:hover {
|
||||||
|
background: #0f0;
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
.output {
|
||||||
|
white-space: pre-line;
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
.input-group {
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div id="output" class="output"></div>
|
||||||
|
<div id="input-area" class="input-group"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Global variables to maintain state
|
||||||
|
let currentStep = 0;
|
||||||
|
let tutorial = false;
|
||||||
|
let accuracytype = 0;
|
||||||
|
let playtime = 0;
|
||||||
|
let number_length = 0;
|
||||||
|
let end_time = 0;
|
||||||
|
let score = 0;
|
||||||
|
let questioncount = 0;
|
||||||
|
let currentResult = 0;
|
||||||
|
let gameRunning = false;
|
||||||
|
|
||||||
|
function print(text) {
|
||||||
|
document.getElementById('output').innerHTML += text + '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearInput() {
|
||||||
|
document.getElementById('input-area').innerHTML = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function createInput(placeholder, callback) {
|
||||||
|
const inputArea = document.getElementById('input-area');
|
||||||
|
const input = document.createElement('input');
|
||||||
|
input.type = 'text';
|
||||||
|
input.placeholder = placeholder;
|
||||||
|
input.addEventListener('keypress', function(e) {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
const value = input.value;
|
||||||
|
callback(value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
inputArea.appendChild(input);
|
||||||
|
input.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUsername() {
|
||||||
|
// Browser equivalent of getenv("USER")
|
||||||
|
return "Player";
|
||||||
|
}
|
||||||
|
|
||||||
|
function randMod(max) {
|
||||||
|
return Math.floor(Math.random() * max);
|
||||||
|
}
|
||||||
|
|
||||||
|
function time() {
|
||||||
|
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() {
|
||||||
|
const username = getUsername();
|
||||||
|
print(`Hello ${username}!`);
|
||||||
|
print("This is a game written for AgnoxGD.");
|
||||||
|
print("Would you like to see a tutorial");
|
||||||
|
print("Type 1 for no, or 0 for yes.");
|
||||||
|
|
||||||
|
createInput("Enter 0 or 1", function(input) {
|
||||||
|
if (isvalidnumber(input)) {
|
||||||
|
const tempInput = parseInt(input);
|
||||||
|
tutorial = tempInput;
|
||||||
|
} else {
|
||||||
|
print("Error! An invalid character was entered.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearInput();
|
||||||
|
|
||||||
|
if (tutorial) {
|
||||||
|
print("OK! Lets continue.");
|
||||||
|
} else {
|
||||||
|
print("Welcome to Agg! This game tests your math skills against the clock.\n\nHow to Play:\n\n1. Set Your Playtime: First, you'll decide how long you want to play by entering a duration in seconds.\n2. Solve Math Problems: Once the game starts, you'll be presented with a series of random math problems: addition, division, subtraction, and multiplication. Your goal is to solve as many as you can before time runs out.\n3. Enter Your Answer: After each problem, type your answer and press Enter. The game will immediately tell you if you're correct or incorrect.\n4. Rack Up Points: For every correct answer, you'll earn a point. Your score will be tallied at the end.\n5. Time's Up! The game ends automatically when your chosen playtime runs out. Good luck, and have fun!");
|
||||||
|
}
|
||||||
|
|
||||||
|
askAccuracyType();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function askAccuracyType() {
|
||||||
|
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) {
|
||||||
|
if (isvalidnumber(input)) {
|
||||||
|
accuracytype = parseInt(input);
|
||||||
|
} else {
|
||||||
|
print("Error! An invalid character was entered.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clearInput();
|
||||||
|
askPlaytime();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function askPlaytime() {
|
||||||
|
print("\nHow long would you like to play for? Answer in seconds.");
|
||||||
|
createInput("Enter seconds", function(input) {
|
||||||
|
playtime = parseInt(input);
|
||||||
|
clearInput();
|
||||||
|
askNumberLength();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function askNumberLength() {
|
||||||
|
print("Please enter maximum possible number");
|
||||||
|
createInput("Enter max number", function(input) {
|
||||||
|
number_length = parseInt(input);
|
||||||
|
clearInput();
|
||||||
|
startGameLoop();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function startGameLoop() {
|
||||||
|
const unix_time = time();
|
||||||
|
end_time = unix_time + playtime;
|
||||||
|
score = 0;
|
||||||
|
questioncount = 0;
|
||||||
|
gameRunning = true;
|
||||||
|
|
||||||
|
nextQuestion();
|
||||||
|
}
|
||||||
|
|
||||||
|
function nextQuestion() {
|
||||||
|
let unix_time = time();
|
||||||
|
|
||||||
|
if (unix_time >= end_time) {
|
||||||
|
endGame();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const num1 = randMod(number_length) + 1;
|
||||||
|
const num2 = randMod(number_length) + 1;
|
||||||
|
const type = randMod(4) + 1;
|
||||||
|
let result;
|
||||||
|
|
||||||
|
if (type == 1) {
|
||||||
|
print(`Add ${num1} and ${num2}`);
|
||||||
|
result = num1 + num2;
|
||||||
|
} else if (type == 2) {
|
||||||
|
print(`Divide ${num1} by ${num2}`);
|
||||||
|
result = num1 / num2;
|
||||||
|
} else if (type == 3) {
|
||||||
|
print(`Subtract ${num1} from ${num2}`);
|
||||||
|
result = num1 - num2;
|
||||||
|
} else if (type == 4) {
|
||||||
|
print(`Multiply ${num1} by ${num2}`);
|
||||||
|
result = num1 * num2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update time after generating question (like C version)
|
||||||
|
unix_time = time();
|
||||||
|
currentResult = result;
|
||||||
|
questioncount++;
|
||||||
|
|
||||||
|
createInput("Enter your answer", function(entered) {
|
||||||
|
if (isvalidnumber(entered)) {
|
||||||
|
const answer = parseFloat(entered);
|
||||||
|
|
||||||
|
if (currentResult == answer) {
|
||||||
|
print("Correct!");
|
||||||
|
score++;
|
||||||
|
} else {
|
||||||
|
print(`Incorrect! The correct answer is ${currentResult}.`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print("Error! An invalid character was entered.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearInput();
|
||||||
|
setTimeout(nextQuestion, 10); // Small delay to prevent blocking
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function endGame() {
|
||||||
|
gameRunning = false;
|
||||||
|
const username = getUsername();
|
||||||
|
|
||||||
|
const accuracy = score / questioncount * 100;
|
||||||
|
|
||||||
|
print(`Your score is ${score}!`);
|
||||||
|
if (score >= 1) {
|
||||||
|
print(`Great job, ${username}!`);
|
||||||
|
} else {
|
||||||
|
print(`Try again!, ${username}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accuracytype == 1) {
|
||||||
|
print(`You got an accuracy of ${Math.floor(accuracy)}%!`);
|
||||||
|
} else {
|
||||||
|
print(`You got an accuracy of ${accuracy}%!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the game when page loads
|
||||||
|
window.onload = function() {
|
||||||
|
startGame();
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Reference in a new issue