Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int i = 0;
int rabbit = 0;
int go = 0;
int row = 0;
int column = 0;
int line = 0;
char island[6][6] =
{
{'w','w','w','w','w','w'},
{'w',' ',' ',' ',' ','w'},
{'w',' ',' ',' ',' ','w'},
{'w',' ',' ',' ',' ','w'},
{'w',' ',' ',' ',' ','w'},
{'w','w','w','w','w','w'},
};
for( i = 0; i<=19; i++)
{
printf("\n\n");
printf(" %c | %c | %c | %c | %c | %c |\n", island[0][0], island[0][1], island[0][2], island[0][3], island[0][4], island[0][5]);
printf("--------------------------\n");
printf(" %c | %c | %c | %c | %c | %c |\n", island[1][0], island[1][1], island[1][2], island[1][3], island[1][4], island[1][5]);
printf("--------------------------\n");
printf(" %c | %c | %c | %c | %c | %c |\n", island[2][0], island[2][1], island[2][2], island[2][3], island[2][4], island[2][5]);
printf("--------------------------\n");
printf(" %c | %c | %c | %c | %c | %c |\n", island[3][0], island[3][1], island[3][2], island[3][3], island[3][4], island[3][5]);
printf("--------------------------\n");
printf(" %c | %c | %c | %c | %c | %c |\n", island[4][0], island[4][1], island[4][2], island[4][3], island[4][4], island[4][5]);
printf("--------------------------\n");
printf(" %c | %c | %c | %c | %c | %c |\n", island[5][0], island[5][1], island[5][2], island[5][3], island[5][4], island[5][5]);
printf("--------------------------\n");
srand (time(NULL));
int i = 0;
while(i < 20)
{
int moves = rand() % 9 + 1;
}
}
}
My plan to simulate the creature hopping is to use a random number generator that randomly chooses a number between 0-8. Each number corresponds to the creature moving 1 space diagonally, vertically or to the sides. For example, 0 would correspond to the creature moving up to the left 1 would correspond to the creature moving up one space vertically etc. This would just correspond to a column and/or row change of 1. I wish to know how I can accomplish this. And I also wish to know how I can randomly generate a creature on the island.