網站首頁 編程語言 正文
本文實例為大家分享了C++實現五子棋小游戲的具體代碼,供大家參考,具體內容如下
?(這是一個顏色會變化的呦)
#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 << "玩家一使用系統(tǒng)外掛" << 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 << "玩家二使用系統(tǒng)外掛" << 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;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
?
?
? ? }
}
原文鏈接:https://blog.csdn.net/WUHU648/article/details/108139362
相關推薦
- 2022-02-05 flask報錯:The method is not allowed for the requeste
- 2023-01-07 Flutter?Widget開發(fā)Shortcuts快捷鍵實例_Android
- 2022-08-30 android dialog懸浮和圓角
- 2022-07-03 C#常用數據結構之數組Array_C#教程
- 2022-02-09 linux下源碼包安裝的服務管理_Linux
- 2022-05-18 TypeScript中的函數和類你了解嗎_基礎知識
- 2022-07-29 Golang?統(tǒng)計字符串中數字字母數量的實現方法_Golang
- 2022-11-05 ASP.NET?MVC實現樹形導航菜單_實用技巧
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支