Name this game... [Archive] - C Board

PDA

View Full Version : Name this game...


guesst
04-29-2008, 12:19 PM
Okay, a very simple curses program here, the idea is loosely based on a faint memory I have of a type-in in basic that I typed in and played some years back.

Synopsis- your thing ('O') runs around the outside edge. When you press space it shoots one of it's bullets into the internal space. The object is to hit the 15 Xs on the inside. Eliminate the targets and get 15 more targets, 15 more bullets, and you go a little faster. If you can hit 2 with one bullet you've just saved yourself a bullet. If you beat level 10 you win the game.

So what's would you give for setting, story, and name of this game?
#include <curses.h>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>

int dirs[6] = {0, 1, 0, -1, 0, 1};

void init () {
srand (time(NULL));
initscr ();
raw (); nodelay(stdscr,1); noecho(); curs_set(0); nonl(); keypad(stdscr,1);
}

void play () {
int x, y, bx, by, c, d, in, bul, lvl, buf[LINES][COLS];

y = x = d = lvl = 0; bul = 10;
do {
bx = x; by = y;
clear ();
lvl++; bul += 15;
mvprintw (LINES - 1, 37, "Round %d", lvl);
for (y = 0; y < LINES; y++) for (x = 0; x < COLS; x++) buf[y][x] = 0;
for (c = 0; c < 15; c++) { /* Set up enemies. */
do {
y = 1 + rand () % (LINES - 3); x = 1 + rand () % (COLS - 2);
} while (buf[y][x]);
buf[y][x] = 1;
mvaddch (y, x, 'X');
}
x = bx; y = by;
mvaddch (y, x, 'O');
mvprintw (LINES - 1, 0, "Bullets : %d", bul);
mvprintw (LINES - 1, 60, "Press SPACE to fire.");
refresh ();
while ((bul > 0) && (c > 0)) {
in = getch ();
if (tolower(in) == 'q') return;
if (in == ' ') { /* shoot a bullet */
bul--;
mvprintw (LINES - 1, 0, "Bullets : %d ", bul);
bx = x; by = y;
do {
x += dirs[d + 1]; y += dirs[d + 2];
if (buf[y][x]) {
beep ();
buf[y][x] = 0;
c--;
}
else mvaddch (y, x, '.');
refresh ();
napms (15);
mvaddch (y, x, ' ');
} while (!((x == 0) + (y == 0) + (x == COLS - 1) + (y == LINES - 2)));
x = bx; y = by;
}
mvaddch (y, x, ' ');
x += dirs[d]; y += dirs[d + 1];
if (((x == 0) + (y == 0) + (x == COLS - 1) + (y == LINES - 2)) == 2) {
d ++; d %= 4;
}
mvaddch (y, x, 'O');
refresh ();
napms (275 - 25 * lvl);
} /* end of level loop. Either out of bullets or out of enemies. */
} while ((c == 0) && (lvl < 10));
if (c) mvprintw (10, 27, "Out of bullets. Game over.");
else mvprintw (10, 15, "Congratulations! You have defeated every enemy!");
refresh ();
}

int main () {
init ();
play ();
nodelay(stdscr,0); getch ();
endwin ();
return 0;
}

Magos
04-29-2008, 12:53 PM
Ow, my eyes. It burns, it burns...

mramazing
04-29-2008, 04:45 PM
yea, very very very very very very messy code... not only that but there are no comments. RTFM :D!

medievalelks
04-30-2008, 02:19 PM
Sounds fun. Try adding obstacles that you can't shoot through on later levels. And make the X's move. Powerups could give you a special bullet that ricochets back and forth to help with those moving targets.

Anyway, there's not much story, so just name it something catchy, like "Blork!". :-)

guesst
04-30-2008, 04:27 PM
yea, very very very very very very messy code... not only that but there are no comments. RTFM :D!

How is that messy code? Uncommented, yes, but the code practically reads like a book. (Exaggerating in defense of a program that took me all of 2 hours to write.)

Sounds fun. Try adding obstacles that you can't shoot through on later levels. And make the X's move. Powerups could give you a special bullet that ricochets back and forth to help with those moving targets.

Anyway, there's not much story, so just name it something catchy, like "Blork!". :-)

Ooh, good suggestions. However, as for not being a story, just means I'm leaving it open for you to write. Blork it good. Had someone say to combine Shoot with O and X to get ShOX.

brewbuck
04-30-2008, 04:29 PM
If I remember correctly, the game was called Gyruss, and it had a very cool symphonic soundtrack.

