I have a project which is to design a came called Miensfeld.
In Miensfeld, the player, Timmy, is located on one side of a 8 by 10 cell area minefield. My task is to move Timmy safely through the minefield to get to the other side, earning points as he moves:
* Timmy is located in the first box at the top left corner
To move around in miensfeld, I would need to use the keyboard. I can move Timmy in any of the 8 directions from his current position by using the 8 keys surrounding the 'j' key:
So far, I've created the display module consisting of the game's layout (grid).
/* File: grid.c */
/* This program prints the grid for the minefield */
#include <stdio.h>
#include "rows.h"
#include "tfdef.h"
/*
#define DEBUG
*/
main()
{
/* Declare variables */
int row = 1;
int count = 0;
while(row <= 23)
{
/* Prints the first three tabs before each line */
printf("\t\t\t");
/* Check if it is a blue line */
if(row==1||row==2||row==4||row==5||row==7||row==8||row==10||row==11||row==13||row==14||row==16||row==17||row==19||row==20||row==22||row==23)
{
blue_row();
if(row==2) printf(" MINES");
if(row==16) printf(" SCORE");
}
/* Check if it is a pink line */
if(row==3||row==6||row==9||row==12||row==15||row==18||row==21)
{
pink_row();
if(row==9) printf(" FLAGS");
}
/* Prints a new line after each line */
printf("\n");
/* Increase the row by one */
row++;
}
}
/* File: rows.h */
#define BLUE(c) (((c)==1)||((c)==2)||((c)==4)||((c)==5)||((c)==7)||((c)==8)||((c)==10)||((c)==11)||((c)==13)||((c)==14)||((c)==16)||((c)==17)||((c)==19)||((c)==20)||((c)==22)||((c)==23))
#define PINK(c) (((c)==3)||((c)==6)||((c)==9)||((c)==12||((c)==15)||((c)==18)||((c)==21))
/* This function prints out the blue row */
void blue_row(void);
/* Given: nothing
* Returns: nothing
*/
/* This function prints out the pink row */
void pink_row(void);
/* Given: nothing
* Returns: nothing
*/
/* File: rows.c */
/* This program prints out a first attempt of the blue
* and pink rows. The rows are categorized as either
* blue, pink, green, or orange to differentiate
* between the different types of output it will produce. */
#include <stdio.h>
#include "rows.h"
#include "tfdef.h"
#define DEBUG
void blue_row(void)
{
/* Declare variables */
int count=0;
/* Print the tabs and '|' characters */
while(count < 10)
{
/* Print the three spaces */
printf(" ");
/* If less than 9 tabs have been
printed print the '|' character */
if(count < 9)
printf("|");
/* Increase the count by one */
count++;
}
return;
}
void pink_row(void)
{
/* Declare variable */
int count = 0;
while(count < 10)
{
/* Print the three '-' characters */
printf("---");
/* If less than 9 '---' characters have been printed */
if(count < 9)
printf("|");
/* Increase count by one */
count++;
}
return;
}
/* File: tfdef.h */
/* Header file defining true and false macros */
#define FALSE 0
#define TRUE 1
I am confused as to how I could get Timmy to move about in the minefield. My idea is to create an array and use if-else statements for each of the letters used to navigate Timmy, to move him about, over the grid. However, I have a feeling this would not work due to the format of the grid. Does anyone have any tips or suggestions? What would be the easiest way to do this?