/* HARRY GOES HOME By Stephen Smith (stevo@REMOVE-THIScarlyle-smith.demon.co.uk) Based on the Spectrum Game of the same name */ #include "stdio.h" #include "conio.h" #include "stdlib.h" #include "time.h" // Prototypes void setmap(void); void minecheck(void); void showmines(void); // variables int map[31][21]; int x,y,z; // reusable variable int hx,hy; //Harry's cords int diflevel; // Difficulty level int gotkey; void main(void) { clrscr(); randomize(); printf("Harry Goes Home by Stephen Smith (stevo@REMOVE-THIScarlyle-smith.demon.co.uk)\n\n"); printf("Please enter the difficulty level.\nThe lower the number, the harder it will be.\n"); scanf("%d",&diflevel); setmap(); do { minecheck(); x = getch(); gotoxy(hx+1,hy+1); printf("+"); if(x == 'q' && hy>1) { hy--; } if(x == 'a' && hy<20) { hy++; } if(x == 'o' && hx>1) { hx--; } if(x == 'p' && hx<30) { hx++; } gotoxy(hx+1,hy+1); printf("&"); if (map[hx][hy] == 2) { gotkey=1; gotoxy(3,25); printf("You've got the key!"); } if (map[hx][hy] == 1) { gotoxy(3,25); printf("You just walked into a mine!"); showmines(); exit(0); } } while (map[hx][hy]!=3 || gotkey==0); gotoxy(3,25); printf("You've completed the game!"); showmines(); exit(0); } void minecheck(void) { z=0; for(y=hy-1 ; y0 && y<21 && x>0 && x<31) { if (x!=hx && y!=hy) {} else { if (map[x][y]==1) { z++; } } } } } gotoxy(3,24); printf("There are %d mines next to you.",z); } void setmap(void) { for(y=1 ; y<21 ; y++) { for(x=1 ; x<31 ; x++) { z = random(diflevel); if(z == 0) { map[x][y] = 1; // mine } else { map[x][y] = 0; // no mine } } } map[random(31)][1] = 3; //the house map[random(20)+5][random(10)+5] = 2; //the key hx = random(20)+5; hy = 20; map[hx][hy] = 0; gotkey=0; clrscr(); gotoxy(1,1); printf("--------------------------------"); gotoxy(1,22); printf("--------------------------------"); for(y=2 ; y<22 ; y++) { gotoxy(1,y); printf("| |"); } for(y=1 ; y<21 ; y++) { for(x=1 ; x<31 ; x++) { gotoxy(x+1,y+1); switch(map[x][y]) { case 0: printf(" "); break; //nothing case 1: printf(" "); break; //mine case 2: printf("K"); break; //key case 3: printf("H"); break; //house default: printf(" "); break; } } } gotoxy(hx+1,hy+1); printf("&"); gotoxy(35,1); printf("Harry Goes Home"); gotoxy(35,2); printf("By Stephen Smith (stevo@REMOVE-THIScarlyle-smith.demon.co.uk)"); gotoxy(35,4); printf("Use qaop to move your man '&' to get the"); gotoxy(35,5); printf("key 'K' and then to his home 'H'. Nuff said."); gotoxy(35,7); printf("Oh yeah, avoid the mines!"); } void showmines(void) { for(y=1 ; y<21 ; y++) { for(x=1 ; x<31 ; x++) { gotoxy(x+1,y+1); switch(map[x][y]) { case 1: printf("m"); break; //mine default: printf(""); break; } } } }