Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Repost from /lounge/ - sicp.c

Name: Anonymous 2015-02-12 21:06

Thank you very much to the anon who originally wrote this and shared it! This is the sort of thing I love seeing on this board.

Originally here: http://bbs.progrider.org/lounge/read/1423532111

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>

int main(void)
{
int i, j;

struct { char *name; int num, min, max; } invs[2][4] =
{{{ "", -1, -1, -1 },
{ "HANDFUL OF PARENTHESES", 10, 5, 5 },
{ "HARDCOVER COPY OF SICP", 5, 15, 15 },
{ "SICP VIDEO LECTURES ON YOUR IPOD", 20, 5, 25 }},
{{ "UNINDENTED JAVASCRIPT", 30, 5, 5 },
{ "EARNEST DEFENSE OF SEPPLES", 5, 10, 5 },
{ "EXPERT WEB DEVELOPMENT SOLUTION", 3, 8, 40 }}};

int hps[2] = { 100, 100 };
char *faces[2][4][10] =
{{{ "_ ___.....___ ",
" `.__ ,-' ,-.`-, ",
" `''-------' ( p ) `._ ",
" `-' ( ",
" \\ ",
" . \\ ",
" \\---..,--' ",
"................._ --...--, ",
" `-.._ _.-' ",
" `'-----'' " },
{ "_ ___.....___ ",
" `.__ ,-' ,-.`-, ",
" `''-------' ( p ) `._ ",
" `-' ( ",
" \\ ",
" \\ ",
" .---..,--' ",
"................._ |--...--, ",
" `-.._ _.-' ",
" `'-----'' " },
{ "_ ___.....___ ",
" `.__ ,-' .-' \\ ",
" `''-------' / o ) `._ ",
" `-' ( ",
" \\ ",
" \\",
" ______)",
"................._ .-'' / ",
" `-.._ _.-' ",
" `'-----'' " },
{ "_ ___.....___ ",
" `.__ ,-' ,-.`-, ",
" `''-------' ( x ) `._ ",
" `-' ( ",
" \\ ",
" \\ ",
" ---..,--' ",
"................._ /--...--, ",
" `-.._ ` _.-' ",
" `'-----'' " }},
{{ " ",
" /-------._ ",
" .´ ''-. ",
" .´ .-. +----------",
" .´ ( o ) ",
" / '-´ / ",
": .------´ ",
"+------´ .--------",
" '---------------------´ ",
" " },
{ " ",
" /-------._ ",
" .´ ''-. ",
" .´ .-. +----------",
" .´ ( o ) ",
" / '-´ ",
": .------ ",
"+------´ .--------",
" '---------------------´ ",
" " },
{ " ",
" /-------._ ",
" .´ ''-. ",
" .´ .-. +----------",
" .´ ( o ) ",
" / '-´ ",
": ",
"+------ .--------",
" '---------------------´ ",
" " },
{ " ",
" /-------._ ",
" .´ ''-. ",
" .´ .-. +----------",
" .´ ( X ) ",
" / '-´ ",
": ",
"+------ .--------",
" '---------------------´ ",
" " }}};

srand((unsigned int)time(NULL));

for (;;) {
int acted = 0;
char action;

printf("\033[2J\033[0;0H\n"
" "
"PROGSNAKE FITE\n\n");

for (i = 0; i < 10; ++i)
printf("%s %s\n", faces[0][3 - (hps[0] + 32) * 3 / 100][i],
faces[1][3 - (hps[1] + 32) * 3 / 100][i]);
printf("\n");

switch (rand() % 2) {
case 0:
if (rand() % 100 > 40) {
j = rand() % 16 + 8;

printf("Opponent attacks, and hits you for %d HP!\n", j);
hps[0] -= j;

} else
printf("Opponent attacks, but misses!\n");

break;

case 1:
i = rand() % 3;

if (invs[1][i].num == 0) {
printf("Opponent wanted to use %s, but doesn't have any!\n",
invs[1][i].name);

} else {
j = rand() % invs[1][i].max + invs[1][i].min;

printf("Opponent uses %s! You lose %d HP!\n",
invs[1][i].name, j);
hps[0] -= j;
--invs[1][i].num;

}

break;
}

sleep(1);
if (hps[0] <= 0) break;

printf("\nYou have %d HP. Your opponent has %d HP.\n", hps[0], hps[1]);

do {
printf("\nWhat do? [F]ight, [I]tem, [A]bility, [R]un: ");

action = (char)getchar();
action &= 0xdf;

while (getchar() != 10);

printf("\n");

switch (action) {
case 'F':
if (rand() % 100 > 40) {
j = rand() % 16 + 10;
printf("You attack, dealing %d damage!\n", j);
hps[1] -= j;

} else
printf("You try to attack, but miss!\n");

acted = 1;
break;

case 'I':
printf("Inventory:\n");

for (i = 1; i < 4; ++i) {
printf("\t%d. %35s (%d)\n", i, invs[0][i].name,
invs[0][i].num);
}

printf("\nWhich will you use? [1-3] ");

do {
action = (char)getchar();
} while (action < 48 || action > 57);

while (getchar() != 10);

i = action - 48;

switch (i) {
case 1:
case 2:
case 3:
if (invs[0][i].num > 0) {
j = rand() % invs[0][i].max + invs[0][i].min;

printf("\nYou use %s! ", invs[0][i].name);

if (i == 3) {
printf("You gain %d HP!\n", j);
hps[0] += j;
} else {
printf("Opponent loses %d HP!\n", j);
hps[1] -= j;
}

--invs[0][i].num;

} else
printf("\nYou try to use %s, but don't have any!\n",
invs[0][i].name);

acted = 1;
break;

default:
break;
}
break;

case 'A':
printf("You have not yet reached Satori, so you do not "
"have any special abilities!\n");
break;

case 'R':
printf("Real men don't back down!\n");
break;

default:
printf("I don't understand that.\n");
}

} while (!acted);

sleep(2);
if (hps[1] <= 0) break;

}

printf("\033[2J\033[0;0H\n\t\t\t\tGAME OVER\n\n");

for (i = 0; i < 10; ++i)
printf("\t\t\t%s\n", faces[hps[0] > 0 ? 1 : 0][3][i]);

printf(hps[0] > 0 ? "\n\t\t\tYou have defeated your opponent!\n\n"
: "\n\t\t\tYou have been defeated.\n\n");

return 0;
}


