10 x 20 1 #################### # # # Z ######## # # # # ##### # # # # # # # X # # # # ##### # Y # # # # ####################The first line gives number of rows x number of columns, followed by the number of Z's you'll find on the board. The X marks the goal position on the board. This is where the player is trying to get to. The Y marks the player's starting position.
Zs are "spawn spots". These are
positions that moving, death-dealing objects spawn from.
There can be multiple spawn spots.
do {
usleep(150000);
char c = wgetch(W);
if (c == 'y') break; // game exits with a 'y'
} while(true);
... so that the board stays on the screen until the user
presses y on the keyboard.
After exiting the loop, the program must
exit ncurses (by calling endwin();), and then print out
the row,col coords of the player start spot and the spawn
spots, just so we're sure we've got them right.
hit enter
press y
keypad(W, true); to the ncurses
initialization code. E.g.
WINDOW *W = initscr(); curs_set(0); cbreak(); noecho(); nodelay(W,true); keypad(W, true);
wgetch(W) in an int, not a char.
So, instead of char kb = wgetch(W); do:
int kb = wgetch(W);You can still check for characters like "
kb == 'a'", but you
can also compare kb to the constants
KEY_LEFT,
KEY_RIGHT,
KEY_UP,
KEY_DOWN that ncurses defines.
So, for example,
int kb = wgetch(W);
if (kb == 'a') { /* an a got pressed */ }
if (kb == KEY_LEFT) { /* a left arrow got pressed */ }
*'s
in the game) that kill the player if they collide with it.
Stars bounce off walls, but simply pass through one another.
Here
are the details:
1. let dc = Player column position - Killer column position 2. let dr = Player row position - Killer row position 3. if dc < 0 let cdir = 3 else let cdir = 1 4. if dr < 0 let rdir = 0 else let rdir = 2 5. with prob 1/2 set Killer's direction to rdir, otherwise set Killer's direction to cdir
boardYYXXXX.txt,
where YYXXXX is your alpha code. Be creative, but make sure
your program still works with your board file as input!
,-|number of stars spawned per spawn-spot
/
board2Rm.txt 5 1 points = 1000 ←|number of points for winning this board
------------ \
board file name `-|number of killers spawned per spawn-spot
A player working through the game plays the board as
described by the first line of gameScript.txt
until either dying three times or winning. If the player
wins, the game moves on to the board desceribed by the
second line of gameScript.txt,
and so on and so forth. Nobody except Neo could possibly
finish the entire script, so we don't worry about it.
|
Adding Color To add color to ncurses we need to start color support
|
Using an extended character set Full unicode in ncurses seems to be a bit messy. But it does support a more modest extended character set pretty nicely: altcharset chart, extended charset chart. The altcharset has predefind constants like ACS_CHKBOARD. You write them to the screen
like this:
waddch(W, ACS_CKBOARD | A_ALTCHARSET);For the extended charset there are simply numeric codes. If you look at chart you'll see that the copyright symbol has code 169, so you'd write it like this: waddch(W, 169 | A_ALTCHARSET); |
README whose first line is the
proper g++ command to compile your project
— the basic project, that is, the furthest Part you
successfully completed without any extra credit.
We will use
this to compile your code, so it better be right!
The following lines should include your name and alpha,
and a description of your game (especially any extra credit
goodies that you've added on).
If you did any extra credit, the last line should be
the proper g++ command to compile yout extra credit
assignment.
codeprint README part4.cpp board.h board.cpp... and turn in a printout of that. Please make sure that your name and alpha code appear in at least the README file (and far preferrably in all files!)
submit proj03 files-to-includeWhere files-to-include is a list of all .cpp and .h files specific to this project, as well as your gameScript.txt file, README file, the
boardYYXXXX.txt file you
created, and all board-files required to run your project.
Submitting more than you need to submit is always
OK. Just be sure
that all the files needed to compile and run your project
(including the extra credit version of your project) are
there. So, assuming you have a directory for this project and
that you are in that directory, you could submit like this:
submit proj03 README *.cpp *.h *.txtRemember to include the g++ lines used to compile your program as the first line in the README file, and if you did any extra credit the g++ line used to compile the extra credit should be the last line of the README file. You may submit files at any time, but only the last submission will be used for grading.