1.狼人杀:
#include <iostream>//C++输入输出流库
#include <cstdlib>//使用srand函数要用到这个库
#include <ctime>//使用time函数要用到这个库
#include <Windows.h>
#include <conio.h>
using namespace std;
void brc()
{
system("cls");
int jy=1;
int sy=3;
srand((int)time(0));
int n=rand()%15+1;
cout<<" 你是"<<n<<"号"<<endl;
cout<<" 正在分配身份"<<endl;
Sleep(1500);
int m[20];
for(int i=1;i<=15;i++)
m[i]=1;
int s[20]={0};
int yy[20]={0};
int l=0,w=0,j=0,p=0;
for(int i=1;i<=15;i++)
{
do
{
int a=rand()%4+1;
if(a==1&&l<2)
{
l++;
s[i]=1;
}
else if(a==2&&w<2)
{
w++;
s[i]=2;
}
else if(a==4&&p<1)
{
p++;
s[i]=4;
}
else if(a==3&&j<10)
{
j++;
s[i]=3;
}
}
while(s[i]==0);
}
if(s[n]==1)
cout<<" 你是>>杀手<<"<<endl;
else if(s[n]==2)
cout<<" 你是>>预言家<<"<<endl;
else if(s[n]==3)
cout<<" 你是>>平民<<"<<endl;
else
cout<<" 你是>>女巫<<"<<endl;
cout<<" 游戏将在5秒后开始"<<endl;
Sleep(5000);
int c=15;
int f=0,flag=0;
int day=1;
int lr;
int tp[20]={0};
do
{
lr=0;
system("cls");
cout<<" 第"<<day<<"晚开始"<<endl;
int x;
for(int i=1;i<=15;i++)
{
if(i==n&&m[n]==1)
{
if(s[n]==1)
{
cout<<" 你是杀手"<<endl;
for(int j=1;j<=15;j++)
if(m[j]==1&&s[j]!=1)
cout<<j<<" ";
cout<<endl;
cout<<" 你选择杀掉"<<endl;
int a;
cin>>a;
m[a]=0;
cout<<endl;
cout<<" 杀手杀了"<<a<<"号";
if(s[a]==1)
cout<<"(杀手)"<<endl;
else if(s[a]==2)
cout<<"(预言家)"<<endl;
else if(s[a]==3)
cout<<"(平民)"<<endl;
else
cout<<"(女巫)"<<endl;
c--;
}
else if(s[n]==2)
{
cout<<" 你是预言家"<<endl;
cout<<" ";
for(int j=1;j<=15;j++)
if(m[j]==1)
cout<<j<<" ";
cout<<endl;
cout<<" 你选择预言谁的身份"<<endl;
int a;
cin>>a;
if(s[a]==1)
{
cout<<" "<<a<<"号是杀手,请注意"<<endl;
Sleep(1000);
}
else
cout<<" "<<a<<"号是平民"<<endl;
}
}
else if(s[i]==1&&m[i]==1)
{
int a;
do
{
a=rand()%15+1;
}
while(a==i||m[a]==0||s[a]==1);
cout<<" 杀手杀掉了"<<a<<"号";
if(s[a]==1)
cout<<"(杀手)"<<endl;
else if(s[a]==2)
cout<<"(预言家)"<<endl;
else if(s[a]==3)
cout<<"(平民)"<<endl;
else
cout<<"(女巫)"<<endl;
m[a]=0;
c--;
}
else if(s[i]==2)
{
if(flag==0||m[flag]==0)
{
int a;
do
{
a=rand()%15+1;
}
while(a==i||m[a]==0);
if(s[a]==1)
yy[a]=1;
else if(s[a]==3)
yy[a]=3;
}
}
else if(s[i]==4)
{
f=0;
while(f==0)
{
int a;
a=rand()%2+1;
if(a==1)
{
if(sy>0)
{
sy--;
f=1;
int b;
do
{
b=rand()%15+1;
b=rand()%15+1;
}
while(b==i||m[b]==0);
m[b]=0;
cout<<" 女巫毒死了"<<b<<"号";
if(s[b]==1)
cout<<"(杀手)"<<endl;
else if(s[b]==2)
cout<<"(预言家)"<<endl;
else if(s[b]==3)
cout<<"(平民)"<<endl;
c--;
}
}
else if(a==2&&day>1)
{
if(jy>0)
{
jy--;
f=1;
int b;
do
{
b=rand()%15+1;
}
while(b==i||m[b]==1);
c++;
cout<<" 女巫复活了"<<b<<"号"<<endl;
m[b]=1;
}
}
}
}
}
if(s[n]==4)
{
cout<<" 你是女巫"<<endl;
cout<<"存活状况:"<<endl;
for(int j=1;j<=15;j++)
if(m[j]==1)
cout<<j<<" ";
cout<<endl;
cout<<" 你选择 1.* 杀 *还是 2.* 救 *"<<endl;
int a,f=0;
while(f==0)
{
cin>>a;
if(a==1)
{
if(sy>0)
{
sy--;
f=1;
cout<<" 你选择了杀人"<<endl;
for(int i=1;i<=15;i++)
if(m[i]==1)
cout<<i<<" ";
cout<<endl;
int b;
cin>>b;
if(s[b]==1)
cout<<"(杀手)"<<endl;
else if(s[b]==2)
cout<<"(预言家)"<<endl;
else if(s[b]==3)
cout<<"(平民)"<<endl;
else
cout<<"(女巫)"<<endl;
m[b]=0;
c--;
}
else
{
cout<<">>毒药<<不足"<<endl;
}
}
else if(a==2)
{
if(jy>0)
{
jy--;
f=1;
cout<<"你选择了复活"<<endl;
cout<<"阵亡名单:"<<endl;
for(int i=1;i<=15;i++)
if(m[i]==0)
cout<<i<<"号,身份:"<<s[i]<<" "<<endl;;
int b;
cin>>b;
m[b]=1;
c++;
}
else
{
cout<<">>复活药水<<不足"<<endl;
}
}
}
}
Sleep(1000);
double p[20]={0};
cout<<" 第"<<day<<"晚结束"<<endl;
cout<<endl;
if(m[n]==0)
{
cout<<" 你已经>>死<<了";
break;
}
cout<<" 存活:"<<endl;
cout<<" ";
for(int i=1;i<=15;i++)
if(m[i]==1)
cout<<i<<" ";
cout<<endl;
cout<<" 请投票...."<<endl;
for(int i=1;i<=15;i++)
{
if(i==n&&m[n]==1)
{
cout<<endl;
cout<<" 你选择投几号"<<endl;
int a=99;
while(a==99)
{
cin>>a;
if(a==99)
for(int i=1;i<=15;i++)
if(m[i]==1)
cout<<" "<<i<<"."<<s[i]<<endl;
}
if(s[i]==3&&day>4)
p[a]+=1.5;
else
p[a]++;
cout<<endl;
cout<<" "<<i<<"->"<<a<<endl;
if(s[a]==3)
{
tp[a]=i;
}
}
else if(s[i]==1&&m[i]==1)
{
int a;
do
{
a=rand()%15+1;
}
while(m[a]==0||a==i||s[a]==1);
p[a]++;
cout<<" "<<i<<"->"<<a<<endl;
if(s[a]==3)
{
tp[a]=i;
}
}
else if(s[i]==2&&m[i]==1)
{
if(flag!=0)
{
p[f]++;
cout<<" "<<i<<"->"<<flag<<endl;
}
else
{
int a;
do
{
a=rand()%15+1;
}
while(m[a]==0||a==i||yy[a]==3);
p[a]++;
if(s[a]==3)
{
tp[a]=i;
}
cout<<" "<<i<<"->"<<a<<endl;
}
}
else if(s[i]==3&&m[i]==1)
{
if(tp[i]==0)
{
int a;
do
{
a=rand()%15+1;
}
while(m[a]==0||a==i);
p[a]++;
cout<<" "<<i<<"->"<<a<<endl;
}
else
{
if(m[tp[i]]==1)
{
p[tp[i]]++;
cout<<" "<<i<<"->"<<tp[i]<<endl;
}
else
{
int a;
do
{
a=rand()%15+1;
}
while(m[a]==0||a==i);
p[a]++;
cout<<" "<<i<<"->"<<a<<endl;
}
}
}
else if(s[i]==4&&m[i]==1)
{
int a;
do
{
a=rand()%15+1;
}
while(m[a]==0||a==i);
p[a]++;
cout<<" "<<i<<"->"<<a<<endl;
}
}
system("cls");
cout<<" 投票情况:"<<endl;
for(int i=1;i<=15;i++)
if(m[i]==1)
cout<<" "<<i<<"号"<<" 票数:"<<p[i]<<endl;
int sw,max=-100;
for(int i=1;i<=15;i++)
{
if(p[i]>max)
{
sw=i;
max=p[i];
}
}
m[sw]=0;
cout<<" "<<sw<<"死了"<<endl;
c--;
cout<<" "<<sw<<"号的身份是";
if(s[sw]==1)
cout<<"杀手"<<endl;
else if(s[sw]==2)
cout<<"预言家"<<endl;
else if(s[sw]==3)
cout<<"平民"<<endl;
else
cout<<"女巫"<<endl;
day++;
if(s[n]!=1)
{
for(int i=1;i<=15;i++)
if(s[i]==1&&m[i]==1)
lr=1;
}
else
{
if(s[n]==1&&c==2)
lr=0;
}
system("pause");
cout<<endl;
}
while(m[n]==1&&c>1);
cout<<" 游戏结束"<<endl;
}
int main()
{
srand((int)time(0));
char a='1';
while(1)
{
system("cls");
cout<<" 杀手游戏"<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<" 1.开始游戏"<<endl;
cout<<" 2.查看游戏规则"<<endl;
a=getch();
if(a=='1')
{
cout<<" 1. 15人场"<<endl;
cout<<" 2. 30人娱乐战(10猎人)<敬请期待>"<<endl;
a='2';
while(a=='2')
{
a=getch();
switch(a)
{
case '1':
brc();
break;
}
if(a=='1')
break;
}
if(a=='1')
break;
}
else if(a=='2')
{
cout<<"杀手:每当晚上的时候可使用杀人权杀掉一人"<<endl;//1
cout<<"预言家:每天晚上可以知道一个人的身份"<<endl;//2
cout<<"平民:无技能,当玩家是平民时,在第5天拥有1.5票的投票权"<<endl;//3
cout<<"猎人:此身份仅限于30人娱乐局中,死亡后可带走一人"<<endl;
cout<<"投票细则:\n游戏中除了你以外全是由超级AI人工代替"<<endl;
cout<<"杀手不会杀掉朋友,但不包括投票环节"<<endl;
cout<<"预言家如果预言到杀手将一直对他投票,如果预言到平民将永远不会对他投票"<<endl;
cout<<"平民将投上一个晚上对他投票他的人"<<endl;
cout<<"********利用好超级AI游戏规则找出杀手**********"<<endl;
system("pause");
}
}
return 0;
}
/*
————————————————
版权声明:本文为CSDN博主「小小小小小小小小小小小小小虾」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/chg__262523/article/details/102979551
*/
2.飞机大战:
#include<iostream>
#include<cstdlib>
#include<conio.h>
#include<windows.h> // gotoxy 和HideCursor的头文件
using namespace std;
int sizex=50;//空间的宽
int sizey=40;//空间的高度;
int plane_x=sizex/2;//飞机的位置x,y;
int plane_y=sizey/2;
int gunx=0,guny=0;
int speed=0;
int score=0;
int dp_x=rand()%sizex,dp_y=0; //敌机位置
char ss;//输入按键;
void notin();
void in();
void gotoxy(int x,int y) //清屏,屏幕不抖动
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X=x;
pos.Y =y;
SetConsoleCursorPosition(handle,pos);
}
void HideCursor() //隐藏光标;
{
CONSOLE_CURSOR_INFO cursor_info={1,0};//第二个值为0 表示隐藏光标
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
void show()//初始化显示
{
gotoxy(0,0) ;
HideCursor() ;
for(int y=1;y<=sizey;++y)
{ for(int x=1;x<=sizex;++x)
{
if(x==plane_x&&y==plane_y)
{
cout<<"*" ;
}
else if(x==gunx&&y==guny)
{
cout<<"|";
}
else if(x==dp_x&&y==dp_y)
{
cout<<"&" ;
}
else
{
cout<<" ";
}
}
cout<<endl;
}
cout<<"得分:"<<score;
}
void in()
{//和输入有关的
if(kbhit())
{
ss=getch();
switch(ss)
{
case'w': if(plane_y>1)plane_y--;break; //控制方向同时设置边界
case's': if(plane_y<sizey)plane_y++;break;
case'a': if(plane_x>1)plane_x--;break;
case'd': if(plane_x<sizex)plane_x++;break;
case' ': gunx=plane_x,guny=plane_y-1;break;
}
}
}
void notin()
{//和输入无关的;
if(guny!=0)
{
guny--;
}
if(speed<5) //把敌机来临的速度变成子弹飞行的1/5倍
speed++;
if(speed==5)
{
if(dp_y<sizey)
{
dp_y++;
speed=0;
}
if(dp_y==sizey)
{
dp_y=0;
dp_x=rand()%sizex;//改变生成的敌机位
speed=0;
}
}
if(gunx==dp_x&&guny==dp_y)
{
dp_y=0;
guny=-1 ;
dp_x=rand()%sizex; //当击中敌机
score++;
}
}
int main()
{
while(1)
{
show();
notin();
in() ;
}
return 0;
}
/*
————————————————
版权声明:本文为CSDN博主「艾上克」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_45337491/article/details/106559141
*/
3.汉诺塔:
#include <bits/stdc++.h>
#include <conio.h>
#include <windows.h>
using namespace std;
const int COLUMN[4] = { 0, 2, 5, 8 };
const int DISC_CNT_MAX = 10;
const int ROW_OP_CNT = 2, COL_OP_CNT = 16;
const int ROW_MESSAGE = 3, COL_MESSAGE = 16;
const int ROW_HELP = 15, COL_HELP = 1;
const int ROW_MAX = 30, COL_MAX = 120;
const int BLUE = 1;
const int GREEN = 2;
const int CYAN = 3;
const int AQUA = 3;
const int RED = 4;
const int PURPLE = 5;
const int YELLOW = 6;
const int WHITE = 7;
int n;
stack<int> rod[4];
int sz[4] = { 0 };
int pos1, pos2;
int key;
bool prev_key_is_esc;
int op_cnt;
bool is_moving;
int moved_disc;
template <typename T>
inline T read() {
T x = 0;
T multiplier = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') {
multiplier = -1;
}
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch & 15);
ch = getchar();
}
return x * multiplier;
}
void set_caret_pos(int row = 1, int col = 1) {
COORD pos;
pos.X = col - 1;
pos.Y = row - 1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
int get_caret_row() {
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
return info.dwCursorPosition.Y + 1;
}
int get_caret_col() {
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
return info.dwCursorPosition.X + 1;
}
pair<int, int> get_caret_pos() {
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
return make_pair(info.dwCursorPosition.Y + 1, info.dwCursorPosition.X + 1);
}
void set_foreground_color(int x, bool intensity = false) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
x | (intensity << 3));
}
void set_cursor_visibility(bool visibility = true) {
CONSOLE_CURSOR_INFO cc_info;
cc_info.bVisible = visibility;
cc_info.dwSize = 1;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cc_info);
}
void disp_init_state(int n) {
for (int i = 1; i <= n; i++) {
set_caret_pos(i, COLUMN[1]);
printf("%d", i);
}
for (int i = 1; i <= 3; i++) {
set_caret_pos(n + 1, COLUMN[i] - 1);
printf("---");
set_caret_pos(n + 2, COLUMN[i]);
putchar('A' + i - 1);
}
set_caret_pos(ROW_OP_CNT, COL_OP_CNT);
printf("0");
}
void disp_help() {
set_caret_pos(ROW_HELP, COL_HELP);
printf("How to play:\n"
"The numbers indicate the size of discs.\n"
"Discs on each rod must be stacked in ascending order of size.\n"
"Use left and right arrow keys to select rod.\n"
"Press Enter to pick up the top disc on selected rod.\n"
"Then use left and right keys to move.\n"
"Press ESC to cancel current move.\n"
"Press Enter again to drop the disc on current rod.\n"
"Press R to restart.\n"
"Press ESC twice to quit.\n");
}
void disp_pos(int pos1, int pos2 = 0) {
for (int i = 1; i <= 3; i++) {
set_caret_pos(n + 3, COLUMN[i]);
printf(" ");
}
set_caret_pos(n + 3, COLUMN[pos1]);
printf("^");
if (pos2) {
set_caret_pos(n + 3, COLUMN[pos2]);
set_foreground_color(GREEN, true);
printf("^");
set_foreground_color(WHITE);
}
}
void clear() {
for (int i = 1; i <= DISC_CNT_MAX + 3; i++) {
for (int j = 1; j <= COL_MAX; j++) {
set_caret_pos(i, j);
putchar(' ');
}
}
}
void moving_disc(int pos1, int pos2) {
int x = rod[pos1].top();
set_caret_pos(n + 1 - sz[pos1], COLUMN[pos1]);
set_foreground_color(RED, true);
printf("%d", x);
set_foreground_color(WHITE);
set_caret_pos(n - sz[pos2] + (pos1 == pos2), COLUMN[pos2]);
set_foreground_color(GREEN, true);
printf("%d", x);
set_foreground_color(WHITE);
}
void update_discs(int pos1, int pos2) {
int x = rod[pos1].top();
set_caret_pos(n + 1 - sz[pos1], COLUMN[pos1]);
printf(" ");
rod[pos1].pop();
sz[pos1]--;
rod[pos2].push(x);
sz[pos2]++;
set_caret_pos(n + 1 - sz[pos2], COLUMN[pos2]);
printf("%d", x);
}
void remove_temp_disc(int pos) {
set_caret_pos(n - sz[pos], COLUMN[pos]);
printf(" ");
}
void update_op_cnt() {
op_cnt++;
set_caret_pos(ROW_OP_CNT, COL_OP_CNT);
printf("%d", op_cnt);
}
int main() {
printf("Enter the number of discs (not exceeding %d): ", DISC_CNT_MAX);
n = min(read<int>(), DISC_CNT_MAX);
set_cursor_visibility(false);
disp_help();
for (; n <= DISC_CNT_MAX; n++) {
clear();
for (int i = 1; i <= 3; i++) {
while (!rod[i].empty()) {
rod[i].pop();
}
sz[i] = 0;
}
for (int i = n; i >= 1; i--) {
rod[1].push(i);
}
sz[1] = n;
is_moving = false;
pos1 = 1;
op_cnt = 0;
prev_key_is_esc = false;
disp_init_state(n);
disp_pos(1);
while (true) {
if (sz[3] == n) {
set_caret_pos(ROW_MESSAGE, COL_MESSAGE);
if (op_cnt != (1 << n) - 1) {
printf("Congratulations! You completed the puzzle in %d "
"moves.",
op_cnt);
} else {
printf("Congratulations! You completed the puzzle in a "
"minimum number of moves.");
}
Sleep(2000);
break;
}
key = getch();
if (key == 224) {
key = getch();
if (!is_moving) {
if (key == 75) { // Left arrow key
pos1 = (pos1 + 1) % 3 + 1;
} else if (key == 77) { // Right arrow key
pos1 = pos1 % 3 + 1;
}
disp_pos(pos1);
} else {
remove_temp_disc(pos2);
if (key == 75) { // Left arrow key
pos2 = (pos2 + 1) % 3 + 1;
} else if (key == 77) { // Right arrow key
pos2 = pos2 % 3 + 1;
}
moving_disc(pos1, pos2);
disp_pos(pos1, pos2);
}
} else if (key == 13) { // Enter key
if (!is_moving) {
if (rod[pos1].empty()) {
continue;
}
is_moving = true;
moved_disc = rod[pos1].top();
pos2 = pos1;
moving_disc(pos1, pos2);
disp_pos(pos1, pos2);
} else {
if (!rod[pos2].empty() && rod[pos2].top() < moved_disc) {
set_caret_pos(ROW_MESSAGE, COL_MESSAGE);
printf("Error: discs not stacked in ascending order on "
"current rod.");
continue;
}
is_moving = false;
update_discs(pos1, pos2);
update_op_cnt();
pos1 = pos2;
disp_pos(pos1);
}
} else if (key == 27) { // Escape key
if (prev_key_is_esc) { // Double ESC
break;
}
if (is_moving) {
is_moving = false;
remove_temp_disc(pos2);
update_discs(pos1, pos1);
disp_pos(pos1);
} else {
prev_key_is_esc = true;
}
} else if (key == 'R' || key == 'r') {
n--;
break;
}
}
if (prev_key_is_esc && key == 27) { // Double ESC
break;
}
}
set_caret_pos(ROW_MAX - 1, 1);
return 0;
}
4.草原战争:
//感觉解释不全,很难玩
#include <bits/stdc++.h> //WEWILLFINDYOUANDHANTYOU
#include <windows.h> //GETYOUANDKILLYOUEATYOU!
#include <conio.h>
using namespace std;
int t,g[15][15],h;
int xf=1,yf=1,hf=10,ff=1,gf=1;
int xs=12,ys=12,hs=10,fs=0,gs=1;
int xt,yt,xln,yln,fx[]={-1,1,0,0},fy[]={0,0,-1,1};
int dp[15][15][15][15],cd;
bool bt,bl,bn,bs;
string st="▓",f[4]={"↑","↓","←","→"},s;
string gz=" <( 操作方法 )>\n1.A 用w a s d移动, 按x键攻击.\n2.B 用u h j k移动, 按n键攻击.\n";
void col(int c1,int c2,string c){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c1*16+c2);
cout<<c;
} void HideCursor(){
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
} int makeg(int k){
if(k<=600) return 0;//荒原
if(k<=690) return 1;//草地
if(k<=780) return 2;//沼泽
if(k<=870) return 3;//冰川
if(k<=980) return 4;//废墟
if(k<=986) return 5;//小炮
if(k<=988) return 6;//大炮
if(k<=991) return 7;//穿透枪
if(k<=992) return 8;// 弹炮
if(k<=997) return 9;//火矢
if(k<=999) return 10;//脉冲枪
if(k<=1000) return 11;//手榴弹
} void make(){
int i=14,j;
col(cd,7,"");
while(i--) cout<<st;
cout<<endl;
for(i=1;i<=12;i++){
col(cd,7,st);
for(j=1;j<=12;j++){
if(i==xf&&j==yf) col(10,2,f[ff]);
else if(i==xs&&j==ys) col(12,4,f[fs]);
else if(g[i][j]==4) col(cd,7,st);
else if(g[i][j]==3) col(cd,11,st);
else if(g[i][j]==2) col(cd,13,st);
else if(g[i][j]==1) col(cd,10,st);
else if(g[i][j]==11) col(cd,2,"⊕");
else if(g[i][j]==10) col(cd,7,"◎");
else if(g[i][j]==9) col(cd,13,"Δ");
else if(g[i][j]==8) col(cd,12,"¤");
else if(g[i][j]==7) col(cd,11,"≈");
else if(g[i][j]==6) col(cd,14,"≡");
else if(g[i][j]==5) col(cd,10,"=");
else col(cd,7," ");
} col(cd,7,st);
cout<<endl;
} i=14;
col(cd,7,"");
while(i--) cout<<st;
cout<<endl<<endl;
col(10,0,"");
if(gf==1) cout<<" ";
if(gf==5) cout<<"=";
if(gf==6) cout<<"≡";
if(gf==7) cout<<"≈";
if(gf==8) cout<<"¤";
if(gf==9) cout<<"Δ";
if(gf==10) cout<<"◎";
if(gf==11) cout<<"⊕";
col(cd,10," ph : ");
printf("%-4d",hf);
col(12,0,"");
if(gs==1) cout<<" ";
if(gs==5) cout<<"=";
if(gs==6) cout<<"≡";
if(gs==7) cout<<"≈";
if(gs==8) cout<<"¤";
if(gs==9) cout<<"Δ";
if(gs==10) cout<<"◎";
if(gs==11) cout<<"⊕";
col(cd,12," ph : ");
printf("%-4d",hs);
} bool dfs(int x,int y,int xl,int yl){
if(x==xl&&y==yl) return dp[x][y][xl][yl]=1;
if(dp[x][y][xl][yl]!=-1) return dp[x][y][xl][yl];
int te=g[x][y];
bool btool=0;
g[x][y]=-1;
for(int i=0;i<4;i++){
xln=x+fx[i]; yln=y+fy[i];
if(xln>0&&xln<13&&yln>0&&yln<13&&(g[xln][yln]==0||g[xln][yln]>4)){
if(dfs(xln,yln,xl,yl)) btool=1;
}
} g[x][y]=te;
return dp[x][y][xl][yl]=btool;
} int main(){
system("title skgame");
srand((unsigned)time(0));
HideCursor();
cd=0;
system("cls");
for(int i=1;i<=12;i++)
for(int j=1;j<=12;j++)
for(int k=1;k<=12;k++)
for(int l=1;l<=12;l++)
dp[i][j][k][l]=-1;
for(int i=1;i<=12;i++)
for(int j=1;j<=12;j++)
g[i][j]=makeg(rand()%1000+1);
g[1][1]=g[12][12]=0;
col(cd,7,"");
for(int i=0;i<gz.length();i++){
cout<<gz[i];
Sleep(30);
}
string que="3.武器:\n(1).小炮";
for(int i=0;i<que.length();i++){
cout<<que[i];
Sleep(30);
}
col(cd,10,"=");
col(cd,7,"");
cout<<endl;
Sleep(30);
que="(2).大炮";
for(int i=0;i<que.length();i++){
cout<<que[i];
Sleep(30);
}
col(cd,14,"≡");
col(cd,7,"");
cout<<endl;
Sleep(30);
que="(3).穿透枪";
for(int i=0;i<que.length();i++){
cout<<que[i];
Sleep(30);
}
col(cd,11,"≈");
Sleep(30);
cout<<endl;
col(cd,7,"");
que="(4).弹炮";
for(int i=0;i<que.length();i++){
cout<<que[i];
Sleep(30);
}
col(cd,12,"¤");
col(cd,7,"");
cout<<endl;
Sleep(30);
que="(5).火栓";
for(int i=0;i<que.length();i++){
cout<<que[i];
Sleep(30);
}
col(cd,13,"Δ");
col(cd,7,"");
cout<<endl;
Sleep(30);
que="(6).脉冲枪";
for(int i=0;i<que.length();i++){
cout<<que[i];
Sleep(30);
}
col(cd,7,"◎");
col(cd,7,"");
cout<<endl;
Sleep(30);
que="(7).手榴弹";
for(int i=0;i<que.length();i++){
cout<<que[i];
Sleep(30);
}
col(cd,2,"⊕");
col(cd,7,"");
cout<<endl;
Sleep(30);
cout<<"4.周围:"<<endl;
que="(1).墙";
for(int i=0;i<que.length();i++){
cout<<que[i];
Sleep(30);
}
col(cd,7,"▓");
col(cd,7,"");
cout<<endl;
Sleep(30);
que="(2).草";
for(int i=0;i<que.length();i++){
cout<<que[i];
Sleep(30);
}
col(cd,10,"▓");
col(cd,7,"");
cout<<endl;
Sleep(30);
que="(3).沼泽地";
for(int i=0;i<que.length();i++){
cout<<que[i];
Sleep(30);
}
col(cd,13,"▓");
col(cd,7,"");
cout<<endl;
Sleep(30);
que="(4).湖";
for(int i=0;i<que.length();i++){
cout<<que[i];
Sleep(30);
}
col(cd,11,"▓");
col(cd,7,"");
Sleep(30);
cout<<endl;
cout<<"按s键开始游戏\n按0键结束游戏"<<endl;
t=getch();
while(t!='s') t=getch();
system("cls");
make();
col(cd,12,"\n Game will start on 3 s\b\b");
for(int i=3;i>=1;i--){
Sleep(1000);
cout<<"\b"<<i;
} cout<<"开始!"<<endl;
system("cls");
make();
t=getch();
while(t!='0'){
bl=1;
if(t=='w'&&xf>1&&(g[xf-1][yf]==0||g[xf-1][yf]==1)&&!((xf-1==xs)&&(yf==ys))){
xf--; ff=0;
} else if(t=='w'&&xf>1&&g[xf-1][yf]==2&&!((xf-1==xs)&&(yf==ys))){
xf--; hf--; ff=0;
if(hf<=0) break;
} else if(t=='w'&&xf>1&&g[xf-1][yf]>4&&!((xf-1==xs)&&(yf==ys))){
xf--; ff=0;
gf=g[xf][yf];
g[xf][yf]=0;
} else if(t=='s'&&xf<12&&(g[xf+1][yf]==0||g[xf+1][yf]==1)&&!((xf+1==xs)&&(yf==ys))){
xf++; ff=1;
} else if(t=='s'&&xf<12&&g[xf+1][yf]==2&&!((xf+1==xs)&&(yf==ys))){
xf++; hf--; ff=1;
if(hf<=0) break;
} else if(t=='s'&&xf<12&&g[xf+1][yf]>4&&!((xf+1==xs)&&(yf==ys))){
xf++; ff=1;
gf=g[xf][yf];
g[xf][yf]=0;
} else if(t=='a'&&yf>1&&(g[xf][yf-1]==0||g[xf][yf-1]==1)&&!((xf==xs)&&(yf-1==ys))){
yf--; ff=2;
} else if(t=='a'&&yf>1&&g[xf][yf-1]==2&&!((xf==xs)&&(yf-1==ys))){
yf--; hf--; ff=2;
if(hf<=0) break;
} else if(t=='a'&&yf>1&&g[xf][yf-1]>4&&!((xf==xs)&&(yf-1==ys))){
yf--; ff=2;
gf=g[xf][yf];
g[xf][yf]=0;
} else if(t=='d'&&yf<12&&(g[xf][yf+1]==0||g[xf][yf+1]==1)&&!((xf==xs)&&(yf+1==ys))){
yf++; ff=3;
} else if(t=='d'&yf<12&&g[xf][yf+1]==2&&!((xf==xs)&&(yf+1==ys))){
yf++; hf--; ff=3;
if(hf<=0) break;
} else if(t=='d'&&yf<12&&g[xf][yf+1]>4&&!((xf==xs)&&(yf+1==ys))){
yf++; ff=3;
gf=g[xf][yf];
g[xf][yf]=0;
} else if(t=='x'){
xt=yt=bt=bn=bs=0; h=1;
if(gf==8){
if(dfs(xf,yf,xs,ys)) bt=1;
} if(gf==10){
if(sqrt(pow(xf-xs,2)+pow(yf-ys,2))<4){
bt=1; h=2;
}
} if(gf==11){
if(ff==0) xt=-1;
if(ff==1) xt=1;
if(ff==2) yt=-1;
if(ff==3) yt=1;
int xn,yn;
for(xn=xf+xt,yn=yf+yt;xn<=12&&xn>=1&&yn<=12&&yn>=1;xn+=xt,yn+=yt){
if(g[xn][yn]==0||g[xn][yn]>4) break;
} if(xn<=12&&xn>=1&&yn<=12&&yn>=1){
if(sqrt(pow(xn-xs,2)+pow(yn-ys,2))<3){
bt=1;
h=2;
}
}
} else{
if(gf==9) bs=1;
if(gf==7) bn=1;
if(gf==6) h=3;
if(gf==5) h=2;
if(ff==0) xt=-1;
if(ff==1) xt=1;
if(ff==2) yt=-1;
if(ff==3) yt=1;
for(int xn=xf,yn=yf;xn<=12&&xn>=1&&yn<=12&&yn>=1;xn+=xt,yn+=yt){
if(xn==xs&&yn==ys){
bt=1;
break;
} if((g[xn][yn]==1||g[xn][yn]==4)&&bn==0) break;
}
} if(bt==1){
hs-=h;
if(hf<10) hf+=bs;
} if(hs<=0) break;
} else if(t=='u'&&xs>1&&(g[xs-1][ys]==0||g[xs-1][ys]==1)&&!((xs-1==xf)&&(ys==yf))){
xs--; fs=0;
} else if(t=='u'&&xs>1&&g[xs-1][ys]==2&&!((xs-1==xf)&&(ys==yf))){
xs--; hs--; fs=0;
if(hs<=0) break;
} else if(t=='u'&&xs>1&&g[xs-1][ys]>4&&!((xs-1==xf)&&(ys==yf))){
xs--; fs=0;
gs=g[xs][ys];
g[xs][ys]=0;
} else if(t=='j'&&xs<12&&(g[xs+1][ys]==0||g[xs+1][ys]==1)&&!((xs+1==xf)&&(ys==yf))){
xs++; fs=1;
} else if(t=='j'&&xs<12&&g[xs+1][ys]==2&&!((xs+1==xf)&&(ys==yf))){
xs++; hs--; fs=1;
if(hs<=0) break;
} else if(t=='j'&&xs<12&&g[xs+1][ys]>4&&!((xs+1==xf)&&(ys==yf))){
xs++; fs=1;
gs=g[xs][ys];
g[xs][ys]=0;
} else if(t=='h'&&ys>1&&(g[xs][ys-1]==0||g[xs][ys-1]==1)&&!((xs==xf)&&(ys-1==yf))){
ys--; fs=2;
} else if(t=='h'&&ys>1&&g[xs][ys-1]==2&&!((xs==xf)&&(ys-1==yf))){
ys--; hs--; fs=2;
if(hs<=0) break;
} else if(t=='h'&&ys>1&&g[xs][ys-1]>4&&!((xs==xf)&&(ys-1==yf))){
ys--; fs=2;
gs=g[xs][ys];
g[xs][ys]=0;
} else if(t=='k'&&ys<12&&(g[xs][ys+1]==0||g[xs][ys+1]==1)&&!((xs==xf)&&(ys+1==yf))){
ys++; fs=3;
} else if(t=='k'&ys<12&&g[xs][ys+1]==2&&!((xs==xf)&&(ys+1==yf))){
ys++; hs--; fs=3;
if(hs<=0) break;
} else if(t=='k'&&ys<12&&g[xs][ys+1]>4&&!((xs==xf)&&(ys+1==yf))){
ys++; fs=3;
gs=g[xs][ys];
g[xs][ys]=0;
} else if(t=='n'){
xt=yt=bt=bn=bs=0; h=1;
if(gs==8){
if(dfs(xf,yf,xs,ys)) bt=1;
} if(gs==10){
if(sqrt(pow(xf-xs,2)+pow(yf-ys,2))<4){
bt=1; h=2;
}
} if(gs==11){
if(fs==0) xt=-1;
if(fs==1) xt=1;
if(fs==2) yt=-1;
if(fs==3) yt=1;
int xn,yn;
for(xn=xs+xt,yn=ys+yt;xn<=12&&xn>=1&&yn<=12&&yn>=1;xn+=xt,yn+=yt){
if(g[xn][yn]==0||g[xn][yn]>4) break;
} if(xn<=12&&xn>=1&&yn<=12&&yn>=1){
if(sqrt(pow(xn-xf,2)+pow(yn-yf,2))<3){
bt=1;
h=2;
}
}
} else{
if(gs==9) bs=1;
if(gs==7) bn=1;
if(gs==6) h=3;
if(gs==5) h=2;
if(fs==0) xt=-1;
if(fs==1) xt=1;
if(fs==2) yt=-1;
if(fs==3) yt=1;
for(int xn=xs,yn=ys;xn<=12&&xn>=1&&yn<=12&&yn>=1;xn+=xt,yn+=yt){
if(xn==xf&&yn==yf){
bt=1;
break;
} if((g[xn][yn]==1||g[xn][yn]==4)&&bn==0) break;
}
} if(bt==1){
hf-=h;
if(hs<10) hs+=bs;
} if(hf<=0) break;
} else bl=0;
if(bl==1){
system("cls");
make();
} t=getch();
} system("cls");
if(hf<=0){
col(cd,7,"\n ");
col(12,0," ");
col(cd,12," wins!");
} else if(hs<=0){
col(cd,7,"\n ");
col(10,0," ");
col(cd,10," wins!");
} else col(cd,7,"\n end!\n\n");
Sleep(1000);
col(cd,7,"");
return 0;
}
5.单人大战:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<windows.h>
#include<conio.h>
#include<time.h>
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
using namespace std;
string a[21][20]= {"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■",
"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■",
"■","■","□","□","□","□","□","□","□","□","□","□","□","□","□","▓","▓","▲","■","■",
"■","□","□","□","■","■","□","■","□","■","■","■","■","■","■","▓","▓","▓","■","■",
"■","□","□","□","□","□","∷","□","□","■","∷","∷","∷","□","□","□","▓","▓","■","■",
"■","□","■","□","□","□","□","■","□","■","∷","∷","■","□","□","□","■","□","■","■",
"■","□","■","□","□","□","□","■","□","■","∷","■","□","□","□","□","■","□","■","■",
"■","□","□","∷","□","□","□","□","□","■","□","□","□","□","■","∷","■","□","■","■",
"■","□","■","□","■","■","□","□","■","■","□","□","□","■","∷","∷","■","□","■","■",
"■","□","□","□","□","□","□","■","□","□","□","□","□","∷","∷","∷","■","□","■","■",
"■","□","■","■","■","■","■","■","□","■","□","■","■","■","■","■","■","□","■","■",
"■","□","■","∷","∷","∷","□","□","□","□","□","■","□","□","□","□","□","□","■","■",
"■","□","■","∷","∷","■","□","□","□","■","■","□","□","■","■","□","■","□","■","■",
"■","□","■","∷","■","□","□","□","□","■","□","□","□","□","□","∷","□","□","■","■",
"■","□","■","□","□","□","□","■","∷","■","□","■","□","□","□","□","■","□","■","■",
"■","□","■","□","□","□","■","∷","∷","■","□","■","□","□","□","□","■","□","■","■",
"■","▓","▓","□","□","□","∷","∷","∷","■","□","□","∷","□","□","□","□","□","■","■",
"■","▓","▓","▓","■","■","■","■","■","■","□","■","□","■","■","□","□","□","■","■",
"■","●","▓","▓","□","□","□","□","□","□","□","□","□","□","□","□","□","■","■","■",
"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■",
"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■","■",
}; //地图
string jz[8]; //用来加载的变量
int xxxx,i,j,lev1=0,lev2=0; //一堆没用的变量=.=
int n1=1000,m1=10,l1=1; //玩家1相关信息
int n2=1000,m2=10,l2=1; //玩家2相关信息
int t,t1,t2,t3,t4; //计算时间的变量
double t5,t6; //计算时间的变量
int x=18,y=1; //玩家1坐标
int p=2,q=17; //玩家2坐标
int p2=2,q2=7; //玩家2辅助坐标
char ch,ch1,ch2; //输入字符,玩家1保留字符,玩家2保留字符
int gbdw1(); //光标定位1函数
int gbdw2(); //光标定位2函数
int gbdw3(); //光标定位3函数
int gbdw4(); //光标定位4函数
int hpzy(); //获取资源函数
int jzz(); //加载中函数
int p1kz(); //玩家1控制函数
int p2kz(); //玩家2控制函数
int zcd(); //主菜单函数
void draw(); //画图函数
void hidden(); //隐藏光标函数
void zanting(); //暂停函数
void renji(); //人机模式
void renji_suiji(); //人机模式(防bug)
void renji_gress(); //吃草
void zanting() {
system("cls");
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
cout<<"■■■■■■■■■■■■■■■■■■■"<<endl;
return;
}
int gbdw1() {
COORD pos = {0, 22};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
int gbdw2() {
COORD pos = {40, 22};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
int gbdw3() {
COORD pos = {0, 23};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
int gbdw4() {
COORD pos = {40, 23};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void draw() {
if(n1>=1000) n1=1000;
if(n2>=1000) n2=1000;
if(n1<=0) n1=0;
if(n2<=0) n2=0;
if(m1>=500) m1=500;
if(m2>=500) m2=500;
if(m1<=0) m1=0;
if(m2<=0) m2=0;
if(l1>=20) l1=20;
if(l1>=20) l1=20;
COORD pos = {0, 0};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
cout<<"Already start "<<((int)time(NULL)-t)/60<<" minute for "<<((int)time(NULL)-t)%60<<" seconds"<<endl;
for(i=1; i<=19; i++) {
for(j=0; j<=18; j++) {
if(a[i][j]=="■") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED);
cout<<a[i][j];
}
if(a[i][j]=="∷") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);
cout<<a[i][j];
}
if(a[i][j]=="▓") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
cout<<a[i][j];
}
if(a[i][j]=="□") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_GREEN);
cout<<a[i][j];
}
if(a[i][j]=="●"||a[i][j]=="▲") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
cout<<a[i][j];
}
}
cout<<endl;
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
printf("●player 1: ▲player 2:\n");
printf("Lv:%2d HP:%4d mana:%3d Lv:%2d HP:%4d mana:%3d\n",l1,n1,m1,l2,n2,m2);
gbdw1();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
printf("HP: ");
for(j=1; j<=n1/10/8; j++)
printf("█");
xxxx=n1/10%8;
cout<<jz[xxxx];
printf("%d",n1);
printf(" ");
gbdw2();
printf("HP: ");
for(j=1; j<=n2/10/8; j++)
printf("█");
xxxx=n2/10%8;
cout<<jz[xxxx];
printf("%d",n2);
printf(" \n");
gbdw3();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_GREEN);
printf("moon:");
for(j=1; j<=m1/5/8; j++)
printf("█");
xxxx=m1/5%8;
cout<<jz[xxxx];
printf("%d",m1);
printf(" ");
gbdw4();
printf("moon:");
for(j=1; j<=m2/5/8; j++)
printf("█");
xxxx=m2/5%8;
cout<<jz[xxxx];
printf("%d",m2);
printf(" \n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
return;
}
int zcd() {
while(1) {
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
system("cls");
printf("Welcome to square in the world!\n");
printf("-------------------------------\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
printf("S.[Start the game]\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED | FOREGROUND_GREEN);
printf("T.[The program diagram]\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);
printf("H.[Help]\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
printf("Q.[Quit the game]\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
printf("-------------------------------\n");
ch=getch();
if(ch=='s'||ch=='S') {
system("cls");
for(i=1; i<=136; i++) {
xxxx=i%8;
COORD pos = {0, 0};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
printf("Being parsed~ Loading...\n");
printf("----------------------------------\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
for(j=1; j<=i/8; j++)
printf("█");
cout<<jz[xxxx]<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
printf("----------------------------------\n");
}
printf("Initialize the...");
Sleep(1000);
break;
}
if(ch=='t'||ch=='T') {
COORD pos = {0, 0};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
printf("┏━━━━━━━━━━━━━━━━┓\n");
printf("┃[square big showdown 4.11] ┃\n");
printf("┃[Human-machine version] ┃\n");
printf("┃┃ ┃\n");
printf("┃┣[Start the game] ┃\n");
printf("┃┃ ┃\n");
printf("┃┣[The program tree diagram] ┃\n");
printf("┃┃┃ ┃\n");
printf("┃┃┗[The current] ┃\n");
printf("┃┃ ┃\n");
printf("┃┣[Help] ┃\n");
printf("┃┃┃ ┃\n");
printf("┃┃┣[Look at the map] ┃\n");
printf("┃┃┃ ┃\n");
printf("┃┃┣[Operation to help] ┃\n");
printf("┃┃┃ ┃\n");
printf("┃┃┗[The developer] ┃\n");
printf("┃┃ ┃\n");
printf("┃┗[Quit the game] ┃\n");
printf("┗━━━━━━━━━━━━━━━━┛\n");
ch=getch();
}
if(ch=='h'||ch=='H') {
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
printf("Do you need any help?\n");
printf("---------------------\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
printf("1.[Look at the map]\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED | FOREGROUND_GREEN);
printf("2.[Operation to help]\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);
printf("3.[The developer]\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
printf("---------------------\n");
ch=getch();
if(ch=='1') {
draw();
printf("●player 1;\n");
printf("▲Player 2;\n");
printf("■Is a wall, do not walk;\n");
printf("□Is a way, you can walk;\n");
printf("∷The grass;\n");
printf("▓Is the birth place of both parties.\n");
printf("Two lines are at the bottom of the both sides of the case;\n");
printf(" Press any key to return;\n");
ch=getch();
continue;
}
if(ch=='2') {
system("cls");
printf("player 1:\n");
printf(" w.up s.down a.left d.right\n");
printf(" v.attack b.Respond to health n.vampire\n");
printf(" f.flash g.To attract\n");
printf("-----------------------------------------------\n");
printf("player 2:\n");
printf(" ↑.up ↓.down ←.left →.right\n");
printf(" 1.attack 2.Respond to health 3.crit\n");
printf(" 4.flash 5.Back to home\n");
printf("-----------------------------------------------\n");
printf("Click on the x for details!\n");
ch=getch();
if(ch=='x'||ch=='X') {
system("cls");
printf("player 1:---------------------------------\n");
printf("---control--- P1HP moon P2HP moon\n");
printf(" w.up ---- +1 ---- ----\n");
printf(" s.down ---- +1 ---- ----\n");
printf(" a.left ---- +1 ---- ----\n");
printf(" d.right ---- +1 ---- ----\n");
printf(" \n");
printf(" v.attack ---- +2 -20 ----\n");
printf(" b.Respond to health +200 -50 ---- ----\n");
printf(" n.vampire +150 -100 -150 -20\n");
printf(" f.flash ---- -20 ---- ----\n");
printf(" g.To attract ---- -70 -100 ----\n");
printf("player 2:---------------------------------\n");
printf("---control--- P1HP moon P2HP moon\n");
printf(" ↑.up ---- ---- ---- +1\n");
printf(" ↓.down ---- ---- ---- +1\n");
printf(" ←.left ---- ---- ---- +1\n");
printf(" →.right ---- ---- ---- +1\n");
printf(" \n");
printf(" 1.attack -20 ---- ---- +2\n");
printf(" 2.Respond to health ---- ---- +200 -50\n");
printf(" 3.crit -200 ---- ---- -100\n");
printf(" 4.flash ---- ---- ---- -20\n");
printf(" 5.Back to home ---- ---- ---- -70\n");
printf("------------------------------------------");
ch=getch();
}
continue;
}
if(ch=='3') {
system("cls");
printf("The development team:\n");
printf(" Alliance primary school\n");
printf("Development date:\n");
printf(" 16/11/17 18:35\n");
printf("Belonging to:\n");
printf(" China's fujian province\n");
ch=getch();
continue;
}
}
if(ch=='q'||ch=='Q') {
if(1) {
system("cls");
printf("Really want to quit?\n");
printf("--------------------\n");
printf("Y.[Yes] N.[No]\n");
printf("--------------------\n");
while(ch!='y'&&ch!='Y'&&ch!='N'&&ch!='n')
ch=getch();
}
if(ch=='Y'||ch=='y') {
system("cls");
for(i=1; i<=136; i++) {
xxxx=i%8;
COORD pos = {0, 0};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
printf("Deleting records~ \n");
printf("----------------------------------\n");
for(j=1; j<=i/8; j++)
printf("█");
cout<<jz[xxxx]<<endl;
printf("----------------------------------\n");
}
printf("Delete the success.");
Sleep(1000);
exit(0);
}
if(ch=='N'||ch=='n')
continue;
}
}
return 0;
}
void hidden() {
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(hOut,&cci);
cci.bVisible=0;
SetConsoleCursorInfo(hOut,&cci);
return;
}
int hqzy() {
MessageBox(NULL,"The game need to get access to local resources \n agree? (I am bored!)","Access to resources",MB_ICONEXCLAMATION|MB_OK);
return 0;
}
int p1kz() {
if(ch=='w'||ch=='s'||ch=='a'||ch=='d'
||ch=='W'||ch=='S'||ch=='A'||ch=='D')
ch1=ch;
if(ch=='a'||ch=='A') {
if(x==2&&y==15||x==2&&y==16||x==2&&y==17
||x==3&&y==15||x==3&&y==16||x==3&&y==17
||x==4&&y==16||x==4&&y==17
||x==16&&y==1||x==16&&y==2
||x==17&&y==1||x==17&&y==2||x==17&&y==3
||x==18&&y==1||x==18&&y==2||x==18&&y==3) {
if(a[x][y-1]!="■"&&a[x][y-1]!="▲") {
a[x][y]="▓";
y--;
a[x][y]="●";
m1++;
draw();
}
} else {
if(a[x][y-1]!="■"&&a[x][y-1]!="▲") {
a[x][y]="□";
if(a[x][y-1]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n1+=50;
}
case 1: {
m1+=20;
}
}
}
y--;
a[x][y]="●";
m1++;
draw();
}
}
}
if(ch=='d'||ch=='D') {
if(x==2&&y==15||x==2&&y==16||x==2&&y==17
||x==3&&y==15||x==3&&y==16||x==3&&y==17
||x==4&&y==16||x==4&&y==17
||x==16&&y==1||x==16&&y==2
||x==17&&y==1||x==17&&y==2||x==17&&y==3
||x==18&&y==1||x==18&&y==2||x==18&&y==3) {
if(a[x][y+1]!="■"&&a[x][y+1]!="▲") {
a[x][y]="▓";
y++;
a[x][y]="●";
m1++;
draw();
}
} else {
if(a[x][y+1]!="■"&&a[x][y+1]!="▲") {
a[x][y]="□";
if(a[x][y+1]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n1+=50;
}
case 1: {
m1+=20;
}
}
}
y++;
a[x][y]="●";
m1++;
draw();
}
}
}
if(ch=='w'||ch=='W') {
if(x==2&&y==15||x==2&&y==16||x==2&&y==17
||x==3&&y==15||x==3&&y==16||x==3&&y==17
||x==4&&y==16||x==4&&y==17
||x==16&&y==1||x==16&&y==2
||x==17&&y==1||x==17&&y==2||x==17&&y==3
||x==18&&y==1||x==18&&y==2||x==18&&y==3) {
if(a[x-1][y]!="■"&&a[x-1][y]!="▲") {
a[x][y]="▓";
x--;
a[x][y]="●";
m1++;
draw();
}
} else {
if(a[x-1][y]!="■"&&a[x-1][y]!="▲") {
a[x][y]="□";
if(a[x-1][y]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n1+=50;
}
case 1: {
m1+=20;
}
}
}
x--;
a[x][y]="●";
m1++;
draw();
}
}
}
if(ch=='s'||ch=='S') {
if(x==2&&y==15||x==2&&y==16||x==2&&y==17
||x==3&&y==15||x==3&&y==16||x==3&&y==17
||x==4&&y==16||x==4&&y==17
||x==16&&y==1||x==16&&y==2
||x==17&&y==1||x==17&&y==2||x==17&&y==3
||x==18&&y==1||x==18&&y==2||x==18&&y==3) {
if(a[x+1][y]!="■"&&a[x+1][y]!="▲") {
a[x][y]="▓";
x++;
a[x][y]="●";
m1++;
draw();
}
} else {
if(a[x+1][y]!="■"&&a[x+1][y]!="▲") {
a[x][y]="□";
if(a[x+1][y]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n1+=50;
}
case 1: {
m1+=20;
}
}
}
x++;
a[x][y]="●";
m1++;
draw();
}
}
}
if(ch=='v'||ch=='V') {
if(a[x][y-2]=="▲"
||a[x][y+2]=="▲"
||a[x-2][y]=="▲"
||a[x+2][y]=="▲"
||a[x-1][y-1]=="▲"
||a[x+1][y-1]=="▲"
||a[x-1][y+1]=="▲"
||a[x+1][y+1]=="▲"
||a[x][y-1]=="▲"
||a[x][y+1]=="▲"
||a[x-1][y]=="▲"
||a[x+1][y]=="▲") {
n2-=20;
m1+=2;
n2-=(l1-1)*2;
if(lev1==l1) {
lev1=0;
l1++;
}
lev1++;
draw();
}
}
if(ch=='b'||ch=='B') {
if(m1>=50) {
n1+=200;
m1-=50;
draw();
}
}
if(ch=='n'||ch=='N') {
if(m1>=100) {
n2-=150;
n1+=150;
m1-=100;
n2-=(l1-1)*10;
n1+=(l1-1)*10;
m1+=20;
m2-=20;
if(lev1==l1) {
lev1=0;
l1++;
}
lev1++;
draw();
}
}
if(ch=='f'||ch=='F') {
if(m1>=20) {
if(ch1=='w'||ch1=='W') {
if(x==2&&y==15||x==2&&y==16||x==2&&y==17
||x==3&&y==15||x==3&&y==16||x==3&&y==17
||x==4&&y==16||x==4&&y==17
||x==16&&y==1||x==16&&y==2
||x==17&&y==1||x==17&&y==2||x==17&&y==3
||x==18&&y==1||x==18&&y==2||x==18&&y==3) {
if(a[x-2][y]=="▓"||a[x-2][y]=="□") {
a[x][y]="▓";
x-=2;
a[x][y]="●";
m1-=20;
draw();
}
} else {
if(a[x-2][y]=="▓"||a[x-2][y]=="□"||a[x-2][y]=="∷") {
a[x][y]="□";
if(a[x-2][y]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n1+=50;
m1+=30;
}
case 1: {
m1+=30;
}
}
}
x-=2;
a[x][y]="●";
m1-=20;
draw();
}
}
}
if(ch1=='s'||ch1=='S') {
if(x==2&&y==15||x==2&&y==16||x==2&&y==17
||x==3&&y==15||x==3&&y==16||x==3&&y==17
||x==4&&y==16||x==4&&y==17
||x==16&&y==1||x==16&&y==2
||x==17&&y==1||x==17&&y==2||x==17&&y==3
||x==18&&y==1||x==18&&y==2||x==18&&y==3) {
if(a[x+2][y]=="▓"||a[x+2][y]=="□") {
a[x][y]="▓";
x+=2;
a[x][y]="●";
m1-=20;
draw();
}
} else {
if(a[x+2][y]=="▓"||a[x+2][y]=="□"||a[x+2][y]=="∷") {
a[x][y]="□";
if(a[x+2][y]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n1+=50;
m1+=30;
}
case 1: {
m1+=30;
}
}
}
x+=2;
a[x][y]="●";
m1-=20;
draw();
}
}
}
if(ch1=='a'||ch1=='A') {
if(x==2&&y==15||x==2&&y==16||x==2&&y==17
||x==3&&y==15||x==3&&y==16||x==3&&y==17
||x==4&&y==16||x==4&&y==17
||x==16&&y==1||x==16&&y==2
||x==17&&y==1||x==17&&y==2||x==17&&y==3
||x==18&&y==1||x==18&&y==2||x==18&&y==3) {
if(a[x][y-2]=="▓"||a[x][y-2]=="□") {
a[x][y]="▓";
y-=2;
a[x][y]="●";
m1-=20;
draw();
}
} else {
if(a[x][y-2]=="▓"||a[x][y-2]=="□"||a[x][y-2]=="∷") {
a[x][y]="□";
if(a[x][y-2]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n1+=50;
m1+=30;
}
case 1: {
m1+=30;
}
}
}
y-=2;
a[x][y]="●";
m1-=20;
draw();
}
}
}
if(ch1=='d'||ch1=='D') {
if(x==2&&y==15||x==2&&y==16||x==2&&y==17
||x==3&&y==15||x==3&&y==16||x==3&&y==17
||x==4&&y==16||x==4&&y==17
||x==16&&y==1||x==16&&y==2
||x==17&&y==1||x==17&&y==2||x==17&&y==3
||x==18&&y==1||x==18&&y==2||x==18&&y==3) {
if(a[x][y+2]=="▓"||a[x][y+2]=="□") {
a[x][y]="▓";
y+=2;
a[x][y]="●";
m1-=20;
draw();
}
} else {
if(a[x][y+2]=="▓"||a[x][y+2]=="□"||a[x][y+2]=="∷") {
a[x][y]="□";
if(a[x][y+2]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n1+=50;
m1+=30;
}
case 1: {
m1+=30;
}
}
}
y+=2;
a[x][y]="●";
m1-=20;
draw();
}
}
}
}
}
if(ch=='g'||ch=='G') {
if(m1>=70) {
if(p==2&&q==15||p==2&&q==16||p==2&&q==17
||p==3&&q==15||p==3&&q==16||p==3&&q==17
||p==4&&q==16||p==4&&q==17
||p==16&&q==1||p==16&&q==2
||p==17&&q==1||p==17&&q==2||p==17&&q==3
||p==18&&q==1||p==18&&q==2||p==18&&q==3) {
if(a[x+1][y]!="■") {
a[p][q]="▓";
p=x+1;
q=y;
a[p][q]="▲";
m1-=70;
n2-=100;
return 0;
}
if(a[x-1][y]!="■") {
a[p][q]="▓";
p=x-1;
q=y;
a[p][q]="▲";
m1-=70;
n2-=100;
return 0;
}
if(a[x][y+1]!="■") {
a[p][q]="▓";
p=x;
q=y+1;
a[p][q]="▲";
m1-=70;
n2-=100;
return 0;
}
if(a[x][y-1]!="■") {
a[p][q]="▓";
p=x;
q=y-1;
a[p][q]="▲";
m1-=70;
n2-=100;
return 0;
}
} else {
if(a[x+1][y]!="■") {
a[p][q]="□";
p=x+1;
q=y;
a[p][q]="▲";
m1-=70;
n2-=100;
return 0;
}
if(a[x-1][y]!="■") {
a[p][q]="□";
p=x-1;
q=y;
a[p][q]="▲";
m1-=70;
n2-=100;
return 0;
}
if(a[x][y+1]!="■") {
a[p][q]="□";
p=x;
q=y+1;
a[p][q]="▲";
m1-=70;
n2-=100;
return 0;
}
if(a[x][y-1]!="■") {
a[p][q]="□";
p=x;
q=y-1;
a[p][q]="▲";
m1-=70;
n2-=100;
return 0;
}
}
}
}
return 0;
}
int p2kz() {
if(ch==72||ch==80||ch==75||ch==77)
ch2=ch;
if(ch==72) {
if(p==2&&q==15||p==2&&q==16||p==2&&q==17
||p==3&&q==15||p==3&&q==16||p==3&&q==17
||p==4&&q==16||p==4&&q==17
||p==16&&q==1||p==16&&q==2
||p==17&&q==1||p==17&&q==2||p==17&&q==3
||p==18&&q==1||p==18&&q==2||p==18&&q==3) {
if(a[p-1][q]!="■"&&a[p-1][q]!="●") {
a[p][q]="▓";
p--;
a[p][q]="▲";
m2++;
draw();
}
} else {
if(a[p-1][q]!="■"&&a[p-1][q]!="●") {
a[p][q]="□";
if(a[p-1][q]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n2+=50;
}
case 1: {
m2+=20;
}
}
}
p--;
a[p][q]="▲";
m2++;
draw();
}
}
}
if(ch==75) {
if(p==2&&q==15||p==2&&q==16||p==2&&q==17
||p==3&&q==15||p==3&&q==16||p==3&&q==17
||p==4&&q==16||p==4&&q==17
||p==16&&q==1||p==16&&q==2
||p==17&&q==1||p==17&&q==2||p==17&&q==3
||p==18&&q==1||p==18&&q==2||p==18&&q==3) {
if(a[p][q-1]!="■"&&a[p][q-1]!="●") {
a[p][q]="▓";
q--;
a[p][q]="▲";
m2++;
draw();
}
} else {
if(a[p][q-1]!="■"&&a[p][q-1]!="●") {
a[p][q]="□";
if(a[p][q-1]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n2+=50;
}
case 1: {
m2+=20;
}
}
}
q--;
a[p][q]="▲";
m2++;
draw();
}
}
}
if(ch==80) {
if(p==2&&q==15||p==2&&q==16||p==2&&q==17
||p==3&&q==15||p==3&&q==16||p==3&&q==17
||p==4&&q==16||p==4&&q==17
||p==16&&q==1||p==16&&q==2
||p==17&&q==1||p==17&&q==2||p==17&&q==3
||p==18&&q==1||p==18&&q==2||p==18&&q==3) {
if(a[p+1][q]!="■"&&a[p+1][q]!="●") {
a[p][q]="▓";
p++;
a[p][q]="▲";
m2++;
draw();
}
} else {
if(a[p+1][q]!="■"&&a[p+1][q]!="●") {
a[p][q]="□";
if(a[p+1][q]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n2+=50;
}
case 1: {
m2+=20;
}
}
}
p++;
a[p][q]="▲";
m2++;
draw();
}
}
}
if(ch==77) {
if(p==2&&q==15||p==2&&q==16||p==2&&q==17
||p==3&&q==15||p==3&&q==16||p==3&&q==17
||p==4&&q==16||p==4&&q==17
||p==16&&q==1||p==16&&q==2
||p==17&&q==1||p==17&&q==2||p==17&&q==3
||p==18&&q==1||p==18&&q==2||p==18&&q==3) {
if(a[p][q+1]!="■"&&a[p][q+1]!="●") {
a[p][q]="▓";
q++;
a[p][q]="▲";
m2++;
draw();
}
} else {
if(a[p][q+1]!="■"&&a[p][q+1]!="●") {
a[p][q]="□";
if(a[p][q+1]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n2+=50;
}
case 1: {
m2+=20;
}
}
}
q++;
a[p][q]="▲";
m2++;
draw();
}
}
}
if(ch=='1') {
if(a[p][q-1]=="●"
||a[p][q+1]=="●"
||a[p-1][q]=="●"
||a[p+1][q]=="●") {
n1-=20;
m2+=2;
n1-=(l2-1)*2;
if(lev2==l2) {
lev2=0;
l2++;
}
lev2++;
draw();
}
}
if(ch=='2') {
if(m2>=50) {
n2+=200;
m2-=50;
draw();
}
}
if(ch=='3') {
if(m2>=100) {
n1-=200;
m2-=100;
n1-=(l2-1)*20;
if(lev2==l2) {
lev2=0;
l2++;
}
lev2++;
draw();
}
}
if(ch=='4') {
if(m2>=20) {
if(ch2==72) {
if(p==2&&q==15||p==2&&q==16||p==2&&q==17
||p==3&&q==15||p==3&&q==16||p==3&&q==17
||p==4&&q==16||p==4&&q==17
||p==16&&q==1||p==16&&q==2
||p==17&&q==1||p==17&&q==2||p==17&&q==3
||p==18&&q==1||p==18&&q==2||p==18&&q==3) {
if(a[p-2][q]=="▓"||a[p-2][q]=="□") {
a[p][q]="▓";
p-=2;
a[p][q]="▲";
m1++;
m2-=20;
draw();
}
} else {
if(a[p-2][q]=="▓"||a[p-2][q]=="□"||a[p-2][q]=="∷") {
a[p][q]="□";
if(a[p-2][q]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n2+=50;
m2+=30;
}
case 1: {
m2+=30;
}
}
}
p-=2;
a[p][q]="▲";
m1++;
m2-=20;
draw();
}
}
}
if(ch2==80) {
if(p==2&&q==15||p==2&&q==16||p==2&&q==17
||p==3&&q==15||p==3&&q==16||p==3&&q==17
||p==4&&q==16||p==4&&q==17
||p==16&&q==1||p==16&&q==2
||p==17&&q==1||p==17&&q==2||p==17&&q==3
||p==18&&q==1||p==18&&q==2||p==18&&q==3) {
if(a[p+2][q]=="▓"||a[p+2][q]=="□") {
a[p][q]="▓";
p+=2;
a[p][q]="▲";
m1++;
m2-=20;
draw();
}
} else {
if(a[p+2][q]=="▓"||a[p+2][q]=="□"||a[p+2][q]=="∷") {
a[p][q]="□";
if(a[p+2][q]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n2+=50;
m2+=30;
}
case 1: {
m2+=30;
}
}
}
p+=2;
a[p][q]="▲";
m1++;
m2-=20;
draw();
}
}
}
if(ch2==75) {
if(p==2&&q==15||p==2&&q==16||p==2&&q==17
||p==3&&q==15||p==3&&q==16||p==3&&q==17
||p==4&&q==16||p==4&&q==17
||p==16&&q==1||p==16&&q==2
||p==17&&q==1||p==17&&q==2||p==17&&q==3
||p==18&&q==1||p==18&&q==2||p==18&&q==3) {
if(a[p][q-2]=="▓"||a[p][q-2]=="□") {
a[p][q]="▓";
q-=2;
a[p][q]="▲";
m1++;
m2-=20;
draw();
}
} else {
if(a[p][q-2]=="▓"||a[p][q-2]=="□"||a[p][q-2]=="∷") {
a[p][q]="□";
if(a[p][q-2]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n2+=50;
m2+=30;
}
case 1: {
m2+=30;
}
}
}
q-=2;
a[p][q]="▲";
m1++;
m2-=20;
draw();
}
}
}
if(ch2==77) {
if(p==2&&q==15||p==2&&q==16||p==2&&q==17
||p==3&&q==15||p==3&&q==16||p==3&&q==17
||p==4&&q==16||p==4&&q==17
||p==16&&q==1||p==16&&q==2
||p==17&&q==1||p==17&&q==2||p==17&&q==3
||p==18&&q==1||p==18&&q==2||p==18&&q==3) {
if(a[p][q+2]=="▓"||a[p][q+2]=="□") {
a[p][q]="▓";
q+=2;
a[p][q]="▲";
m1++;
m2-=20;
draw();
}
} else {
if(a[p][q+2]=="▓"||a[p][q+2]=="□"||a[p][q+2]=="∷") {
a[p][q]="□";
if(a[p][q+2]=="∷") {
srand((unsigned)time(NULL));
switch(rand()%2) {
case 0: {
n2+=50;
m2+=30;
}
case 1: {
m2+=30;
}
}
}
q+=2;
a[p][q]="▲";
m1++;
m2-=20;
draw();
}
}
}
}
}
if(ch=='5') {
if(m2>=70) {
if(p==2&&q==15||p==2&&q==16||p==2&&q==17
||p==3&&q==15||p==3&&q==16||p==3&&q==17
||p==4&&q==16||p==4&&q==17
||p==16&&q==1||p==16&&q==2
||p==17&&q==1||p==17&&q==2||p==17&&q==3
||p==18&&q==1||p==18&&q==2||p==18&&q==3) {
a[p][q]="▓";
p=2;
q=17;
a[p][q]="▲";
m2-=70;
draw();
} else {
a[p][q]="□";
p=2;
q=17;
a[p][q]="▲";
m2-=70;
draw();
}
}
}
return 0;
}
void renji() {
if(n2<=200) {
if(!(p==2&&q==15||p==2&&q==16||p==2&&q==17
||p==3&&q==15||p==3&&q==16||p==3&&q==17
||p==4&&q==16||p==4&&q==17)) {
if(m2>=70) {
ch='5';
p2kz();
return;
}
} else {
return;
}
}
if(a[p][q-1]=="●"
||a[p][q+1]=="●"
||a[p-1][q]=="●"
||a[p+1][q]=="●") {
ch='1';
p2kz();
return;
}
if(n2<=900) {
if(m2>=50) {
ch='2';
p2kz();
return;
}
}
if(n2>=600) {
if(m2>=100) {
ch='3';
p2kz();
return;
}
}
renji_gress();
if(x<p) {
if(a[p-1][q]=="■") {
if(m2>=20) {
ch2=UP;
ch='4';
}
} else {
ch=UP;
}
p2kz();
if(p!=p2||q!=q2) {
p2=p;
q2=q;
return;
} else {
renji_suiji();
return;
}
}
if(x>p) {
if(a[p+1][q]=="■") {
if(m2>=20) {
ch2=DOWN;
ch='4';
}
} else {
ch=DOWN;
}
p2kz();
if(p!=p2||q!=q2) {
p2=p;
q2=q;
return;
} else {
renji_suiji();
return;
}
}
if(y<q) {
if(a[p][q-1]=="■") {
if(m2>=20) {
ch2=LEFT;
ch='4';
}
} else {
ch=LEFT;
}
p2kz();
if(p!=p2||q!=q2) {
p2=p;
q2=q;
return;
} else {
renji_suiji();
return;
}
}
if(y>q) {
if(a[p][q+1]=="■") {
if(m2>=20) {
ch2=RIGHT;
ch='4';
}
} else {
ch=RIGHT;
}
p2kz();
if(p!=p2||q!=q2) {
p2=p;
q2=q;
return;
} else {
renji_suiji();
return;
}
}
return;
}
void renji_suiji() {
srand((unsigned)time(NULL));
switch(rand()%4) {
case 0: {
ch=UP;
p2kz();
p2kz();
break;
}
case 1: {
ch=DOWN;
p2kz();
p2kz();
break;
}
case 2: {
ch=LEFT;
p2kz();
p2kz();
break;
}
case 3: {
ch=RIGHT;
p2kz();
p2kz();
break;
}
}
}
void renji_gress() {
if(a[p-2][q]=="∷") {
if(a[p-1][q]=="■") {
if(m2>=30) {
ch2=UP;
ch='4';
p2kz();
return;
}
}
}
if(a[p+2][q]=="∷") {
if(a[p+1][q]=="■") {
if(m2>=30) {
ch2=DOWN;
ch='4';
p2kz();
return;
}
}
}
if(a[p][q-2]=="∷") {
if(a[p][q-1]=="■") {
if(m2>=30) {
ch2=LEFT;
ch='4';
p2kz();
return;
}
}
}
if(a[p][q+2]=="∷") {
if(a[p][q+1]=="■") {
if(m2>=30) {
ch2=RIGHT;
ch='4';
p2kz();
return;
}
}
}
if(a[p-1][q]=="∷") {
ch=UP;
p2kz();
return;
}
if(a[p+1][q]=="∷") {
ch=DOWN;
p2kz();
return;
}
if(a[p][q-1]=="∷") {
ch=LEFT;
p2kz();
return;
}
if(a[p][q+1]=="∷") {
ch=RIGHT;
p2kz();
return;
}
}
int main() {
if(1) {
hidden();
jz[1]="▏";
jz[2]="▎";
jz[3]="▍";
jz[4]="▌";
jz[5]="▋";
jz[6]="▊";
jz[7]="▉";
jz[0]="";
}
hqzy();
for(i=1; i<=136; i++) {
xxxx=i%8;
COORD pos = {0, 0};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
printf("Are entering a square in the world~ Loading...\n");
printf("-------------------------------------------------\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
for(j=1; j<=i/8; j++)
printf("█");
cout<<jz[xxxx]<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
printf("----------------------------------\n");
}
printf("Initialize the...");
Sleep(1000);
while(1) {
n1=1000;
m1=10;
n2=1000;
m2=10;
l1=1;
l2=1;
lev1=0;
lev2=0;
zcd();
if(x==2&&y==15||x==2&&y==16||x==2&&y==17
||x==3&&y==15||x==3&&y==16||x==3&&y==17
||x==4&&y==16||x==4&&y==17
||x==16&&y==1||x==16&&y==2
||x==17&&y==1||x==17&&y==2||x==17&&y==3
||x==18&&y==1||x==18&&y==2||x==18&&y==3) {
a[x][y]="▓";
} else {
a[x][y]="□";
}
if(p==2&&q==15||p==2&&q==16||p==2&&q==17
||p==3&&q==15||p==3&&q==16||p==3&&q==17
||p==4&&q==16||p==4&&q==17
||p==16&&q==1||p==16&&q==2
||p==17&&q==1||p==17&&q==2||p==17&&q==3
||p==18&&q==1||p==18&&q==2||p==18&&q==3) {
a[p][q]="▓";
} else {
a[p][q]="□";
}
x=18;
y=1;
p=2;
q=17;
a[4][6]=a[4][10]=a[4][11]=a[4][12]=a[5][10]=a[5][11]=a[6][10]=a[7][3]=a[7][15]=a[8][14]=a[8][15]=a[9][13]=a[9][14]=a[9][15]=a[13][3]=a[12][3]=a[12][4]=a[11][3]=a[11][4]=a[11][5]=a[14][8]=a[15][7]=a[15][8]=a[16][6]=a[16][7]=a[16][8]=a[16][12]=a[13][15]="∷";
a[x][y]="●";
a[p][q]="▲";
t=time(NULL); //开始时间
t1=(int)time(NULL); //当前时间
t2=(int)time(NULL)-t; //扣血时间
t3=(int)time(NULL)-t; //当前时间-开始时间:1 or 0
t5=(double)time(NULL); //
draw();
while(n1>0&&n2>0) {
t1=(int)time(NULL);
t3=(int)time(NULL)-t;
t6=(double)time(NULL)-t5;
if((time(NULL)-t)/60==10) {
draw();
printf(" Game over");
while(1) {
ch=getch();
if(ch=='=') {
return 0;
}
}
}
if(t2!=(int)time(NULL)-t) {
draw();
t2=(int)time(NULL)-t;
if(x==2&&y==15||x==2&&y==16||x==2&&y==17
||x==3&&y==15||x==3&&y==16||x==3&&y==17
||x==4&&y==16||x==4&&y==17) {
n1-=50;
}
if(x==16&&y==1||x==16&&y==2
||x==17&&y==1||x==17&&y==2||x==17&&y==3
||x==18&&y==1||x==18&&y==2||x==18&&y==3) {
n1+=50;
}
if(p==2&&q==15||p==2&&q==16||p==2&&q==17
||p==3&&q==15||p==3&&q==16||p==3&&q==17
||p==4&&q==16||p==4&&q==17) {
n2+=50;
}
if(p==16&&q==1||p==16&&q==2
||p==17&&q==1||p==17&&q==2||p==17&&q==3
||p==18&&q==1||p==18&&q==2||p==18&&q==3) {
n2-=50;
}
}
if(t3%60==0) {
srand((unsigned)time(NULL));
switch(rand()%28) {
case 0:
if(a[4][6]=="□")a[4][6]="∷";
case 1:
if(a[4][10]=="□")a[4][10]="∷";
case 2:
if(a[4][11]=="□")a[4][11]="∷";
case 3:
if(a[4][12]=="□")a[4][12]="∷";
case 4:
if(a[5][10]=="□")a[5][10]="∷";
case 5:
if(a[5][11]=="□")a[5][11]="∷";
case 6:
if(a[6][10]=="□")a[6][10]="∷";
case 7:
if(a[7][3]=="□")a[7][3]="∷";
case 8:
if(a[7][15]=="□")a[7][15]="∷";
case 9:
if(a[8][14]=="□")a[8][14]="∷";
case 10:
if(a[8][15]=="□")a[8][15]="∷";
case 11:
if(a[9][13]=="□")a[9][13]="∷";
case 12:
if(a[9][14]=="□")a[9][14]="∷";
case 13:
if(a[9][15]=="□")a[9][15]="∷";
case 14:
if(a[13][3]=="□")a[13][3]="∷";
case 15:
if(a[12][3]=="□")a[12][3]="∷";
case 16:
if(a[12][4]=="□")a[12][4]="∷";
case 17:
if(a[11][3]=="□")a[11][3]="∷";
case 18:
if(a[11][4]=="□")a[11][4]="∷";
case 19:
if(a[11][5]=="□")a[11][5]="∷";
case 20:
if(a[14][8]=="□")a[14][8]="∷";
case 21:
if(a[15][7]=="□")a[15][7]="∷";
case 22:
if(a[15][8]=="□")a[15][8]="∷";
case 23:
if(a[16][6]=="□")a[16][6]="∷";
case 24:
if(a[16][7]=="□")a[16][7]="∷";
case 25:
if(a[16][8]=="□")a[16][8]="∷";
case 26:
if(a[16][12]=="□")a[16][12]="∷";
case 27:
if(a[13][15]=="□")a[13][15]="∷";
}
draw();
}
if(t6>=0.125) {//速度调节
renji();
t5+=0.125;
}
if(kbhit()) {
ch=getch();
p1kz();
if(ch=='p') {
zanting();
t4=t1;
do {
ch=getch();
} while(ch!='p');
t=t+(int)time(NULL)-t4;
system("cls");
draw();
continue;
}
if(ch=='=') {
exit(0);
}
if(ch=='q') {
m1++;
draw();
}
if(ch=='6') {
m2++;
draw();
}
}
}
draw();
if(n2==0) {
printf(" ●Player 1 -");
while(1) {
ch=getch();
if(ch=='=') {
break;
}
}
} else {
printf(" ▲Player 2 -");
while(1) {
ch=getch();
if(ch=='=') {
break;
}
}
}
}
return 0;
}
6.扫雷:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<conio.h>
#include<windows.h>
#include<cstdlib>
#include<ctime>
using namespace std;
#define MAXN 35
#define MIDX 10
#define MIDY 40
#define CG 25
#define CK 80
int G,K,Lnum,Wnum;//G为地图高,K为地图,Lnum为地图中的雷数,Wnum为剩余的小旗数
int nx,ny;//现在光标所在的位置
bool QR=0,Lose=0,is_flag_true[MAXN][MAXN];//QR为确认模式是否打开,Lose为是否输,第三个是这个位置上的旗是否放对
char map[MAXN][MAXN],tmap[MAXN][MAXN];//第一个是只有雷和空地的地图,第二个是玩家能看到的地图
int map1[MAXN][MAXN],mapc[MAXN][MAXN];//map1为数字的地图,其中0代表空地,-1为雷,1-8为周围雷的个数
//mapc为当前格子的颜色
int col[10]={240,249,242,252,241,244,243,240,248};//col[i]表示windows扫雷中i的颜色,col[0]为空格的颜色
int d[10][4]={{0},{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};//8个方向
bool ZB;//作弊是否打开
/*各种函数*/
void color(int);//颜色
void gto(int,int);//光标位置
void make();//制作随机地图
void print();//打印地图等
bool check(int,int);//判断坐标是否合法
bool is_win();//判断是否赢
bool is_lose();//是否输
void dfs(int,int);//用深搜来打开方块
void st(int,int);//试探,即windows扫雷中的左右键同时按
void flag(int,int);//小旗
void bj(int,int);//标记
void swt();//确认模式
void again();//重新开始
void zb();//作弊模式
void mainmain();//主函数
void print_real_map();//打印最终的地图
void begin();//各种操作
int main()
{
mainmain();
}
void color(int a){SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);}
void gto(int x,int y)
{
COORD pos;pos.X=y;pos.Y=x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void make()
{
for(int i=1;i<=G;i++)
for(int j=1;j<=K;j++)
map[i][j]='#';//初始化
for(int i=1;i<=Lnum;i++)
{
int x=rand()%G+1,y=rand()%K+1;
while(map[x][y]=='O')
x=rand()%G+1,y=rand()%K+1;
map[x][y]='O';
}//随机放雷
for(int i=1;i<=G;i++)
for(int j=1;j<=K;j++)
{
if(map[i][j]=='O')map1[i][j]=-1,mapc[i][j]=240;//如果是雷
else
{
for(int k=1;k<=8;k++)
if(map[i+d[k][0]][j+d[k][1]]=='O')
map1[i][j]++;//计算周围雷的个数
mapc[i][j]=col[map1[i][j]];//根据格子上的数设置颜色
}
}
for(int i=1;i<=G;i++)
for(int j=1;j<=K;j++)
if(mapc[i][j]==0)//空地
mapc[i][j]=240;
}
void print()
{
system("cls");
gto(0,MIDY-4); color(233); printf("扫雷");
color(240);
gto(1,MIDY);
for(int i=2;i<=G+1;i++)
{
gto(i,0);
for(int j=1;j<=K;j++)
printf("#"),tmap[i-1][j]='#';//初始化玩家所看到的地图
}
gto(2,0);
nx=2,ny=0;
color(15);
printf("@");
color(15);
gto(2,2*K+5);printf("-----规则-----");
gto(3,2*K+5);printf("wasd:选择位置");
gto(4,2*K+5);printf("空格:打开");
gto(5,2*K+5);printf("1键:试探周围8个方块,如果其中有雷则不会打开,无");
gto(6,2*K+5);printf(" 雷或旗帜标对了则会将周围无雷的位置打开,");
gto(7,2*K+5);printf(" 如果试探时周围有标错的旗帜,则会游戏失败");
gto(8,2*K+5);printf(" 必须额外确认一次,以便查看周围被试探的区域");
gto(9,2*K+5);printf("2键:放置/取消小旗(F)");
gto(10,2*K+5);printf("3键:放置/取消标记(?)");
gto(11,2*K+5);printf("4键:打开/关闭确认模式,即每次操作需再按一次确认");
gto(12,2*K+5);printf("5键:打开/关闭作弊模式,即显示原本地图");
gto(13,2*K+5);printf("0键:重新开始");//打印规则
gto(G+4,0);printf("-----操作提示-----\n");
printf("请选择方块进行操作");
gto(1,2*K+10);color(12);printf("剩余小旗数:%d",Wnum=Lnum);
}
bool check(int x,int y){return y>=0&&y<K&&x>=2&&x<G+2;}
//因为地图是从2行0列开始打的,而地图是从1行1列开始存的,所以gto(x,y)走到的是map[x-1][y+1]
bool is_win()
{
int cnt=0;
for(int i=1;i<=G;i++)
for(int j=1;j<=K;j++)
if(map[i][j]=='#'&&map1[i][j]==-1)
cnt++;
if(cnt==Lnum) return 1;
//所有没被打开的方块都是雷=>胜利
for(int i=1;i<=G;i++)
for(int j=1;j<=K;j++)
if((tmap[i][j]!='F'&&map1[i][j]==-1)||(tmap[i][j]=='F'&&map1[i][j]!=-1))
return 0;
return 1;
//所有雷都标有旗
}
bool is_lose(){return Lose;}
void dfs(int x,int y)
{
if(map1[x-1][y+1]>0)//只要边界全部是数字就return
{
gto(x,y),color(mapc[x-1][y+1]),printf("%d",map1[x-1][y+1]);
tmap[x-1][y+1]=map1[x-1][y+1]+'0';
return;
}
gto(x,y);color(255);
tmap[x-1][y+1]=' ';
printf(" ");//因为下面判断了雷,上面判断了数字,这里就一定是空地
for(int i=1;i<=8;i++)
{
int xx=x+d[i][0]-1,yy=y+d[i][1]+1;//这里的xx和yy是在map中的,而不是gto中的
if(check(xx+1,yy-1)&&tmap[xx][yy]=='#'&&map1[xx][yy]!=-1)//所以check和dfs的参数要变化
dfs(xx+1,yy-1);
}
}
void st(int x,int y)
{
for(int i=1;i<=8;i++)
{
int xx=x+d[i][0],yy=y+d[i][1];
if(check(xx,yy))
{
gto(xx,yy);
if(tmap[xx-1][yy+1]!='#')
color(mapc[xx-1][yy+1]-128);//减去128使周围的8个格子的背景颜色变为灰色
else
color(112);//这里特判一下'#',应该可以不用
printf("%c",tmap[xx-1][yy+1]);
}
}
gto(G+5,0),color(15),printf("请确认 ");
//试探必须额外确认一次,规则上有说
char c=getch();
if(c=='1')
{
for(int i=1;i<=8;i++)
{
int xx=x+d[i][0],yy=y+d[i][1];
if(check(xx,yy))
if(tmap[xx-1][yy+1]=='F'&&map1[xx-1][yy+1]!=-1)//试探时有格子的小旗标错了=>失败
{
Lose=1;
return;
}
}
for(int i=1;i<=8;i++)
{
int xx=x+d[i][0],yy=y+d[i][1];
if(check(xx,yy))
if(map1[xx-1][yy+1]==-1&&tmap[xx-1][yy+1]!='F')//试探是有格子为雷=>取消打开
return;
}
for(int i=1;i<=8;i++)
{
int xx=x+d[i][0],yy=y+d[i][1];
if(check(xx,yy)&&tmap[xx-1][yy+1]=='#')//打开周围8个格子
dfs(xx,yy);
}
}
}
void flag(int x,int y)
{
x-=1,y+=1;
if(tmap[x][y]=='F')//原本为小旗=>取消小旗
{
tmap[x][y]='#';mapc[x][y]=240;
gto(x+1,y-1),color(240),printf("#");
Wnum++;//更新小旗数
}
else//否则就放置小旗
{
is_flag_true[x][y]=map1[x][y]==-1;//判断小旗是否放对
tmap[x][y]='F';mapc[x][y]=253;
gto(x+1,y-1),color(253),printf("F");
Wnum--;//更新小旗数
}
gto(1,2*K+10);color(12);printf("剩余小旗数: ");
gto(1,2*K+22);printf("%d",Wnum);//更新小旗数
}
void bj(int x,int y)//和放小旗差不多,只是不用更新is_flag_true
{
x-=1,y+=1;
if(tmap[x][y]=='?')
{
gto(x+1,y-1),color(240),printf("#");
tmap[x][y]='#';mapc[x][y]=240;
}
else
{
if(tmap[x][y]=='F')//如果原本这个位置上是小旗,而你把它变为了标记,就要更新小旗数
{
Wnum++;
gto(1,2*K+10);color(12);printf("剩余小旗数: ");
gto(1,2*K+22);printf("%d",Wnum);
}
gto(x+1,y-1),color(240),printf("?");
tmap[x][y]='?';mapc[x][y]=240;
}
}
void swt(){QR=!QR;}
void zb()
{
if(ZB)//如果本来作弊打开了就把作弊地图清除
{
for(int i=1;i<=G;i++)
{
gto(i+1,K+2);
for(int j=1;j<=K;j++)
color(15),printf(" ");
}
ZB=0;
}
else//否则打印作弊地图
{
for(int i=1;i<=G;i++)
{
gto(i+1,K+2);
for(int j=1;j<=K;j++)
{
color(mapc[i][j]);
if(map1[i][j]==-1) printf("O");
else if(map1[i][j]>0) printf("%d",map1[i][j]);
else printf(" ");
}
}
ZB=1;
}
}
void again()
{
G=K=Lnum=nx=ny=Lose=ZB=0;
QR=0;
memset(is_flag_true,0,sizeof(is_flag_true));
memset(map,0,sizeof(map));
memset(tmap,0,sizeof(tmap));
memset(map1,0,sizeof(map1));
memset(mapc,0,sizeof(mapc));
color(15);
system("cls");//初始化
mainmain();
}
void begin()//各种操作
{
char c=getch();
gto(G+5,0),color(15),printf("请选择方块进行操作");
color(240);
if(c=='w'&&check(nx-1,ny))
{
gto(nx,ny);
if(tmap[nx-1][ny+1]!='#'||tmap[nx-1][ny+1]==' ')
color(mapc[nx-1][ny+1]);
printf("%c",tmap[nx-1][ny+1]);
gto(nx-=1,ny);color(15);printf("@");
}
else if(c=='s'&&check(nx+1,ny))
{
gto(nx,ny);if(tmap[nx-1][ny+1]!='#'||tmap[nx-1][ny+1]==' ')color(mapc[nx-1][ny+1]);printf("%c",tmap[nx-1][ny+1]);
gto(nx+=1,ny);color(15);printf("@");
}
else if(c=='a'&&check(nx,ny-1))
{
gto(nx,ny);if(tmap[nx-1][ny+1]!='#'||tmap[nx-1][ny+1]==' ')color(mapc[nx-1][ny+1]);printf("%c",tmap[nx-1][ny+1]);
gto(nx,ny-=1);color(15);printf("@");
}
else if(c=='d'&&check(nx,ny+1))
{
gto(nx,ny);if(tmap[nx-1][ny+1]!='#'||tmap[nx-1][ny+1]==' ')color(mapc[nx-1][ny+1]);printf("%c",tmap[nx-1][ny+1]);
gto(nx,ny+=1);color(15);printf("@");
}
//上下左右移动
else
{
if(c==' '&&(!(tmap[nx-1][ny+1]<='9'&&tmap[nx-1][ny+1]>='0'))&&tmap[nx-1][ny+1]!='F')
{
mapc[nx-1][ny+1]=col[map1[nx-1][ny+1]];//如果本来放了标记,mapc[nx-1][ny+1]的颜色为黑色,在打开时里面的颜色却不一定是黑色
if(QR)
{
gto(G+5,0),color(15),printf("请确认 ");
if(getch()==' ')
{
if(map1[nx-1][ny+1]==-1) {Lose=1;return;}
dfs(nx,ny);
}
}
else
{
if(map1[nx-1][ny+1]==-1) {Lose=1;return;}
dfs(nx,ny);
}
}
else if(c=='1')
{
if(QR)
{
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='1') st(nx,ny);
}
else st(nx,ny);
for(int i=1;i<=8;i++)
{
int xx=nx+d[i][0],yy=ny+d[i][1];
if(check(xx,yy))
{
gto(xx,yy);
if(tmap[xx-1][yy+1]!='#') color(mapc[xx-1][yy+1]);
else color(240);
printf("%c",tmap[xx-1][yy+1]);
}
}
}
else if(c=='2'&&(tmap[nx-1][ny+1]>'9'||tmap[nx-1][ny+1]<'1'))
{
if(QR)
{
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='2') flag(nx,ny);
}
else flag(nx,ny);
}
else if(c=='3'&&(tmap[nx-1][ny+1]>'9'||tmap[nx-1][ny+1]<'1'))
{
if(QR)
{
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='3') bj(nx,ny);
}
else bj(nx,ny);
}
else if(c=='4')
{
if(QR)
{
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='4') swt();
}
else swt();
}
else if(c=='5')
{
if(QR)
{
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='5') zb();
}
else zb();
}
else if(c=='0')
{
if(QR)
{
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='0') again();
}
else again();
}
}
}
void mainmain()
{
system("mode con cols=120 lines=35");//设置窗口大小
srand((unsigned)time(NULL));
int mode;
printf("1.初级\n2.中级\n3.高级\n4.自定义\n");
scanf("%d",&mode);if(mode>4) mode=4;
if(mode==1) G=9,K=9,Lnum=10;
else if(mode==2) G=16,K=16,Lnum=40;
else if(mode==3) G=16,K=30,Lnum=99;//三种等级的参数
else
{
printf("请输入雷区高度:");scanf("%d",&G);
printf("请输入雷区宽度:");scanf("%d",&K);
printf("请输入雷个数(建议不超过总大小的三分之一):");scanf("%d",&Lnum);
if(G>24) G=24;if(K>30) K=30;
if(G<9) G=9;if(K<9) K=9;
if(Lnum<10) Lnum=10;if(Lnum>G*K*9/10) Lnum=G*K*9/10;
//控制参数的范围,最后一个if是雷的数量不超过地图大小的9/10
}
make();
print();
while(1)
{
begin();
bool f1=is_win(),f2=is_lose();
if(f1||f2)
{
gto(0,0);
if(f1)
color(202),gto(0,0),printf("你 赢 了!!是否重来?(y/n)");
if(f2)
color(137),gto(0,0),printf("你 输 了!!是否重来?(y/n)");//输赢
print_real_map();
char c=getch();
if(c=='y'||c=='Y') again();
else
{
color(15);
system("cls");
gto(MIDX,MIDY-5);
printf("欢迎下次再来");
return;
}
}
}
}
void print_real_map()
{
color(240);
for(int i=1;i<=G;i++)
{
gto(i+1,0);
for(int j=1;j<=K;j++)
{
if(tmap[i][j]=='F'&&is_flag_true[i][j]==0)//如果旗标错了显示红色的X
color(252),printf("X");
else if(map1[i][j]==-1)//雷为黑色O
color(240),printf("O");
else if(map1[i][j]==0)//空
color(240),printf(" ");
else//数字
color(mapc[i][j]),printf("%d",map1[i][j]);
}
}}
|