Pastebin link: http://pastebin.com/JfRmDeBk

Name: Anonymous 2015-02-12 23:32

bampu pantsu

Name: Anonymous 2015-02-13 2:21

That's a fun game!
Too bad the snake doesn't render properly on my terminal emulator. Well, it's probably my fault for using st.
But I like this!

Name: Anonymous 2015-02-13 4:54

I remember this. Xarn wrote it for a /prog/ contest in 2010. This is the original thread:
http://dis.4chan.org/read/prog/1277834662

Name: Anonymous 2015-02-13 6:06

Name: Anonymous 2015-02-13 6:14

>>5
Looks like the newline bug. Because of the way Shiitchan stores posts, you could create an arbitrary number of blank posts by having newlines in the name or e-mail fields. I think Bun was the first to figure that out.

Name: Anonymous 2015-02-13 6:30

>>4
I want to see more threads like that on this board. There were 6 or 7 actual runnable programs in that thread. I can see why there were so many posts and threads about archiving old prog a few months ago if that is indicative of the quality of the board.

Name: Anonymous 2015-02-13 6:33

>>4
Also, I like comment 18:

This is highly entertaining.
The segfault is like an instant loss for playing God with the HP.

Name: Anonymous 2015-02-13 6:43

>>7
It was a magical place. The link from /g/ was disasterous to board health.

Name: Anonymous 2015-02-13 18:26

>>9
The shit that eventually killed it didn't come from /g/, though. It came from /pol/.

Name: RedCream 2015-02-14 0:01

Smoak foar thousand doobies everyday. Check em!

Name: Anonymous 2015-02-14 1:41

>>7
I bet Cudder would post an epic fizzbuzz if we got one of those challenges again.

Name: Anonymous 2015-02-14 3:12

>>12
Cudder is all talk and no action.

Name: Anonymous 2015-02-14 4:37

We know Cudder since 2008 and he finally released his first program (the fizzbuzz) last week.
So it took only 7 years to clean it up, fix all bugs and refactor. But it's okay, because he's got lots of work from the big company he works for. And he's also been cleaning up the source code for Anonix, the disassembler, his web-browser, etc. in the meantime.
How long until he releases his next program?
7 more years? Yeah, maybe if it's another fizzbuzz.
I will bet low, 13 years for his next program to be released.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List