RCRPG/C: Difference between revisions
m
Fixed syntax highlighting.
m (→Code: last minute bug fix) |
m (Fixed syntax highlighting.) |
||
(10 intermediate revisions by 6 users not shown) | |||
Line 1:
{{collection|RCRPG}}
This [[
==What's in use==
Line 6 ⟶ 7:
* [[wp:ncurses|ncurses]] library for advanced terminal I/O
* functions (also with variable number of arguments)
* enumerations
* structures, their allocation and pointers
Line 38 ⟶ 39:
{{works with|POSIX}}
{{libheader|ncurses}}
<
#include <stdlib.h>
#include <stdbool.h>
Line 51 ⟶ 52:
/* position */
struct position {
};
typedef struct position position_t;
Line 82 ⟶ 83:
};
const char *str_dirs = "nsewud";
struct room {
Line 89 ⟶ 90:
int lo; /* last object */
int description;
};
typedef struct room room_t;
/* descriptions */
const char *descriptions[] = {
"cold dark room",
"very stinky room",
Line 107 ⟶ 108:
};
const char *objs[] = {
"nothing", "sledge", "ladder", "gold", "equipped sledge"
};
const char *dirnames[] = {
"north", "south", "east", "west", "up", "down"
};
Line 117 ⟶ 118:
/* room stores and more (private) */
room_t *rooms[NS_LIMIT*EW_LIMIT*UD_LIMIT];
int py = 0;
Line 123 ⟶ 124:
#define MAX_CARRYABLE 25
object_t carrylist[MAX_CARRYABLE];
/* where are you */
Line 155 ⟶ 156:
/* check goal */
{
if ( (my_pos.ns == p->ns) &&
Line 185 ⟶ 186:
rooms[room_i]->visited = false;
rooms[room_i]->description = rangerandom(0, sizeof(descriptions)/sizeof(
/* put some random object - sledge or gold */
Line 213 ⟶ 214:
/* show description */
void print_cmd(int y, int x, const char *str)
{
int i, l;
Line 338 ⟶ 339:
/* cmd_get */
{
if ( carried_number == MAX_CARRYABLE ) {
Line 354 ⟶ 355:
/* cmd_equip */
{
if ( carried_number == 0 ) {
Line 375 ⟶ 376:
}
{
int d, c;
if ( carried_number == 0 ) {
Line 407 ⟶ 408:
case 'u':
case 'd':
d =
if ( ((my_pos.ns + incdir[d].ns) >= NS_LIMIT) ||
((my_pos.ew + incdir[d].ew) >= EW_LIMIT) ||
Line 439 ⟶ 440:
/* cmd_drop */
{
if ( carried_number == 0 ) {
Line 455 ⟶ 456:
/* main loop */
{
int c, d;
Line 507 ⟶ 508:
case 'u':
case 'd':
d =
if ( currentroom->dirs[d] == NULL ) {
clrtoeol();
Line 547 ⟶ 548:
{
int i;
initscr(); cbreak(); noecho();
srand(time(NULL));
Line 592 ⟶ 593:
free_rooms();
nocbreak(); echo(); endwin();
return EXIT_SUCCESS;
}
}</syntaxhighlight>
|