Maze exploration

Source: Internet
Author: User
Tags manual int size

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 ++ ;};
        }

<

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.