Instance programming: Maze Pathfinder I

Source: Internet
Author: User
Tags manual int size

Ever heard of a maze of tricks: go along the side of the wall.

(Always along the left side or along the right side). This program has achieved this

Thought, the villain had been walking along the left.

The maze is randomly generated.

At the beginning, press the number 1 key to enter the manual control mode; Press W,s,

A,d respectively represents the upper, lower, left, and right directions.

At the beginning, press any key except the number 1 to enter the automatic mode;

The villain is controlled by the computer.

Press the Q key to end the program.

/*
Name:maze.c
Author:zhuqing
Description: Maze Adventure

date:28-08-03 10: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,int,int,int,int);
void Drawman (Int,int,int);
void rect (int,int,int,int);

void Main () {*/* Main () starts/*
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;};
}
Break
Case ' d ':
if (J<n-1&&bg[i][j 1]==0) {
if (x<639-step) {x =step;j;}
}
Break
Case ' W ':
if (i>0&&bg[i-1][j]==0) {
if (y>step) {y-=step;i--;}
}
Break
Default:break;
}
Drawman (X,y,len);
Delay (800);
if (i>=m-1&&j>=n-1) {
Settextstyle (4,0,3);
SetColor (RED);
Outtextxy (150,260, "you win!");
}
SetColor (white);
}
Closegraph ();
}/* Manual Control End * *


else{
/* Computer control *
/* Direc indicates the direction of the last move
/* and indicate the direction of the next move * *
* * 0~3, respectively, west, north, East, South * *

direc=2;
i=j=0;
while (i<m-1| | j<n-1) {
Delay (80000);
Drawman (X,y,len);
Switch (DIREC) {
Case 0:

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.