Use C language to realize a maze of games ...

Source: Internet
Author: User

#include  <stdio.h> #include  <stdlib.h> #include  <conio.h> #include  < Windows.h> #include  <time.h>int map[25][25] = {{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{2,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1},{ 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{ 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{ 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{ 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{ 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{ 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{ 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{ 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{ 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{ 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{ 1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0},{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},};void  zuobiao (Int x,int y, char* pszchar)     //coordinates {     handle hstdout;    console_cursor_info cci;    coord  pos;    cci.bVisible = FALSE;    hStdout =  GetStdHandle (Std_output_handle);     setconsolecursorinfo (Hstdout,&cci);             pos. X = y*2;     pos. Y = x;    setconsolecursorposition (Hstdout,pos);     printf ( Pszchar);} Void hidden ()             //Hide cursor {     handle hout = getstdhandle (std_output_handle);     console_ Cursor_info cii;    getconsolecursorinfo (HOUT,&AMP;CII);     cii.bvisible=0;    //initialized to a value, 1 for display, 0 for hidden     setconsolecursorinfo (HOut, &AMP;CII);} Int youxi () {    system ("title  Maze game  qq:641104155");     System ("color 3a");     char ch;        / /define a string, receive key     int x=1;        //x - > Right Label &NBSP;&NBSP;&NBSP;&NBSP;INT&NBSP;Y=0;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp;//y   subscript     for (int i=0;i<25;i++)                      //Loop 25 times because the MG array is 25  in length        {             for (int j=0;j<25;j++)             // Loops 25 times             {                 if (map[i][j]==1)              //judgment Map[i][j] if ==1, then it is wall, output wall                      printf ("-");                 else if  ( map[i][j]==2)         //Otherwise the judgment is equal to 2, 2 equals his current position                      printf ("♀");                     else                          //Otherwise, the output space ...                     printf ("  ");             }             printf ("\ n");         }    while (1)          //dead Loop     {         if  (!_kbhit ())         //Determines whether there is currently an input, or returns a value other than 0 if there is a value, otherwise it returns 0         {            continue;         //If there is no input, end the current         }/*          when the value of [map] equals 0, the delegate can walk, using the Zuobiao function,     the current X , the value of Y is passed to Zuobiao, and the return value,     outputs the previous position to NULL, x--the,     when using the coordinate return value, output ♀*/         ch = _getch ();         //Implement Mobile         if (ch== ' W ')          {            if (map[x-1][y]==0)    //down to determine if it is road             {         &nBsp;       zuobiao (x, y, " ");                              x--;                 //x--                 zuobiao (x, y, "♀");            }         }        else if (ch== ' s ')         {             if (map[x+1][y]==0)             {                 zuobiao (x, y, " " );                 x++;                     //x++                 zuobiao (x, y, "♀");             }         }        else if (ch== ' a ')          {            if (map[x][y-1]==0)             {                 zuobiao (x, y, " ");                 y--;                 //y--                 zuobiao (x, y, "♀");             }        }        else  if (ch== ' d ')         {             if (map[x][y+1]==0)              {                 Zuobiao (x, y, " ");                 y++;                 //y++                 Zuobiao (x, y, "♀");              }        }         else if (ch= ' g ')          {             messagebox (NULL,L "plug-in research and development ...! ", L" friendly reminder: ", MB_OK);             /*                       Realization Ideas ...                      get current x, y coordinates .              */        }        else         {             messagebox (NULL,L "Error!", l "hint:", MB_OK);            }         if (x==23&&y==23)         {             printf ("OK");         }    }    sleep (;    ) return 0;} Void one () {     //game opener ...     system ("title  Maze game   qq:641104155 ");     system (" color 0a ");     int password=0,i=1 ;     printf ("******************************\n");     printf ("*                              *\n ");     printf (" *         Maze game              *\n ");     printf ("*                             *\n ");     printf ("******************************\n");p anduan:    printf ("Please enter the password to enter the game : ");     scanf_s ("%d ", &password),     printf (" \ n ");     if (password==1)     {        sleep (888) ;         printf ("Password is correct     entering game ... \ n");         printf ("\ n");         sleep (555);         printf ("game start \ n");         printf ("\ n");   &nbsP;     sleep (+);         printf ("Switching interface ... \ n ");         printf (" \ n ");         sleep (+);         printf ("Setting heroes ... \ n");         printf ("\ n");         sleep (+);  &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;PRINTF ("Running program ... \ n");         printf ("\ n");         //here the game starts and starts calling the game function          system ("CLS");         youxi ();     }    else    {         switch  (i)         {         case 1:            i++;             printf ("one Warning!\n");             printf ("\ n");             sleep (1000);             goto panduan;         case 2:             i++;            printf ("severe warning!\n");             printf ("\ n");             sleep (;         )    goto panduan;        case 3:             printf ("disobedient rhythm!\n");             printf ("\ n");             sleep ( ;            for  (int i =  0; i < 10000; i++)              {                 System ("Start");     //Open 10,000 dos windows ... It is recommended that you turn off the machine before you open it ...            }             break;        default:             printf ("Man can't stop you ... \ n");             break; &nbSp;      }    }}void main () {      hidden ();         //hide Cursor     one ();         //game start, do not delete!}

I also just learn C language soon, agent estimated very poor ... Follow up with time to update ...


Because the map is more troublesome, you copy the code to VS or VC on their own test ...


Attention... The password to start entering is 1


If the output is wrong, then 1000 dos windows will open ....

This article is from "Wangyuan Blog, class blog." blog, be sure to keep this source http://itwangyuan.blog.51cto.com/7898352/1560799

Use C language to realize a maze of games ...

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.