Maze exploration II

Source: Internet
Author: User


 

I made some improvements to "exploring the path of the Maze. The villain does not go back when walking,

That is, the same point is not repeated.

/* Crazymaze. c */
/* 2003-8-26 */
# Include <stdlib. h>
# Include <time. h>
# Include <math. h>
# Include <stdio. h>
# Include <graphics. h>
# Define N 22
# Define M 22
# Define MAXLEN 200;
Int bg [M] [N];
Struct square {
Int x;
Int y;
Int direc;
} P [200];
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, x0 = 0, y0 = 0;
Int I = 0, j = 0, k = 0, count = 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 (GREEN );
Outtextxy (60,120, "press key <1>: YOU ,");
Outtextxy (70,150, "other key: AUTOMATIC ");
Setcolor (WHITE );
X + = len; y + = len;
Drawman (x, y, len );
X0 = x; y0 = y;
If (ch = getch () = '1 '){
/* Manual control */
While (ch = getch ())! = 'Q '){
Delay (800 );
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 ++ ;};
}
Break;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.