「游戏」c++ 炸弹人2.0(新增人机)

博主分享了使用c++编程实现的经典炸弹人游戏的2.0版本,该版本新增了人机对战模式。尽管游戏中的人工智能角色表现简单,有时甚至会把自己困在炸弹中,但整体游戏体验有所提升。欢迎在评论区提出代码改进意见。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

终于,经历了千辛万苦,我终于写出了人机(一个ZZ,能把自己闷在炸弹堆里)…
这个代码打得有些仓促,有问题请在评论区留言。

经典模式(1.0)

C o d e Code Code

#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
#include <queue>
#include <utility>
using namespace std;

const int M = 1e3 + 5;
int wall[15][15] = {
   {
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{
   0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},{
   0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},{
   0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1},{
   0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},{
   0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1},{
   0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},{
   0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1},{
   0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1},{
   0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},{
   0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1},{
   0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},{
   0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1},{
   0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},{
   0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}};
int block[15][15] = {
   {
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{
   0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},{
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{
   0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0},{
   0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0},{
   0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0},{
   0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0},{
   0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0},{
   0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0},{
   0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0},{
   0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0},{
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{
   0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},{
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
int thing[M][M];
int num, start;
int last;

int wa[15][15] = {
   {
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{
   0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},{
   0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},{
   0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1},{
   0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},{
   0, 1, 0, 1, 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 0, 1, 0},{
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{
   0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},{
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};

void stop() {
   
	for (int i = 2; i <= 5; i ++) {
   
		system("pause");
	}
}

void put(char *p) {
   
    while(1) {
   
        if(*p != 0)
            printf("%c", *p ++);
        else
            break;
        Sleep(20);
    }
}

struct player{
   
	int x, y;
	int bown;
	int nom_bown;
	int time;
	int life;
	int fire;
}a[M];

struct bown{
   
	int x, y;
	int time;
	int from;
}b[M];

bool bow(int x, int y) {
   
	for(int i = start; i <= num && num != 0; i ++) {
   
		if(b[i].x == x && b[i].y == y) return true;
	}
	return false;
}

void put_map() {
   
	system("cls");
	for(int i = 0; i <= 15; i ++) {
   
		for(int j = 0; j <= 15; j ++) {
   
			if(a[1].x == i && a[1].y == j) printf("①");
			else if(a[2].x == i && a[2].y == j) printf("②");
			else if(a[3].x == i && a[3].y == j) 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值