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

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

用C++基础语句写一个五子棋游戏(这是一个颜色会变化的呦)

#include <iostream>
using namespace std;
int b[][];
int n;
int m;
void qipan()
{
system("cls");
int k = ;
for (int k = ;k < n;++k)
{
for (int j = ;j < m;++j)
{
cout << " ---- ";
}
cout << endl;
for (int i = ;i < n;++i)
{
for (int j = ;j < m;++j)
{
if (b[i][j] < && b[i][j] >= ) cout << "| " << << b[i][j] << " |";
else if (b[i][j] == -) cout << "| " << "█" << " |";
else if (b[i][j] == -) cout << "|" << " ○ " << "|";
else cout << "| " << b[i][j] << " |"; k++;
} cout << endl;
for (int j = ;j < m;++j)
{
cout << " ---- ";
}
cout << endl;
}
}
}
void success()
{
long time;
for (;;)
{
system("color a");
for (time = ; time < ; time++);
system("color b");
for (time = ; time < ; time++);
system("color c");
for (time = ; time < ; time++);
system("color d");
for (time = ; time < ; time++);
system("color e");
for (time = ; time < ; time++);
system("color f");
for (time = ; time < ; time++);
system("color 0");
for (time = ; time < ; time++);
system("color 1");
for (time = ; time < ; time++);
system("color 2");
for (time = ; time < ; time++);
system("color 3");
for (time = ; time < ; time++);
system("color 4");
for (time = ; time < ; time++);
system("color 5");
for (time = ; time < ; time++);
system("color 6");
for (time = ; time < ; time++);
system("color 7");
for (time = ; time < ; time++);
system("color 8");
for (time = ; time < ; time++);
system("color 9");
}
}
int main()
{
cout << "请选择你们想要的棋盘大小(棋盘的面积请不要大于100)" << endl;
cout << "棋盘的长:(推荐长度为10)" << endl;
cin >> m;
cout << "棋盘的宽:(推荐长度为10)" << endl;
cin >> n;
for (int i = ;i < n;++i)
{
for (int j = ;j < m;++j)
{
b[i][j] = i * m + j;
}
}
qipan();
while ()
{
int x;
cout << "请玩家一输入:" << endl;
cin >> x;
if (x == )
{
cout << "玩家一使用系统外挂" << endl;
cout << "游戏结束" << endl;
cout << "玩家一获胜" << endl;
success();
return ;
}
for (int i = ;i < n;++i)
{
for (int j = ;j < m;++j)
{
if (b[i][j] == x) b[i][j] = -;
}
}
for (int i = ;i < n;++i)
{
for (int j = ;j < m - ;++j)
{
if ((b[i][j] == - && b[i][j + ] == - && b[i][j + ] == - && b[i][j + ] == - && b[i][j + ] == -)
|| (b[i][j] == - && b[i + ][j] == - && b[i + ][j] == - && b[i + ][j] == - && b[i + ][j] == -)
|| (b[i][j] == - && b[i + ][j + ] == - && b[i + ][j + ] == - && b[i + ][j + ] == - && b[i + ][j + ] == -))
{
cout << "游戏结束" << endl;
cout << "玩家一获胜" << endl;
success();
return ;
}
else if (i >= && (b[i][j] == - && b[i - ][j + ] == - && b[i - ][j + ] == - && b[i - ][j + ] == - && b[i - ][j + ] == -))
{
cout << "游戏结束" << endl;
cout << "玩家一获胜" << endl;
success();
return ;
}
}
}
qipan();
cout << "请玩家二输入:" << endl;
cin >> x;
if (x == )
{
cout << "玩家二使用系统外挂" << endl;
cout << "游戏结束" << endl;
cout << "玩家二获胜" << endl;
success();
return ;
}
for (int i = ;i < n;++i)
{
for (int j = ;j < m;++j)
{
if (b[i][j] == x) b[i][j] = -;
}
}
qipan();
for (int i = ;i < n;++i)
{
for (int j = ;j < m - ;++j)
{
if ((b[i][j] == - && b[i][j + ] == - && b[i][j + ] == - && b[i][j + ] == - && b[i][j + ] == -)
|| (b[i][j] == - && b[i + ][j] == - && b[i + ][j] == - && b[i + ][j] == - && b[i + ][j] == -)
|| (b[i][j] == - && b[i + ][j + ] == - && b[i + ][j + ] == - && b[i + ][j + ] == - && b[i + ][j + ] == -))
{
cout << "游戏结束" << endl;
cout << "玩家二获胜" << endl;
success();
return ;
}
else if (i >= && (b[i][j] == - && b[i - ][j + ] == - && b[i - ][j + ] == - && b[i - ][j + ] == - && b[i - ][j + ] == -))
{
cout << "游戏结束" << endl;
cout << "玩家二获胜" << endl;
success();
return ;
}
}
} }
}
上一篇:linux搭建的LNMP环境下的mysql授权远程连接


下一篇:MD5加密