制造字符游戏(1)

        最近我初学了C++,就想做游戏,但我不会啊…

        于是,我到网上疯狂搜教学,直到找到了这个:

C++ 字符跑酷#4 游戏制作实录_一块铌金属的博客-CSDN博客

        这……字符跑酷?(当时我脑子里想的是以为只靠print做出来的,然后就入坑了)

        太适合我了,二话不说,开搞!

        首先拿出我们亲爱的基础引擎~

#include <iostream>
#include <cstdio>
#include <conio.h>
#include <windows.h>
using namespace std;
int main(){



}

接着,那肯定是创建一个窗口啊用上我们的system("");函数

system("title 迷宫游戏");


    然后,就是迷宫了(我的画画技术不好)。

char a[100][100]={
        "#########################",
		"# I       #          #  #",
		"#      #                #",
		"###  ###  ######  ####  #",
		"#    ###  ##   #  #     #",                                      
		"## ####   #    #  #     #",                                      
		"#     #   ## #  ##      #",                                      
		"#########################",

接着,就是移动了,而且,这里不需要任何高端函数,简单的要命!

我写一段代码你们大概就明白了

ch=_getch();
        if(ch=='a'){
            if(a[x][y-1]!='#'){
                a[x][y]=' ';
                y--;
                a[x][y]='*';
            }
        }

看吧,如此简单!

接着,我把代码完善(此处省略)

然后,全部代码如下喽:



#include <iostream>
#include <cstdio>
#include <conio.h>
#include <windows.h>
using namespace std;
int main(){
    system("title 迷宫游戏");
    char a[100][100]={
        "#########################",
		"# I       #          #  #",
		"#      #                #",
		"###  ###  ######  ####  #",
		"#    ###  ##   #  #     #",                                      
		"## ####   #    #  #     #",                                      
		"#     #   ## #  ##      #",                                      
		"#########################",
    };
    for(int i=0;i<=10;i++)
        puts(a[i]);
    char ch;
    int x=1,y=1;
    while(1){
        ch=_getch();
        if(ch=='a'){
            if(a[x][y-1]!='#'){
                a[x][y]=' ';
                y--;
                a[x][y]='*';
            }
        }
        if(ch=='s'){
            if(a[x+1][y]!='#'){
                a[x][y]=' ';
                x++;
                a[x][y]='*';
            }
        }
        if(ch=='d'){
            if(a[x][y+1]!='#'){
                a[x][y]=' ';
                y++;
                a[x][y]='*';
            }
        }
        if(ch=='w'){
            if(a[x-1][y]!='#'){
                a[x][y]=' ';
                x--;
                a[x][y]='*';
            }
        }
        system("cls");
        for(int i=0;i<=10;i++)
            puts(a[i]);
    }
    return 0;
}
        

记得,点赞,收藏,关注,转发,一键三连!!!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值