zoukankan      html  css  js  c++  java
  • 简易迷宫游戏c++

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<cstdlib>
     5 #include<algorithm>
     6 #include<cstring>
     7 #include<ctime>
     8 #include<windows.h>
     9 #include<conio.h>
    10 #define tab system("cls")
    11 using namespace std;
    12 string a[101];
    13 int n=10,m=10,k,x=1,y=1;
    14 
    15 void out()
    16 {
    17     int i,j;
    18     for(i=1;i<=n;i++)
    19     {
    20         for(j=0;j<=m;j++)
    21         {
    22             cout<<a[i][j]<<" ";
    23         }
    24         cout<<endl;
    25     }
    26     return;
    27 }
    28 
    29 bool judge(int x,int y)
    30 {
    31     if(x<1||y<0)return 0;
    32     if(x>10||y>10)return 0;
    33     if(a[x][y]=='*')return 0;
    34     return 1;
    35 }
    36 
    37 int main()
    38 {
    39     int i,j;
    40     a[1]="*@*********";
    41     a[2]="* *   *   *";
    42     a[3]="* * * * * *";
    43     a[4]="* * * * * *";
    44     a[5]="* * * * * *";
    45     a[6]="* * * * * *";
    46     a[7]="* * * * * *";
    47     a[8]="* * * * * *";
    48     a[9]="*   *   * *";
    49     a[10]="********* *";
    50     out();
    51     char c;
    52     for(;;)
    53     {
    54         c=getch();tab;
    55         if(c=='w')
    56         {
    57             if(judge(x-1,y))
    58             {
    59                 swap(a[x-1][y],a[x][y]);
    60                 x--;
    61             }
    62         }
    63         if(c=='a')
    64         {
    65             if(judge(x,y-1))
    66             {
    67                 swap(a[x][y-1],a[x][y]);
    68                 y--;
    69             }
    70         }
    71         if(c=='s')
    72         {
    73             if(judge(x+1,y))
    74             {
    75                 swap(a[x+1][y],a[x][y]);
    76                 x++;
    77             }
    78         }
    79         if(c=='d')
    80         {
    81             if(judge(x,y+1))
    82             {
    83                 swap(a[x][y+1],a[x][y]);
    84                 y++;
    85             }
    86         }
    87         out();
    88         if(x==10&&y==9)
    89         {
    90             tab;
    91             cout<<"YOU WIN";
    92             Sleep(2000);
    93             getch();
    94             break;
    95         }
    96     }
    97     return 0;
    98 }
  • 相关阅读:
    python实现的列表操作
    python的静态方法
    python标准库学习2
    javascript继承原型继承的例子
    jQuery高亮显示文本中重要的关键字
    表格展开伸缩
    jQuery设计思想
    python标准库学习3
    python中的继承和抽象类的实现
    表格的变色问题
  • 原文地址:https://www.cnblogs.com/freedomchaser/p/5806923.html
Copyright © 2011-2022 走看看