summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-12-02 14:58:38 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-12-02 14:58:38 +1300
commit8c8e35dbc14abd5136d69215e5c7f375867d9ad7 (patch)
tree3d3fa047ea7e921f6cf4b41fe1662dd0c13b1bd1
parentRemove typedefs, be explicit with enum/struct (diff)
downloadtexad-8c8e35dbc14abd5136d69215e5c7f375867d9ad7.tar.gz
texad-8c8e35dbc14abd5136d69215e5c7f375867d9ad7.zip
Use arrays rather than number suffixes
-rw-r--r--texad.c68
1 files changed, 34 insertions, 34 deletions
diff --git a/texad.c b/texad.c
index 1b631c3..eabd59e 100644
--- a/texad.c
+++ b/texad.c
@@ -69,54 +69,54 @@ struct world *genesis(void)
{
struct world *w;
struct player *p;
- struct room *r1, *r2, *r3;
- struct door *d12, *d21, *d23, *d32;
+ struct room *r[3];
+ struct door *d[4];
w = (struct world*) malloc(sizeof(struct world));
p = (struct player*) malloc(sizeof(struct player));
- r1 = (struct room*) malloc(sizeof(struct room));
- r2 = (struct room*) malloc(sizeof(struct room));
- r3 = (struct room*) malloc(sizeof(struct room));
+ r[0] = (struct room*) malloc(sizeof(struct room));
+ r[1] = (struct room*) malloc(sizeof(struct room));
+ r[2] = (struct room*) malloc(sizeof(struct room));
- r1->title = "The foo room";
- r1->description = "You are in the foo room. Sunlight streams from the windows.";
+ r[0]->title = "The foo room";
+ r[0]->description = "You are in the foo room. Sunlight streams from the windows.";
- r2->title = "The bar room";
- r2->description = "You are in the bar room. A vague sense of despair washes over you.";
+ r[1]->title = "The bar room";
+ r[1]->description = "You are in the bar room. A vague sense of despair washes over you.";
- r3->title = "The baz room";
- r3->description = "You are in the baz room. It is richly furnished.";
+ r[2]->title = "The baz room";
+ r[2]->description = "You are in the baz room. It is richly furnished.";
- d12 = (struct door*) malloc(sizeof(struct door));
- d21 = (struct door*) malloc(sizeof(struct door));
- d23 = (struct door*) malloc(sizeof(struct door));
- d32 = (struct door*) malloc(sizeof(struct door));
+ d[0] = (struct door*) malloc(sizeof(struct door));
+ d[1] = (struct door*) malloc(sizeof(struct door));
+ d[2] = (struct door*) malloc(sizeof(struct door));
+ d[3] = (struct door*) malloc(sizeof(struct door));
- d12->direction = EAST;
- d12->src = r1;
- d12->dst = r2;
+ d[0]->direction = EAST;
+ d[0]->src = r[0];
+ d[0]->dst = r[1];
- d21->direction = WEST;
- d21->src = r2;
- d21->dst = r1;
+ d[1]->direction = WEST;
+ d[1]->src = r[1];
+ d[1]->dst = r[0];
- d23->direction = NORTH;
- d23->src = r2;
- d23->dst = r3;
+ d[2]->direction = NORTH;
+ d[2]->src = r[1];
+ d[2]->dst = r[2];
- d32->direction = SOUTH;
- d32->src = r3;
- d32->dst = r2;
+ d[3]->direction = SOUTH;
+ d[3]->src = r[2];
+ d[3]->dst = r[1];
- struct door *ds1[] = {d12, NULL};
- struct door *ds2[] = {d21, d23, NULL};
- struct door *ds3[] = {d32, NULL};
+ struct door *ds1[] = {d[0], NULL};
+ struct door *ds2[] = {d[1], d[2], NULL};
+ struct door *ds3[] = {d[3], NULL};
- r1->doors = ds1;
- r2->doors = ds2;
- r3->doors = ds3;
+ r[0]->doors = ds1;
+ r[1]->doors = ds2;
+ r[2]->doors = ds3;
- p->room = r1;
+ p->room = r[0];
w->player = p;