C++小游戏源代码,是的,你没有看错,没有代码我:奥里给干了它。

本文分享了三款C++小游戏的源代码,包括双人枪战多地图版、杀手小游戏和一款非同寻常的贪吃蛇游戏,每款游戏都有独特的玩法和体验。作者鼓励读者尝试并给予支持。
摘要由CSDN通过智能技术生成

当你看到这篇文章,请留下你的赞赞给一个害羞的初中生信心❤
我是个敢直爽的人,讨厌假标题,直接上代码
1.双人枪战多地图版(好玩到吃鸡蛋🙃):

#include <iostream>
#include <cstdio>
#include <windows.h>
#include <conio.h>
using namespace std;
int SIZ = 20;
HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord;
HANDLE hCon;
enum Color {
    DARKBLUE = 1, DARKGREEN, DARKTEAL, DARKRED, DARKPINK, DARKYELLOW, GRAY, DARKGRAY, BLUE, GREEN, TEAL, RED, PINK, YELLOW, WHITE };
void SetColor(Color c) {
   
    if (hCon == NULL)
        hCon = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hCon, c);
}
SYSTEMTIME sys;
//sys.wYear,sys.wMonth,sys.wDay,sys.wHour,sys.wMinute, sys.wSecond,sys.wMilliseconds,sys.wDayOfWeek
struct PLAYER {
   
    int x, y;
    int hp;
    int gun;
    int direct;
} p1, p2;
int map[1005][1005];
int abs(int x) {
   
    if (x < 0) return -x;
    return x;
}
void locate(int x, int y) {
   
    coord.X = y - 1;
    coord.Y = x - 1;
    SetConsoleCursorPosition(hout, coord);
}
void print_map() {
   
    locate(1, 1);
    SetColor(GRAY);
    for (int i = 1; i <= SIZ; i++) cout << "■";
    locate(SIZ, 1);
    for (int i = 1; i <= SIZ; i++) cout << "■";
    for (int i = 2; i < SIZ; i++) {
   
        locate(i, 1);
        cout << "■";
        locate(i, SIZ * 2 - 1);
        cout << "■";
    }
    locate(SIZ + 1, 1);
    SetColor(WHITE);
}
void create_tree(int x, int y) {
   
    map[x][y] = map[x + 1][y] = map[x - 1][y] = map[x][y + 1] = map[x][y - 1] = 2;
}
void use_map(int x) {
   
    if (x == 1) {
   
        SIZ = 20;
        SetColor(DARKGREEN);
        map[16][6] = map[15][6] = map[17][6] = map[16][7] = map[16][5] = map[14][13] = map[13][12] = map[13][13] = 2;
        for (int i = 2; i < SIZ; i++) {
   
            for (int j = 2; j < SIZ; j++) {
   
                if (map[i][j] == 2) {
   
                    locate(i, j * 2 - 1);
                    cout << "■";
                }
            }
        }
        SetColor(GRAY);
        for (int i = 5; i <= 15; i++) {
   
            map[i][i] = 1;
            locate(i, i * 2 - 1);
            cout << "■";
        }
        SetColor(WHITE);
    } else if (x == 2) {
   
        SIZ = 30;
        SetColor(GRAY);
        for (int i = 4; i <= 26; i++) {
   
            if (i == 13 || i == 14 || i == 15) continue;
            map[i][4] = map[4][i] = map[26][i] = map[i][26] = 1;
        }
        for (int i = 1; i <= SIZ; i++) {
   
            for (int j = 1; j <= SIZ; j++) {
   
                if (map[i][j] == 1) {
   
                    locate(i, j * 2 - 1);
                    cout << "■";
                }
            }
        }
        SetColor(DARKGREEN);
        for (int i = 10; i <= 20; i++) {
   
            if (i == 13 || i == 17) continue;
            map[i][10] = map[10][i] = map[20][i] = map[i][20] = 2;
        }
        create_tree(5, 5);
        create_tree(18, 18);
        for (int i = 1; i <= SIZ; i++) {
   
            for (int j = 1; j <= SIZ; j++) {
   
                if (map[i][j] == 2) {
   
                    locate(i, j * 2 - 1);
                    cout << "■";
                }
            }
        }
        SetColor(WHITE);
    }
}
void cleanbody(int x, int y);
void putbody(int x, int y, int z);
void player_init() {
   
    p1.hp = p2.hp = 300;
    p1.gun = p2.gun = 1;
    p1.direct = 4;
    p2.direct = 2;
    p1.x = 2;
    p1.y = 2;
    p2.x = SIZ - 1;
    p2.y = SIZ - 1;
    putbody(p1.x, p1.y, 1);
    putbody(p2.x, p2.y, 2);
}
void mapinit() {
   
    for (int i = 1; i <= SIZ; i++) {
   
        map[i][1] = map[1][i] = map[SIZ][i] = map[i][SIZ] = 1;
    }
}
void init() {
   
    printf("Use Which Map?\n");
    int x;
    cin >> x;
    system("cls");
    use_map(x);
    mapinit();
    print_map();
    player_init();
}
void putbody(int x, int y, int z) {
   
    if (z == 1) SetColor(BLUE);
    else if (z == 
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值