第三部分2019.9.26至今(真可惜第二次整合我现在不能做,几乎所有程序我都能嵌到心慌方中作为陷阱惩罚,但我终究慢一步)(不像作为作业的第一部分,这部分纯核心玩法,我没有加设置,排行榜,玩法说明,有些游戏可能不说明不会玩,这也是我之后要做的事)
四十、get16
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <vector>
#include <math.h>
#include <iomanip>
#include <graphics.h>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
MOUSEMSG m;
struct Node
{
int posx,posy;
int lifenum;
int num;
};
IMAGE pic[16];
Node box[17];
clock_t t1,t2;
int sum,one[2],two[2],step;
int seed1,seed2,exit1;
void initialization()
{
int i,j,k;
seed1=0,seed2=2;step=1;exit1=0;
initgraph(500, 500,SHOWCONSOLE);
loadimage(&pic[1], _T("../素材/1.png"),80,80);
loadimage(&pic[2], _T("../素材/2.png"),80,80);
loadimage(&pic[3], _T("../素材/3.png"),80,80);
loadimage(&pic[4], _T("../素材/4.png"),80,80);
loadimage(&pic[5], _T("../素材/5.png"),80,80);
loadimage(&pic[6], _T("../素材/6.png"),80,80);
loadimage(&pic[7], _T("../素材/7.png"),80,80);
loadimage(&pic[8], _T("../素材/8.png"),80,80);
loadimage(&pic[9], _T("../素材/9.png"),80,80);
loadimage(&pic[10], _T("../素材/10.png"),80,80);
loadimage(&pic[11], _T("../素材/11.png"),80,80);
loadimage(&pic[12], _T("../素材/12.png"),80,80);
loadimage(&pic[13], _T("../素材/13.png"),80,80);
loadimage(&pic[14], _T("../素材/14.png"),80,80);
loadimage(&pic[15], _T("../素材/15.png"),80,80);
for(i=0;i<4;i++){
for(j=1;j<=4;j++){
box[i*4+j].posx=50+i*100;
box[i*4+j].posy=-50+j*100;
box[i*4+j].lifenum=0;
box[i*4+j].num=0;
}
}
box[0].lifenum=1;
}
void creact()
{
int i,j,k;
seed1++;
srand(seed1);
i=rand()%8+1;
j=0;k=0;
while(box[j].lifenum==1){
seed2++;
srand(seed2);
j=rand()%16+1;
k++;
if(k==6){
j=0;
break;
}
}
if(j!=0){
exit1++;
box[j].lifenum=1;
box[j].num=i;
putimage(box[j].posx,box[j].posy, &pic[box[j].num]);
}
// cout<<k<<' ';
seed1++;
srand(seed1);
i=rand()%8+8;
j=0;k=0;
while(box[j].lifenum==1){
seed2++;
srand(seed2);
j=rand()%16+1;
k++;
if(k==6){
j=0;
break;
}
}
box[j].lifenum=1;
box[j].num=i;
if(j!=0){
exit1++;
box[j].lifenum=1;
box[j].num=i;
putimage(box[j].posx,box[j].posy, &pic[box[j].num]);
} //cout<<k<<' ';
}
void oneclick()
{
int i,j;
if(MouseHit()){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
for(i=1;i<=16;i++){
if(m.x>=box[i].posx&&m.x<=box[i].posx+80&&m.y>=box[i].posy&&m.y<=box[i].posy+80){
one[0]=box[i].num;
step=2;
one[1]=i;
}
}
}
}
}
void twoclick()
{
int i,j;
if(MouseHit()){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
for(i=1;i<=16;i++){
if(m.x>=box[i].posx&&m.x<=box[i].posx+80&&m.y>=box[i].posy&&m.y<=box[i].posy+80&&i!=one[1]){
sum=box[i].num+one[0];
step=3;
two[1]=i;
}
}
}
}
}
void after_click()
{
//cout<<sum<<endl;
if(sum==16){
clearrectangle(box[one[1]].posx,box[one[1]].posy,box[one[1]].posx+80,box[one[1]].posy+80);
clearrectangle(box[two[1]].posx,box[two[1]].posy,box[two[1]].posx+80,box[two[1]].posy+80);
box[one[1]].lifenum=0;
box[two[1]].lifenum=0;
exit1=exit1-2;
}
step=1;
}
void carry()
{
int i,j,k;
initialization();
t1=clock();
t2=clock();
while(exit1<16){
if(step==1){oneclick();}
if(step==2){twoclick();}
if(step==3){after_click();}
t2=clock();
if(t2-t1>=1500){
t1=clock();
creact();
cout<<exit1<<endl;
}
}
_getch();
closegraph();
}
int main()
{
carry();
return 0;
}
四十一、躲球
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <vector>
#include <math.h>
#include <iomanip>
#include <graphics.h>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
MOUSEMSG m;
struct Node
{
int posx,posy;
int lifenum;
int num;
};
IMAGE pic[16];
Node box[17];
clock_t t1,t2;
int sum,one[2],two[2],step;
int seed1,seed2,exit1;
void initialization()
{
int i,j,k;
seed1=0,seed2=2;step=1;exit1=0;
initgraph(500, 500,SHOWCONSOLE);
loadimage(&pic[1], _T("../素材/1.png"),80,80);
loadimage(&pic[2], _T("../素材/2.png"),80,80);
loadimage(&pic[3], _T("../素材/3.png"),80,80);
loadimage(&pic[4], _T("../素材/4.png"),80,80);
loadimage(&pic[5], _T("../素材/5.png"),80,80);
loadimage(&pic[6], _T("../素材/6.png"),80,80);
loadimage(&pic[7], _T("../素材/7.png"),80,80);
loadimage(&pic[8], _T("../素材/8.png"),80,80);
loadimage(&pic[9], _T("../素材/9.png"),80,80);
loadimage(&pic[10], _T("../素材/10.png"),80,80);
loadimage(&pic[11], _T("../素材/11.png"),80,80);
loadimage(&pic[12], _T("../素材/12.png"),80,80);
loadimage(&pic[13], _T("../素材/13.png"),80,80);
loadimage(&pic[14], _T("../素材/14.png"),80,80);
loadimage(&pic[15], _T("../素材/15.png"),80,80);
for(i=0;i<4;i++){
for(j=1;j<=4;j++){
box[i*4+j].posx=50+i*100;
box[i*4+j].posy=-50+j*100;
box[i*4+j].lifenum=0;
box[i*4+j].num=0;
}
}
box[0].lifenum=1;
}
void creact()
{
int i,j,k;
seed1++;
srand(seed1);
i=rand()%8+1;
j=0;k=0;
while(box[j].lifenum==1){
seed2++;
srand(seed2);
j=rand()%16+1;
k++;
if(k==6){
j=0;
break;
}
}
if(j!=0){
exit1++;
box[j].lifenum=1;
box[j].num=i;
putimage(box[j].posx,box[j].posy, &pic[box[j].num]);
}
// cout<<k<<' ';
seed1++;
srand(seed1);
i=rand()%8+8;
j=0;k=0;
while(box[j].lifenum==1){
seed2++;
srand(seed2);
j=rand()%16+1;
k++;
if(k==6){
j=0;
break;
}
}
box[j].lifenum=1;
box[j].num=i;
if(j!=0){
exit1++;
box[j].lifenum=1;
box[j].num=i;
putimage(box[j].posx,box[j].posy, &pic[box[j].num]);
} //cout<<k<<' ';
}
void oneclick()
{
int i,j;
if(MouseHit()){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
for(i=1;i<=16;i++){
if(m.x>=box[i].posx&&m.x<=box[i].posx+80&&m.y>=box[i].posy&&m.y<=box[i].posy+80){
one[0]=box[i].num;
step=2;
one[1]=i;
}
}
}
}
}
void twoclick()
{
int i,j;
if(MouseHit()){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
for(i=1;i<=16;i++){
if(m.x>=box[i].posx&&m.x<=box[i].posx+80&&m.y>=box[i].posy&&m.y<=box[i].posy+80&&i!=one[1]){
sum=box[i].num+one[0];
step=3;
two[1]=i;
}
}
}
}
}
void after_click()
{
//cout<<sum<<endl;
if(sum==16){
clearrectangle(box[one[1]].posx,box[one[1]].posy,box[one[1]].posx+80,box[one[1]].posy+80);
clearrectangle(box[two[1]].posx,box[two[1]].posy,box[two[1]].posx+80,box[two[1]].posy+80);
box[one[1]].lifenum=0;
box[two[1]].lifenum=0;
exit1=exit1-2;
}
step=1;
}
void carry()
{
int i,j,k;
initialization();
t1=clock();
t2=clock();
while(exit1<16){
if(step==1){oneclick();}
if(step==2){twoclick();}
if(step==3){after_click();}
t2=clock();
if(t2-t1>=1500){
t1=clock();
creact();
cout<<exit1<<endl;
}
}
_getch();
closegraph();
}
int main()
{
carry();
return 0;
}
四十二、合十
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <vector>
#include <math.h>
#include <iomanip>
#include <graphics.h>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
struct Node
{
int posx,posy;
int num;
int lifenum;
};
Node box[5][5];
int D=80;
int X,Y;
int seed1;
MOUSEMSG m;
IMAGE shuzi[11];
int change;
void initialization()
{
int i,j,k;seed1=0;change=0;
initgraph(500,500,SHOWCONSOLE);
loadimage(&shuzi[1], _T("../素材/1.png"),D,D);
loadimage(&shuzi[2], _T("../素材/2.png"),D,D);
loadimage(&shuzi[3], _T("../素材/3.png"),D,D);
loadimage(&shuzi[4], _T("../素材/4.png"),D,D);
loadimage(&shuzi[5], _T("../素材/5.png"),D,D);
loadimage(&shuzi[6], _T("../素材/6.png"),D,D);
loadimage(&shuzi[7], _T("../素材/7.png"),D,D);
loadimage(&shuzi[8], _T("../素材/8.png"),D,D);
loadimage(&shuzi[9], _T("../素材/9.png"),D,D);
loadimage(&shuzi[10], _T("../素材/10.png"),D,D);
for(i=0;i<=4;i++){
for(j=0;j<=4;j++){
box[i][j].posx=i*80+50;
box[i][j].posy=j*80+50;
seed1=seed1++;
srand(seed1);
k=rand()%3+1;
box[i][j].num=k;
box[i][j].lifenum=1;
putimage(box[i][j].posx,box[i][j].posy,&shuzi[box[i][j].num]);
//cout<<i;
}
}
}
void creact()
{
int i,j,k;
for(i=0;i<=4;i++){
for(j=0;j<=4;j++){
if(box[i][j].lifenum==0){
seed1=seed1++;
srand(seed1);
k=rand()%3+1;
box[i][j].num=k;
box[i][j].lifenum=1;
putimage(box[i][j].posx,box[i][j].posy,&shuzi[box[i][j].num]);
}
}
}
if(change!=0){
box[X][Y].num++;
putimage(box[X][Y].posx,box[X][Y].posy,&shuzi[box[X][Y].num]);
}
change=0;
}
void check(){
int i,j,k,n;
for(i=X-1;i>=0;i--){
if(box[i][Y].num!=box[i+1][Y].num){
break;
}
else{
box[i][Y].lifenum=0;change++;
}
}
j=i+1;
for(i=X+1;i<=4;i++){
if(box[i][Y].num!=box[X][Y].num){
break;
}
else{box[i][Y].lifenum=0;change++;
}
}
k=i-1;
for(i=j;i<=k;i++){
for(n=Y-1;n>=0;n--){
if(box[i][n].num!=box[i][n+1].num){
break;
}
else{box[i][n].lifenum=0;change++;
}
}
for(n=Y+1;n<=4;n++){
if(box[i][n].num!=box[i][n-1].num){
break;
}
else{box[i][n].lifenum=0;change++;
}
}
}
///
for(j=Y-1;j>=0;j--){
if(box[X][j].num!=box[X][j+1].num){
break;
}
else{box[X][j].lifenum=0;change++;
}
}
i=j+1;
for(j=Y+1;j<=4;j++){
if(box[X][j].num!=box[X][j-1].num){
break;
}
else{box[X][j].lifenum=0;change++;
}
}
k=j-1;
for(j=i;j<=k;j++){
for(n=X-1;n>=0;n--){
if(box[n][j].num!=box[n+1][j].num){
break;
}
else{box[n][j].lifenum=0;change++;
}
}
for(n=X+1;n<=4;n++){
if(box[n][j].num!=box[n-1][j].num){
break;
}
else{box[n][j].lifenum=0;change++;
}
}
}
}
void click()
{
int i,j;
if(MouseHit()){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
for(i=0;i<=4;i++){
for(j=0;j<=4;j++){
if(m.x>=box[i][j].posx&&m.x<=box[i][j].posx+D&&m.y>=box[i][j].posy&&m.y<=box[i][j].posy+D){
X=i;Y=j;
check();
creact();
}
}
}
}
}
}
void carry()
{
initialization();
while(true){
click();
}
_getch();
closegraph();
}
int main()
{
carry();
}
四十三、画个圆
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <vector>
#include <math.h>
#include <iomanip>
#include <graphics.h>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
struct Node
{
int posx,posy;
};
int mm;
MOUSEMSG m;
double R;
Node draw[3600];
double pi=3.141592653;
void initialization()
{
initgraph(500,500,SHOWCONSOLE);
R=100;
circle(250,250,R);
line(250,250,250+sin(2)*R,250+cos(2)*R);
Sleep(1000);
// cleardevice();
line(250,250,250+sin(2)*R,250+cos(2)*R);
}
void move()
{
int i=0,j=0,k=0;
while(k==0){
if(MouseHit()){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
draw[i].posx=m.x;
draw[i].posy=m.y;
while(j==0){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
j++;k++;
}
else if(m.uMsg==WM_MOUSEMOVE){
line(draw[i].posx,draw[i].posy,m.x,m.y);
i++;//cout<<i<<endl;
draw[i].posx=m.x;
draw[i].posy=m.y;
}
}
}
}
}
mm=i;
}
void check()
{
int i,j,k;
double sum=0,l;
for(i=0;i<=mm;i++){
l=sqrt((draw[i].posx-sin(2+pi/double(180*mm/360)*i))*(draw[i].posx-sin(2+pi/double(180*mm/360)*i))+(draw[i].posy-cos(2+pi/double(180*mm/360)*i))*(draw[i].posy-cos(2+pi/double(180*mm/360)*i)))*double(36000/mm)*0.000001;
sum=sum+l;
}//more double!!! 在l的式子里都加上double,别忘了
cout<<(sum-13)*100;
}
void carry()
{
initialization();
move();
check();
_getch();
closegraph();
}
int main()
{
carry();
}
四十四、见缝插针
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <vector>
#include <math.h>
#include <iomanip>
#include <graphics.h>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
int exit1,seed1;
struct Node
{
int posx,posy;
int numx,numy;
int num;
clock_t t1,t2;
};
Node box[25];
MOUSEMSG m;
double pi=3.141592653;
int boxnum;
void initialization()
{
exit1=0;
seed1=0;boxnum=0;
initgraph(500,500,SHOWCONSOLE);
//circle(250,150,150);
}
void creact()
{
int i;double j,k;
box[boxnum].t1=clock();
box[boxnum].t2=clock();
box[boxnum].posx=250;
box[boxnum].posy=300;
box[boxnum].numx=250;
box[boxnum].numy=225;
for(i=0;i<boxnum;i++){
j=box[i].posx-box[boxnum].posx;
k=box[i].posy-box[boxnum].posy;
cout<<j*j+k*k<<' ';
if(j*j+k*k<400){
exit1=1;
}
}
boxnum++;
}
void move()
{
int i,k;
double j;
BeginBatchDraw();
creact();
while(exit1==0){
if(MouseHit()){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
creact();
}
}
FlushBatchDraw();
cleardevice();
circle(250,450,10);
circle(250,150,75);
for(i=0;i<boxnum;i++){
box[i].t2=clock();
j=(box[i].t2-box[i].t1)/10;
box[i].posx=250-150*sin(pi/180*j);
box[i].posy=150+150*cos(pi/180*j);
box[i].numx=250-75*sin(pi/180*j);
box[i].numy=150+75*cos(pi/180*j);;
circle(box[i].posx,box[i].posy,10);
line(box[i].numx,box[i].numy,box[i].posx,box[i].posy);
}
}
EndBatchDraw();
}
void carry()
{
initialization();
move();
_getch();
closegraph();
}
int main()
{
carry();
}
四十五、你的一秒有
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <vector>
#include <math.h>
#include <iomanip>
#include <graphics.h>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
clock_t t1,t2;
MOUSEMSG m;
void initialization()
{
initgraph(500,500,SHOWCONSOLE);
}
void move()
{
int i,j=0,k=0;
while(k==0){
if(MouseHit()){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
t1=clock();
while(j==0){
if(MouseHit()){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
t2=clock();
j++;k++;
}
}
}
}
}
}
cout<<double(t2-t1)/double(1000);
}
void carry()
{
initialization();
move();
_getch();
closegraph();
}
int main()
{
carry();
}
四十六、双人跳
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <vector>
#include <math.h>
#include <iomanip>
#include <graphics.h>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
int exit1,seed1;
struct Node
{
int posx,posy;
int lifenum;
clock_t t3,t4;
};
Node box[10];
IMAGE img[4];
clock_t t1,t2,t5,t6,t7,t8;
int one,two;
MOUSEMSG m;
void initialization()
{
int i,j,k;
for(i=0;i<=9;i++){
box[i].lifenum=0;
}
exit1=0;seed1=1;one=1;two=1;
initgraph(500,500,SHOWCONSOLE);
setfillcolor(WHITE);
solidrectangle(0,0,500,250);
loadimage(&img[0], _T("../素材/one.png"),40,20);
loadimage(&img[1], _T("../素材/two.png"),40,20);
loadimage(&img[2], _T("../素材/1.png"),20,20); //i=1,2
loadimage(&img[3], _T("../素材/2.png"),20,20);
putimage(260,250, &img[1]);
putimage(200,230, &img[0]);
}
void creact()
{
int i,j,k;
seed1++;
srand(seed1);
i=rand()%2+1;
for(j=0;j<=9;j++){
if(box[j].lifenum==0){
box[j].lifenum=i;
box[j].t3=clock();
box[j].t4=clock();
box[j].posx=250;
break;
}
}
}
void move()
{
int i,j,k;
t1=clock();
t2=clock();
BeginBatchDraw();
while(exit1==0){
if(MouseHit()){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
if(m.y<250&&one==1){
one=0;t5=clock();t6=clock();
}
if(m.y>250&&two==1){
two=0;t7=clock();t8=clock();
}
}
}
if(one==0){
t6=clock();
if(t6-t5>1500){
t5=clock();
one=1;
}
}
if(two==0){
t8=clock();
if(t8-t7>500){
t7=clock();
two=1;
}
}
t2=clock();
while(t2-t1>500){
t1=clock();
creact();
}
FlushBatchDraw();
cleardevice();
solidrectangle(0,0,500,250);
if(two==1){putimage(260,251, &img[1]);}else{putimage(260,280, &img[1]);}
if(one==1){putimage(200,230, &img[0]);}else{putimage(200,200, &img[0]);}
for(i=0;i<=9;i++){
if(box[i].lifenum==1){
box[i].posx=500-(box[i].t4-box[i].t3)/10;
box[i].posy=230;
box[i].t4=clock();
putimage(box[i].posx,box[i].posy,&img[box[i].lifenum+1]);
if(box[i].posx<=-20){
box[i].lifenum=0;
}
if(one==1&&box[i].posx>=230&&box[i].posx<=240){
exit1=1;
}
}
if(box[i].lifenum==2){
box[i].posx=(box[i].t4-box[i].t3)/10;
box[i].posy=251;
box[i].t4=clock();
putimage(box[i].posx,box[i].posy,&img[box[i].lifenum+1]);
if(box[i].posx>=500){
box[i].lifenum=0;
}
if(two==1&&box[i].posx>=250&&box[i].posx<=260){
exit1=1;
}
}
}
}
EndBatchDraw();
}
void carry()
{
initialization();
move();
_getch();
closegraph();
}
int main()
{
carry();
}
四十七、算术
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <vector>
#include <math.h>
#include <iomanip>
#include <graphics.h>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
int seed1,seed2,exit1;
struct Node
{
int posx,posy;
int numx,numy;
int num;
};
Node box[4];int D=100;
IMAGE shuzi[11];
clock_t t1,t2;
MOUSEMSG m;
void initialization()
{
initgraph(500, 500,SHOWCONSOLE);
seed1=0;seed2=10;exit1=1;
setbkcolor(WHITE);
setlinecolor(RED);
setlinestyle(PS_SOLID ,10);
cleardevice();
int i,j,k;
box[0].posx=90;box[0].posy=100;
box[1].posx=310;box[1].posy=100;
box[2].posx=90;box[2].posy=300;
box[3].posx=310;box[3].posy=300;
loadimage(&shuzi[1], _T("../素材/1.png"),D,D);
loadimage(&shuzi[2], _T("../素材/2.png"),D,D);
loadimage(&shuzi[3], _T("../素材/3.png"),D,D);
loadimage(&shuzi[4], _T("../素材/4.png"),D,D);
loadimage(&shuzi[5], _T("../素材/5.png"),D,D);
loadimage(&shuzi[6], _T("../素材/6.png"),D,D);
loadimage(&shuzi[7], _T("../素材/7.png"),D,D);
loadimage(&shuzi[8], _T("../素材/8.png"),D,D);
loadimage(&shuzi[9], _T("../素材/9.png"),D,D);
loadimage(&shuzi[10], _T("../素材/10.png"),D,D);
}
void move()
{
cleardevice();
int i,j,k,n;
seed1++;
srand(seed1);
i=rand()%5+1;
box[0].num=i;
seed2++;
srand(seed2);
i=rand()%5+1;
box[1].num=i;
box[2].num=box[0].num+box[1].num;
while(box[2].num==box[0].num+box[1].num){
seed1++;
srand(seed1);
i=rand()%10+1;
box[2].num=i;
}
box[3].num=box[0].num+box[1].num;
while(box[3].num==box[0].num+box[1].num){
seed2++;
srand(seed2);
i=rand()%10+1;
box[3].num=i;
}
seed2++;
srand(seed2);
i=rand()%2;
box[i+2].num=box[0].num+box[1].num;
line(210,150,290,150);
line(250, 110, 250,190);
for(i=0;i<=3;i++){
putimage(box[i].posx,box[i].posy, &shuzi[box[i].num]);
}
t1=clock();
t2=clock();
i=0;
while(t2-t1<=4000&&i==0){
t2=clock();
if(MouseHit()){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
if(m.x>=box[3].posx&&m.y>=box[3].posy&&m.x<=box[3].posx+D&&m.y<=box[3].posy+D){
if(box[3].num==9||(box[3].num!=box[0].num+box[1].num&&box[0].num+box[1].num!=9)){
}
else{
exit1=0;
}
i++;//cout<<i;
}
else if(m.x>=box[2].posx&&m.y>=box[2].posy&&m.x<=box[2].posx+D&&m.y<=box[2].posy+D){
if(box[2].num==9||(box[2].num!=box[0].num+box[1].num&&box[0].num+box[1].num!=9)){
}
else{
exit1=0;
}
i++;//cout<<i;
}
}
}
}
if(i==0){
exit1=0;
}
}
void carry()
{
initialization();
while(exit1==1){
move();
}
_getch();
closegraph();
}
int main()
{
carry();
}
四十八、搭桥
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <vector>
#include <math.h>
#include <iomanip>
#include <graphics.h>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
int seed1,seed2;
clock_t t1,t2;
MOUSEMSG m;
struct Node
{
int posx,posy;
int numx,numy;
};
Node gunzi;
int exit1;
double pi=3.141592653;
void initialization()
{
initgraph(500, 500);//,SHOWCONSOLE);
seed1=0;seed2=10;exit1=1;
setbkcolor(WHITE);
cleardevice();
setfillcolor(BLACK);
solidrectangle(0,300,100,500);
gunzi.posx=100;
gunzi.posy=300;
}
void move()
{
int i,j,k=0,n=0;
seed1++;
srand(seed1);
i=rand()%11;
i=150+i*25;gunzi.numx=i;
seed2++;
srand(seed2);
j=rand()%10+1;
j=j*10;gunzi.numy=j;
solidrectangle(i,300,i+j,500);
while(k==0){
if(MouseHit()){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
t1=clock();
while(n==0){
setlinecolor(BLACK);
line(gunzi.posx,gunzi.posy,gunzi.posx,gunzi.posy-(t2-t1)/10);
t2=clock();
if(MouseHit()){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
n++;k++;
}
}
}
}
}
}
i=(t2-t1)/10;
t1=clock();
BeginBatchDraw();
while(gunzi.posy+sin(-pi/2+pi/10*(t2-t1)/500)*i<gunzi.posy){
FlushBatchDraw();
setlinecolor(WHITE);
line(gunzi.posx,gunzi.posy,gunzi.posx+cos(-pi/2+pi/10*(t2-t1)/500)*i,gunzi.posy+sin(-pi/2+pi/10*(t2-t1)/500)*i);
t2=clock();
setlinecolor(BLACK);
line(gunzi.posx,gunzi.posy,gunzi.posx+cos(-pi/2+pi/10*(t2-t1)/500)*i,gunzi.posy+sin(-pi/2+pi/10*(t2-t1)/500)*i);
}
EndBatchDraw();
Sleep(200);
if(i>=gunzi.numx-gunzi.posx&&i<=gunzi.numx-gunzi.posx+gunzi.posy){
gunzi.posx=gunzi.numy;
cleardevice();
solidrectangle(0,300,gunzi.posx,500);
}
else {
exit1=0;
}
}
void carry()
{
initialization();
while(exit1==1){
move();
}
_getch();
closegraph();
}
int main()
{
carry();
}
四十九、无尽空间
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <vector>
#include <math.h>
#include <iomanip>
#include <graphics.h>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
struct Node
{
int posx,posy;
int numx,numy;
int num;
int lifenum;
};
IMAGE yuantu[3];
IMAGE yanma[3];
IMAGE glass[2];
IMAGE people[2],zuanshi[2];
clock_t t1,t2,t3;
Node box[10];
int seed1;
int D=10;
void initialization()
{
int i,j,k=1,h=1;seed1=1;
initgraph(500,500,SHOWCONSOLE);
setbkcolor(WHITE);
cleardevice();
loadimage(&glass[0], _T("../素材/glass1.png"),50, 50);
loadimage(&glass[1], _T("../素材/glass2.png"),50, 50);
for(i=175;i<=275;i=i+50){
for(j=175;j<=275;j=j+50){
box[h].posx=i;box[h].posy=j;
box[h].num=k;
putimage(box[h].posx,box[h].posy,&glass[box[h].num]);
if(k==1) k--;
else k++;
h++;
}
}
loadimage(&people[0], _T("../素材/people1.png"),50, 50);
loadimage(&zuanshi[0], _T("../素材/zuanshi1.png"),30, 30);
loadimage(&people[1], _T("../素材/people2.png"),50, 50);
loadimage(&zuanshi[1], _T("../素材/zuanshi2.png"),30, 30);
putimage(225,225, &people[1],SRCAND);
putimage(225,225, &people[0],SRCPAINT);
box[0].posx=225;
box[0].posy=225;
box[0].num=5;
}
void creact()
{
int i,j,k;
seed1++;srand(seed1);
j=rand()%9;
putimage(box[j].posx+D,box[j].posy+D, &zuanshi[1],SRCAND);
putimage(box[j].posx+D,box[j].posy+D, &zuanshi[0],SRCPAINT);
}
void move()
{
int i,k;
char j;
t1=clock();
t2=clock();
while(true){
if (_kbhit()){
j=_getch();
//fflush(stdin);
putimage(box[box[0].num].posx,box[box[0].num].posy, &glass[box[box[0].num].num]);
switch(j){
case 'w':{
if(box[0].posy>175){box[0].posy=box[0].posy-50;box[0].num=box[0].num-1;}
else if(box[0].posy==175){box[0].posy=275;box[0].num=box[0].num+2;creact();}
break;
}
case 'd':{
if(box[0].posx<275){box[0].posx=box[0].posx+50;box[0].num=box[0].num+3;}
else if(box[0].posx==275){box[0].posx=175;box[0].num=box[0].num-6;creact();}
break;
}
case 's':{
if(box[0].posy<275){box[0].posy=box[0].posy+50;box[0].num=box[0].num+1;}
else if(box[0].posy==275){box[0].posy=175;box[0].num=box[0].num-2;creact();}
break;
}
case 'a':{
if(box[0].posx>175){box[0].posx=box[0].posx-50;box[0].num=box[0].num-3;}
else if(box[0].posx==175){box[0].posx=275;box[0].num=box[0].num+6;creact();}
break;
}
default:break;
}
putimage(box[0].posx,box[0].posy, &people[1],SRCAND);
putimage(box[0].posx,box[0].posy, &people[0],SRCPAINT);
fflush(stdin);
}
}
}
void carry()
{
initialization();
move();
_getch();
}
int main()
{
carry();
return 0;
}
五十、消消看
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <vector>
#include <math.h>
#include <iomanip>
#include <graphics.h>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
struct Node
{
int posx,posy;
int colornum;
int lifenum;
COLORREF color;
};
Node box[5][5];
int D=80;
int X,Y;
int seed1;
MOUSEMSG m;
void initialization()
{
int i,j,k;seed1=0;
initgraph(500,500,SHOWCONSOLE);
for(i=0;i<=4;i++){
for(j=0;j<=4;j++){
box[i][j].posx=i*80+50;
box[i][j].posy=j*80+50;
seed1=seed1+3;
srand(seed1);
k=rand()%5;
box[i][j].colornum=k;
box[i][j].lifenum=1;
switch(k){
case 0:box[i][j].color=RED;break;
case 1:box[i][j].color=BLUE;break;
case 2:box[i][j].color=GREEN;break;
case 3:box[i][j].color=YELLOW;break;
case 4:box[i][j].color=WHITE;break;
default:break;
}
setfillcolor(box[i][j].color);
fillrectangle(box[i][j].posx,box[i][j].posy,box[i][j].posx+D,box[i][j].posy+D);
//cout<<i;
}
}
}
void creact()
{
int i,j,k;
setfillcolor(BLACK);
for(i=0;i<=4;i++){
for(j=0;j<=4;j++){
if(box[i][j].color==BLACK){
seed1=seed1+3;
srand(seed1);
k=rand()%5;
box[i][j].colornum=k;
switch(k){
case 0:box[i][j].color=RED;break;
case 1:box[i][j].color=BLUE;break;
case 2:box[i][j].color=GREEN;break;
case 3:box[i][j].color=YELLOW;break;
case 4:box[i][j].color=WHITE;break;
default:break;
}
setfillcolor(box[i][j].color);
fillrectangle(box[i][j].posx,box[i][j].posy,box[i][j].posx+D,box[i][j].posy+D);
}
}
}
}
void check(){
int i,j,k,n;
for(i=X-1;i>=0;i--){
if(box[i][Y].colornum!=box[i+1][Y].colornum){
break;
}
else{
box[i][Y].color=BLACK;
}
}
j=i+1;
for(i=X+1;i<=4;i++){
if(box[i][Y].colornum!=box[X][Y].colornum){
break;
}
else{
box[i][Y].color=BLACK;
}
}
k=i-1;
for(i=j;i<=k;i++){
for(n=Y-1;n>=0;n--){
if(box[i][n].colornum!=box[i][n+1].colornum){
break;
}
else{
box[i][n].color=BLACK;
}
}
for(n=Y+1;n<=4;n++){
if(box[i][n].colornum!=box[i][n-1].colornum){
break;
}
else{
box[i][n].color=BLACK;
}
}
}
///
for(j=Y-1;j>=0;j--){
if(box[X][j].colornum!=box[X][j+1].colornum){
break;
}
else{
box[X][j].color=BLACK;
}
}
i=j+1;
for(j=Y+1;j<=4;j++){
if(box[X][j].colornum!=box[X][j-1].colornum){
break;
}
else{
box[X][j].color=BLACK;
}
}
k=j-1;
for(j=i;j<=k;j++){
for(n=X-1;n>=0;n--){
if(box[n][j].colornum!=box[n+1][j].colornum){
break;
}
else{
box[n][j].color=BLACK;
}
}
for(n=X+1;n<=4;n++){
if(box[n][j].colornum!=box[n-1][j].colornum){
break;
}
else{
box[n][j].color=BLACK;
}
}
}
}
void click()
{
int i,j;
if(MouseHit()){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
for(i=0;i<=4;i++){
for(j=0;j<=4;j++){
if(m.x>=box[i][j].posx&&m.x<=box[i][j].posx+D&&m.y>=box[i][j].posy&&m.y<=box[i][j].posy+D){
X=i;Y=j;
box[i][j].color=BLACK;
check();
creact();
}
}
}
}
}
}
void carry()
{
initialization();
while(true){
click();
}
_getch();
closegraph();
}
int main()
{
carry();
}
五十一、选颜色
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <vector>
#include <math.h>
#include <iomanip>
#include <graphics.h>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
int seed1,seed2;
LPCTSTR test,gg;
COLORREF mm;
clock_t t1,t2;
MOUSEMSG m;
COLORREF fang[4];
void initialization()
{
initgraph(500, 500,SHOWCONSOLE);
seed1=0;seed2=1;
test="GREEN";
setbkcolor(WHITE);cleardevice();
}
void creact()
{
t1=clock();
cleardevice();
gg=test;
int i,j,k;
while(gg==test){
seed1++;
srand(seed1);
i=rand()%4;
switch(i){
case 1:test="RED";mm=RED;break;
case 2:test="GREEN";mm=GREEN;break;
case 3:test="YELLOW";mm=YELLOW;break;
case 0:test="BLUE";mm=BLUE;break;
default:break;
}
}
seed2++;
srand(seed2);
k=rand()%4;
switch(k){
case 1:settextcolor(RED);break;
case 2:settextcolor(GREEN);break;
case 3:settextcolor(YELLOW);break;
case 0:settextcolor(BLUE);break;
default:break;
}
settextstyle(75, 0, _T("宋体"));
outtextxy(150, 50, test);
seed2++;
srand(seed2);
j=rand()%4;
for(i=0;i<=3;i++){
if(i==j){
setfillcolor(mm);
fillrectangle(50,150+i*100,450,200+i*100);
fang[i]=mm;
}
else {
seed2++;
srand(seed2);
k=rand()%4;
switch(k){
case 1:setfillcolor(RED);fang[i]=RED;break;
case 2:setfillcolor(GREEN);fang[i]=GREEN;break;
case 3:setfillcolor(YELLOW);fang[i]=YELLOW;break;
case 0:setfillcolor(BLUE);fang[i]=BLUE;break;
default:break;
}
fillrectangle(50,150+i*100,450,200+i*100);
}
}
}
void carry()
{
initialization();
t1=clock();
int i,j,k;
creact();
while(t2-t1<=2000){
t2=clock();
if(MouseHit()){
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN){
for(i=0;i<=3;i++){
if(m.x>=50&&m.x<=450&&m.y>=150+i*100&&m.y<=200+i*100){
if(fang[i]==mm){
creact();
}
}
}
}
}
}
_getch();
closegraph();
}
int main()
{
carry();
}
五十二、心慌方内置程序(数字模块是作为一部分)
/*一个九位数
若其存在质数因子偶数幂则为危险数
反正为安全数*/
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <vector>
#include <math.h>
#include <iomanip>
#include <graphics.h>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
int zhishu[3402];
int num,exit1;
int seed1,seed2;
void initialization()
{
zhishu[0]=2;
int i=2,j,k=0,n=0;
seed1=0;seed2=100;
while(true){
i++;
k=0;
if(i*i>=1000000000){ //9-10 3400 8-9 1228 7-8 445 6-7 167 5-6 64 4-5 24 3-4 10 2-1 10 0-1 3
break;
}
for(j=2;j<=i/2+1;j++){
if(i%j==0){
k=1;
break;
}
}
if(k==0){
n++;
zhishu[n]=i;
}
}
/*for(i=0;i<=3401;i++){
cout<<zhishu[i]<<endl;
}*///0-3400
}
void check()
{
int i,j,k;
i=num;
k=0;
for(j=2;j<=i/2+1;j++){
if(i%j==0){
k=1;
break;
}
}
if(k==0){
cout<<"质数"<<endl;
}
k=0;
while(i>1&&k<3401){
for(k=0;k<=3400;k++){
if(i%zhishu[k]==0){
cout<<zhishu[k]<<endl;
i=i/zhishu[k];
break;
}
}
}
if(k==3401){
cout<<i<<endl;
}
}
void peacenum()
{
system("cls");
int i,j,k;
num=1;
for(i=0;i<=3400;i++){
if((num*zhishu[i]>=1000000000||num*zhishu[i]<0)&&num<100000000){
i=1;
}
else if(num<1000000000&&num>100000000){
break;
}
seed1++;
srand(seed1);
j=rand()%2;
switch(j){
case 0:break;
case 1:num=num*zhishu[i];
default:break;
}
}
}
void dangernum()
{
system("cls");
int i,j,k,g;
num=1;
seed2++;
srand(seed2);
j=rand()%10+1;
g=j;
num=num*zhishu[j]*zhishu[j];
for(i=0;i<=3400;i++){
if((num*zhishu[i]>=1000000000||num*zhishu[i]<0)&&num<100000000){
i=1;
}
else if(num<1000000000&&num>100000000){
break;
}
seed1++;
srand(seed1);
j=rand()%2;
if(i==g){
j=0;
}
switch(j){
case 0:break;
case 1:num=num*zhishu[i];
//case 2:num=num*zhishu[i]*zhishu[i]*zhishu[i];cout<<endl<<zhishu[i];
default:break;
}
}
}
void ramdownum()
{
system("cls");
int i,j,k;
num=0;k=1;
for(i=1;i<=8;i++){
seed2++;
srand(seed2);
j=rand()%10;
num=num+j*k;
k=k*10;
}
seed2++;
srand(seed2);
j=rand()%9+1;
num=num+j*k;
}
void carry()
{
int i,j,k;
initialization();
exit1=0;
while(exit1==0){
system("cls");
cout<<"1.peacenum 2.dangernum 3.ramdownum 4.setnum 5.exit"<<endl;
num=0;
cin>>i;
switch(i){
case 1:peacenum();break;
case 2:dangernum();break;
case 3:ramdownum();break;
case 4:system("cls");cin>>num;break;
case 5:exit1=1;break;
default:break;
}
if(num>0){
cout<<"待验证数字:"<<num<<endl<<"按任意键验证"<<endl;
_getch();
check();
cout<<"按任意键结束"<<endl;
_getch();
}
}
}
int main()
{
carry();
return 0;
}