admin管理员组文章数量:1657214
//BUG:清除一行后上方的方块会重力下落
#include <iostream>
#include <windows.h>
#include <vector>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
using namespace std;
#define GameW 10
#define GameH 20
const int CtrlLeft = GameW*2+4 + 3;
struct Point {
Point(){}
Point(int x, int y) {_x = x, _y = y;}
int _x, _y;
};
HANDLE g_hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE g_hInput = GetStdHandle(STD_INPUT_HANDLE);
Point g_ptCursor(0,0);
BOOL isChecking = FALSE;
BOOL g_bGameOver = FALSE;
int g_nGameBack[GameH][GameW], Case;
int nowKeyInfo = -1;
int g_nDiff = 1;
int g_nLife = 2;
int g_nScore = 0;
void SetCursor(COORD cd) {
SetConsoleCursorPosition(g_hOutput, cd);
}
void SetCursor(int x, int y){
COORD cd = {x, y};
SetCursor(cd);
}
void SetBlockCursor(int x, int y){
COORD cd = {2*x + 2, y + 1};
SetCursor(cd);
}
void SetBack(int x, int y, BOOL bk) {
SetBlockCursor(x, y);
if (bk)
printf("%s", "■");
else
printf(" ");
}
bool Out(int x, int y) {
return x < 0 || y < 0 || x >= GameW || y >= GameH;
}
struct xBlock {
public:
int len;
int nowRotateID;
BOOL mask[4][4][4];
static vector <xBlock> List;
xBlock() { len = 0; }
xBlock(int l, char *str) {
int i, j, k;
len = l;
memset(mask, FALSE, sizeof(mask));
for(i = 0; i < l; i++) {
for(j = 0; j < l; j++) {
mask[0][i][j] = str[i*l + j] - '0';
}
}
for(k = 1; k < 4; k++) {
for(i = 0; i < len; i++) {
for(j = 0; j < len; j++) {
mask[k][i][j] = mask[k-1][j][len-1-i];
}
}
}
nowRotateID = rand() % 4;
}
void rotate() {
nowRotateID ++;
if (nowRotateID >= 4)
nowRotateID = 0;
}
BOOL getUnit(int x, int y, int roID) {
if (roID == -1) {
roID = nowRotateID;
}
return mask[roID][y][x];
}
};
vector <xBlock> xBlock::List;
class Block {
public:
int x, y;
int ID;
xBlock bk;
void reset(xBlock *pbk) {
bk = *pbk;
x = 4, y = 0;
ID = ++ Case;
if(collide(0,0)) {
lifeDown();
}
draw();
*pbk = xBlock::List[rand() % xBlock::List.size()];
}
void lifeDown() {
int i, j;
for(i = 0; i < GameH; i++) {
for(j = 0; j < GameW; j++) {
SetBack(j, i, TRUE);
Sleep(10);
}
}
if(g_nLife) {
g_nLife --;
for(i = g_nLife; i < 6; i++) {
SetCursor(CtrlLeft + i, 15);
printf("%c", ' ');
}
for(i = GameH-1; i >= 0; i--) {
for(j = GameW-1; j >= 0; j--) {
SetBack(j, i, FALSE);
Sleep(10);
g_nGameBack[i][j] = 0;
}
}
}else {
g_bGameOver = TRUE;
}
}
void erase() {
int i, j;
for(i = 0; i < bk.len; i++) {
for(j = 0; j < bk.len; j++) {
if (bk.getUnit(j, i, -1)) {
if(!Out(j+x, i+y) && g_nGameBack[i+y][j+x]) {
SetBack(j+x, i+y, FALSE);
g_nGameBack[i+y][j+x] = 0;
}
}
}
}
}
void draw() {
int i, j;
for(i = 0; i < bk.len; i++) {
for(j = 0; j < bk.len; j++) {
if (bk.getUnit(j, i, -1)) {
if(!Out(j+x, i+y) && !g_nGameBack[i+y][j+x]) {
SetBack(j+x, i+y, TRUE);
g_nGameBack[i+y][j+x] = ID;
}
}
}
}
}
void draw(int x, int y) {
int i, j;
for(i = 0; i < 4; i++) {
for(j = 0; j < 4; j++) {
SetCursor(x + 2*j, y + i);
if (bk.getUnit(j, i, -1)) {
printf("%s", "■");
}else
printf(" ");
}
}
}
bool collide(int dx, int dy, int roID = -1) {
int i, j;
for(i = 0; i < bk.len; i++) {
for(j = 0; j < bk.len; j++) {
if (bk.getUnit(j, i, roID)) {
Point ptPos(j + x + dx, i + y + dy);
if(Out(ptPos._x, ptPos._y)
|| g_nGameBack[ptPos._y][ptPos._x] && ID != g_nGameBack[ptPos._y][ptPos._x]) {
return TRUE;
}
}
}
}
return FALSE;
}
void rotate(int nTimes = 1) {
int nextro = (bk.nowRotateID + nTimes) % 4;
if(collide(0, 0, nextro)) {
return ;
}
Beep(12000, 50);
erase();
bk.nowRotateID = nextro;
draw();
}
BOOL changepos(int dx, int dy) {
if(collide(dx, dy)) {
return FALSE;
}
erase();
x += dx;
y += dy;
draw();
return TRUE;
}
};
void GameInit() {
CONSOLE_CURSOR_INFO cursor_info;
cursor_info.bVisible = FALSE;
cursor_info.dwSize = 100;
SetConsoleCursorInfo(g_hOutput, &cursor_info);
xBlock::List.push_back(xBlock(3, "010111000"));
xBlock::List.push_back(xBlock(3, "110110000"));
xBlock::List.push_back(xBlock(3, "111001000"));
xBlock::List.push_back(xBlock(3, "111100000"));
xBlock::List.push_back(xBlock(3, "110011000"));
xBlock::List.push_back(xBlock(3, "011110000"));
xBlock::List.push_back(xBlock(4, "1000100010001000"));
}
void DrawFrame(int x, int y, int nWidth, int nHeight) {
int i;
for(i = 0; i < nWidth; i++) {
SetCursor(x + 2*i + 2, y);
printf("%s", "一");
SetCursor(x + 2*i + 2, y + nHeight+1);
printf("%s", "┄");
}
for(i = 0; i < nHeight; i++) {
SetCursor(x, y + i + 1);
printf("%s", "┆");
SetCursor(x + nWidth*2+2, y + i + 1);
printf("%s", "┆");
}
SetCursor(x, y);
printf("%s", "┌");
SetCursor(x, y + nHeight+1);
printf("%s", "└");
SetCursor(x + nWidth*2+2, y);
printf("%s", "┐");
SetCursor(x + nWidth*2+2, y + nHeight+1);
printf("%s", "┘");
}
void MissionInit() {
memset(g_nGameBack, FALSE, sizeof(g_nGameBack));
Case = 1;
int i;
DrawFrame(0, 0, GameW, GameH);
DrawFrame(GameW*2+4, 0, 4, GameH);
SetCursor(CtrlLeft, 2);
printf("Next");
SetCursor(CtrlLeft, 8);
printf("Speed");
for(i = 0; i < g_nDiff; i++) {
SetCursor(CtrlLeft + i, 9);
printf("%c", 1);
}
SetCursor(CtrlLeft, 11);
printf("Score");
SetCursor(CtrlLeft, 12);
printf("%d", g_nScore);
SetCursor(CtrlLeft, 14);
printf("Life");
for(i = 0; i < g_nLife; i++) {
SetCursor(CtrlLeft + i, 15);
printf("%c", 3);
}
SetCursor(CtrlLeft-1, 19);
printf("@Metaphu");
SetCursor(CtrlLeft-1, 20);
printf("Revised");
}
void Check() {
isChecking = TRUE;
int i, j, k;
vector <int> line;
for(i = 0; i < GameH; i++) {
for(j = 0; j < GameW; j++) {
if(!g_nGameBack[i][j])
break;
}
if(j == GameW) {
line.push_back(i);
}
}
if(line.size()) {
int nCount = 7;
while(nCount --) {
for(i = 0; i < line.size(); i++) {
for(j = 0; j < GameW; j++) {
SetBack(j, line[i], nCount&1);
}
}
Sleep(70);
}
for(i = 0; i < line.size(); i++) {
for(j = 0; j < GameW; j++) {
g_nGameBack[line[i]][j] = 0;
}
}
for(i = 0; i < GameW; i++) {
int next = GameH-1;
for(j = GameH-1; j >= 0; j--) {
for(k = next; k >= 0; k--) {
if(g_nGameBack[k][i])
break;
}
next = k - 1;
BOOL is = (k >= 0);
SetBack(i, j, is);
g_nGameBack[j][i] = is;
}
}
g_nScore += 2*line.size()-1;
SetCursor(CtrlLeft, 12);
printf("%d", g_nScore);
if( g_nScore >= g_nDiff * g_nDiff * 10) {
if(g_nDiff <= 6)
g_nDiff ++;
}
if( g_nScore >= 50 * (g_nLife+1)) {
if(g_nLife <= 6)
g_nLife ++;
}
}
isChecking = FALSE;
}
int main() {
Block* obj = new Block();
Block* buf = new Block();
BOOL bCreateNew = FALSE;
int nTimer = GetTickCount();
int LastKeyDownTime = GetTickCount();
GameInit();
MissionInit();
buf->bk = xBlock::List[rand() % xBlock::List.size()];
while(1) {
if(!bCreateNew) {
bCreateNew = TRUE;
obj->reset(&buf->bk);
if(g_bGameOver)
break;
buf->draw(CtrlLeft - 1, 4);
}
if (GetTickCount() - nTimer >= 1000 / g_nDiff) {
nTimer = GetTickCount();
if (!obj->collide(0, 1))
obj->changepos(0, 1);
else {
Check();
bCreateNew = FALSE;
}
}
if (GetTickCount() - LastKeyDownTime >= 100) {
if(FALSE == isChecking) {
LastKeyDownTime = GetTickCount();
if (GetAsyncKeyState(VK_UP)) {
obj->rotate();
}
if (GetAsyncKeyState(VK_LEFT)) {
obj->changepos(-1, 0);
}
if (GetAsyncKeyState(VK_RIGHT)) {
obj->changepos(1, 0);
}
if (GetAsyncKeyState(VK_DOWN)) {
if( FALSE == obj->changepos(0, 2) )
obj->changepos(0, 1);
}
}
}
}
SetCursor(8, 10);
printf("Game Over");
SetCursor(0, GameH+3);
printf("按ESC键退出游戏");
while(1) {
if (GetAsyncKeyState(VK_ESCAPE))
break;
}
return 0;
}
1.flappy_bird
#include<bits/stdc++.h>
#include<Windows.h>
#define PR_Box printf("■")
#define PR_Gold printf("★")
#define PR_Ag printf("☆")
#define PR_FBird printf("Ю")
#define PR_DBird printf("Ф")
#define PR_Land printf("┳┳┯")
#define PR_Bg_TL printf("╔")
#define PR_Bg_TR printf("╗")
#define PR_Bg_DL printf("╚")
#define PR_Bg_DR printf("╝")
#define PR_Bg_X printf("═")
#define PR_Bg_Y printf("║")
#define PR_Blank printf(" ");
int Grade=1,C_Gold=0,C_Ag=0,Score=0,Delay_time=1000,Max_blank=9,Distance=18;
struct Birds {
int x,y;
int condition;
};
Birds*Bird=(Birds*)malloc(sizeof(Birds));
struct Bg {
int x,y;
int l_blank;
int reward[9];
Bg*pri;
Bg*next;
};
Bg*Bg1=new Bg[sizeof(Bg)];
void Position(int x,int y) {
COORD pos= {x-1,y-1};
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out,pos);
}
void CreatBird() {
Bird->x=41;
Bird->y=10;
Bird->condition=0;
}
void CreatBg() {
Bg*Bg2=(Bg*)malloc(sizeof(Bg));
Bg1->x=90;
Bg1->y=8;
Bg2->x=Bg1->x+Distance;
Bg2->y=9;
Bg1->l_blank=Max_blank-Grade;
Bg2->l_blank=Max_blank-Grade;
Bg1->next=Bg2;
Bg1->pri=Bg2;
Bg2->next=Bg1;
Bg2->pri=Bg1;
}
void InsertBg(Bg*p) {
int temp;
Bg*Bgs=(Bg*)malloc(sizeof(Bg));
Bgs->x=p->pri->x+Distance;
Bgs->l_blank=Max_blank-Grade;
srand((int)time(0));
temp=rand();
if(temp%2==0) {
if((temp%4+p->pri->y+Max_blank-Grade)<21)Bgs->y=p->pri->y+temp%4;
else Bgs->y=p->pri->y;
} else {
if((p->pri->y-temp%4)>2)Bgs->y=p->pri->y-temp%4;
else Bgs->y=p->pri->y;
}
Bgs->pri=p->pri;
Bgs->next=p;
p->pri->next=Bgs;
p->pri=Bgs;
}
void Check_Bg(Bg*q) {
Bg*p=q;
int i=0,temp;
while(++i<=5) {
if(p->x>-4)p=p->next;
else {
srand((int)time(0));
temp=rand();
if(temp%2==0) {
if((temp%4+p->y+Max_blank-Grade)<21)p->y=p->y+temp%4;
else p->y=p->y;
p->x=p->pri->x+Distance;
p->l_blank=Max_blank-Grade;
} else {
if((p->y-temp%4)>2)p->y=p->y-temp%4;
else p->y=p->y;
p->x=p->pri->x+Distance;
p->l_blank=Max_blank-Grade;
}
}
}
}
void Loop_Bg(Bg*q) {
Bg*p=q;
int i=0;
while(++i<=5) {
p->x=p->x-1;
p=p->next;
if(Bird->x==p->x) {
Score+=1;
if(Score%4==0&&Grade<4)Grade++;
}
}
}
void Prt_Bg(Bg*q) {
Bg*p=q;
int i=0,k,j;
while(++i<=5) {
if(p->x>0&&p->x<=78) {
for(k=2; k<p->y; k++) {
Position(p->x+1,k);
PR_Box;
PR_Box;
PR_Blank
}
Position(p->x,p->y);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
Position(p->x,p->y+p->l_blank);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
k=k+p->l_blank+1;
for(k; k<=22; k++) {
Position(p->x+1,k);
PR_Box;
PR_Box;
PR_Blank;
}
Position(p->x,23);
for(k=1; k<Distance/3-2; k++)PR_Land;
}
p=p->next;
if(p->x==0) {
for(j=2; j<p->y; j++) {
Position(p->x+1,j);
PR_Blank;
PR_Blank;
}
Position(p->x+1,p->y);
PR_Blank;
PR_Blank;
PR_Blank;
Position(p->x+1,p->y+Max_blank-Grade);
PR_Blank;
PR_Blank;
PR_Blank;
j=j+Max_blank-Grade+1;
for(j; j<=22; j++) {
Position(p->x+1,j);
PR_Blank;
PR_Blank;
}
}
}
}
void PrtBg() {
int i;
Position(1,1);
PR_Bg_TL;
Position(79,1);
PR_Bg_TR;
Position(1,24);
PR_Bg_DL;
Position(79,24);
PR_Bg_DR;
for(i=3; i<=78; i+=2) {
Position(i,1);
PR_Bg_X;
Position(i,24);
PR_Bg_X;
}
}
void PrtBird() {
Position(Bird->x,Bird->y-1);
PR_Blank;
Position(Bird->x,Bird->y);
PR_FBird;
Position(38,2);
printf("Score:%d",Score);
}
int CheckYN(Bg*q) {
Bg*p=q;
int i=0;
while(++i<=5) {
if(Bird->y>23)return 0;
if(Bird->x==p->x&&Bird->y<=p->y)return 0;
if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y)return 0;
if(Bird->x==p->x&&Bird->y>p->y+p->l_blank)return 0;
if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y+p->l_blank)return 0;
p=p->next;
}
return 1;
}
void Prtfirst() {
printf("══════════════════════════════════════\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■ C++语言版 Flappy Bird\n");
printf(" ■■ ■■ 瞎搞人:额…………\n");
printf(" ■■ ■■ 瞎搞日期:2022.7.3\n");
printf(" ■■ ■■ 耗时:2.46小时\n");
printf(" ■■■ ■■ 游戏说明:\n");
printf(" ■■ 1-按上箭头使鸟起飞\n");
printf(" ■■ 2-等级越高,难度越大!\n");
printf(" Ю ■■■\n");
printf("\n");
printf(" \n\n\n\n\n\n\n\n");
printf(" ┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳\n");
system("pause");
Position(1,1);
int i=0;
while(i++<40*25)PR_Blank;
}
int main() {
int i=0;
char ch;
Prtfirst();
PrtBg();
CreatBg();
InsertBg(Bg1);
InsertBg(Bg1);
InsertBg(Bg1);
CreatBird();
while(1) {
if(!CheckYN(Bg1))break;
Check_Bg(Bg1);
Prt_Bg(Bg1);
PrtBird();
Loop_Bg(Bg1);
Bird->y=Bird->y+1;
if(GetAsyncKeyState(VK_UP)) {
Position(Bird->x,Bird->y-1);
PR_Blank;
Bird->y=Bird->y-4;
}
while(i++<500);
{
Sleep(100);
}
i=0;
}
Position(38,10);
printf("Game Over!");
Position(1,25);
system("pause");
}
2.猜数字
#include<cstdio>
#include<cstdlib>
#include<windows.h>
#include<map>
#include<iostream>
#include<string>
#include<conio.h>
#include<fstream>
#include<cstring>
#include<ctime>
#define N 2
#define M 3
using namespace std;
bool mord[M+1];
int maxc[M+1],c[M+1]={0},np,point[10];
char name[10][20];
void color(int a)//颜色函数
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void gotoxy(int x,int y)//位置函数
{
COORD pos;
pos.X=2*x;
pos.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
int play();
int set_g(int set1);
int main()
{
map<int,string>ma;
char chti[10]={" ·>"};
ma[1]="单人竞猜";
ma[2]="多人竞猜";
ma[N+1]="返回";
int ch=1;
system("color f0");
while(1)
{
for(int i=1;i<=N+1;i++)
{
if(i==ch)
{
color(192);
printf("%s",chti);
}
else
{
color(240);
for(int i=1;i<=strlen(chti);i++)
printf(" ");
}
cout<<ma[i];
for(int j=80-ma[i].size()-strlen(chti);j>0;j--)cout<<" ";
color(240);
}
char x;
x=getch();
if(x=='w'&&ch>1)ch--;
if(x=='s'&&ch<N+1)ch++;
if(x==13)
{
if(ch==N+1)
return 0;
switch(ch)
{
case 1:np=1;break;
case 2:system("cls");printf("请输入玩家数:\n");
cin>>np;break;
}
set_g(ch);
}
system("cls");
}
return 0;
}
int set_g(int set1)
{
system("cls");
bool setmord[N+1][M+1]=
{{1,0,0,0}, //空行
{1,1,1,0},
{1,1,1,1}};
map<int,string>ma;
char chti[10]={" ·>"};
ma[1]="难度";maxc[1]=4;
ma[2]="噩梦";maxc[2]=3;
ma[3]="自动跳过";maxc[3]=5;
ma[M+1]="下一步";
ma[M+2]="返回";
int ch=1;
system("color f0");
for(int i=1;i<=M;i++)
mord[i]=setmord[set1][i];
while(1)
{
for(int i=1;i<=M+2;i++)
{
if(i<=M&&!mord[i])
continue;
if(i==ch)
{
color(192);
printf("%s",chti);
}
else
{
color(240);
for(int i=1;i<=strlen(chti);i++)
printf(" ");
}
cout<<ma[i];
for(int j=80-ma[i].size()-strlen(chti);j>0;j--)cout<<" ";
if(i<=M)
{
gotoxy(20,i-1);
int co=i==ch?192:240;
for(int j=0;j<=maxc[i];j++)
{
if(j!=c[i])co+=8;
color(co);
printf("%d",j);
if(j!=c[i])co-=8;
color(co);
printf(" ");
}
gotoxy(0,i);
}
color(240);
}
char x;
x=getch();
if(x=='w'&&ch>1)
{
ch--;
while(!mord[ch]&&ch<=M)ch--;
}
if(x=='s'&&ch<M+2)
{
ch++;
while(!mord[ch]&&ch<=M)ch++;
}
if(ch<=M)
{
if(x=='d'&&c[ch]<maxc[ch])
c[ch]++;
if(x=='a'&&c[ch]>=1)
c[ch]--;
}
if(x==13)
{
if(ch==M+2)
return 0;
if(ch==M+1)
break;
}
system("cls");
}
system("cls");
bool flag=0;
for(int i=1;i<=np;i++)
{
if(flag||set1==1)printf("请输入玩家%d名字:\n",i);
gets(name[i]);
point[i]=0;
if(!flag&&set1!=1)
{
i--;
flag=1;
}
}
Sleep(500);
play();
return 0;
}
int play()
{
system("cls");
srand(time(NULL));
int fw1,fw2=1,ans;
if(c[1]==0)fw1=5000;
else fw1=10000*c[1];
ans=rand()%fw1+1;
printf("数据范围1~%d\n",fw1);
system("pause");
system("cls");
int findit=0,l=0,lnum,ld,lz,em;
bool around=0;
while(!findit)
{
printf("提示: ");
if(c[2]==0)printf("未开启\n");
else printf("%5d ~ %5d \n",fw2,fw1);
printf("噩梦: ");
if(em==1)printf("数变大了\n");
if(em==-1)printf("数变小了\n");
else printf("未发生\n");
printf("\n上一回合:\n");
if(around)
{
cout<<"玩家"<<l<<" "<<name[l]<<endl;
if(ld!=2)printf("%d\n",lnum);
if(ld==1)printf("大了 ");
if(ld==-1)printf("小了 ");
if(ld==0)printf("出错\n");
if(ld==2)printf("被跳过\n");
else
switch(lz)
{
case 1:color(252);point[l]+=7;printf("近在眼前\n");break;
case 2:color(253);point[l]+=5;printf("百步之遥\n");break;
case 3:color(249);point[l]+=3;printf("仰望莫及\n");break;
case 4:color(240);point[l]+=1;printf("远在天边\n");break;
}
color(240);
}
else
{
printf("无\n\n");
around=1;
}
Sleep(500);
l=l%np+1;
printf("\n当前回合:\n");
cout<<"玩家"<<l<<" "<<name[l];
ld=rand()%10<c[3]?2:0;
if(ld==2)
{
printf("\n回合被跳过\n");
Sleep(2000);
system("cls");
continue;
}
printf(" 请猜数:\n");
char readn[20];
gets(readn);
lnum=0;
for(int i=0;i<strlen(readn)&&readn[i]<='9'&&readn[i]>='0';i++)
lnum=lnum*10+readn[i]-'0';
if(lnum<=0||lnum>=40000)
{
ld=0;lz=0;
}
else
{
if(lnum>ans)
{ld=1;if(lnum<fw1)fw1=lnum;}
if(lnum<ans)
{ld=-1;if(lnum>fw2)fw2=lnum;}
if(lnum==ans)findit=1;
lz=abs(lnum-ans);
if(lz<=10)lz=1;
else if(lz<=100)lz=2;
else if(lz<=1000)lz=3;
else lz=4;
}
if(findit)
printf("正确\n");
else
{
if(ld==1)printf("大了 ");
if(ld==-1) printf("小了 ");
if(ld==0)printf("出错\n");
switch(lz)
{
case 1:color(252);printf("近在眼前\n");break;
case 2:color(253);printf("百步之遥\n");break;
case 3:color(249);printf("仰望莫及\n");break;
case 4:color(240);printf("远在天边\n");break;
}
color(240);
}
em=0;
if(lz<=3&&c[2])
{
em=rand()%2==0?-1:1;
int em1;
em1=rand()%(2*c[2]);
if(em1*em>40000||em1*em<=0)em=em*-1;
ans=ans+em*em1;
if(em==1)
fw1+=2*c[2];
else
fw2-=2*c[2];
}
Sleep(1000);
system("cls");
}
point[l]+=20;
printf("玩家%d %s 猜对了\n",l,name[l]);
system("pause");
system("cls");
int poi=0;
for(int i=1;i<=np;i++)poi+=point[i];
poi=poi/100+1;
for(int i=1;i<=np;i++)
{
point[i]=point[i]/poi;
printf("玩家%d %s 得分 ",i,name[i]);
if(point[i]>=50)color(254);
else if(point[i]>=30)color(249);
else if(point[i]>=20)color(250);
else color(248);
printf("%d\n",point[i]);
color(240);
Sleep(500);
}
system("pause");
system("cls");
return 0;
}
3.吃豆人
#include <cstdio>
#include <iostream>
#include <ctime>
#include <conio.h>
#include <windows.h> //停顿:Sleep();
#include <cstdlib> //清屏:system("cls");
#include <cstring>
using namespace std;
const int n=809;
struct Point {int x,y;};
int dali;
int fx[4]={-1,27,1,-27};
int fxfx[4][2]={{0,-1},{1,0},{0,1},{-1,0}};
int dis[1000][1000]; //0:墙 1:有分的路 2:没分的路 3:怪物的家
int changdi[30][27]={
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0},
{0,1,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1,0},
{0,1,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1,0},
{0,1,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1,0},
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
{0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0},
{0,1,1,1,1,1,1,0,0,1,1,1,1,0,1,1,1,1,0,0,1,1,1,1,1,1,0},
{0,0,0,0,0,0,1,0,0,0,0,0,2,0,2,0,0,0,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,0,0,0,2,0,2,0,0,0,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,2,2,2,2,2,2,2,2,2,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,2,0,0,0,3,0,0,0,2,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,2,0,3,3,3,3,3,0,2,0,0,1,0,0,0,0,0,0},
{2,2,2,2,2,2,1,2,2,2,0,3,3,3,3,3,0,2,2,2,1,2,2,2,2,2,2},
{0,0,0,0,0,0,1,0,0,2,0,3,3,3,3,3,0,2,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,2,0,0,0,0,0,0,0,2,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,2,2,2,2,2,2,2,2,2,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,2,0,0,0,0,0,0,0,2,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,2,0,0,0,0,0,0,0,2,0,0,1,0,0,0,0,0,0},
{0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0},
{0,1,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1,0},
{0,1,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1,0},
{0,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,0},
{0,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0},
{0,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0},
{0,1,1,1,1,1,1,0,0,1,1,1,1,0,1,1,1,1,0,0,1,1,1,1,1,1,0},
{0,1,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0},
{0,1,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0},
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
int x,x1,x2,x3,x4,y,y1,y2,y3,y4;
int now,now1,now2,now3,now4;
int g1,g2,g3,g4;
int fangx,nextfx,last1,last2,last3,last4;
int fenshu,guozi,guaitimer;
int T1,T2,t1,t2,stopped; //T:计时 t1:玩家速度 t2:怪物速度
int f=0; //f:{0:继续 1:被吃 2:赢了 3:输了}
int beichi;
void color(int a)//颜色函数
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void gotoxy(int x,int y)//位置函数(行为x 列为y)
{
COORD pos;
pos.X=2*y;
pos.Y=x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void begin(){
system("cls");
color(11); printf(" ★"); color(10); printf("吃豆人"); color(11); printf("★\n\n"); color(7);
printf(" 请将窗口开至"); color(11); printf("全屏\n"); color(7);
printf(" 正在初始化,请耐心等待");
for (int i=0; i<=n; i++) for (int j=1; j<=n; j++) dis[i][j]=900;
for (int i=0; i<=n; i++){
for (int j=0; j<=3; j++){
if (i+fx[j]>=0 && i+fx[j]<=n){
int k=i+fx[j],xx=k/27,yy=k%27,kk;
if (changdi[i/27][i%27] && changdi[xx][yy]) dis[i][k]=kk=1;
}
}
}
for (int k=0; k<=n; k++)if(changdi[k]){
for (int i=0; i<=n; i++)if(changdi[i])
for (int j=0; j<=n; j++)if(changdi[j])
if (dis[i][j]>dis[i][k]+dis[k][j]) dis[i][j]=dis[i][k]+dis[k][j];
if (k%80==0){color (13); gotoxy(3,12); printf("│");}
if (k%80==20){color(13); gotoxy(3,12); printf("╱");}
if (k%80==40){color(13); gotoxy(3,12); printf("─");}
if (k%80==60){color(13); gotoxy(3,12); printf("╲");}
if (k%60==0){color(11); gotoxy(5,k/60); printf("●");}
}
}
void shuru(){
char ch=getch();
if (ch=='1' | ch=='j') if (changdi[x+fxfx[0][0]][y+fxfx[0][1]]==1|changdi[x+fxfx[0][0]][y+fxfx[0][1]]==2) fangx=nextfx=0; else nextfx=0;
else if (ch=='2' | ch=='k') if (changdi[x+fxfx[1][0]][y+fxfx[1][1]]==1|changdi[x+fxfx[1][0]][y+fxfx[1][1]]==2) fangx=nextfx=1; else nextfx=1;
else if (ch=='3' | ch=='l') if (changdi[x+fxfx[2][0]][y+fxfx[2][1]]==1|changdi[x+fxfx[2][0]][y+fxfx[2][1]]==2) fangx=nextfx=2; else nextfx=2;
else if (ch=='5' | ch=='i') if (changdi[x+fxfx[3][0]][y+fxfx[3][1]]==1|changdi[x+fxfx[3][0]][y+fxfx[3][1]]==2) fangx=nextfx=3; else nextfx=3;
else if (ch=='0' | ch=='s') stopped=(stopped+1)%2;
else if (ch=='4' | ch=='a') t1++;
else if (ch=='7' | ch=='q') t2++;
else if ((ch=='6' | ch=='d') && t1-1>0) t1--;
else if ((ch=='9' | ch=='e') && t2-1>0) t2--;
else if (ch=='g') dali=(dali+1)%2;
}
void reset(){
system("cls"); color(7);
gotoxy(2,30); printf("控制方向:1/2/3/5");
gotoxy(4,30); printf("你的速度:4/6");
gotoxy(6,30); printf("怪物速度:7/9");
x=22; y=13;
x1=x2=x3=x4=14; y1=11; y2=12; y3=14; y4=15;
now=607; now1=389; now2=390; now3=392; now4=393;
for (int k=0; k<=n; k++){
int i=k/27,j=k%27;
gotoxy(i,j);
if (changdi[i][j]==1){color(7); printf("?");}
else if (!changdi[i][j]){color(1); printf("■");}
if (j=26){gotoxy(i,27); color(7); printf("%d",i);}
}
gotoxy(0,0);
gotoxy(x,y); color(14); printf("●");
gotoxy(x1,y1); color(4); printf("◆");
gotoxy(x2,y2); color(5); printf("◆");
gotoxy(x3,y3); color(3); printf("◆");
gotoxy(x4,y4); color(2); printf("◆");
fangx=0; T1=T2=guaitimer=0; t1=75; t2=100;stopped=0; fenshu=0; guozi=237; g1=g2=g3=g4=0; dali=0;
gotoxy(14,30); printf(" ");
}
void move1(){
int xx,yy;
xx=x+fxfx[nextfx][0]; yy=y+fxfx[nextfx][1];
if (changdi[xx][yy]){
if (changdi[xx][yy]==1){fenshu+=1; changdi[xx][yy]=2;}
color(14);
gotoxy(x,y); printf(" ");
gotoxy(xx,yy); if (!dali) printf("◎"); else printf("☆");
now=x*27+y; x=xx; y=yy;
fangx=nextfx;
}
else{
if (x==13 && y==0 && fangx==0){xx=x; yy=26;}
else if (x==13 && y==26 && fangx==2){xx=x; yy=0;}
else{xx=x+fxfx[fangx][0]; yy=y+fxfx[fangx][1];}
if (changdi[xx][yy]){
if (changdi[xx][yy]==1){fenshu+=1; changdi[xx][yy]=2;}
color(14);
gotoxy(x,y); printf(" ");
gotoxy(xx,yy); if (!dali) printf("◎"); else printf("☆");
now=x*27+y; x=xx; y=yy;
}
}
color(7);
//gotoxy(15,28); printf("(%d,%d) ",x,y); gotoxy(16,28); printf("now:%d ",now); gotoxy(17,28); printf("%d (%d,%d) ",fangx,fxfx[fangx][0],fxfx[fangx][1]); gotoxy(18,28); printf("(%d,%d) changdi:%d ",xx,yy,changdi[xx][yy]);
}
void move2(){
int haha,minhaha,xx,yy,chi=0;
if (g1){
minhaha=2147483647;
if (now1%27==0 | now1%27==26) haha=last1;
else if (!dali){
for (int i=0; i<=3; i++)
if (changdi[(now1+fx[i])/27][(now1+fx[i])%27] && i!=last1 && minhaha>dis[now1+fx[i]][now])
{minhaha=dis[now1+fx[i]][now]; haha=i;}
}
else{
minhaha=-minhaha;
for (int i=0; i<=3; i++)
if (changdi[(now1+fx[i])/27][(now1+fx[i])%27] && i!=last1 && minhaha<dis[now1+fx[i]][now])
{minhaha=dis[now1+fx[i]][now]; haha=i;}
}
xx=now1/27; yy=now1%27; gotoxy(xx,yy);
if (changdi[xx][yy]==1) printf("?");else printf(" ");
now1+=fx[haha]; last1=(haha+2)%4;
xx=now1/27; yy=now1%27; gotoxy(xx,yy); color(4); printf("◆"); color(7);
if (xx==x && yy==y){
if (!dali) chi+=1;
else {
guozi+=50;
fenshu+=50;
last1=0;
gotoxy(now1/27,now1%27);
if (changdi[now1/27][now1%27]==1) printf("?"); else printf(" ");
now1=389;
}
}
}
if (g2){
int k;
minhaha=2147483647;
if (fangx==0 | fangx==2){
k=y+(fxfx[fangx][1])*3;
while (k>25 | !changdi[x][k]) k--;
while (k<1 | !changdi[x][k]) k++;
} else{
k=x+(fxfx[fangx][0])*3;
while (k>28 | !changdi[k][y]) k--;
while (k<1 | !changdi[k][y]) k++;
}
if (fangx==0 | fangx==2) k=x*27+k; else k=k*27+y;
if (now2%27==0 | now2%27==26) haha=last2;
else if (!dali)
for (int i=0; i<=3; i++){
if (changdi[(now2+fx[i])/27][(now2+fx[i])%27] && i!=last2 && minhaha>dis[now2+fx[i]][k])
{minhaha=dis[now2+fx[i]][k]; haha=i;}
}
else{
minhaha=-minhaha;
for (int i=0; i<=3; i++){
if (changdi[(now2+fx[i])/27][(now2+fx[i])%27] && i!=last2 && minhaha<dis[now2+fx[i]][k])
{minhaha=dis[now2+fx[i]][k]; haha=i;}
}
}
xx=now2/27; yy=now2%27; gotoxy(xx,yy);
if (changdi[xx][yy]==1) printf("?");else printf(" ");
now2+=fx[haha]; last2=(haha+2)%4; gotoxy(18,30);
xx=now2/27; yy=now2%27; gotoxy(xx,yy); color(5); printf("◆"); color(7);
if (xx==x && yy==y){
if (!dali) chi+=1;
else {
guozi+=50;
fenshu+=50;
last2=0;
gotoxy(now2/27,now2%27);
if (changdi[now2/27][now2%27]==1) printf("?"); else printf(" ");
now2=390;
}
}
}
if (g3){
int k;
minhaha=2147483647;
if (fangx==0 | fangx==2){
k=y+(fxfx[(fangx+1)%4][1])*3;
while (k>25 | !changdi[x][k]) k--;
while (k<1 | !changdi[x][k]) k++;
} else{
k=x+(fxfx[(fangx+1)%4][0])*3;
while (k>28 | !changdi[k][y]) k--;
while (k<1 | !changdi[k][y]) k++;
}
if (fangx==0 | fangx==2) k=x*27+k; else k=k*27+y;
if (now3%27==0 | now3%27==26) haha=last3;
else if (!dali)
for (int i=0; i<=3; i++){
if (changdi[(now3+fx[i])/27][(now3+fx[i])%27] && i!=last3 && minhaha>dis[now3+fx[i]][k])
{minhaha=dis[now3+fx[i]][k]; haha=i;}
}
else {
minhaha=-minhaha;
for (int i=0; i<=3; i++){
if (changdi[(now3+fx[i])/27][(now3+fx[i])%27] && i!=last3 && minhaha<dis[now3+fx[i]][k])
{minhaha=dis[now3+fx[i]][k]; haha=i;}
}
}
xx=now3/27; yy=now3%27; gotoxy(xx,yy);
if (changdi[xx][yy]==1) printf("?");else printf(" ");
now3+=fx[haha]; last3=(haha+2)%4; gotoxy(18,30);
xx=now3/27; yy=now3%27;
gotoxy(xx,yy); color(3); printf("◆"); color(7);
if (xx==x && yy==y){
if (!dali) chi+=1;
else {
guozi+=50;
fenshu+=50;
last3=0;
gotoxy(now3/27,now3%27);
if (changdi[now3/27][now3%27]==1) printf("?"); else printf(" ");
now3=341;
}
}
}
if (chi) beichi++;
}
int main(){
begin();
int jixu=1;
reset();
string bb[4]={"●","①","②","③"}; color(7);
gotoxy(12,12); printf("倒计时"); color(12);
for (int i=3; i>=0; i--){if (i==0) color(11);gotoxy(13,13); cout<<bb[i]; Sleep(1000);}
gotoxy(12,12); printf(" "); gotoxy(13,13); printf(" "); color(7);
while (!f){
Sleep(1);
gotoxy(10,30); printf("得分:%d ",fenshu);
gotoxy(8,30); printf("怪物速度:%d ",300-t2);
gotoxy(9,30); printf("你的速度:%d ",300-t1);
gotoxy(15,30); printf("被吃次数:%d ",beichi);
if (kbhit()) shuru();
if (stopped) continue;
T1=(T1+1)%t1; T2=(T2+1)%t2;
if (T1%t1==0 && now+fx[fangx]>0 && now+fx[fangx]<n) move1();
if (T2%t2==0){
if (guaitimer<=8){
if (guaitimer==0) g1=1;
if (guaitimer==8) g2=1;
guaitimer++;
}
if (!g3 && fenshu>=30) g3=1;
move2();
}
if (fenshu==guozi)f=2;
}
if (f=2) {
Sleep(3000);
system("cls");
printf("恭喜你吃完了!\n你一共被怪物吃掉了 %d 次",beichi);
Sleep(3000);
char ying;
scanf("%c",&ying);
}
}
4.打方块
#include<bits/stdc++.h>//打方块 Windows10
#include<windows.h>
using namespace std;
int fen,mb[10][18],leaf;
void kg(int a) {
for(int i=0; i<a; i++)
cout<<' ';
}
void go(int x, int y) {
COORD p;
p.X=(x-1)*2;
p.Y=y-1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),p);
}
void printtu(int x,int y,bool a) {
go(x,y);
cout<<"■";
if(x>2&&x<11) {
go(x-1,y+1);
cout<<"■■■";
} else if(x==2) {
go(x,y+1);
cout<<"■■";
} else if(x==11) {
go(x-1,y+1);
cout<<"■■";
} else;
if(a)
for(int i=0; i<18; i++) {
go(2,i+2);
kg(20);
}
Sleep(100);
go(x,y);
kg(2);
if(x>2&&x<11) {
go(x-1,y+1);
kg(6);
} else if(x==2) {
go(x,y+1);
kg(4);
} else if(x==11) {
go(x-1,y+1);
kg(4);
} else;
go(14,5);
kg(4);
cout<<"\b\b\b\b"<<fen;
if(a)
for(int i=0; i<18; i++) {
go(2,i+2);
for(int o=0; o<10; o++) {
if(mb[o][i])
cout<<"■";
else kg(2);
}
}
}
void sj(int x) {
int i;
for(i=19;; i--) {
go(x,i);
cout<<"■";
Sleep(10);
cout<<"\b\b";
kg(2);
if(i<3)break;
if(mb[x-2][i-3]==1)break;
}
mb[x-2][i-2]=1;
go(x,i);
cout<<"■";
fen-=10;
for(int o=0; o<10; o++)
if(mb[o][i-2]==0)return;
for(int o=0; o<10; o++)
mb[o][i-2]=0;
for(int o=i-2; o<17; o++)
for(int j=0; j<10; j++)
mb[j][o]=mb[j][o+1];
for(int o=0; o<10; o++)
mb[o][17]=0;
printtu(x,20,1);
fen+=100;
}
void mouse(int &x,int &y) {
POINT p;
HWND h=GetForegroundWindow();
GetCursorPos(&p);
ScreenToClient(h,&p);
x=p.x;
y=p.y;
}
void m(int wt) {
lkr:
;
fen=-500;
leaf=8;
srand(time(0));
system("mode con cols=33 lines=24");
system("cls");
cout<<"┌ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┐"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆ 分数"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆ 生命"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆ ";
printf("%c %c %c %c\n",3,3,3,3);
cout<<"┆ ";
kg(20);
cout<<"┆ ";
printf("%c %c %c %c\n",3,3,3,3);
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"└ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┘"<<endl;
lk:
;
for(int i=0; i<10; i++)
for(int o=0; o<18; o++)
mb[i][o]=0;
int x=6;
for(int i=wt*10;;) {
if(i<wt*10)goto asd;
for(int i=0; i<10; i++)
for(int o=0; o<18; o++)
if(mb[i][o]!=0)goto qwe;
fen+=500;
qwe:
;
for(int o=0; o<10; o++)
if(mb[o][17]==1)goto as;
for(int o=17; o>0; o--)
for(int j=0; j<10; j++)
mb[j][o]=mb[j][o-1];
for(int o=0; o<10; o++)
mb[o][0]=rand()%2;
asd:
;
if(GetAsyncKeyState(VK_RIGHT)!=0&&x<11)x++;
if(GetAsyncKeyState(VK_LEFT)!=0&&x>2)x--;
if(GetAsyncKeyState(VK_UP)!=0)sj(x);
printtu(x,20,i>=wt*10);
if(i<wt*10)i++;
else i=1;
}
as:
;
for(int i=2; i<22; i++) {
go(2,i);
kg(20);
}
fen-=600;
switch(leaf) {
case 1:
go(13,8);
cout<<' '<<' ';
break;
case 2:
leaf--;
go(14,8);
cout<<' '<<' ';
goto lk;
case 3:
leaf--;
go(15,8);
cout<<' '<<' ';
goto lk;
case 4:
leaf--;
go(16,8);
cout<<' '<<' ';
goto lk;
case 5:
leaf--;
go(13,9);
cout<<' '<<' ';
goto lk;
case 6:
leaf--;
go(14,9);
cout<<' '<<' ';
goto lk;
case 7:
leaf--;
go(15,9);
cout<<' '<<' ';
goto lk;
case 8:
leaf--;
go(16,9);
cout<<' '<<' ';
goto lk;
}
go(5,7);
cout<<"你输了!";
go(3,8);
cout<<" ┆ 再来[R]┆ ┆ 返回[E]┆";
for(;;) {
if(GetAsyncKeyState('R')!=0||GetAsyncKeyState('r')!=0)goto lkr;
if(GetAsyncKeyState('E')!=0||GetAsyncKeyState('e')!=0)return;
}
}
void dafangkuai() {}
int main() {
SetConsoleTitle("打方块Windows10");
int q=3;
a:
;
system("mode con cols=80 lines=25");
system("cls");
bool jh[8][27]= {0,0,1,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,0,0,1,0,0,1,1,1,1,1,1,1,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,1,1,1,1,1,0,0,0,1,1,1,0,0,1,0,0,0,0,1,1,1,1,0,1,1,1,0,0,0,1,0,1,0,1,1,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,1,0,1,1,1,1,1,1,1,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,1,1,0,0,0,1,0,0,0,0,1,1,0,0,0,1,1,0,0,0,1,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0};
for(int i=2; i<10; i++) {
go(7,i);
for(int o=0; o<27; o++) {
if(jh[i-2][o])
cout<<"■";
else cout<<' '<<' ';
}
}
go(17,11);
cout<<"|开始游戏|";
go(17,13);
cout<<"|设置游戏|";
go(17,15);
cout<<"|游戏规则|";
go(17,17);
cout<<"|退出游戏|";
go(1,23);
cout<<"[L]确定";
int y=1;
for(;;) {
if(GetAsyncKeyState(VK_DOWN)!=0)y+=((y==4)?-3:1);
if(GetAsyncKeyState(VK_UP)!=0)y-=((y==1)?-3:1);
if(GetAsyncKeyState('l')!=0||GetAsyncKeyState('L')!=0)
switch(y) {
case 1:
system("cls");
m(q);
goto a;
case 2:
system("cls");
go(16,11);
cout<<' '<<q<<"秒增加一行";
go(16,10);
printf("[%c]",30);
go(16,12);
printf("[%c]",31);
go(1,23);
cout<<"[K]确定";
for(;;) {
if(GetAsyncKeyState(VK_UP)!=0&&q<9) {
q++;
go(16,11);
cout<<' '<<q;
}
if(GetAsyncKeyState(VK_DOWN)!=0&&q>1) {
q--;
go(16,11);
cout<<' '<<q;
}
if(GetAsyncKeyState('k')!=0||GetAsyncKeyState('K')!=0)goto a;
Sleep(100);
}
case 3:
MessageBox(0,"点确定浏览规则" ,"规则",MB_OK);
MessageBox(0,"←→控制炮台","规则",MB_OK);
MessageBox(0,"满一行即消除","规则",MB_OK);
MessageBox(0,"每消除一行+100","规则",MB_OK);
MessageBox(0,"少一条命-100","规则",MB_OK);
MessageBox(0,"全部消除+500","规则",MB_OK);
MessageBox(0,"发射一炮-10","规则",MB_OK);
case 4:
return 0;
}
go(16,11);
cout<<' '<<' ';
go(22,11);
cout<<' ';
go(16,13);
cout<<' '<<' ';
go(22,13);
cout<<' ';
go(16,15);
cout<<' '<<' ';
go(22,15);
cout<<' ';
go(16,17);
cout<<' '<<' ';
go(22,17);
cout<<' ';
go(16,9+2*y);
cout<<' '<<'>';
go(22,9+2*y);
cout<<'<';
Sleep(100);
}
}
5.俄罗斯方块1到3
//上下左右键控制
#include<bits/stdc++.h>
#include<windows.h>
int a[24][17],i,j,tim=800,ti=800,shape=0,b,bn,ta[4][4],turn[4][4],nex[4][4],nextshape,add=0,score=0,speed=1,ok=1,mouse=0,best=0;
void Place(const int x, const int y)
{
COORD PlaceCursorHere;
PlaceCursorHere.X = y;
PlaceCursorHere.Y = x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), PlaceCursorHere);
return;
}
void color(int x)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x);
}
void appear()
{
for(i=3; i<=22; i++) for(j=1; j<=15; j++) if(a[i][j]!=0)
{
Place(i-2,2*j);
printf("■");
}
}
void disappear()
{
for(i=3; i<=22; i++) for(j=1; j<=15; j++) if(a[i][j]==2)
{
Place(i-2,2*j);
printf(" ");
}
}
int search(int x0,int y0,int x,int y)
{
POINT pt;
HWND h=GetForegroundWindow();
GetCursorPos(&pt);
ScreenToClient(h,&pt);
if(pt.x>=x0&&pt.y>=y0&&pt.x<=x&&pt.y<=y)
{
if(mouse!=0)
{
Sleep(100);
return 2;
}
else return 1;
}
else return 0;
}
void button(int x)
{
int m=x*10;
if(x<3)
{
Place(22,m);
printf("┌┄┄┄┐");
Place(23,m);
{
if(x==0)
{
if(ok!=0) printf("┆开始 ┆");
else printf("┆暂停 ┆");
}
if(x==1) printf("┆重置 ┆");
if(x==2) printf("┆退出 ┆");
}
Place(24,m);
printf("└┄┄┄┘");
}
else
{
Place(9,m-33);
printf("┌┄┄┐");
Place(10,m-33);
{
if(x==4) printf("┆是┆");
else printf("┆否┆");
}
Place(11,m-33);
printf("└┄┄┘");
}
}
void menu(int x)
{
int k,l;
if(x==0)
{
if(ok!=0)
{
ok=0;
return;
}
else while(1)
{
mouse=GetAsyncKeyState(VK_LBUTTON);
Place(9,13);
printf("暂停");
if(search(7,360,71,390)==2) break;
Sleep(50);
}
Place(9,12);
for(j=1; j<=6; j++) printf(" "); //appear();
}
else
{
for(i=1; i<=20; i++) for(j=2; j<=30; j++)
{
Place(i,j);
printf(" ");
}
Place(7,2);
for(i=1; i<=15; i++) printf("┄");
Place(12,2);
for(i=1; i<=15; i++) printf("┄");
Place(8,6);
printf("你想要 ");
if(x==1) printf("重置?");
if(x==2) printf("exit?");
button(4);
button(5);
while(1)
{
mouse=GetAsyncKeyState(VK_LBUTTON);
for(i=0; i<=1; i++)
{
k=search(63+i*80,150,110+i*80,180);
if(k!=2)
{
if(k==1) color(15);
else color(7);
button(i+4);
}
else
{
for(l=7; l<=12; l++) for(j=2; j<=30; j++)
{
Place(l,j);
printf(" ");
}
if(i==0)
{
if(x==1) ok=2;
else exit(0);
}
return;
}
}
Sleep(50);
}
}
}
void click()
{
for(i=0; i<=2; i++)
{
mouse=GetAsyncKeyState(VK_LBUTTON);
int k=search(i*80+7,360,i*80+71,390);
if(k!=2)
{
if(k==1) color(15);
else color(7);
button(i);
color(7);
}
else
{
menu(i);
return;
}
}
Sleep(50);
}
void ss()
{
Place(9,39);
printf("%d",score);
if(score>=speed*100)
{
speed++;
ti=ti-200;
if(ti<0) ti=0;
else
{
for(i=1; i<=4; i++)
{
Place(9,12);
printf("加速!");
Sleep(70);
Place(9,12);
for(j=1; j<=9; j++) printf(" ");
Sleep(70);
}
Sleep(200);
}
}
if(best<score) best=score;
appear();
Place(12,39);
printf("%d",speed);
Place(15,39);
printf("%d",best);
}
void replace()
{
for(i=1; i<=20; i++) for(j=2; j<=30; j++)
{
Place(i,j);
printf(" ");
}
for(i=0; i<=22; i++) for(j=1; j<=15; j++) a[i][j]=0;
for(i=1; i<=15; i++) a[23][i]=1;
for(i=1; i<=23; i++)
{
a[i][0]=1;
a[i][16]=1;
}
ss();
tim=800;
ti=800;
shape=0;
add=0;
score=0;
speed=1;
}
void change(int x)
{
int q=0,l;
for(l=1; l<=x; l++)
{
for(j=0; j<=2+add; j++)
{
for(i=2+add; i>=0; i--)
{
turn[j][q]=ta[i][j];
q++;
if(q>2+add) q=0;
}
}
for(i=0; i<=3; i++) for(j=0; j<=3; j++) ta[i][j]=turn[i][j];
}
}
void born()
{
int x,q=0;
srand(time(NULL));
bn=b;
shape=nextshape;
x=rand()%12+1;
if(b==5&&x>1)
{
x--;
add=1;
}
for(i=0; i<=2+add; i++) for(j=x; j<=x+2+add; j++)
{
a[i][j]=nex[i][q];
q++;
if(q>2+add) q=0;
}
add=0;
}
void next()
{
srand(time(NULL));
b=rand()%7;
nextshape=rand()%4;
add=0;
for(i=3; i<=6; i++) for(j=37; j<=45; j++)
{
Place(i,j);
printf(" ");
}
for(i=0; i<=3; i++) for(j=0; j<=3; j++) nex[i][j]=turn[i][j]=ta[i][j]=0;
ta[1][1]=2;
if(b==0) ta[1][2]=ta[1][0]=ta[0][1]=2;
if(b==1) ta[1][2]=ta[1][0]=ta[0][0]=2;
if(b==2) ta[1][2]=ta[1][0]=ta[0][2]=2;
if(b==3) ta[1][0]=ta[0][1]=ta[0][2]=2;
if(b==4) ta[0][0]=ta[0][1]=ta[1][2]=2;
if(b==5)
{
ta[1][0]=ta[1][2]=ta[1][3]=2;
add=1;
}
if(b==6) ta[0][0]=ta[0][1]=ta[1][0]=2;
if(nextshape>0&&b!=6)
{
change(nextshape);
for(i=0; i<=3; i++) for(j=0; j<=3; j++)
{
nex[i][j]=turn[i][j];
if(nex[i][j]==2)
{
Place(i+3,j*2+37);
printf("■");
}
}
}
else
{
for(i=0; i<=3; i++) for(j=0; j<=3; j++)
{
nex[i][j]=ta[i][j];
if(nex[i][j]==2)
{
Place(i+3,j*2+37);
printf("■");
}
}
}
}
void clear()
{
int c=0,f=0,l[23],s=0,k;
for(i=3; i<=22; i++)
{
l[i]=0;
for(j=1; j<=15; j++) c=a[i][j]+c;
if(c==15)
{
for(j=1; j<=15; j++) a[i][j]=0;
for(k=i-1; k>=2; k--) for(j=1; j<=15; j++) a[k+1][j]=a[k][j];
f++;
l[i]=1;
s=5;
}
c=0;
}
score=score+f*10;
while(f>1)
{
score=score+f*5;
f--;
}
f=0;
while(s>0)
{
for(i=22; i>=3; i--) if(l[i]==1)
{
Place(i-2,2);
for(j=1; j<=15; j++) printf("■");
}
Sleep(70);
for(i=22; i>=3; i--) if(l[i]==1)
{
Place(i-2,2);
for(j=1; j<=30; j++) printf(" ");
}
Sleep(70);
s--;
}
for(i=3; i<=22; i++) for(j=1; j<=15; j++)
{
Place(i-2,2*j);
printf(" ");
}
appear();
}
void control()
{
int up,down,right,left,c=0,d=0,x,y,no=0,k,l=0,q=0;
k=shape;
add=0;
up=GetAsyncKeyState(VK_UP);
down=GetAsyncKeyState(VK_DOWN);
right=GetAsyncKeyState(VK_RIGHT);
left=GetAsyncKeyState(VK_LEFT);
if(down!=0)
{
tim=0;
}
if(left!=0||right!=0)
{
Sleep(100);
disappear();
for(i=0; i<=22; i++) for(j=1; j<=15; j++)
{
if(a[i][j]==2&&a[i][j-1]!=1) c++;
if(a[i][j]==2&&a[i][j+1]!=1) d++;
}
for(i=0; i<=22; i++) for(j=1; j<=15; j++) if(left!=0&&c==4&&a[i][j]==2)
{
a[i][j-1]=a[i][j];
a[i][j]=0;
}
for(i=0; i<=22; i++) for(j=15; j>=1; j--) if(right!=0&&d==4&&a[i][j]==2)
{
a[i][j+1]=a[i][j];
a[i][j]=0;
}
appear();
}
if(up!=0&&bn!=6)
{
Sleep(150);
disappear();
for(i=0; i<=22; i++)
{
for(j=1; j<=15; j++) if(a[i][j]==2)
{
x=i;
no=1;
break;
}
if(no==1) break;
}
no=0;
for(j=1; j<=15; j++)
{
for(i=0; i<=22; i++) if(a[i][j]==2)
{
y=j;
no=1;
break;
}
if(no==1) break;
}
no=0;
if(k==1) y--;
if(k==2) x--;
add=0;
if(bn==5)
{
add=1;
if(k==0||k==2) x--;
if(k==1||k==3) y--;
}
for(i=0; i<=3; i++) for(j=0; j<=3; j++) ta[i][j]=a[x+i][y+j];
if(bn>=0&&bn<5)
{
if(k==0) ta[2][0]=0;
if(k==1) ta[0][0]=0;
if(k==2) ta[0][2]=0;
if(k==3) ta[2][2]=0;
}
if(bn==5)
{
if(k==0) ta[0][3]=ta[2][0]=ta[2][1]=ta[3][1]=ta[3][0]=0;
if(k==1) ta[0][0]=ta[1][0]=ta[0][1]=ta[1][1]=ta[3][3]=0;
if(k==2) ta[3][0]=ta[0][2]=ta[0][3]=ta[1][2]=ta[1][3]=0;
if(k==3) ta[0][0]=ta[2][2]=ta[2][3]=ta[3][2]=ta[3][3]=0;
}
for(i=0; i<=2+add; i++) for(j=0; j<=2+add; j++) if(ta[i][j]!=1) l++;
if(l==9+add*7)
{
change(1);
for(i=0; i<=22; i++) for(j=1; j<=15; j++) if(a[i][j]==2) a[i][j]=0;
for(i=0; i<=2+add; i++) for(j=0; j<=2+add; j++) if(turn[i][j]==2) a[x+i][y+j]=turn[i][j];
shape++;
}
if(shape>3) shape=0;
appear();
}
}
int main()
{
int k,start,finish,d;
printf("┌");
for(i=1; i<=15; i++) printf("┄");
printf("┐\n");
for(i=1; i<=20; i++) printf("┆\n");
printf("└");
for(i=1; i<=15; i++) printf("┄");
printf("┘");
for(i=1; i<=20; i++)
{
Place(i,32);
printf("┆\n");
}
Place(2,37);
printf("下一个");
Place(8,37);
printf("得分");
Place(14,37);
printf("最高分");
Place(11,37);
printf("速度");
for(i=0; i<=2; i++) button(i);
while(ok==1) click();
while(ok!=1)
{
replace();
next();
while(1)
{
born();
next();
while(1)
{
appear();
k=0;
start=clock();
while(1)
{
finish=clock();
d=finish-start;
if(d>=tim) break;
control();
click();
if(ok==2) break;
}
if(ok==2) break;
disappear();
for(i=22; i>=0; i--) for(j=1; j<=15; j++) if(a[i][j]==2&&a[i+1][j]!=1) k++;
if(k==4)
{
for(i=22; i>=0; i--) for(j=1; j<=15; j++) if(a[i][j]==2)
{
a[i+1][j]=2;
a[i][j]=0;
}
}
else
{
for(i=22; i>=0; i--) for(j=1; j<=15; j++) if(a[i][j]==2) a[i][j]=1;
break;
}
tim=ti;
appear();
}
if(ok==2) break;
appear();
clear();
ss();
for(i=1; i<=15; i++) if(a[2][i]==1)
{
ok=1;
break;
}
}
if(ok==2)
{
ok=0;
continue;
}
for(i=1; i<=20; i++) for(j=2; j<=30; j++)
{
Place(i,j);
printf(" ");
}
Place(9,12);
printf("游戏结束!");
while(ok==1) click();
}
return 0;
}
//J,L左移右移;D变换方向
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <windows.h>
#include <ctime>
#include <conio.h>
#include <iostream>
using namespace std;
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define inf 2147483647
struct type_block
{
int a[10][10];
int color;
int size;
}now, nextA, nextB, nextC, hold;
int sblock[20][10][10] = {{{7, 0, 0, 0}, {0, 0, 1, 1}, {0, 1, 1, 0}, {0, 0, 0, 0}},
{{8, 0, 0, 0}, {0, 1, 1, 0}, {0, 0, 1, 1}, {0, 0, 0, 0}},
{{9, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{{10, 0, 0, 0}, {0, 0, 0, 1}, {0, 1, 1, 1}, {0, 0, 0, 0}},
{{13, 0, 0, 0}, {0, 1, 0, 0}, {0, 1, 1, 1}, {0, 0, 0, 0}},
{{5, 0, 0, 0}, {0, 1, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}},
{{16, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 1, 1}, {0, 0, 0, 0}},
{{0, 0, 0, 0}, {0, 1, 0, 0}, {0, 1, 1, 0}, {0, 0, 1, 0}},
{{1, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 1, 0}, {0, 1, 0, 0}},
{{2, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}},
{{11, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 1}, {0, 0, 0, 0}},
{{12, 0, 0, 0}, {0, 1, 1, 1}, {0, 1, 0, 0}, {0, 0, 0, 0}}, //11
{{3, 0, 1, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 0}},
{{14, 1, 1, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}},
{{15, 1, 1, 1}, {0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{{4, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 1, 1}, {0, 0, 0, 0}},
{{17, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 1, 1}, {0, 0, 1, 0}},
{{18, 0, 0, 0}, {0, 0, 0, 0}, {0, 1, 1, 1}, {0, 0, 1, 0}}, //17
{{6, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 1, 0}, {0, 0, 1, 0}}};
HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE);
int map[22][12];
int mode = 1;
int fraction = 0;
int positionX, positionY;
bool locked;
int keytime = 100000000;
bool keytimeflag;
int sleeptime = 0;
bool holdflag = 1;
int passcondition = 200;
int addlinetime = 10000, addlineflag;
int locktime = 1000;
int keydownflag;
int xray = 0;
int firstwin = 1;
int exfraction = 0;
int exgamestarttime;
int blind = 0;
int lockdelay = 300;
int clockms, stclockms;
double blockpersecond, blockperminute;
int blocknum;
void gotoxy (int x, int y);
void welcomepage ();
void reset ();
void choosedifficulty ();
void ready_go ();
void updatedata ();
void updatetime ();
type_block roundblock ();
void printblock (type_block m_block, int x, int y);
void clearblock (type_block m_block, int x, int y);
int checkblock (type_block m_block, int x, int y);
type_block myup (type_block m_block);
type_block mydown (type_block m_block);
void checkkey ();
void checkline ();
void addline ();
void gameover ();
void win ();
void easy_extra_game ();
void master_extra_game ();
void shirase_extra_game ();
int main()
{
welcomepage ();
reset ();
choosedifficulty();
ready_go ();
clearblock (nextA, 34, 4); clearblock (nextB, 38 + nextA.size, 4); clearblock (nextC, 42 + nextA.size + nextB.size, 4);
now = nextA; nextA = nextB; nextB = nextC; nextC = roundblock();
printblock (nextA, 34, 4); printblock (nextB, 38 + nextA.size, 4); printblock (nextC, 42 + nextA.size + nextB.size, 4);
positionX = 0; positionY = 4; locked = 0;
keytime = clock(); keytimeflag = 1;
addlineflag = clock (); stclockms = clock ();
while (1)
{
updatedata (); updatetime ();
if (locked)
{
++blocknum;
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
now.color = -xray * 2;
printblock (now, positionY * 2 + 8, positionX + 1);
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 4; ++j)
{
if (!(i + j))
continue;
if (now.a[i][j])
map[positionX + i][positionY + j] = 1;
}
}
checkline ();
Sleep (lockdelay);
updatetime ();
if (blind)
clearblock (now, positionY * 2 + 8, positionX + 1);
locked = 0;
clearblock (nextA, 34, 4); clearblock (nextB, 38 + nextA.size, 4); clearblock (nextC, 42 + nextA.size + nextB.size, 4);
now = nextA; nextA = nextB; nextB = nextC; nextC = roundblock();
printblock (nextA, 34, 4); printblock (nextB, 38 + nextA.size, 4); printblock (nextC, 42 + nextA.size + nextB.size, 4);
positionX = 0; positionY = 4;
if (!checkblock (now, positionX, positionY))
gameover ();
if (fraction % 100 != 99 && fraction != passcondition)
++fraction;
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
gotoxy (56, 10);
printf ("%4d", fraction);
gotoxy (57, 11);
printf ("---");
gotoxy (56, 12);
int lssc = fraction % 100 ? (fraction / 100 + 1) * 100 : fraction;
if (mode == 1 && lssc >= 200) lssc = 200;
if (mode == 2 && lssc >= 999) lssc = 900;
if (mode == 3 && lssc >= 1300) lssc = 1300;
printf ("%4d", lssc);
keytime = clock(); holdflag = 1;
if (clock () - addlineflag > addlinetime)
{
addlineflag = clock ();
addline ();
}
keydownflag = 0;
}
if (checkblock (now, positionX + 1, positionY))
while (checkblock (now, positionX + 1, positionY))
{
++positionX; updatetime ();
if (sleeptime)
{
printblock (now, positionY * 2 + 8, positionX + 1);
int sttime = clock (), timeover;
while ((timeover = (clock () - sttime < sleeptime)) && !kbhit());
clearblock (now, positionY * 2 + 8, positionX + 1);
if (timeover)
checkkey ();
}
checkkey ();
}
printblock (now, positionY * 2 + 8, positionX + 1);
Sleep (100);
clearblock (now, positionY * 2 + 8, positionX + 1);
checkkey ();
}
}
void gotoxy (int x, int y)
{
COORD pos;
pos.X = x; pos.Y = y;
SetConsoleCursorPosition (hOut, pos);
}
void welcomepage ()
{
puts (" ");
puts (" ■■■■■■■■■■ ");
puts (" ■■■■■■■■■■ ");
puts (" ■■ ");
puts (" ■■ ");
puts (" ■■ ");
puts (" ■■ ■■■■ ■ ■ ■ ■■■ ");
puts (" ■■ ■ ■ ■■■■ ■ ■■■ ■ ■ ");
puts (" ■■ ■■■■ ■ ■■ ■ ■ ");
puts (" ■■ ■ ■ ■ ■ ■■■ ");
puts (" ■■ ■■■■ ■ ■ ■ ■ ");
puts (" ■ ");
puts (" ■■■■ ");
puts (" ");
puts (" ------------------------------------------------------------------ ");
puts (" CHAMPION ");
puts (" ");
puts (" ");
puts (" ");
puts (" ");
puts (" ");
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
int modnum = 0;
while (1)
{
gotoxy (22, 20);
if (modnum)
puts ("PUSH START BUTTOM");
else
puts (" ");
int sttime = clock (), timeover;
while ((timeover = (clock () - sttime < 700)) && !kbhit());
if (timeover)
{
if (_getch () == ' ')
break;
}
modnum ^= 1;
}
gotoxy (0, 0);
for (int i = 1; i <= 25; ++i)
puts (" ");
gotoxy (0, 0);
}
void reset ()
{
srand (time (0));
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
puts ("");
puts (" ■■■■■■■■■■■■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■■■■■■■■■■■■");
nextA = roundblock (); nextB = roundblock (); nextC = roundblock ();
for (int i = 34; i <= 34 + nextA.size; ++i)
{
gotoxy (i, 4);
for (int j = 4; j <= 4 + nextA.size; ++j)
printf (" ");
}
printblock (nextA, 34, 4);
for (int i = 38 + nextA.size; i <= 38 + nextA.size + nextB.size; ++i)
{
gotoxy (i, 4);
for (int j = 4; j <= 4 + nextB.size; ++j)
printf (" ");
}
printblock (nextB, 38 + nextA.size, 4);
for (int i = 42 + nextA.size + nextB.size; i <= 42 + nextA.size + nextB.size + nextC.size; ++i)
{
gotoxy (i, 4);
for (int j = 4; j <= 4 + nextC.size; ++j)
printf (" ");
}
printblock (nextC, 42 + nextA.size + nextB.size, 4);
for (int i = 1; i <= 20; ++i)
map[i][0] = map[i][11] = 1;
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo (hOut, &CursorInfo);
CursorInfo.bVisible = 0;
SetConsoleCursorInfo (hOut, &CursorInfo);
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
gotoxy (56, 10);
printf ("%4d", fraction);
gotoxy (57, 11);
printf ("---");
gotoxy (56, 12);
if (fraction)
printf ("%4d", fraction % 100 ? (fraction / 100 + 1) * 100 : fraction);
else
printf (" 100");
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
gotoxy (45, 20);
printf ("00:00:00");
}
void choosedifficulty ()
{
while (1)
{
gotoxy (0, 0);
switch (mode)
{
case 1:
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
puts ("");
puts (" ■■■■■■■■■■■■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■■■■■■■■■■■■");
gotoxy (18, 9);
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
puts (" EASY ");
gotoxy (10, 16);
printf ("慢速的经典俄罗斯");
gotoxy (10, 17);
printf ("方块,适合初学者.");
break;
case 2:
SetConsoleTextAttribute(hOut, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
puts ("");
puts (" ■■■■■■■■■■■■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■■■■■■■■■■■■");
gotoxy (17, 9);
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
puts ("MASTER ");
gotoxy (10, 16);
printf ("中速的街机俄罗斯");
gotoxy (10, 17);
printf ("方块,适合中级者.");
break;
case 3:
SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_INTENSITY);
puts ("");
puts (" ■■■■■■■■■■■■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■ ■");
puts (" ■■■■■■■■■■■■");
gotoxy (16, 9);
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
puts ("SHIRASE");
gotoxy (10, 16);
printf ("高速俄罗斯方块,");
gotoxy (10, 17);
printf ("挑战速度的极限.");
break;
}
char key = _getch ();
if (key == 'i' && mode != 1)
--mode;
if (key == 'k' && mode != 3)
++mode;
gotoxy (10, 16);
printf (" ");
gotoxy (10, 17);
printf (" ");
if (key == ' ')
break;
}
gotoxy (16, 9);
printf (" ");
}
void ready_go ()
{
SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
Sleep (1000);
gotoxy (18, 8);
puts ("READY");
Sleep (800);
gotoxy (18, 8);
puts (" GO! ");
Sleep (800);
gotoxy (18, 8);
puts (" ");
}
void updatedata ()
{
switch (mode)
{
case 1:
addlinetime = inf; lockdelay = 300;
if (fraction >= 0)
{
sleeptime = 2000 - fraction * 5;
locktime = 800;
}
else if (fraction >= 100)
{
sleeptime = 1000 - fraction * 5 / 2;
locktime = 700;
}
if (fraction >= 200)
win ();
break;
case 2:
addlinetime = inf; lockdelay = 300;
if (fraction >= 0)
{
sleeptime = 1000 - fraction * 3;
locktime = 700;
}
if (fraction >= 100)
{
sleeptime = 1000 - fraction * 3;
locktime = 600;
}
if (fraction >= 200)
{
sleeptime = 1000 - fraction * 3;
locktime = 500;
if (fraction >= 300)
locktime = 700;
else if (fraction >= 400)
locktime = 600;
}
if (fraction >= 999)
win ();
break;
case 3:
addlinetime = inf; lockdelay = 300 - fraction / 400 * 50; sleeptime = 0;
locktime = 240 - fraction / 300 * 40;
if (fraction >= 600)
addlinetime = 10000;
if (fraction >= 800)
addlinetime = 7000;
if (fraction >= 1000)
{
addlinetime = inf;
xray = 1;
}
if (fraction >= 1300)
win ();
}
}
void updatetime ()
{
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
gotoxy (45, 20); clockms = clock () - stclockms;
printf ("%02d:%02d:%02d", clockms / 60000 % 100, clockms / 1000 % 60, clockms % 1000 / 10);
}
type_block roundblock ()
{
type_block c;
int kind = rand () % 7;
while (kind < 2 && fraction <= 6)
kind = rand () % 7;
c.size = 4; c.color = kind + 1;
if (xray) c.color = -2;
for (int i = 0; i < c.size; ++i)
for (int j = 0; j < c.size; ++j)
c.a[i][j] = sblock[kind][i][j];
return c;
}
void printblock (type_block m_block, int x, int y)
{
switch (m_block.color)
{
case 1:
SetConsoleTextAttribute (hOut, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
break;
case 2:
SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_INTENSITY);
break;
case 3:
SetConsoleTextAttribute (hOut, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
break;
case 4:
SetConsoleTextAttribute (hOut, FOREGROUND_GREEN | FOREGROUND_RED);
break;
case 5:
SetConsoleTextAttribute (hOut, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
break;
case 6:
SetConsoleTextAttribute (hOut, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
break;
case 7:
SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_BLUE);
break;
case -1:
SetConsoleTextAttribute (hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
break;
case -2:
SetConsoleTextAttribute (hOut, FOREGROUND_GREEN);
break;
default:
SetConsoleTextAttribute (hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
break;
}
for (int i = 0; i < m_block.size; ++i)
{
for (int j = 0 + !i; j < m_block.size; ++j)
if (m_block.a[i][j])
{
gotoxy (x + j * 2, y + i);
if (xray)
puts ("[]");
else
puts ("■");
}
}
}
void clearblock (type_block m_block, int x, int y)
{
for (int i = 0; i < m_block.size; ++i)
{
for (int j = 0 + !i; j < m_block.size; ++j)
if (m_block.a[i][j])
{
gotoxy (x + j * 2, y + i);
puts (" ");
}
}
}
int checkblock (type_block m_block, int x, int y)
{
for (int i = 0; i < m_block.size; ++i)
for (int j = 0; j < m_block.size; ++j)
{
if (!(i + j))
continue;
if (m_block.a[i][j] && (map[x + i][y + j] || x + i > 20 || y + j < 1 || y + j > 10))
return 0;
}
return 1;
}
type_block myup (type_block m_block)
{
type_block c;
int kind = m_block.a[0][0];
for (int i = 0; i < m_block.size; ++i)
for (int j = 0; j < m_block.size; ++j)
c.a[i][j] = sblock[kind][i][j];
c.size = m_block.size; c.color = m_block.color;
return c;
}
type_block mydown (type_block m_block)
{
type_block c = m_block;
for (int t = 1; t <= 3; ++t)
c = myup (c);
return c;
}
void checkkey ()
{
if (checkblock (now, positionX + 1, positionY) && keydownflag < (sleeptime > 100 ? 0 : 4))
{
++keydownflag;
if (KEY_DOWN('J'))
{
if (checkblock (now, positionX, positionY - 1))
--positionY;
}
if (KEY_DOWN('L'))
{
if (checkblock (now, positionX, positionY + 1))
++positionY;
}
}
if (kbhit())
{
keytime = clock ();
char key = _getch();
if (key == 'j')
{
if (checkblock (now, positionX, positionY - 1))
--positionY;
}
if (key == 'l')
{
if (checkblock (now, positionX, positionY + 1))
++positionY;
}
if (key == 's')
{
if (!holdflag)
return;
if (hold.a[0][0])
{
clearblock (hold, 60, 5);
type_block t = now; now = hold; hold = t;
printblock (hold, 60, 5);
positionX = 0; positionY = 4; keytime = clock();
holdflag = 0;
}
else
{
SetConsoleTextAttribute(hOut, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
gotoxy (60, 4);
puts ("Hold");
clearblock (hold, 60, 5);
hold = now;
printblock (hold, 60, 5);
clearblock (nextA, 34, 4); clearblock (nextB, 38 + nextA.size, 4); clearblock (nextC, 42 + nextA.size + nextB.size, 4);
now = nextA; nextA = nextB; nextB = nextC; nextC = roundblock();
printblock (nextA, 34, 4); printblock (nextB, 38 + nextA.size, 4); printblock (nextC, 42 + nextA.size + nextB.size, 4);
positionX = 0; positionY = 4; keytime = clock();
}
}
if (key == 'f')
{
type_block newnow = myup (now);
if (checkblock (newnow, positionX, positionY))
now = newnow;
else if (checkblock (newnow, positionX - 1, positionY))
{
now = newnow;
--positionX;
}
else if (checkblock (newnow, positionX - 2, positionY))
{
now = newnow;
positionX -= 2;
}
else if (checkblock (newnow, positionX, positionY - 1))
{
now = newnow;
--positionY;
}
else if (checkblock (newnow, positionX, positionY + 1))
{
now = newnow;
++positionY;
}
}
if (key == 'd')
{
type_block newnow = mydown (now);
if (checkblock (newnow, positionX, positionY))
now = newnow;
else if (checkblock (newnow, positionX - 1, positionY))
{
now = newnow;
--positionX;
}
else if (checkblock (newnow, positionX - 2, positionY))
{
now = newnow;
positionX -= 2;
}
else if (checkblock (newnow, positionX, positionY - 1))
{
now = newnow;
--positionY;
}
else if (checkblock (newnow, positionX, positionY + 1))
{
now = newnow;
++positionY;
}
}
if (KEY_DOWN(' '))
{
for (int i = 1; i <= 20; ++i)
if (checkblock (now, positionX + 1, positionY))
++positionX;
locked = 1;
}
}
if (clock() - keytime > locktime && !checkblock (now, positionX + 1, positionY))
locked = 1;
}
void checkline ()
{
bool tf = 0;
for (int i = 1; i <= 20; ++i)
{
int x = 0;
for (int j = 1; j <= 10; ++j)
if (map[i][j])
++x;
if (x == 10)
{
tf = 1;
for (int k = i; k >= 1; --k)
for (int l = 1; l <= 10; ++l)
map[k][l] = map[k - 1][l];
SetConsoleTextAttribute (hOut, FOREGROUND_RED);
gotoxy (10, i + 1);
for (int k = 1; k <= 10; ++k)
{
map[1][k] = 0;
printf ("..");
}
if (firstwin)
++fraction;
}
}
if (tf)
{
Sleep (100);
if (xray)
SetConsoleTextAttribute (hOut, FOREGROUND_GREEN);
else
SetConsoleTextAttribute (hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
for (int i = 1; i <= 20; ++i)
{
gotoxy (10, i + 1);
for (int j = 1; j <= 10; ++j)
if (map[i][j] && !blind)
if (xray)
printf ("[]");
else
printf ("■");
else
printf (" ");
}
}
}
void addline ()
{
for (int i = 1; i <= 19; ++i)
for (int j = 1; j <= 10; ++j)
map[i][j] = map[i + 1][j];
for (int i = 1; i <= 10; ++i)
map[20][i] = map[19][i];
if (xray)
SetConsoleTextAttribute (hOut, FOREGROUND_GREEN);
else
SetConsoleTextAttribute (hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
for (int i = 1; i <= 20; ++i)
{
gotoxy (10, i + 1);
for (int j = 1; j <= 10; ++j)
if (map[i][j] && !(i != 1 && blind))
if (xray)
printf ("[]");
else
printf ("■");
else
printf (" ");
}
if (blind)
{
Sleep (200);
gotoxy (10, 2);
printf (" ");
}
}
void gameover ()
{
clockms = clock () - stclockms;
blockpersecond = (double) blocknum / clockms * 1000; blockperminute = blockpersecond * 60.0;
for (int i = 20; i >= 1; --i)
{
for (int j = 1; j <= 10; ++j)
{
gotoxy (j * 2 + 8, i + 1);
puts (" ");
}
Sleep (150);
}
Sleep (2000);
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
gotoxy (14, 10);
puts (" 暂定段位");
gotoxy (13, 19);
printf ("BPS %lf", blockpersecond);
gotoxy (13, 20);
printf ("BPM %lf", blockperminute);
for (int i = 1; i <= 29; ++i)
{
if (i % 2)
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
else
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
gotoxy (19, 13);
switch (mode)
{
case 1:
gotoxy (18, 13);
printf ("H%d", fraction + exfraction * 10 + rand () % 10);
break;
case 2:
if (fraction >= 999)
printf ("S13");
else if (fraction >= 950)
printf ("S12");
else if (fraction >= 900)
printf ("S11");
else if (fraction >= 850)
printf ("S10");
else if (fraction >= 800)
printf ("S9");
else if (fraction >= 750)
printf ("S8");
else if (fraction >= 700)
printf ("S7");
else if (fraction >= 650)
printf ("S6");
else if (fraction >= 600)
printf ("S5");
else if (fraction >= 550)
printf ("S4");
else if (fraction >= 500)
printf ("S3");
else if (fraction >= 450)
printf ("S2");
else if (fraction >= 400)
printf ("S1");
else if (fraction >= 350)
printf (" 1");
else if (fraction >= 300)
printf (" 2");
else if (fraction >= 250)
printf (" 3");
else if (fraction >= 200)
printf (" 4");
else if (fraction >= 150)
printf (" 5");
else if (fraction >= 100)
printf (" 6");
else if (fraction >= 50)
printf (" 7");
else printf (" 8");
break;
case 3:
if (fraction >= 1300)
printf ("S13");
else if (fraction >= 1200)
printf ("S12");
else if (fraction >= 1100)
printf ("S11");
else if (fraction >= 1000)
printf ("S10");
else if (fraction >= 900)
printf ("S9");
else if (fraction >= 800)
printf ("S8");
else if (fraction >= 700)
printf ("S7");
else if (fraction >= 600)
printf ("S6");
else if (fraction >= 500)
printf ("S5");
else if (fraction >= 400)
printf ("S4");
else if (fraction >= 300)
printf ("S3");
else if (fraction >= 200)
printf ("S2");
else if (fraction >= 100)
printf ("S1");
else
{
gotoxy (15, 13);
printf ("Let's go");
gotoxy (15, 14);
printf ("better");
gotoxy (15, 15);
printf ("next time!");
}
break;
}
Sleep (120);
}
Sleep (2000);
system ("pause>nul");
exit (0);
}
void win ()
{
if (firstwin)
{
for (int i = 20; i >= 1; --i)
{
for (int j = 1; j <= 10; ++j)
{
gotoxy (j * 2 + 8, i + 1);
puts (" ");
map[i][j] = 0;
}
Sleep (150);
}
Sleep (1000);
firstwin = 0;
switch (mode)
{
case 1:
easy_extra_game ();
break;
case 2:
master_extra_game ();
break;
case 3:
shirase_extra_game ();
break;
default:
break;
}
return;
}
gotoxy (15, 9);
switch (mode)
{
case 1:
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
puts (" EASY MODE ");
break;
case 2:
SetConsoleTextAttribute(hOut, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
puts (" MASTER MODE");
break;
case 3:
SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_INTENSITY);
puts ("SHIRASE MODE");
break;
}
gotoxy (15, 10);
puts (" ALL CLEAR ");
Sleep (5000);
gotoxy (15, 9);
puts (" ");
gotoxy (15, 10);
puts (" ");
gameover ();
}
void easy_extra_game ()
{
sleeptime = 0; exgamestarttime = clock (); locktime = 300; keytime = clock ();
if (mode == 3)
locktime = 200;
while (clock () - exgamestarttime < 40000)
{
if (locked)
{
++exfraction;
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
now.color = -xray * 2;
printblock (now, positionY * 2 + 8, positionX + 1);
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 4; ++j)
{
if (!(i + j))
continue;
if (now.a[i][j])
map[positionX + i][positionY + j] = 1;
}
}
checkline ();
Sleep (lockdelay);
if (blind)
clearblock (now, positionY * 2 + 8, positionX + 1);
locked = 0;
clearblock (nextA, 34, 4); clearblock (nextB, 38 + nextA.size, 4); clearblock (nextC, 42 + nextA.size + nextB.size, 4);
now = nextA; nextA = nextB; nextB = nextC;
if (mode == 3 && !rand () % 4)
xray = 0;
nextC = roundblock();
xray = 1;
printblock (nextA, 34, 4); printblock (nextB, 38 + nextA.size, 4); printblock (nextC, 42 + nextA.size + nextB.size, 4);
positionX = 0; positionY = 4;
if (!checkblock (now, positionX, positionY))
gameover ();
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
gotoxy (56, 10);
printf ("%4d", fraction);
gotoxy (57, 11);
printf ("---");
gotoxy (56, 12);
int lssc = fraction % 100 ? (fraction / 100 + 1) * 100 : fraction;
if (mode == 1 && lssc >= 200) lssc = 200;
if (mode == 2 && lssc >= 999) lssc = 900;
if (mode == 3 && lssc >= 1300) lssc = 1300;
printf ("%4d", lssc);
keytime = clock(); holdflag = 1;
if (clock () - addlineflag > addlinetime)
{
addlineflag = clock ();
addline ();
}
keydownflag = 0;
}
if (checkblock (now, positionX + 1, positionY))
while (checkblock (now, positionX + 1, positionY))
{
++positionX;
if (sleeptime)
{
printblock (now, positionY * 2 + 8, positionX + 1);
int sttime = clock (), timeover;
while ((timeover = (clock () - sttime < sleeptime)) && !kbhit());
clearblock (now, positionY * 2 + 8, positionX + 1);
if (timeover)
checkkey ();
}
checkkey ();
}
printblock (now, positionY * 2 + 8, positionX + 1);
Sleep (100);
clearblock (now, positionY * 2 + 8, positionX + 1);
checkkey ();
}
if (xray)
SetConsoleTextAttribute (hOut, FOREGROUND_GREEN);
else
SetConsoleTextAttribute (hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
for (int i = 1; i <= 20; ++i)
{
gotoxy (10, i + 1);
for (int j = 1; j <= 10; ++j)
if (map[i][j])
if (xray)
printf ("[]");
else
printf ("■");
else
printf (" ");
}
win ();
}
void master_extra_game ()
{
blind = 1;
easy_extra_game ();
}
void shirase_extra_game ()
{
blind = 1;
easy_extra_game ();
}
6.仿猫国建设者
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <windows.h>
#include <conio.h>
#include <bitset>
using namespace std;
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
#define KEY_DOWM(vk_c) (GetAsyncKeyState(vk_c)&0x8000?1:0)
void color(int a){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void HideCursor(){
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void block(int x,int y){
HANDLE hCon;
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
COORD setps;
setps.X = x;
setps.Y = y;
SetConsoleCursorPosition(hCon,setps);
}
bitset<128>pre;
bitset<128>down;
void pan(char c){
bool hahbhchdhehfhg;
if(c == 'w'){
if(!KEY_DOWN(VK_UP))hahbhchdhehfhg=0;
else hahbhchdhehfhg=1;
}else if(c == 's'){
if(!KEY_DOWN(VK_DOWN))hahbhchdhehfhg=0;
else hahbhchdhehfhg=1;
}else if(c == 'a'){
if(!KEY_DOWN(VK_LEFT))hahbhchdhehfhg=0;
else hahbhchdhehfhg=1;
}else if(c == 'd'){
if(!KEY_DOWN(VK_RIGHT))hahbhchdhehfhg=0;
else hahbhchdhehfhg=1;
}else if(c == '1'){
if(!KEY_DOWN(VK_NUMPAD1) && !KEY_DOWN('1'))hahbhchdhehfhg=0;
else hahbhchdhehfhg=1;
}else if(c == '2'){
if(!KEY_DOWN(VK_NUMPAD2) && !KEY_DOWN('2'))hahbhchdhehfhg=0;
else hahbhchdhehfhg=1;
}else if(c == '3'){
if(!KEY_DOWN(VK_NUMPAD3) && !KEY_DOWN('3'))hahbhchdhehfhg=0;
else hahbhchdhehfhg=1;
}else{
if(!KEY_DOWN(c))hahbhchdhehfhg=0;
else hahbhchdhehfhg=1;
}
if(hahbhchdhehfhg)down[c]=1;
else down[c]=0;
}
bool check(char c){
if(down[c] != pre[c]){
pre[c] = down[c];
if(down[c]){
return true;
}
}
return false;
}
int heng[31] = {0, 1, 4};
int shu[31][101] = {{0},
{0, 1, 2, 3, 4},
{0, 1},
{0, 1}
};
string hengs[31] = {"0", "营火", "小村庄", "科学", "成就", "工坊", "贸易", "独角兽"};
string shus[31][101] = {{"0"},
{"0", "采集猫薄荷", "猫薄荷田", "锻造木头", "小屋", "图书馆", "粮仓", "矿井", "工坊"},
{"0", "伐木工", "农民", "学者", "猎人", "矿工"},
{"0", "日期", "农业", "箭业", "采矿", "畜牧业", "金属加工", "行政部门", "数学", "建筑业"}
};
int shus1[101] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
int shus2[101] = {0, 1, 2, 3, 4, 5};
bool z1[1010];
int hengl = 2, shul[31] = {0, 4, 0, 1};
int x = 1;
int y = 1;
int zz11 = 1;
double zz12[101][5] = {{0}, {0, 0}, {0, 10}, {0, 100}, {0, 5}, {0, 25}, {0, 70}, {0, 100}, {0, 100, 400}};
int zz13[101] = {0, 0, 1, 1, 2, 2, 2, 2, 302};
string zz14[31] = {"0", "猫薄荷", "木头", "矿物"};
int zz15[101] = {0};
int zz16[101][5] = {{0}, {0, 0}, {0, 10}, {0, 100}, {0, 5}, {0, 25}, {0, 70}, {0, 100}, {0, 100, 400}};
double zz17[101] = {0, 0, 1.12, 0, 2.5, 1.15, 1.25, 1.15, 1.15};
bool zz31[101];
int zz32[101] = {0, 30, 100, 300, 500, 500, 900};
int zz33 = 1;
int zz21[10];
int zz22 = 0;
int zz23 = 1;
double bohe1 = 0;
double mutou1 = 0;
double keji1 = 0;
double catli1 = 0;
double kuangwu1 = 0;
int cat1 = 0;
int cat2 = 0;
int bohe2 = 5000;
int mutou2 = 200;
int keji2 = 500;
int catli2 = 150;
int kuangwu2 = 250;
bool maopi1 = false;
double maopi = 0.0;
bool xiangya1 = false;
double xiangya = 0.0;
bool xinqing1 = false;
int xinqing = 100;
int tim0 = 0, tim1 = 1, tim2 = 1, tim3 = 0;
int timm1 = 0, timm2 = 0;
string tim[5] = {"0", "春季", "夏季", "秋季", "冬季"};
bool h1 = true;
bool pai1(int x1, int y1){
return shus1[x1] < shus1[y1];
}
bool pai2(int x1, int y1){
return shus2[x1] < shus2[y1];
}
void output(double x){
if(x >= 1000000){
x /= 1000000;
if((int)x != x){
if((int)(x * 10) / 10.0 != x){
printf("%.2fM", x);
}else{
printf("%.1fM", x);
}
}else{
cout << x << "M";
}
}else if(x >= 10000){
x /= 1000;
if((int)x != x){
if((int)(x * 10) / 10.0 != x){
printf("%.2fK", x);
}else{
printf("%.1fK", x);
}
}else{
cout << x << "K";
}
}else{
if((int)x != x){
if((int)(x * 10) / 10.0 != x){
printf("%.2f", x);
}else{
printf("%.1f", x);
}
}else{
cout << x;
}
}
}
void output00(){
int m1 = 3;
if(xinqing1){
color(13);
block(1, m1);
cout << " ";
block(1, m1);
cout << "幸福度:" << xinqing << "%";
m1++;
}
color(15);
block(1, m1);
cout << " ";
block(1, m1);
cout << "猫薄荷:" ;
if(bohe1 > bohe2){
bohe1 = bohe2;
}
if(bohe1 >= bohe2 * 0.9){
color(14);
}
output(bohe1);
color(7);
cout << "/";
output(bohe2);
m1++;
color(15);
block(1, m1);
cout << " ";
block(1, m1);
cout << "木头:";
if(mutou1 > mutou2){
mutou1 = mutou2;
}
if(mutou1 >= mutou2 * 0.9){
color(14);
}
output(mutou1);
color(7);
cout << "/";
output(mutou2);
m1++;
if(zz31[4]){
color(15);
block(1, m1);
cout << " ";
block(1, m1);
cout << "矿物:";
if(kuangwu1 > kuangwu2){
kuangwu1 = kuangwu2;
}
if(kuangwu1 >= kuangwu2 * 0.9){
color(14);
}
output(kuangwu1);
color(7);
cout << "/";
output(kuangwu2);
m1++;
}
if(zz31[3]){
color(15);
block(1, m1);
cout << " ";
block(1, m1);
color(12);
cout << "猫力:";
if(catli1 > catli2){
catli1 = catli2;
}
if(catli1 >= catli2 * 0.9){
color(14);
}else{
color(15);
}
output(catli1);
color(7);
cout << "/";
output(catli2);
m1++;
}
if(zz15[5] > 0){
color(15);
block(1, m1);
cout << " ";
block(1, m1);
color(11);
cout << "科技点:";
if(keji1 > keji2){
keji1 = keji2;
}
if(keji1 >= keji2 * 0.9){
color(14);
}else{
color(15);
}
output(keji1);
color(7);
cout << "/";
output(keji2);
m1++;
}
if(cat2 > 0){
color(15);
block(1, m1);
cout << " ";
block(1, m1);
cout << "小猫:";
if(cat1 == cat2){
color(14);
}
cout << cat1;
color(7);
cout << "/" << cat2;
m1++;
}
if(maopi1){
color(15);
block(1, m1);
cout << " ";
block(1, m1);
color(13);
cout << "毛皮:";
color(15);
output(maopi);
m1++;
}
if(xiangya1){
color(15);
block(1, m1);
cout << " ";
block(1, m1);
color(13);
cout << "象牙:";
color(15);
output(xiangya);
m1++;
}
}
void output01(){
color(15);
for(int i = 4; i <= 23; i++){
block(20, i);
cout << " ";
}
}
void output02(){
color(15);
if(tim3 == 18){
tim3 = 0;
tim2++;
}
if(tim2 == 100){
tim2 = 0;
tim1++;
}
if(tim1 == 5){
tim1 = 1;
tim0++;
}
if(zz31[1]){
block(1, 1);
cout << " ";
block(1, 1);
cout << "第" << tim0 << "年," << tim[tim1] << "第" << tim2 << "天";
}else{
block(1, 1);
cout << tim[tim1];
}
}
void output0(){
for(int i = 1; i <= hengl; i++){
if(i == x){
color(0 + 15 * 16);
}else{
color(15);
}
block(i * 8 + 20, 1);
cout << " |";
block(i * 8 + 20, 1);
cout << hengs[heng[i]];
block(i * 8 + 20, 2);
cout << "-------|";
}
}
void output13(){
block(43, zz11);
color(15);
cout << " ";
block(43, zz11 + 1);
cout << " ";
block(43, zz11 + 2);
cout << " ";
}
void output12(int x1){
color(15);
if(shu[1][y] == 1){
block(43, x1);
cout << "1.采集";
}else if(shu[1][y] == 3){
block(43, x1);
cout << "1.锻造100猫薄荷";
}else{
block(43, x1);
cout << "1.建造";
int i = 1;
while(zz12[shu[1][y]][i] != 0){
block(49, x1 + i - 1);
output(zz12[shu[1][y]][i]);
cout << zz14[zz13[shu[1][y]] % (int)(pow(10, i * 2)) / (int)(pow(10, (i * 2 - 2)))];
i++;
}
}
zz11 = x1;
}
void output11(int y1){
for(int i = 1; i <= 5; i++){
if(i > shul[1]){
break;
}
if(y1 + i == y){
output12(i * 3 + 1);
color(0 + 15 * 16);
}else{
color(15);
}
block(25, i * 3 + 1);
cout << "╭——————╮";
block(25, i * 3 + 2);
cout << "| |";
block(27, i * 3 + 2);
cout << shus[1][shu[1][y1 + i]] << "(" << zz15[shu[1][y1 + i]] << ")";
block(25, i * 3 + 3);
cout << "╰——————╯";
}
}
void output1(){
if(x != 1){
cout << "???";
Sleep(500);
return;
}
output13();
if(shul[1] <= 5){
output11(0);
}else if(y < 3) {
output11(0);
}else if(y > shul[1] - 2){
output11(shul[1] - 5);
}else{
output11(y - 3);
}
}
void output31(int x3, int y3){
if(x3 == y){
block(43, x3 * 3 + 1);
if(zz31[shu[3][y3]]){
cout << "已研发";
}else{
cout << "1.研发";
output(zz32[shu[3][y3]]);
cout << "科技点";
}
color(0 + 15 * 16);
zz33 = x3 * 3 + 1;
}else{
color(15);
}
block(25, x3 * 3 + 1);
cout << "╭——————╮";
block(25, x3 * 3 + 2);
cout << "| |";
block(27, x3 * 3 + 2);
cout << shus[3][shu[3][y3]];
block(25, x3 * 3 + 3);
cout << "╰——————╯";
}
void output3(){
color(15);
block(43, zz33);
cout << " ";
int x3 = 1;
for(int i = 1; i <= shul[3]; i++){
output31(x3, i);
x3++;
}
}
void output2(){
color(15);
block(43, zz23);
cout << " ";
block(43, zz23 + 1);
cout << " ";
block(43, zz23 + 2);
cout << " ";
for(int i = 1; i <= shul[2]; i++){
if(i == y){
block(43, i * 3 + 1);
cout << "1.加";
block(43, i * 3 + 2);
cout << "2.减";
if(shu[2][i] == 4){
block(43, i * 3 + 3);
cout << "3.派出猎人";
if(catli1 > 199){
cout << "×" << (int)(catli1 / 100);
}
}
color(0 + 15 * 16);
zz23 = i * 3 + 1;
}else{
color(15);
}
block(25, i * 3 + 1);
cout << "╭——————╮";
block(25, i * 3 + 2);
cout << "| |";
block(27, i * 3 + 2);
cout << shus[2][shu[2][i]] << "(" << zz21[shu[2][i]] << ")";
block(25, i * 3 + 3);
cout << "╰——————╯";
}
}
void output_1(){
if(heng[x] == 1){
output1();
}else if(heng[x] == 3){
output3();
}else if(heng[x] == 2){
output2();
}
}
int main( ){
system("mode con cols=70 lines=25");
color(15);
HideCursor();
Sleep(1500);
cout << "欢迎来到(高仿版)猫国建设者!" << endl;
Sleep(1000);
cout << " //本游戏原型为 https://likexia.gitee.io/cat-zh#/" << endl;
Sleep(500);
cout << " //本游戏由XTW蒟蒻编制而成" << endl;
Sleep(500);
cout << endl << "请按任意键继续……";
char zzzzzzzzzzzzzzzzzzzz = getch();
system("cls");
output0();
output00();
output1();
while(true){
output00();
output02();
pan('w');
pan('s');
pan('a');
pan('d');
pan('1');
pan('2');
pan('3');
if(check('w')){
if(y > 0){
y--;
output_1();
}
}else if(check('s')){
if(y < shul[heng[x]]){
y++;
output_1();
}
}else if(check('a')){
if(y == 0 && x > 1){
x--;
output0();
output01();
output_1();
}
}else if(check('d')){
if(y == 0 && x < hengl){
x++;
output0();
output01();
output_1();
}
}else if(check('1')){
if(heng[x] == 1){
if(shu[1][y] == 1){
bohe1 += 1;
}else if(shu[1][y] == 3){
if(bohe1 >= 100){
bohe1 -= 100;
mutou1 += 1;
}
}else{
h1 = true;
int i = 1;
while(zz12[shu[1][y]][i] != 0){
if(zz13[shu[1][y]] % (int)(pow(10, i * 2)) / (int)(pow(10, (i * 2 - 2))) == 1){
if(bohe1 < zz12[shu[1][y]][i]){
h1 = false;
break;
}
}else if(zz13[shu[1][y]] % (int)(pow(10, i * 2)) / (int)(pow(10, (i * 2 - 2))) == 2){
if(mutou1 < zz12[shu[1][y]][i]){
h1 = false;
break;
}
}else if(zz13[shu[1][y]] % (int)(pow(10, i * 2)) / (int)(pow(10, (i * 2 - 2))) == 3){
if(kuangwu1 < zz12[shu[1][y]][i]){
h1 = false;
break;
}
}else{
block(1, 19);
cout << zz13[shu[1][y]] % (int)(pow(10, i * 2)) / (int)(pow(10, (i * 2 - 2)));
cout << "?????";
Sleep(1500);
}
i++;
}
if(h1){
i = 1;
while(zz12[shu[1][y]][i] != 0){
if(zz13[shu[1][y]] % (int)(pow(10, i * 2)) / (int)(pow(10, (i * 2 - 2))) == 1){
zz15[shu[1][y]]++;
bohe1 -= zz12[shu[1][y]][i];
zz12[shu[1][y]][i] = (int)(pow(zz17[shu[1][y]], zz15[shu[1][y]]) * zz16[shu[1][y]][i] * 100 + 0.5) / 100.0;
}else if(zz13[shu[1][y]] % (int)(pow(10, i * 2)) / (int)(pow(10, (i * 2 - 2))) == 2){
zz15[shu[1][y]]++;
mutou1 -= zz12[shu[1][y]][i];
zz12[shu[1][y]][i] = (int)(pow(zz17[shu[1][y]], zz15[shu[1][y]]) * zz16[shu[1][y]][i] * 100 + 0.5) / 100.0;
}else if(zz13[shu[1][y]] % (int)(pow(10, i * 2)) / (int)(pow(10, (i * 2 - 2))) == 3){
zz15[shu[1][y]]++;
kuangwu1 -= zz12[shu[1][y]][i];
zz12[shu[1][y]][i] = (int)(pow(zz17[shu[1][y]], zz15[shu[1][y]]) * zz16[shu[1][y]][i] * 100 + 0.5) / 100.0;
}
i++;
}
if(shu[1][y] == 4){
cat2 += 2;
catli2 += 75;
if(!z1[1]){
hengl++;
heng[2] = 2;
heng[3] = 4;
shul[2] = 1;
z1[1] = true;
shul[1]++;
shu[1][5] = 5;
output0();
}
}else if(shu[1][y] == 5){
keji2 += 250;
if(!z1[2]){
hengl++;
heng[3] = 3;
heng[4] = 4;
shu[2][2] = 3;
shul[2]++;
z1[2] = true;
}
}else if(shu[1][y] == 6){
bohe2 += 5000;
mutou2 += 200;
kuangwu2 += 250;
}else if(shu[1][y] == 7){
if(!z1[3]){
shul[2]++;
shu[2][shul[2]] = 5;
sort(shu[2] + 1, shu[2] + shul[2] + 1, pai2);
shul[1]++;
shu[1][shul[1]] = 8;
sort(shu[1] + 1, shu[1] + shul[1] + 1, pai1);
z1[3] = true;
}
}
}
}
output1();
}else if(heng[x] == 2){
if(zz22 > 0){
zz21[shu[2][y]]++;
zz22--;
output2();
}
}else if(heng[x] == 3){
if(keji1 >= zz32[shu[3][y]]){
zz31[shu[3][y]] = true;
keji1 -= zz32[shu[3][y]];
if(shu[3][y] == 1){
shul[3] = 1;
shu[3][1] = 2;
output_1();
}else if(shu[3][y] == 2) {
shul[3] = 2;
shu[3][1] = 3;
shu[3][2] = 4;
shu[2][2] = 2;
shu[2][3] = 3;
shul[2]++;
shul[1]++;
shu[1][6] = 6;
}else if(shu[3][y] == 3){
shu[3][y] = 5;
shul[2]++;
shu[2][shul[2]] = 4;
sort(shu[2] + 1, shu[2] + 1 + shul[2], pai2);
xinqing1 = true;
}else if(shu[3][y] == 4){
shu[3][y] = 6;
shul[1]++;
shu[1][shul[1]] = 7;
sort(shu[1] + 1, shu[1] + 1 + shul[1], pai1);
}
output3();
}
}
}else if(check('2')){
if(heng[x] == 1){
}else if(heng[x] == 2){
if(zz21[shu[2][y]] > 0){
zz21[shu[2][y]]--;
zz22++;
output2();
}
}
}else if(check('3')){
if(heng[x] == 1){
}else if(heng[x] == 2){
if(shu[2][y] == 4 && catli1 >= 100){
catli1 -= 100;
srand(time(NULL));
int sui1 = (rand() % 2001) + 3000;
int sui2 = (rand() % 1001);
int sui3 = (rand() % 3);
maopi1 = true;
maopi += sui1 / 100.0;
if(sui3 == 0){
xiangya1 = true;
xiangya += sui2 / 100.0;
}
}
}
}
if(tim1 == 1){
bohe1 += zz15[2] * 0.063 * 1.5;
}else if(tim1 == 4){
bohe1 += zz15[2] * 0.063 * 0.25;
}else{
bohe1 += zz15[2] * 0.063;
}
bohe1 -= cat1 * 0.4;
mutou1 += zz21[1] * 0.009 * xinqing / 100;
bohe1 += zz21[2] * 0.5 * xinqing / 100;
keji1 += zz21[3] * 0.0175 * (1 + 0.1 * zz15[5]) * xinqing / 100;
catli1 += zz21[4] * 0.03 * xinqing / 100;
kuangwu1 += zz21[5] * 0.025 * (1 + 0.2 * zz15[7]) * xinqing / 100;
if(maopi > 0){
maopi -= cat1 * 0.005;
if(maopi < 0){
maopi = 0;
}
}
if(xiangya > 0){
xiangya -= cat1 * 0.0035;
if(xiangya < 0){
xiangya = 0;
}
}
if(!xinqing1 && cat1 > 4){
xinqing1 = true;
}
xinqing = 100 - max(cat1 * 2 - 10, 0);
if(maopi > 0){
xinqing += 10;
}
if(xiangya > 0){
xinqing += 10;
}
if(bohe1 <= 0 && cat1 > 0){
timm2 = 0;
bohe1 = 0;
timm1++;
if(timm1 == 54){
cat1--;
if(zz22 <= 0){
for(int i = 1; i <= shul[2]; i++){
if(zz21[shu[2][i]] > 0){
zz21[shu[2][i]]--;
break;
}
}
}else{
zz22--;
}
timm1 = 0;
}
}else{
timm1 = 0;
if(cat2 > cat1){
timm2++;
if(timm2 == 108){
cat1++;
zz22++;
timm2 = 0;
}
}
}
if(z1[30] == 0 && cat2 >= 8){
hengs[2] = "村庄";
z1[30]++;
}
Sleep(100);
tim3++;
}
return 0;
}
7.狼人杀(人机)
//永远不要对没有发言环节的狼人杀抱有希望
#include<bits/stdc++.h>
using namespace std;
int life[7]={1,1,1,1,1,1};
int potions[5]={-1,1};
int vote[7]={0};
string name[7]={"预言家","女巫","平民","平民","狼人","狼人"};
int seer(int x,int y,int n,int p1,int p2,int l1,int l2)
{
int rescued;
int die;
int die_potions;
bool gameover=false;
while(gameover==false)
{
cout<<endl<<"下一天:----------------------------"<<endl;
for(int i=1;i<=4;i++)
{
if(i==1&&(life[l1]>=0 or life[l2]>=0))
{
cout<<"狼人:"<<endl;
srand((unsigned)time(NULL));
die=rand()%6;
while(name[die]=="狼人"||life[die]==-1) die=rand()%6;
life[die]--;
cout<<"狼人杀了"<<name[die]<<endl;
}
if(i==2&&life[x]>=0)
{
cout<<"预言家:"<<endl;
cout<<"你是预言家,请输入0~5的编号(代表相应的人)(除了"<<x<<"号)来预言"<<endl;
int res;
cin>>res;
if(name[res]=="平民"||name[res]=="女巫"||name[res]=="预言家") cout<<"好人"<<endl;
if(name[res]=="狼人") cout<<"坏人"<<endl;
}
if(i==3&&life[n]>=0)
{
cout<<"女巫:"<<endl;
int dor;
srand((unsigned)time(NULL));
dor=rand()%3;
if(dor==0)
{
die_potions=rand()%6;
while(name[die_potions]=="女巫"||life[die_potions]<=0) die_potions=rand()%6;
life[die_potions]--;
potions[dor]++;
cout<<"女巫杀了"<<name[die_potions]<<endl;
}
if(dor==1)
{
int help;
for(int i=0;i<6;i++) if(life[i]==0) life[i]++,help=i;
potions[dor]--;
cout<<"女巫救了"<<name[help]<<endl;
}
if(dor==2)
{
cout<<"没用药"<<endl;
}
}
if(i==4)
{
int sum_die=0;
cout<<"今晚";
for(int j=0;j<6;j++)
{
if(life[j]==0)
{
sum_die++;
life[j]--;
cout<<j<<"号"<<name[j]<<"死了";
}
}
if(sum_die==0) cout<<"是平安夜";
int fl=0,fp=0;
for(int j=0;j<6;j++)
{
if(life[j]==1)
{
if(name[j]=="狼人") fl++;
else fp++;
}
}
if(fl==0)
{
cout<<endl<<"平民赢了"<<endl;
gameover=true;
continue;
}
if(fp==0)
{
cout<<endl<<"狼人赢了"<<endl;
gameover=true;
continue;
}
cout<<endl<<"投票"<<endl;
int a[7]={0,0,0,0,0,0};
for(int j=0;j<6;j++)
{
if(j==x&&life[x]==1)
{
cout<<"请投0~5号你认为是狼人的";
int ps;
cin>>ps;
a[ps]++;
}
else if(life[j]==1)
{
srand((unsigned)time(NULL));
int cs;
cs=rand()%6;
while(life[cs]!=1||cs==j) cs=rand()%6;
a[cs]++;
}
}
cout<<"投票结果:"<<endl;
cout<<"0 1 2 3 4 5"<<endl;
for(int j=0;j<6;j++) cout<<a[j]<<" ";
cout<<endl;
int max=-1,mp;
for(int j=0;j<6;j++) if(a[j]>=max) max=a[j],mp=j;
cout<<mp<<"号"<<name[mp]<<"出局"<<endl<<endl;
life[mp]=-1;
int good=0,bad=0;
for(int j=0;j<6;j++)
{
if(life[j]==1&&(name[j]=="平民"||name[j]=="女巫"||name[j]=="预言家")) good++;
if(life[j]==1&&name[j]=="狼人") bad++;
}
if(bad==0)
{
cout<<"平民赢了"<<endl;
gameover=true;
}
if(good==0)
{
cout<<"狼人赢了"<<endl;
gameover=true;
}
}
}
system("pause");
}
return 0;
}
int Lycan(int x,int y,int n,int p1,int p2,int l1,int l2)
{
int rescued;
int die;
int die_potions;
bool gameover=false;
while(gameover==false)
{
cout<<endl<<"下一天:----------------------------"<<endl;
for(int i=1;i<=4;i++)
{
if(i==1&&life[x]>=0)
{
cout<<"狼人:"<<endl;
cout<<"你是狼人,请输入0~5的编号(代表相应的人)(除了"<<x<<"和"<<l1+l2-x<<"号)来杀死"<<endl;
cin>>die;
life[die]--;
cout<<"狼人杀了"<<name[die]<<endl;
}
if(i==1&&life[x]==-1&&life[l1+l2-x]>=0)
{
cout<<"狼人:"<<endl;
srand((unsigned)time(NULL));
die=rand()%6;
while(name[die]=="狼人"||life[die]==-1) die=rand()%6;
life[die]--;
cout<<"狼人杀了"<<name[die]<<endl;
}
if(i==2&&life[y]>=0)
{
cout<<"预言家:"<<endl;
cout<<"预言完毕"<<endl;
}
if(i==3&&life[n]>=0)
{
cout<<"女巫:"<<endl;
int dor;
srand((unsigned)time(NULL));
dor=rand()%3;
if(dor==0)
{
die_potions=rand()%6;
while(name[die_potions]=="女巫"||life[die_potions]<=0) die_potions=rand()%6;
life[die_potions]--;
potions[dor]++;
cout<<"女巫杀了"<<name[die_potions]<<endl;
}
if(dor==1)
{
int help;
for(int i=0;i<6;i++) if(life[i]==0) life[i]++,help=i;
potions[dor]--;
cout<<"女巫救了"<<name[help]<<endl;
}
if(dor==2)
{
cout<<"没用药"<<endl;
}
}
if(i==4)
{
int sum_die=0;
cout<<"今晚";
for(int j=0;j<6;j++)
{
if(life[j]==0)
{
sum_die++;
life[j]--;
cout<<j<<"号"<<name[j]<<"死了";
}
}
if(sum_die==0) cout<<"是平安夜";
int fl=0,fp=0;
for(int j=0;j<6;j++)
{
if(life[j]==1)
{
if(name[j]=="狼人") fl++;
else fp++;
}
}
if(fl==0)
{
cout<<endl<<"平民赢了"<<endl;
gameover=true;
continue;
}
if(fp==0)
{
cout<<endl<<"狼人赢了"<<endl;
gameover=true;
continue;
}
cout<<endl<<"投票"<<endl;
int a[7]={0,0,0,0,0,0};
for(int j=0;j<6;j++)
{
if(j==x&&life[x]==1)
{
cout<<"请投0~5号你认为是狼人的";
int ps;
cin>>ps;
a[ps]++;
}
else if(life[j]==1)
{
srand((unsigned)time(NULL));
int cs;
cs=rand()%6;
while(life[cs]!=1||cs==j) cs=rand()%6;
a[cs]++;
}
}
cout<<"投票结果:"<<endl;
cout<<"0 1 2 3 4 5"<<endl;
for(int j=0;j<6;j++) cout<<a[j]<<" ";
cout<<endl;
int max=-1,mp;
for(int j=0;j<6;j++) if(a[j]>=max) max=a[j],mp=j;
cout<<mp<<"号"<<name[mp]<<"出局"<<endl<<endl;
life[mp]=-1;
int good=0,bad=0;
for(int j=0;j<6;j++)
{
if(life[j]==1&&(name[j]=="平民"||name[j]=="女巫"||name[j]=="预言家")) good++;
if(life[j]==1&&name[j]=="狼人") bad++;
}
if(bad==0)
{
cout<<"平民赢了"<<endl;
gameover=true;
}
if(good==0)
{
cout<<"狼人赢了"<<endl;
gameover=true;
}
}
}
system("pause");
}
return 0;
}
int witch(int x,int y,int n,int p1,int p2,int l1,int l2)
{
int rescued;
int die;
int die_potions;
bool gameover=false;
while(gameover==false)
{
cout<<endl<<"下一天:----------------------------"<<endl;
for(int i=1;i<=4;i++)
{
if(i==1&&(life[l1]>=0 or life[l2]>=0))
{
cout<<"狼人:"<<endl;
srand((unsigned)time(NULL));
die=rand()%6;
while(name[die]=="狼人"||life[die]==-1) die=rand()%6;
life[die]--;
cout<<"狼人杀了"<<name[die]<<endl;
}
if(i==2&&life[y]>=0)
{
cout<<"预言家:"<<endl;
cout<<"预言完毕"<<endl;
}
if(i==3&&life[n]>=0)
{
cout<<"女巫:"<<endl;
cout<<"你是女巫,请输入d、r、n。d代表要杀、r代表要救,n代表不用药"<<endl;
char dor;
cin>>dor;
if(dor=='d')
{
cout<<"请输入0~5号你要杀的人(除了"<<n<<"号)"<<endl;
cin>>die_potions;
life[die_potions]--;
potions[0]++;
cout<<"女巫杀了"<<name[die_potions]<<endl;
}
if(dor=='r')
{
int help;
for(int i=0;i<6;i++) if(life[i]==0) life[i]++,help=i;
potions[1]--;
cout<<"女巫救了"<<name[help]<<endl;
}
if(dor=='n')
{
cout<<"没用药"<<endl;
}
}
if(i==4)
{
int sum_die=0;
cout<<"今晚";
for(int j=0;j<6;j++)
{
if(life[j]==0)
{
sum_die++;
life[j]--;
cout<<j<<"号"<<name[j]<<"死了";
}
}
if(sum_die==0) cout<<"是平安夜";
int fl=0,fp=0;
for(int j=0;j<6;j++)
{
if(life[j]==1)
{
if(name[j]=="狼人") fl++;
else fp++;
}
}
if(fl==0)
{
cout<<endl<<"平民赢了"<<endl;
gameover=true;
continue;
}
if(fp==0)
{
cout<<endl<<"狼人赢了"<<endl;
gameover=true;
continue;
}
cout<<endl<<"投票"<<endl;
int a[7]={0,0,0,0,0,0};
for(int j=0;j<6;j++)
{
if(j==x&&life[x]==1)
{
cout<<"请投0~5号你认为是狼人的";
int ps;
cin>>ps;
a[ps]++;
}
else if(life[j]==1)
{
srand((unsigned)time(NULL));
int cs;
cs=rand()%6;
while(life[cs]!=1||cs==j) cs=rand()%6;
a[cs]++;
}
}
cout<<"投票结果:"<<endl;
cout<<"0 1 2 3 4 5"<<endl;
for(int j=0;j<6;j++) cout<<a[j]<<" ";
cout<<endl;
int max=-1,mp;
for(int j=0;j<6;j++) if(a[j]>=max) max=a[j],mp=j;
cout<<mp<<"号"<<name[mp]<<"出局"<<endl<<endl;
life[mp]=-1;
int good=0,bad=0;
for(int j=0;j<6;j++)
{
if(life[j]==1&&(name[j]=="平民"||name[j]=="女巫"||name[j]=="预言家")) good++;
if(life[j]==1&&name[j]=="狼人") bad++;
}
if(bad==0)
{
cout<<"平民赢了"<<endl;
gameover=true;
}
if(good==0)
{
cout<<"狼人赢了"<<endl;
gameover=true;
}
}
}
system("pause");
}
return 0;
}
int commoner(int x,int y,int n,int p1,int p2,int l1,int l2)
{
int rescued;
int die;
int die_potions;
bool gameover=false;
while(gameover==false)
{
cout<<endl<<"下一天:----------------------------"<<endl;
for(int i=1;i<=4;i++)
{
if(i==1&&(life[l1]>=0 or life[l2]>=0))
{
cout<<"狼人:"<<endl;
srand((unsigned)time(NULL));
die=rand()%6;
while(name[die]=="狼人"||life[die]==-1) die=rand()%6;
life[die]--;
cout<<"狼人杀了"<<name[die]<<endl;
}
if(i==2&&life[y]>=0)
{
cout<<"预言家:"<<endl;
cout<<"预言完毕"<<endl;
}
if(i==3&&life[n]>=0)
{
cout<<"女巫:"<<endl;
int dor;
srand((unsigned)time(NULL));
dor=rand()%3;
if(dor==0)
{
die_potions=rand()%6;
while(name[die_potions]=="女巫"||life[die_potions]<=0) die_potions=rand()%6;
life[die_potions]--;
potions[dor]++;
cout<<"女巫杀了"<<name[die_potions]<<endl;
}
if(dor==1)
{
int help;
for(int i=0;i<6;i++) if(life[i]==0) life[i]++,help=i;
potions[dor]--;
cout<<"女巫救了"<<name[help]<<endl;
}
if(dor==2)
{
cout<<"没用药"<<endl;
}
}
if(i==4)
{
int sum_die=0;
cout<<"今晚";
for(int j=0;j<6;j++)
{
if(life[j]==0)
{
sum_die++;
life[j]--;
cout<<j<<"号"<<name[j]<<"死了";
}
}
if(sum_die==0) cout<<"是平安夜";
int fl=0,fp=0;
for(int j=0;j<6;j++)
{
if(life[j]==1)
{
if(name[j]=="狼人") fl++;
else fp++;
}
}
if(fl==0)
{
cout<<endl<<"平民赢了"<<endl;
gameover=true;
continue;
}
if(fp==0)
{
cout<<endl<<"狼人赢了"<<endl;
gameover=true;
continue;
}
cout<<endl<<"投票"<<endl;
int a[7]={0,0,0,0,0,0};
for(int j=0;j<6;j++)
{
if(j==x&&life[x]==1)
{
cout<<"请投0~5号你认为是狼人的";
int ps;
cin>>ps;
a[ps]++;
}
else if(life[j]==1)
{
srand((unsigned)time(NULL));
int cs;
cs=rand()%6;
while(life[cs]!=1||cs==j) cs=rand()%6;
a[cs]++;
}
}
cout<<"投票结果:"<<endl;
cout<<"0 1 2 3 4 5"<<endl;
for(int j=0;j<6;j++) cout<<a[j]<<" ";
cout<<endl;
int max=-1,mp;
for(int j=0;j<6;j++) if(a[j]>=max) max=a[j],mp=j;
cout<<mp<<"号"<<name[mp]<<"出局"<<endl<<endl;
life[mp]=-1;
int good=0,bad=0;
for(int j=0;j<6;j++)
{
if(life[j]==1&&(name[j]=="平民"||name[j]=="女巫"||name[j]=="预言家")) good++;
if(life[j]==1&&name[j]=="狼人") bad++;
}
if(bad==0)
{
cout<<"平民赢了"<<endl;
gameover=true;
}
if(good==0)
{
cout<<"狼人赢了"<<endl;
gameover=true;
}
}
}
system("pause");
}
return 0;
}
int main()
{
begin:
cout<<"狼人杀"<<endl;
cout<<"1个预言家 1个女巫 2个平民 2个狼人"<<endl;
srand((unsigned)time(NULL));
for(int i=1;i<=1000;i++)
{
int x=rand()%6;
int y=rand()%6;
swap(name[x],name[y]);
}
int player=rand()%6;
cout<<"你是"<<name[player]<<endl<<"您的编号是"<<player<<endl<<endl;
int l1,l2,l=1;
int y;
int n;
int p1,p2,p=1;
for(int i=0;i<6;i++)
{
if(name[i]=="狼人"&&l==1)
{
l1=i;
l++;
continue;
}
if(name[i]=="狼人"&&l==2) l2=i,l++;
if(name[i]=="预言家") y=i;
if(name[i]=="女巫") n=i;
if(name[i]=="平民"&&p==1)
{
p1=i;
p++;
continue;
}
if(name[i]=="平民"&&p==2) p2=i,p++;
}
if(player==y) seer(player,y,n,p1,p2,l1,l2);
if(player==l1 or player==l2) Lycan(player,y,n,p1,p2,l1,l2);
if(player==n) witch(player,y,n,p1,p2,l1,l2);
if(player==p1 or player==p2) commoner(player,y,n,p1,p2,l1,l2);
else return 0;
}
版权声明:本文标题:C++游戏天堂——经典型(1) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1729778795a1212527.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论