jEssYcAt
04-30-2008, 05:51 PM
So what's would you give for setting, story, and name of this game?
So you are the first on scene at a genetic lab where the creatures have escaped their cages and are making their way out of the building. Not knowing you would be facing such a task you have only limited ammunition, but you only have to hold the tide of creatures back until reinforcements arrive (which is in approximately 10 levels). You set up a perimiter and, thanks to your great physical shape, are able to run around the building and shoot at the creatures for a long time where normal people would drop dead of exhaustion...

You could change things up a bit and include some S's or whatever to be the scientists fleeing for their lives, and so you don't want to shoot them, but the X's (monsters) will move toward the scientists since they want some revenge for all the experiments done to them, so not only are you trying to prevent the creatures from escaping the perimiter you set up, but you are also trying to rescue the fleeing scientists and you get bonus points for every scientist that makes it past your perimiter without being eaten by a monster...

medievalelks
04-30-2008, 06:48 PM
So you are the first on scene at a genetic lab where the creatures have escaped their cages and are making their way out of the building. Not knowing you would be facing such a task you have only limited ammunition, but you only have to hold the tide of creatures back until reinforcements arrive (which is in approximately 10 levels). You set up a perimiter and, thanks to your great physical shape, are able to run around the building and shoot at the creatures for a long time where normal people would drop dead of exhaustion...

You could change things up a bit and include some S's or whatever to be the scientists fleeing for their lives, and so you don't want to shoot them, but the X's (monsters) will move toward the scientists since they want some revenge for all the experiments done to them, so not only are you trying to prevent the creatures from escaping the perimiter you set up, but you are also trying to rescue the fleeing scientists and you get bonus points for every scientist that makes it past your perimiter without being eaten by a monster...

Awesome. This reminds me of some of my old Odyssey II titles.

As I grow older, I don't have time to learn the complex games of today. I like simpler games like this.

