Created
January 15, 2015 03:13
-
-
Save coryalder/0ca6c03fdf29b55498cb to your computer and use it in GitHub Desktop.
adventure game psuedocode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
row1 = 0,0 1,0 2,0 3,0 | |
row2 = 0,1 1,1 2,1 3,1 | |
row3 = 0,2 1,2 2,2 3,2 | |
row4 = 0,3 1,3 2,3 3,3 | |
for row in 0 to 3 { | |
for column in 0 to 3 { | |
create room at row, column | |
n = maze[row-1][column] | |
s = maze[row+2][column] | |
e = maze[row][column-1] | |
w = maze[row][column+1] | |
} | |
} | |
// NW->NE | |
// | | | |
// SW->SE | |
struct room *ROOM_NE = malloc() | |
struct room *ROOM_NW = malloc() | |
struct room *ROOM_SE = malloc() | |
struct room *ROOM_SW = malloc() | |
struct room *treasureRoom = NULL; | |
void maybe_put_treasure(room* maybe_room) { | |
if (treasureRoom == NULL) { | |
if (arc4random_uniform(4) == 1 ) { | |
treasureRoom = maybe_room; | |
} | |
} else { | |
return; | |
} | |
} | |
ROOM_NW->n = NULL; | |
ROOM_NW->s = ROOM_SW; | |
ROOM_NW->e = ROOM_NE; | |
ROOM_NW->w = NULL; | |
ROOM_SW->n = NULL; | |
ROOM_SW->s = ROOM_SW; | |
ROOM_SW->e = ROOM_NE; | |
ROOM_SW->w = NULL; | |
while(treasureRoom == NULL) { | |
maybe_put_treasure(ROOM_NE); | |
maybe_put_treasure(ROOM_NW); | |
maybe_put_treasure(ROOM_SE); | |
maybe_put_treasure(ROOM_SW); | |
} | |
while(myPosition == NULL) { | |
} | |
move_player(int direction) { | |
struct room *newRoom = NULL; | |
switch (direction) { | |
case NORTH: | |
newRoom = myPosition->n; | |
break; | |
case SOUTH: | |
if (my) | |
} | |
if (newRoom == NULL) { | |
// we can't move here, tell the player that | |
} else { | |
myPosition = newRoom; | |
} | |
} | |
move_player(NORTH); | |
move_player(SOUTH); | |
move_player(SOUTH); | |
move_player(SOUTH); | |
move_player(NORTH); | |
while (!i) { | |
char *input; | |
scanf(input); | |
if (input == 'n') { | |
// move player north if possible | |
} else if (input == 's') { | |
// move player south if possible | |
} etc.... | |
if (myPosition->hastreasuyre) { | |
// win, exit the loop | |
} | |
} | |
positon_X = 0 | |
position_Y = 1 | |
move_player(x, y) { | |
positon_x += x; | |
positon_y += y; | |
} | |
move_player(+1, -2); | |
X X i X | |
X X X X | |
X X X X | |
X = { | |
player | |
treasure | |
box | |
N | |
S | |
E | |
W | |
} | |
struct Room bedroom; | |
bedroom.north = livingRoom; | |
bedroom.south = outside; | |
bedroom.player = 0; | |
struct Room bedroom = {livingRoom, outside, NULL, NULL }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment