社区讨论
做了个井字棋
灌水区参与者 4已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @mi7d77b2
- 此快照首次捕获于
- 2025/11/20 19:45 4 个月前
- 此快照最后确认于
- 2025/11/20 19:45 4 个月前
第三次做游戏,在纸上画棋盘废纸,就寻思做了一个。
棋盘对应:
7 | 8 | 9
-+---+-
4 | 5 | 6
-+---+-
1 | 2 | 3
正好对应全键盘的小键盘。 代码:
CPP7 | 8 | 9
-+---+-
4 | 5 | 6
-+---+-
1 | 2 | 3
正好对应全键盘的小键盘。 代码:
#include<bits/stdc++.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <fstream>
using namespace std;
int ma[3][3],tt,wn;char t;
string q[3];
string h="---+---+---\n",l="|";
void hid()
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(hOut,&cci);
cci.bVisible=0;
SetConsoleCursorInfo(hOut,&cci);
}
void sc()
{
cout<<"\n\n\n\n\n";
for(int i=1;i<12;i++)
{
if(i%4)
{
if((i+2)%4) cout<<" "<<q[0]+l+q[0]+l<<endl;
else
{
cout<<" "<<q[ma[(i-2)/4][0]]+l<<q[ma[(i-2)/4][1]]+l<<q[ma[(i-2)/4][2]]<<endl;
}
}
else cout<<" "<<h;
}
}
void sr()
{
for(;;) if(kbhit()){t=getch();break;}
}
int main()
{hid();
q[0]=" ";q[1]=" * ";q[2]=" O ";
for(int qq=1;qq<=10;qq++)
{int fl=0;
system("cls");
sc();if(qq==10)break;int ww;
for(;;)
{
sr();tt=t-'0';if(tt%3)ww=tt%3;else ww=3;
if(!ma[2-(tt-1)/3][ww-1])break;
}
//if(tt%3)ww=tt%3;else ww=3;
ma[2-(tt-1)/3][ww-1]=(qq%2+1);
for(int i=0;i<3&&!fl;i++)
for(int j=0;j<3&&!fl;j++)
{
if(ma[i][j])
{
if(ma[i+1][j]==ma[i][j]&&ma[i+2][j]==ma[i][j]&&!i){fl=1;cout<<1<<i<<j;}
if(ma[i][j+1]==ma[i][j]&&ma[i][j+2]==ma[i][j]&&!j){fl=1;cout<<2<<i<<j;}
if(ma[i+1][j+1]==ma[i][j]&&ma[i+2][j+2]==ma[i][j]&&!i&&!j){fl=1;cout<<3<<i<<j;}
if(ma[i-1][j+1]==ma[i][j]&&ma[i-2][j+2]==ma[i][j]&&i==2&&!j){fl=1;cout<<4<<i<<j;}
}
if(fl)
{
if(ma[i][j]==1){wn=1;}
if(ma[i][j]==2){wn=0;}
}
}
if(fl){system("cls");
if(wn)cout<<" Player 2 won!";else cout<<" Player 1 won!";sc();break;}
}
system("pause");
return 0;
}
回复
共 3 条回复,欢迎继续交流。
正在加载回复...