guesst
04-30-2008, 08:51 PM
Try it out, it's more of a one-switch Gyruss with stationary enemies. I've put it up online. You can download it here (http://cymonsgames.retroremakes.com/pages/xtris/shoot.exe).

So you are the first on scene at a genetic lab where the creatures have escaped their cages and are making their way out of the building. Not knowing you would be facing such a task you have only limited ammunition, but you only have to hold the tide of creatures back until reinforcements arrive (which is in approximately 10 levels). You set up a perimiter and, thanks to your great physical shape, are able to run around the building and shoot at the creatures for a long time where normal people would drop dead of exhaustion...

You could change things up a bit and include some S's or whatever to be the scientists fleeing for their lives, and so you don't want to shoot them, but the X's (monsters) will move toward the scientists since they want some revenge for all the experiments done to them, so not only are you trying to prevent the creatures from escaping the perimiter you set up, but you are also trying to rescue the fleeing scientists and you get bonus points for every scientist that makes it past your perimiter without being eaten by a monster...

Heh, I like it. Only, maybe you've programmed a wall hugging robot that you mount a gun on. (You work in an engineering/genetics lab?) As for adding enemy types or obsticles, hey, I've given you the code. That's kinda the idea behind my site.

Okay, I've made some changes and commented the code somewhat. Does how's this strike you professionals?
#include <curses.h>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>

int dirs[6] = {0, 1, 0, -1, 0, 1};

void init () {
srand (time(NULL));
initscr ();
raw (); nodelay(stdscr,1); noecho(); curs_set(0); nonl(); keypad(stdscr,1);
}

void play () {
int x, y, bx, by, c, d, in, bul, lvl, buf[LINES][COLS];

y = x = d = lvl = 0; bul = 10; /* Set up variables for new game. */
do { /* Set up varaibles for new level */
clear ();
lvl++; bul += 15;
mvprintw (LINES - 1, 37, "Round %d", lvl);
for (by = 0; by < LINES; by++) for (bx = 0; bx < COLS; bx++)
buf[by][bx] = 0; /* clear buffer */
for (c = 0; c < 15; c++) { /* Set up enemies. */
do {
by = 1 + rand () % (LINES - 3); bx = 1 + rand () % (COLS - 2);
} while (buf[by][bx]);
buf[by][bx] = 1;
mvaddch (by, bx, 'X');
} /* c will count targets */
/* Draw last few more things on the screen. */
mvaddch (y, x, 'O');
mvprintw (LINES - 1, 0, "Bullets : %d ", bul); /* space after the d */
mvprintw (LINES - 1, 60, "Press SPACE to fire.");
refresh ();
while ((bul > 0) && (c > 0)) { /* The main game loop */
in = getch ();
if (tolower(in) == 'q') return;
if (in == ' ') { /* shoot a bullet */
bul--;
mvprintw (LINES - 1, 0, "Bullets : %d ", bul); /* space after again. */
bx = x; by = y;
do {
bx += dirs[d + 1]; by += dirs[d + 2]; /* move the bullet */
if (buf[by][bx]) { /* a hit */
beep ();
buf[by][bx] = 0;
c--;
}
mvaddch (by, bx, '.');
refresh ();
napms (15);
mvaddch (by, bx, ' ');
} while (!((bx==0) + (by==0) + (bx==COLS - 1) + (by==LINES - 2)));
/* above line is for edge detection. */
}
mvaddch (y, x, ' ');
x += dirs[d]; y += dirs[d + 1];
if (((x == 0) + (y == 0) + (x == COLS - 1) + (y == LINES - 2)) == 2) {
/* if we're at a corner change direction. */
d++; d %= 4;
}
mvaddch (y, x, 'O');
refresh ();
napms (275 - 25 * lvl);
} /* end of level loop if out of bullets or out of enemies. */
} while ((c == 0) && (lvl < 10));
if (c) mvprintw (10, 27, "Out of bullets. Game over.");
else mvprintw (10, 15, "Congratulations! You have defeated every enemy!");
refresh ();
}

int main () {
init ();
play ();
mvprintw (15, 32, "Press any key...");
nodelay(stdscr,0); getch ();
endwin ();
return 0;
}

medievalelks
04-30-2008, 09:32 PM
Make the initial speed faster...it takes too long to get around.

Also, before you get too far, consider porting it to OpenGL and going full screen. You can add graphic sprites pretty easily.

prog-bman
04-30-2008, 09:44 PM
The code could use some spaces in there. Also your variable names leave something to be desired.

Such as:

void play()
{
//
//Will be used to hold the player position
//
int playerX = 0;
int playerY = 0;

//
//Will be used to hold the bullet position
//
int bulletX = 0;
int bulletY = 0;

//Will be used to hold the status of the game
bool quit = false;

//Will be used to hold the key entered by the user
int userInput = '';

//The main game loop, will handle all play logic
do{
//Grab the user entered character, in lower case to ease input handling
userInput = toLower(getch());

//Special Case: q means the user wants to quit, set quit flag to true
if(userInput == 'q'){
quit = true;
}//if

//Special Case: f means the user wants to fire a bullet, fire a bullet based on
//the ships current position
if(userInput == 'f'){
//Fire bullet here
}//if
}while(!quit);
}

Note: This is assuming // is allowed as a comment, it would be just as simple to use /**/

guesst
05-01-2008, 03:30 AM
Gaah, look at all that wasted space! I see code like that coming off the printer and in a whole page I'll find a dozen functional lines of code. I have to make like a flipbook to read the darn thing.

Can't we find a middle ground?

medievalelks
05-01-2008, 05:50 AM
The code could use some spaces in there. Also your variable names leave something to be desired.

Such as:

void play()
{
//
//Will be used to hold the player position
//
int playerX = 0;
int playerY = 0;

//
//Will be used to hold the bullet position
//
int bulletX = 0;
int bulletY = 0;

//Will be used to hold the status of the game
bool quit = false;

//Will be used to hold the key entered by the user
int userInput = '';

//The main game loop, will handle all play logic
do{
//Grab the user entered character, in lower case to ease input handling
userInput = toLower(getch());

//Special Case: q means the user wants to quit, set quit flag to true
if(userInput == 'q'){
quit = true;
}//if

//Special Case: f means the user wants to fire a bullet, fire a bullet based on
//the ships current position
if(userInput == 'f'){
//Fire bullet here
}//if
}while(!quit);
}

Note: This is assuming // is allowed as a comment, it would be just as simple to use /**/

White space is good, but those comments are redundant and grating on the eyes. Tell me what the comment above "if (userInput == 'q') { quit = true; }" adds to that perfectly understandable code?

All of those comments are unnecessary.

zacs7
05-01-2008, 05:56 AM
As many people have said before, comments should explain why you're doing something not what it's doing -- the code explains that.

guesst
05-01-2008, 11:06 AM
Okay, so what about my revised comments (http://cboard.cprogramming.com/showpost.php?p=748451&postcount=9). Spacing aside, what's yawls take on them. I have a few redundant ones, but some of them have got to be useful.

prog-bman
05-01-2008, 03:10 PM
White space is good, but those comments are redundant and grating on the eyes. Tell me what the comment above if (userInput == 'q') { quit = true; } adds to that perfectly understandable code?

All of those comments are unnecessary.
Indeed, not all those comments are needed. But I have never looked at a piece of code in my life and been like, geez these people commented too much. Now the reverse is very much true. I would rather people say you over comment than under comment. Since I picked up this style of commenting, I have yet to look at an old piece of code and not be able to jump right into it. Also I disagree on the grating of the eyes, but that is just a style preference like everything. I personally think this is grating on the eyes, but through some comments and spaces it looks good to me :D

int x = 10;
int y = 10;
int c = 10;
string z = "Hello";
bool isLooping = false;

mike_g
05-01-2008, 03:28 PM
The problem I find with using lots of comments is that the useful ones get lost in a swamp of inane dribble that just repeats in english what the code does. Also I like my code compact, I'd rather have things a bit more squashed together than have to scroll 6 miles down to find what I want, but thats just my personal preference. As for using descriptive variable names I find that makes code much easier to read.

medievalelks
05-01-2008, 03:39 PM
The problem I find with using lots of comments is that the useful ones get lost in a swamp of inane dribble that just repeats in english what the code does. Also I like my code compact, I'd rather have things a bit more squashed together than have to scroll 6 miles down to find what I want, but thats just my personal preference. As for using descriptive variable names I find that makes code much easier to read.

The biggest problem with comments is that they are notorious liars. Pathological even. Oh, they may tell the truth at first, but sooner or later they'll start fibbing when the code they adorn is updated, and they are not.

robwhit
05-01-2008, 03:40 PM
What's the point of the red? //
//Will be used to hold the player position
//

prog-bman
05-01-2008, 04:20 PM
Whenever I comment something that is spanning more than one line I do that

//
//Initialize the players location on the screen
//
int playerX = 10;
int playerY = 15;
int playerZ = 1;

I find that this looks good. It really is just a style thing though. I am a big commenter and I really can't help it.

guesst
05-04-2008, 03:47 PM
Okay, so now I fell we've heard both sides and I think this just goes to show that comments are a stylistic choice and what you do with them is your business. You can state your opinion or preference, but state it as such when you do.

I hope we're all a little more enlightened.

That aside, I think I'm going to go with Shox, but I'm going to use jEssYcAt's , edited slightly:
Checking into work at Shox biotech/robotic engineering labs you discover the mutated creatures have escaped their cages and are making their way out of the building. Not 100% prepared for such a task you have only limited ammunition, but you only have to hold the tide of creatures back until reinforcements arrive (which is in approximately 10 levels). You set up a perimeter and deploy the containment protocol bot which runs around the perimeter and shoots at the creatures. You initially can only find slightly more ammo than the bot needs, but are sure you can find more as it moves from one room to another.
Should I make the ammo nets so that we're capturing and not killing?

medievalelks
05-04-2008, 07:24 PM
Should I make the ammo nets so that we're capturing and not killing?

Sure, if it assuages your conscience, but have you seen what people are playing nowadays? I see no problem with greasing mutant animals.

guesst
05-05-2008, 08:02 AM
...have you seen what people are playing nowadays?
Yeah. Wii and DS, with almost no mutant splatting games (Resident Evil IV, I think is about it) own the dominant market share. Sorry, but believe it or not, despite the fact that those making the games like grizzled space marines and dark corridors for those playing the game "family fun" is the game d'jour.

And quite frankly it's the sort of thing I enjoy. I should PM jEssY cAt to see what they think.

medievalelks
05-05-2008, 11:17 AM
Nothing wrong with family fun game, I just thought that since they were mutant animals...

jEssYcAt
05-05-2008, 04:16 PM
Okay, so now I fell we've heard both sides and I think this just goes to show that comments are a stylistic choice and what you do with them is your business. You can state your opinion or preference, but state it as such when you do.

I hope we're all a little more enlightened.

That aside, I think I'm going to go with Shox, but I'm going to use jEssYcAt's , edited slightly:

Should I make the ammo nets so that we're capturing and not killing?

Both. This company works with more than one kind of animal afterall.

Some of them are not much more than lab-rats that have mutated beyond good sense and are the size of tow-trucks. You definitely want to kill these since if they get out, they will not be very family friendly. These are the majority of what will be coming out of the building.

Some of them are are a little more exotic, like minks, leopards, chimpanzies, etc. and the company would like to capture them rather than kill them. If it comes down to it however, the expense of paying settlements to the families of anyone they kill is more than the value of this group, so if you can catch, use the nets, otherwise kill them. You might see one of these for every 15-20 of the Tow-truck-rat-creatures. Some of the larger creatures in this category won't die from a single shot either, but will slow it down, so some of these can safely be shot once to slow them down enough for the net to work.

And then there are a few that escaped the bio-lab's deepest, darkest reaches. Some of these are worth more than Bill Gates, and some of them contain strains of disease that have no known cure. For the former, the company would frown upon you killing them and would rather pay settlements to families than have to go through the expense and time of re-creating them. If you kill too many, you may end up replacing them... For the latter, you put a hole in one of their hides and you infect the western half of the United States with something that makes the Super-Flu from Stephen King's "The Stand" look like spring allergies. Use the nets! Some of the bigger variety in this group will walk right through a net, so firing multiple nets is a must. You probably won't see any of these until the later levels, and then only one or two for every 50 or 60 of the tow-truck-rats.

As far as "family oriented entertainment" goes, I am a parent of a 5 year old and a 1 year old (both boys). If this was going to have graphics the likes of Resident Evil, I would keep my kids away from this game until they are quite a bit older. My 5 year old snuck down the stairs just out of eyesight one night while I was watching a scary movie with my other half. I don't remember which movie it was, but it was graphic and he had nightmares for a couple nights after that, and he's still afraid of monkeys.

However, if this is going to be text graphics with the monsters being different letters or symbols to represent each type and the extent of a "kill shot" is the bullet collides with the monster and the monster disappears, then I would happily let my older son play this game. (My 1yo would mostly press random buttons and not get anywhere.)

At the core of the game, it requires some thought about resource management since you have limited ammunition, and it requires some strategic thought about whether to shoot bullets or a net. These are things that I certainly don't have a problem with my kids learning. If I describe things to him as "You are shooting at monsters, but some of the monsters you have to use nets", he is good to go once he learns which monsters need nets and which can use bullets. He doesn't need all the extra of "tow-truck sized rats" and "super-flu-carrying-genetic-monstrosity", but those things make it interesting for those of us who won't have nightmares.

You could then assign 2 "fire" buttons. One would fire bullets, the other would fire nets. You could also leave "powerups" layout around that would enhance the net gun (now one net could hold a big guy) or allow you to fire faster. Perhaps a whistle that when blown will attract all the mosnters nearby to come directly toward you, useful when one or more has gotten past you and close to escaping. And of course, even a simple security bot has a blade for close-quarters combat to protect itself (and to make a last ditch effort when the user squanders all the bullets).

And finally, feel free to use any idea I have posted thus far in any way you like. If I had more time, I would try to make a stab at something like this with ncurses graphics since I know almost nothing about 2- or 3-d graphics yet for lack of ever looking into them. I would be interested to see what you come up with however.

guesst
05-06-2008, 03:56 PM
sniporama
And finally, feel free to use any idea I have posted thus far in any way you like. If I had more time, I would try to make a stab at something like this with ncurses graphics since I know almost nothing about 2- or 3-d graphics yet for lack of ever looking into them. I would be interested to see what you come up with however.
Ha ha, I'm afraid you've seen is what I'm going to come up with, more or less. While I'll admit there's a lot that can be done this program, like all of them on Cymon's Games (http://cymonsgames.retroremakes.com/), is more for showing people what can be done (with curses in this case), providing a framework, and keeping it simple. You've clearly been inspired by it. But as for these modifications and additions, well, I'll let you handle that.

RobotEscape (http://cymonsgames.retroremakes.com/robotescapec/) was another good one for inspiration (IMHO), but unfortunately was harder to understand how it worked, so it probably won't result in many code forks.

abh!shek
05-20-2008, 04:21 PM
Damn! Looks like build-essential does not come with curses.h

I get errors while compiling.

guesst
05-26-2008, 02:00 PM
Damn! Looks like build-essential does not come with curses.h

I get errors while compiling.

Ubunutu. You have to install curses on Ubunutu. I use PDCurses on my windows build, but in Linux I think NCurses is the standard, tho I've heard whisperings that something called libncurses5-dev has everything you need.

Just an update: Shox is now up (http://cymonsgames.retroremakes.com/shox/) on Cymon's Games with jEssY cAt's story.