码迷,mamicode.com
首页 > 编程语言 > 详细

用C++基础语句写一个五子棋游戏

时间:2020-07-20 13:04:49      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:turn   info   变化   外挂   namespace   玩家   ima   ios   long   

技术图片

 

 技术图片(这是一个颜色会变化的呦)

 

#include <iostream>
using namespace std;
int b[20][20];
int n;
int m;
void qipan()
{
    system("cls");
    int k = 1;
    for (int k = 0;k < n;++k)
    {
        for (int j = 0;j < m;++j)
        {
            cout << " ---- ";
        }
        cout << endl;
        for (int i = 0;i < n;++i)
        {
            for (int j = 0;j < m;++j)
            {
                if (b[i][j] < 10 && b[i][j] >= 0) cout << "| " << 0 << b[i][j] << " |";
                else if (b[i][j] == -1) cout << "| " << "" << " |";
                else if (b[i][j] == -2) cout << "|" << "" << "|";
                else cout << "| " << b[i][j] << " |";

                k++;
            }


            cout << endl;
            for (int j = 0;j < m;++j)
            {
                cout << " ---- ";
            }
            cout << endl;
        }
    }
}
void success()
{
    long time;
    for (;;)
    {
        system("color a");
        for (time = 0; time < 99999999; time++);
        system("color b");
        for (time = 0; time < 99999999; time++);
        system("color c");
        for (time = 0; time < 99999999; time++);
        system("color d");
        for (time = 0; time < 99999999; time++);
        system("color e");
        for (time = 0; time < 99999999; time++);
        system("color f");
        for (time = 0; time < 99999999; time++);
        system("color 0");
        for (time = 0; time < 99999999; time++);
        system("color 1");
        for (time = 0; time < 99999999; time++);
        system("color 2");
        for (time = 0; time < 99999999; time++);
        system("color 3");
        for (time = 0; time < 99999999; time++);
        system("color 4");
        for (time = 0; time < 99999999; time++);
        system("color 5");
        for (time = 0; time < 99999999; time++);
        system("color 6");
        for (time = 0; time < 99999999; time++);
        system("color 7");
        for (time = 0; time < 99999999; time++);
        system("color 8");
        for (time = 0; time < 99999999; time++);
        system("color 9");
    }
}
int main()
{
    cout << "请选择你们想要的棋盘大小(棋盘的面积请不要大于100)" << endl;
    cout << "棋盘的长:(推荐长度为10)" << endl;
    cin >> m;
    cout << "棋盘的宽:(推荐长度为10)" << endl;
    cin >> n;
    for (int i = 0;i < n;++i)
    {
        for (int j = 0;j < m;++j)
        {
            b[i][j] = i * m + j;
        }
    }
    qipan();
    while (1)
    {
        int x;
        cout << "请玩家一输入:" << endl;
        cin >> x;
        if (x == 648)
        {
            cout << "玩家一使用系统外挂" << endl;
            cout << "游戏结束" << endl;
            cout << "玩家一获胜" << endl;
            success();
            return 0;
        }
        for (int i = 0;i < n;++i)
        {
            for (int j = 0;j < m;++j)
            {
                if (b[i][j] == x) b[i][j] = -1;
            }
        }
        for (int i = 0;i < n;++i)
        {
            for (int j = 0;j < m - 4;++j)
            {
                if ((b[i][j] == -1 && b[i][j + 1] == -1 && b[i][j + 2] == -1 && b[i][j + 3] == -1 && b[i][j + 4] == -1)
                    || (b[i][j] == -1 && b[i + 1][j] == -1 && b[i + 2][j] == -1 && b[i + 3][j] == -1 && b[i + 4][j] == -1)
                    || (b[i][j] == -1 && b[i + 1][j + 1] == -1 && b[i + 2][j + 2] == -1 && b[i + 3][j + 3] == -1 && b[i + 4][j + 4] == -1))
                {
                    cout << "游戏结束" << endl;
                    cout << "玩家一获胜" << endl;
                    success();
                    return 0;
                }
                else if (i >= 4 && (b[i][j] == -1 && b[i - 1][j + 1] == -1 && b[i - 2][j + 2] == -1 && b[i - 3][j + 3] == -1 && b[i - 4][j + 4] == -1))
                {
                    cout << "游戏结束" << endl;
                    cout << "玩家一获胜" << endl;
                    success();
                    return 0;
                }
            }
        }
        qipan();
        cout << "请玩家二输入:" << endl;
        cin >> x;
        if (x == 648)
        {
            cout << "玩家二使用系统外挂" << endl;
            cout << "游戏结束" << endl;
            cout << "玩家二获胜" << endl;
            success();
            return 0;
        }
        for (int i = 0;i < n;++i)
        {
            for (int j = 0;j < m;++j)
            {
                if (b[i][j] == x) b[i][j] = -2;
            }
        }
        qipan();
        for (int i = 0;i < n;++i)
        {
            for (int j = 0;j < m - 4;++j)
            {
                if ((b[i][j] == -2 && b[i][j + 1] == -2 && b[i][j + 2] == -2 && b[i][j + 3] == -2 && b[i][j + 4] == -2)
                    || (b[i][j] == -2 && b[i + 1][j] == -2 && b[i + 2][j] == -2 && b[i + 3][j] == -2 && b[i + 4][j] == -2)
                    || (b[i][j] == -2 && b[i + 1][j + 1] == -2 && b[i + 2][j + 2] == -2 && b[i + 3][j + 3] == -2 && b[i + 4][j + 4] == -2))
                {
                    cout << "游戏结束" << endl;
                    cout << "玩家二获胜" << endl;
                    success();
                    return 0;
                }
                else if (i >= 4 && (b[i][j] == -2 && b[i - 1][j + 1] == -2 && b[i - 2][j + 2] == -2 && b[i - 3][j + 3] == -2 && b[i - 4][j + 4] == -2))
                {
                    cout << "游戏结束" << endl;
                    cout << "玩家二获胜" << endl;
                    success();
                    return 0;
                }
            }
        }


    }
}

 

用C++基础语句写一个五子棋游戏

标签:turn   info   变化   外挂   namespace   玩家   ima   ios   long   

原文地址:https://www.cnblogs.com/liushipeng648/p/13344331.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!