No, C counts from ZERO, not 1, so int traps[]={0,1,0,0,0,0,0}; puts the bottomless pit at 1, not at 2.
Compare int arr[]={0,1,2,3,4,5} which creates a 6 item array with each element equal to its index.
The game knows that the pit is at 1 because we just lookup traps[pos] where pos is the player's position. If pos is 1 then traps[pos] is 1, otherwise traps[pos]=0. Essentially I'm using the array index as one part of a 1-1 mapping 0->0; 1->1; 2->0; 3->0 etc.
> int traps[]={0,1,0,2,0,0,0}; // 1=bottomless and pit 2= arrow trap
Similarly no, this puts the bottomless pit at 1 and the arrow trap at 3, and the code if an arrow trap just reduces your health by 3 whenever you visit it would be:
Code:
switch (traps[pos])
{
case 0: // nothing
break;
case 1: // bottomless pit
// .. handle bottomless pit
break;
case 2: // arrow trap
health-=3;
break;
}
Or:
if (traps[pos]==2) // !1 see below
{ // !2 see below
health-=3;
}
Code:
c=getchar();
if (c)
{
// ...
}
to:
if (c=getchar())
{
// ...
}
Or perhaps:
while (c=getchar())
{
// process characters until getchar returns 0
}
Without the shortcut you would have the clunky:
while (TRUE)
{
c=getchar();
if (!c) break;
// etc
}
Code:
while (!game_exit)
{
// display the description


