WizardStan
Mega GP Mania
- Joined
- May 24, 2008
- Messages
- 16,733
I attempted the zero hour game jam: make a game in zero hours. Starting at 2am, the clocks rolled back to 1am as we moved away from DST, giving us an extra hour until it was 2am again. And during that hour I wrote this monstrosity
It's buggy and barely a speck of what I had envisioned when I started drinking, but an hour and a bottle of wine later this is what I've got.
It was fun. The bottle is empty, my fingers are light.
/*
* File: main.cpp
* Author: David Goldsmith
*
* Created on November 3, 2013, 2:00 AM
Copyright (c) 2013 David Goldsmith
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* I've been doing a lot of C the last 9 months. I forget how to C++ */
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
static int drunk = 8;
char *neverstrings[] =
{
"Eaten a whole chicken",
"Had sex in an elevator",
"Been to Boston in the fall",
"Finished this gordanged \"game\" on time"
};
int neverstringcount = 4;
void drunkprint(size_t drinks, char* format, ...)
{
char buffer[1024];
size_t len = 0;
va_list a_list;
va_start( a_list, format);
vsnprintf(buffer, 1024, format, a_list);
len = strlen(buffer);
for (int i = 0; i < len; ++i)
{
int typo = rand() % (drunk + drinks);
if (typo < drinks)
{
int mistake = rand() % 2;
switch (mistake)
{
case 0: /* transpose */
if (i > 0)
{
signed char t = buffer;
buffer = buffer[i-1];
buffer[i-1] = t;
}
break;
case 1: /* wrong key */
switch (buffer)
{
case 'a':
case 'A':
buffer -= 'a';
buffer += 's';
break;
case 'b':
case 'B':
buffer -= 'b';
buffer += 'v';
break;
case 'c':
case 'C':
buffer -= 'c';
buffer += 'd';
break;
case 'd':
case 'D':
buffer -= 'd';
buffer += 'e';
break;
case 'e':
case 'E':
buffer -= 'e';
buffer += 'r';
break;
case 'f':
case 'F':
buffer -= 'f';
buffer += 'g';
break;
case 'g':
case 'G':
buffer -= 'g';
buffer += 't';
break;
case 'h':
case 'H':
buffer -= 'h';
buffer += 'j';
break;
case 'i':
case 'I':
buffer -= 'i';
buffer += 'o';
break;
case 'j':
case 'J':
buffer -= 'j';
buffer += 'H';
break;
case 'k':
case 'K':
buffer -= 'k';
buffer += 'i';
break;
case 'l':
case 'L':
buffer -= 'l';
buffer += ';';
break;
case 'm':
case 'M':
buffer -= 'm';
buffer += 'n';
break;
case 'n':
case 'N':
buffer -= 'n';
buffer += 'm';
break;
case 'o':
case 'O':
buffer -= 'o';
buffer += 'p';
break;
case 'p':
case 'P':
buffer -= 'p';
buffer += 'o';
break;
case 'q':
case 'Q':
buffer -= 'q';
buffer += 'w';
break;
case 'r':
case 'R':
buffer -= 'r';
buffer += 'f';
break;
case 's':
case 'S':
buffer -= 's';
buffer += 'd';
break;
case 't':
case 'T':
buffer -= 't';
buffer += 'y';
break;
case 'u':
case 'U':
buffer -= 'u';
buffer += 'i';
break;
case 'v':
case 'V':
buffer -= 'v';
buffer += 'b';
break;
case 'w':
case 'W':
buffer -= 'w';
buffer += 'e';
break;
case 'x':
case 'X':
buffer -= 'x';
buffer += 'c';
break;
case 'y':
case 'Y':
buffer -= 'y';
buffer += 't';
break;
case 'z':
case 'Z':
buffer -= 'z';
buffer += 'x';
break;
}
break;
default:
break;
}
}
}
va_end(a_list);
fprintf(stdout, buffer);
}
bool mainMenu(int drinks)
{
bool valid = 0;
int frustraction = 0;
drunkprint(drinks, "Drinking Game: The Game\n");
drunkprint(drinks, "\n");
drunkprint(drinks, "1) Play\n");
drunkprint(drinks, "2) too drunk << std::endl;\n");
while (1)
{
std::string choice;
int ichoice = 0;
std::cout << "1 or 2";
for (int i = 0; i < frustraction; ++ frustraction)
std::cout << "!";
std::cout << "? ";
std::cin >> choice;
ichoice = atoi(choice.c_str());
if (ichoice = 1) return true;
if (ichoice = 2) return false;
++frustraction;
}
}
bool wantmore(int drinks)
{
int frustraction = 0;
std::string in;
while (1)
{
drunkprint(drinks, "Drunk enough yet? ");
std::cout << "Y/N";
for (int i = 0; i < frustraction; ++i)
{
std::cout << "!";
}
std::cout << ")";
std::cout << std::endl;
std::cin >> in;
if (in[0] == 'y' || in[0] == 'Y') return true;
if (in[0] == 'n' || in[0] == 'N') return false;
++frustraction;
}
}
int playGame(int drinks)
{
int game = rand() % 3;
int value;
switch (game)
{
case 0:
drunkprint(drinks, "Flipping coin... ");
value = rand() % 2;
if (value == 0)
{
drunkprint(drinks, "HEADS! Take a drink.\n");
return 1;
} else
{
drunkprint(drinks, "TAILS! Skip this turn.\n");
return 0;
}
break;
case 1:
drunkprint(drinks, "Rolling die... ");
value = (rand() % 6);
if (value)
drunkprint (drinks, "Take %i drinks\n", value);
else
drunkprint (drinks, "You got lucky, no drinks this time.\n");
return value;
case 2:
drunkprint(drinks, "Never have I ever\n");
int n = rand()%neverstringcount;
int frustraction = 0;
std::string in;
drunkprint(drinks, neverstrings[n]);
drunkprint(drinks, "\n");
while (1)
{
drunkprint(drinks, "Have you? (");
std::cout << "Y/N";
for (int i = 0; i < frustraction; ++i)
{
std::cout << "!";
}
std::cout << ") ";
std::cout << std::endl;
std::cin >> in;
if (in[0] == 'y' || in[0] == 'Y') return 1;
if (in[0] == 'n' || in[0] == 'N') return 0;
++frustraction;
}
}
return 0;
}
int main(int argc, char** argv)
{
bool gameloop = true;
srand (time(NULL));
size_t drinks = 0;
while (gameloop)
{
bool playloop = true;
if (!mainMenu(drinks))
{
playloop = false;
gameloop = false;
}
while (playloop)
{
drinks += playGame(drinks);
playloop = wantmore(drinks);
}
}
std::cout << "Goodbye lush" << std::endl;
return 0;
}
* File: main.cpp
* Author: David Goldsmith
*
* Created on November 3, 2013, 2:00 AM
Copyright (c) 2013 David Goldsmith
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* I've been doing a lot of C the last 9 months. I forget how to C++ */
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
static int drunk = 8;
char *neverstrings[] =
{
"Eaten a whole chicken",
"Had sex in an elevator",
"Been to Boston in the fall",
"Finished this gordanged \"game\" on time"
};
int neverstringcount = 4;
void drunkprint(size_t drinks, char* format, ...)
{
char buffer[1024];
size_t len = 0;
va_list a_list;
va_start( a_list, format);
vsnprintf(buffer, 1024, format, a_list);
len = strlen(buffer);
for (int i = 0; i < len; ++i)
{
int typo = rand() % (drunk + drinks);
if (typo < drinks)
{
int mistake = rand() % 2;
switch (mistake)
{
case 0: /* transpose */
if (i > 0)
{
signed char t = buffer;
buffer = buffer[i-1];
buffer[i-1] = t;
}
break;
case 1: /* wrong key */
switch (buffer)
{
case 'a':
case 'A':
buffer -= 'a';
buffer += 's';
break;
case 'b':
case 'B':
buffer -= 'b';
buffer += 'v';
break;
case 'c':
case 'C':
buffer -= 'c';
buffer += 'd';
break;
case 'd':
case 'D':
buffer -= 'd';
buffer += 'e';
break;
case 'e':
case 'E':
buffer -= 'e';
buffer += 'r';
break;
case 'f':
case 'F':
buffer -= 'f';
buffer += 'g';
break;
case 'g':
case 'G':
buffer -= 'g';
buffer += 't';
break;
case 'h':
case 'H':
buffer -= 'h';
buffer += 'j';
break;
case 'i':
case 'I':
buffer -= 'i';
buffer += 'o';
break;
case 'j':
case 'J':
buffer -= 'j';
buffer += 'H';
break;
case 'k':
case 'K':
buffer -= 'k';
buffer += 'i';
break;
case 'l':
case 'L':
buffer -= 'l';
buffer += ';';
break;
case 'm':
case 'M':
buffer -= 'm';
buffer += 'n';
break;
case 'n':
case 'N':
buffer -= 'n';
buffer += 'm';
break;
case 'o':
case 'O':
buffer -= 'o';
buffer += 'p';
break;
case 'p':
case 'P':
buffer -= 'p';
buffer += 'o';
break;
case 'q':
case 'Q':
buffer -= 'q';
buffer += 'w';
break;
case 'r':
case 'R':
buffer -= 'r';
buffer += 'f';
break;
case 's':
case 'S':
buffer -= 's';
buffer += 'd';
break;
case 't':
case 'T':
buffer -= 't';
buffer += 'y';
break;
case 'u':
case 'U':
buffer -= 'u';
buffer += 'i';
break;
case 'v':
case 'V':
buffer -= 'v';
buffer += 'b';
break;
case 'w':
case 'W':
buffer -= 'w';
buffer += 'e';
break;
case 'x':
case 'X':
buffer -= 'x';
buffer += 'c';
break;
case 'y':
case 'Y':
buffer -= 'y';
buffer += 't';
break;
case 'z':
case 'Z':
buffer -= 'z';
buffer += 'x';
break;
}
break;
default:
break;
}
}
}
va_end(a_list);
fprintf(stdout, buffer);
}
bool mainMenu(int drinks)
{
bool valid = 0;
int frustraction = 0;
drunkprint(drinks, "Drinking Game: The Game\n");
drunkprint(drinks, "\n");
drunkprint(drinks, "1) Play\n");
drunkprint(drinks, "2) too drunk << std::endl;\n");
while (1)
{
std::string choice;
int ichoice = 0;
std::cout << "1 or 2";
for (int i = 0; i < frustraction; ++ frustraction)
std::cout << "!";
std::cout << "? ";
std::cin >> choice;
ichoice = atoi(choice.c_str());
if (ichoice = 1) return true;
if (ichoice = 2) return false;
++frustraction;
}
}
bool wantmore(int drinks)
{
int frustraction = 0;
std::string in;
while (1)
{
drunkprint(drinks, "Drunk enough yet? ");
std::cout << "Y/N";
for (int i = 0; i < frustraction; ++i)
{
std::cout << "!";
}
std::cout << ")";
std::cout << std::endl;
std::cin >> in;
if (in[0] == 'y' || in[0] == 'Y') return true;
if (in[0] == 'n' || in[0] == 'N') return false;
++frustraction;
}
}
int playGame(int drinks)
{
int game = rand() % 3;
int value;
switch (game)
{
case 0:
drunkprint(drinks, "Flipping coin... ");
value = rand() % 2;
if (value == 0)
{
drunkprint(drinks, "HEADS! Take a drink.\n");
return 1;
} else
{
drunkprint(drinks, "TAILS! Skip this turn.\n");
return 0;
}
break;
case 1:
drunkprint(drinks, "Rolling die... ");
value = (rand() % 6);
if (value)
drunkprint (drinks, "Take %i drinks\n", value);
else
drunkprint (drinks, "You got lucky, no drinks this time.\n");
return value;
case 2:
drunkprint(drinks, "Never have I ever\n");
int n = rand()%neverstringcount;
int frustraction = 0;
std::string in;
drunkprint(drinks, neverstrings[n]);
drunkprint(drinks, "\n");
while (1)
{
drunkprint(drinks, "Have you? (");
std::cout << "Y/N";
for (int i = 0; i < frustraction; ++i)
{
std::cout << "!";
}
std::cout << ") ";
std::cout << std::endl;
std::cin >> in;
if (in[0] == 'y' || in[0] == 'Y') return 1;
if (in[0] == 'n' || in[0] == 'N') return 0;
++frustraction;
}
}
return 0;
}
int main(int argc, char** argv)
{
bool gameloop = true;
srand (time(NULL));
size_t drinks = 0;
while (gameloop)
{
bool playloop = true;
if (!mainMenu(drinks))
{
playloop = false;
gameloop = false;
}
while (playloop)
{
drinks += playGame(drinks);
playloop = wantmore(drinks);
}
}
std::cout << "Goodbye lush" << std::endl;
return 0;
}
It's buggy and barely a speck of what I had envisioned when I started drinking, but an hour and a bottle of wine later this is what I've got.
It was fun. The bottle is empty, my fingers are light.