I have heard of a secret about the Maze: walking along one side of the wall.
(Always along the left or right side ). This program implements this
Thought, the villain keeps walking along the left side.
The maze is randomly generated.
At the beginning, press the number 1 to enter the manual control mode; press w, s,
A and d represent the upper, lower, left, and right directions respectively.
At the beginning, press any key other than number 1 to enter the automatic mode;
The villain is controlled by a computer.
Press the Q key to end the program.
/*
Name: maze. c
Author: zhuqing
Description: maze adventure
Date: 28-08-03: 15
Copyright:
*/
# Include <stdlib. h>
# Include <time. h>
# Include <math. h>
# Include <stdio. h>
# Include <graphics. h>
# Define N 22
# Define M 22
Int bg [M] [N];
Void makebg (int, int );
Void drawbg (int [] [], int );
Void drawman (int, int, int );
Void rect (int, int );
Void main () {/* main () start */
Int step = 20;
Int len = 10;
Int size = 20;
Int x = 0, y = 0;
Int I = 0, j = 0;
Int gdriver = DETECT, gmode;
Char ch;
Int direc;
Makebg (M, N );
/* Registerbgidriver (EGAVGA_driver );*/
/* Initgraph (& gdriver, & gmode, "c: \ turboc2 ");*/
Initgraph (& gdriver, & gmode, "c: \ tc20 \ bgi ");
Cleardevice ();
Setwritemode (XOR_PUT );
Settextstyle (1, 0, 3 );
Setcolor (GREEN );
Outtextxy (100,180, "Press <Q> to quit ");
Setcolor (BLUE );
Setfillstyle (LINE_FILL, BLUE );
Drawbg (bg, M, N, size, 0, 0 );
Setcolor (WHITE );
X + = len; y + = len;
Drawman (x, y, len );
Setcolor (GREEN );
Outtextxy (60,120, "press key <1>: YOU ,");
Outtextxy (70,150, "other key: AUTOMATIC ");
Setcolor (WHITE );
If (ch = getch () = '1 '){
/* Manual control */
While (ch = getch ())! = 'Q '){
Drawman (x, y, len );
Switch (ch ){
Case 'a ':
If (j> 0 & bg [I] [j-1] = 0 ){
If (x> step) {x-= step; j --;};
}
Break;
Case's ':
If (I <M-1 & bg [I + 1] [j] = 0 ){
If (y <479-step) {y + = step; I ++ ;};
}
<