Inspired by the 7DRLs I decided to post another game I made. It has highly competitive scoring and a storyline based on greek mythology. Post your high scores here.
#include <ctime>
#include <cstdlib>
#include <curses.h>
using namespace std;
/***************************/
#define legal(w,g) ((w>=0 && w<Y && g>=0 && g<X))
#define superlegal(w,g) ((w>0 && w<Y-1 && g>0 && g<X-1))
#define inView(w,g) ((w>=0 && w<viewY && g>=0 && g<viewX))
#define wall 1
/***************************/
const int Y=24; //height of world
const int X=80; //width of world
const int viewY=24; //height of view
const int viewX=80; //width of view
/***************************/
char VIEW[viewY][viewX];
int COLOR[viewY][viewX];
int MAP[Y][X];
char ground[]={' ',' ',' ',' ',' ',' ',' ',' ','.',',',';','\"','-'};
int quit;
int best=-1;
int steps;
char inchar;
/***************************/
struct player
{
int y;
int x;
bool moved;
};
player you;
/***************************/
void display();
void init();
void input();
void slip();
char* convert(int number, char* strng);
void print(int y, int x, char string[]);
/***************************/
int main()
{
init();
while(!quit) //press q to quit
{
display();
input();
if(rand()%100==0)
slip();
}
refresh();
echo(); // turn echoing back on before exiting
endwin(); // end curses control of the window
}
/***************************/
void init()
{
quit=0;
initscr();
srand(time(NULL)); // initializes the random number generator
clear(); // clear the window
noecho(); // don't show typed characters on the screen
start_color();
init_pair(0, COLOR_WHITE, COLOR_BLACK);
init_pair(1, COLOR_RED, COLOR_BLACK);
for(int y=0; y<Y; y++)
{
for(int x=0; x<X; x++)
{
MAP[y][x]=rand()%10;
}
if(Y/2-best<y && y<Y/2)
MAP[y][X/2]=12;
}
for(int y=0; y<viewY; y++)
{
for(int x=0; x<viewX; x++)
{
COLOR[y][x]=0;
VIEW[y][x]=' ';
}
}
you.y=Y/2;
you.x=X/2;
steps=0;
you.moved=false;
}
/***************************/
void display()
{
int a,b;
for(int y=0; y<Y; y++)
{
a = y - you.y + viewY/2; //moves the map around me
for(int x=0; x<X; x++)
{
b = x - you.x + viewX/2; //moves the map around me
if(inView(a,b)) //stops printing at the edge of the array
{
VIEW[a][b]=ground[MAP[y][x]];
}
}
}
VIEW[viewY/2-1][viewX/2]='O';
VIEW[viewY/2][viewX/2]='@';
MAP[you.y][you.x]=11;
COLOR[viewY/2][viewX/2]=1;
for(int y=0; y<viewY; y++)
{
for(int x=0; x<viewX; x++)
{
attrset(COLOR_PAIR(COLOR[y][x]));
mvaddch(y, x, VIEW[y][x]);
COLOR[y][x]=0;
VIEW[y][x]=' ';
}
}
if(best==-1)
{
char* string1={"Welcome to Sisyphus: The game"};
print(viewY/2-1,viewX/2-14,string1);
char* string2={"wasd or numpad to move, Q to quit"};
print(viewY/2,viewX/2-16,string2);
best=0;
}
refresh(); // refresh the screen
}
/***************************/
void input()
{
inchar = getch();
if(inchar != ERR)
{
if(inchar=='W' || inchar=='w' || inchar=='7')
{
for(int y=Y-1; y>0; y--)
for(int x=0; x<X; x++)
MAP[y][x]=MAP[y-1][x];
for(int x=0; x<X; x++)
MAP[0][x]=rand()%10;
if(steps+Y/2 < best)
MAP[0][X/2]=12;
steps++;
}
else if(inchar=='q' || inchar=='Q')
quit=1;
}
}
/***************************/
void slip()
{
char string1[]={"steps taken: "};
print(viewY/2-1,viewX/2-8,string1);
*convert(steps,string1)='\0';
print(viewY/2-1,viewX/2+5,string1);
char string2[]={"previous best: "};
print(viewY/2,viewX/2-8,string2);
*convert(best,string2)='\0';
print(viewY/2,viewX/2+6,string2);
if(steps>best)
best=steps;
inchar=getch();
while(inchar=='W' || inchar=='w' || inchar=='7')
inchar=getch();
init();
}
/***************************/
void print(int y, int x, char string[])
{
for(int i=0; string[i]!='\0'; i++)
mvaddch(y, i+x, string[i]);
}
/***************************/
char* convert(int number, char* strng) //what this does is converts an integer into a string
{
if(number>9)
strng=convert(number/10, strng);
number=number%10;
strng[0]=char(number+'0');
return &strng[1];
}
/***************************/