VC++制作一个小游戏步骤 求个用VC++C语言编写的小游戏

\u7528C\u8bed\u8a00\u7f16\u5199\u4e00\u4e2a\u5c0f\u6e38\u620f\u8981\u5728vc++6.0\u91cc\u8fd0\u884c

//c\u8bed\u8a00\u7684\u4fc4\u7f57\u65af\u65b9\u5757\u6e38\u620f
//\u4e0d\u80fd\u8fd0\u884c\u518d\u6765\u627e\u6211\uff01

#include
#include
#include
#include
#include
#include

#define LEFT 0x4b
#define RIGHT 0x4d
#define DOWN 0x50
#define CHANGE 0x20
#define ESC 0x1b
#define INTR 0x1C
#define DefaultX 5
#define DefaultY 1
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif

unsigned counter=0;
unsigned shape[7][4][4][4]={
{
{{0, 1, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{{0, 1, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{{0, 1, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{{0, 1, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}},
},
{
{{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{{0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}},
{{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{{0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}},
},
{
{{0, 1, 0, 0}, {1, 1, 1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{{0, 1, 0, 0}, {0, 1, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}},
{{0, 0, 0, 0}, {1, 1, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}},
{{0, 1, 0, 0}, {1, 1, 0, 0}, {0, 1, 0, 0}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
{255, 248, 0, 0, 96, 0, 0, 0, 0, 248, 0, 0, 124, 0},
{255, 248, 0, 0, 97, 128, 0, 0, 3, 248, 0, 0, 192, 0},
{ 0, 112, 0, 0, 97, 128, 0, 0, 7, 0, 0, 1, 128, 48},
{ 0, 224, 0, 0, 96, 0, 0, 0, 14, 0, 0, 1, 128, 48},
{ 1, 192, 0, 0, 96, 0, 0, 0, 12, 0, 0, 1, 128, 48},
{ 3, 128, 120, 15, 97, 128, 240, 60, 12, 0, 15, 15, 249, 255},
{ 7, 0, 252, 31, 225, 131, 248, 127, 14, 0, 31, 143, 249, 255},
{ 7, 1, 142, 48, 225, 135, 24, 227, 7, 240, 49, 193, 128, 48},
{ 14, 3, 134, 96, 97, 142, 24, 192, 3, 252, 112, 193, 128, 48},
{ 8, 3, 6, 96, 97, 140, 25, 192, 0, 28, 96, 193, 128, 48},
{ 56, 3, 6, 96, 97, 140, 25, 128, 0, 6, 96, 193, 128, 48},
{ 56, 3, 6, 96, 97, 140, 25, 128, 0, 6, 96, 193, 128, 48},
{120, 3, 6, 96, 97, 140, 25, 128, 0, 6, 96, 193, 128, 48},
{224, 1, 140, 48, 225, 142, 25, 195, 24, 14, 49, 129, 128, 48},
{255, 249, 252, 63, 225, 135, 252, 255, 28, 28, 63, 129, 128, 48},
{255, 248, 240, 15, 97, 131, 236, 60, 15, 248, 30, 1, 128, 48},
{ 0, 0, 0, 0, 0, 0, 0, 0, 7, 224, 0, 1, 128, 0}};

unsigned long TotalMark=0;
unsigned int Erasered=0, ETimes=0;
int Speed=0;
int CEr=0;
int NumOfLev[5]={0, 0, 0, 0, 0};
int TimeDelay[10]={21, 18, 17, 15, 13, 11, 9, 7, 5, 3};
char NewShape[2];
unsigned PerOnce[4];

void interrupt (*oldhandler)(__CPPARGS);
void interrupt handler(__CPPARGS)
{
++counter;
oldhandler();
}

void DrawBackground()
{
}

void DrawDigital(int x, int y, int a)
{
int i=7;
setcolor(((DigitalShape[a]>>i)&1)*7+4);

i--;
line(x, y+1, x, y+15);
line(x+1, y+2, x+1, y+14);
line(x+2, y+3, x+2, y+13);
setcolor(((DigitalShape[a]>>i)&1)*7+4);
i--;
line(x, y+17, x, y+31);
line(x+1, y+18, x+1, y+30);
line(x+2, y+19, x+2, y+29);
setcolor(((DigitalShape[a]>>i)&1)*7+4);
i--;
line(x, y+17, x, y+31);
line(x+1, y+18, x+1, y+30);
line(x+2, y+19, x+2, y+29);
setcolor(((DigitalShape[a]>>i)&1)*7+4);
i--;
line(x+1, y, x+16, y);
line(x+2, y+1, x+15, y+1);
line(x+3, y+2, x+14, y+2);
setcolor(((DigitalShape[a]>>i)&1)*7+4);
i--;
line(x+2, y+15, x+15, y+15);
line(x+1, y+16, x+16, y+16);
line(x+2, y+17, x+15, y+17);
setcolor(((DigitalShape[a]>>i)&1)*7+4);
i--;
line(x+3, y+30, x+14, y+30);
line(x+2, y+31, x+15, y+31);
line(x+1, y+32, x+16, y+32);
setcolor(((DigitalShape[a]>>i)&1)*7+4);
i--;
line(x+15, y+3, x+15, y+13);
line(x+16, y+2, x+16, y+14);
line(x+17, y+1, x+17, y+15);
setcolor(((DigitalShape[a]>>i)&1)*7+4);
line(x+15, y+19, x+15, y+29);
line(x+16, y+18, x+16, y+30);
line(x+17, y+17, x+17, y+31);
}

void ArtClear()
{
for(int i=480; i>=0; i-=2)
{
setcolor(3);
line(0, i-6, 639, i-6);
setcolor(9);
line(0, i-4, 639, i-4);
setcolor(1);
line(0, i-2, 639, i-2);
setcolor(getbkcolor());
line(0, i, 639, i);
delay(1);
}
for(i=1; i<480; i+=2)
{
setcolor(3);
line(0, i+6, 639, i+6);
setcolor(9);
line(0, i+4, 639, i+4);
setcolor(1);
line(0, i+2, 639, i+2);
setcolor(getbkcolor());
line(0, i, 639, i);
delay(1);
}
}

void end()
{
for(int j=0; j<4; j++)
{
for(int i=j; i<480; i+=4)
{
setcolor(3);
line(0, i+8, 639, i+8);
setcolor(9);
line(0, i+4, 639, i+4);
setcolor(1);
line(0, i, 639, i);
setcolor(getbkcolor());
line(0, i, 639, i);
delay(1);
}
delay(5);
}

setcolor(YELLOW);
outtextxy(260, 200, "[ Game Over ]");
gotoxy(14, 16);
printf("This freeware is written by Daniel.Qu ZodiacSoft 2000");
gotoxy(12, 17);
printf("Please e-mail to [email protected] or visit my homepage at");
gotoxy(12, 18);
printf("http://grocery.2699.com if you have question.");
gotoxy(14, 20);
printf("I will soon provide something new, please wait...");
gotoxy(14, 22);
printf("We hold these truths to be self-evident, that all codes");
gotoxy(12, 23);
printf("are created FREE.");
getch();
clrscr();
closegraph();
exit(0);
}

void ShowTitle()
{
int gdriver=DETECT, gmode, errorcode, i, j, k;
initgraph(&gdriver, &gmode, "C:\\JMSOFT\\DRV");
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("Graphics error: %s\n\007", grapherrormsg(errorcode));
exit(1);
}
setbkcolor(9);
for(i=0; i<11; i++)
{
setcolor(ZodiacBack[i]);
line(200, i*8+100, 440, i*8+100);
}
delay(1000);
for(j=0; j<17; j++)
for(i=0; i<11; i++)
{
setcolor(ZodiacBack[(i+j)%16]);
line(200, i*8+100, 440, i*8+100);
delay(4);
}
for(j=0; j<18; j++)
{
for(i=0; i<14; i++)
{
for(k=7; k>=0; k--)
if((ZodiacSoft[j][i]>>k)&1)
{
putpixel(i*8-k+271, j+122, 14);
}
}
delay(10);
}
for(j=17; j>=0; j--)
{
for(i=0; i<14; i++)
for(k=7; k>=0; k--)
{
if((ZodiacSoft[j][i]>>k)&1)
putpixel(i*8-k+271, 158-j, 5);
}
delay(10);
}
setcolor(15);
outtextxy(295, 171, "Present");
getch();
ArtClear();
}

void DrawShape(int x, int y, int color)
{
setcolor(color);
for(int i=0; i<15; i++)
line(x<<4, (y<<4)+i, (x<<4)+14, (y<<4)+i);
setcolor(8);
line((x<<4)+15, (y<<4)+1, (x<<4)+15, (y<<4)+15);
line((x<<4)+1, (y<<4)+15, (x<<4)+15, (y<<4)+15);
setcolor(color-8);
line((x<<4)+2, (y<<4)+2, (x<<4)+12, (y<<4)+2);
line((x<<4)+2, (y<<4)+2, (x<<4)+2, (y<<4)+12);
}

void DrawNull(int x, int y)
{
setcolor(getbkcolor());
for(int i=0; i<16; i++)
line(x<<4, (y<<4)+i, (x<<4)+15, (y<<4)+i);
}

void show(int x, int y, int CurrentShape, int Status)
{
int temp;
for(int i=0; i<20; i++)
for(int j=2; j<12; j++)
{
if(back[i][j]==1)
DrawShape(6+j, 4+i, 8);
else
DrawNull(6+j, 4+i);
}
for(int l=0; l<4; l++)
for(int p=0; p<4; p++)
{
if(l+x11||p+y>19)
continue;
if(shape[CurrentShape][Status][p][l]==1)
DrawShape(6+l+x, 4+p+y, ShapeColor[CurrentShape]);
if(back[y+p][x+l]==1)
DrawShape(6+l+x, 4+p+y, 8);
}
}

void DrawScore()
{
int temp=TotalMark;
for(int i=0; i<7; i++)
{
DrawDigital(477-i*20, 65, temp%10);
temp/=10;
}
temp=Erasered;
for(i=0; i<4; i++)
{
DrawDigital(491-i*20, 111, temp%10);
temp/=10;
}
if(Erasered==0)
return;
for(i=1; i<5; i++)
{
setfillstyle(1, 8);
bar(378, 163+i*14, 508, 170+i*14);
setfillstyle(1, 5);
bar(378, 163+i*14, 378+130*NumOfLev[i]/ETimes, 170+i*14);
}
DrawDigital(466, 293, Speed);
return;
}

int CreateNewShape()
{
NewShape[1]=NewShape[0];
NewShape[0]=rand()%7;
setfillstyle(1, 0);
bar(447, 240, 514, 288);
for(int l=0; l<4; l++)
for(int p=0; p<4; p++)
if(shape[NewShape[0]][0][p][l]==1)
DrawShape(28+l, 15+p, ShapeColor[7]);
return NewShape[1];
}

int Possible(int x, int y, int CurrentShape, int Status)
{
for(int i=0; i<4; i++)
for(int j=0; j<4; j++)
if(shape[CurrentShape][Status][i][j]+back[y+i][x+j]==2)
return 0;
return 1;
}

void GoLeft(int&x, int&y, int&CurrentShape, int&Status)
{
if(Possible(x-1, y, CurrentShape, Status))
x--;
show(x, y, CurrentShape, Status);
}

void GoRight(int&x, int&y, int&CurrentShape, int&Status)
{
if(Possible(x+1, y, CurrentShape, Status))
x++;
show(x, y, CurrentShape, Status);
}

void GoDown(int&x, int&y, int&CurrentShape, int&Status)
{
int AllAreOne=1, temp=0;
if(Possible(x, y+1, CurrentShape, Status))
{
y++;
show(x, y, CurrentShape, Status);
return;
}
TotalMark+=3*CurrentShape;
for(int i=0; i<4; i++)
for(int j=0; j<4; j++)
back[i+y][j+x]+=shape[CurrentShape][Status][i][j];
for(int r=1; r<20; r++)
{
for(int l=2; l<13; l++)
if(back[r][l]==0)
AllAreOne=0;
if(AllAreOne==1)
{
for(int rr=r; rr>0; rr--)
for(int ll=2; ll<13; ll++)
back[rr][ll]=back[rr-1][ll];
Erasered++;
CEr++;
temp++;
}
AllAreOne=1;
}
CurrentShape=CreateNewShape();
x=DefaultX; y=DefaultY; Status=0;
NumOfLev[temp]++;
TotalMark+=5*temp;
show(x, y, CurrentShape, Status);
counter=0;
if(!Possible(x, y, CurrentShape, Status))
{
getch();
end();
}
if(CEr>=30)
{
Speed=(Speed+1)%10;
CEr/=30;
}
if(temp)
ETimes++;
DrawScore();
return;
}

void ChageShape(int&x, int&y, int&CurrentShape, int&Status)
{
if(Possible(x, y, CurrentShape, (Status+1)%4))
Status=(Status+1)%4;
show(x, y, CurrentShape, Status);
}

void DrawFace()
{
int temp;
setcolor(15);
line(351, 59, 519, 59);
line(351, 60, 518, 60);
line(351, 59, 351, 156);
line(352, 59, 352, 155);
setcolor(7);
line(518, 61, 518, 154);
line(519, 60, 519, 154);
line(353, 155, 519, 155);
line(352, 156, 519, 156);
setcolor(8);
for(int i=61; i<155; i++)
line(353, i, 517, i);
setcolor(7);
line(427, 106, 512, 106);
line(428, 107, 511, 107);
line(427, 106, 427, 147);
line(428, 106, 428, 146);
setcolor(15);
line(512, 106, 512, 147);
line(511, 107, 511, 146);
line(428, 146, 511, 146);
line(427, 147, 512, 147);
settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
setcolor(14);
outtextxy(357, 119, "Erasered");
outtextxy(370, 130, "Level:");
setcolor(15);
line(352, 167, 519, 167);
line(352, 168, 518, 168);
line(352, 169, 352, 407);
line(353, 169, 353, 406);
setcolor(7);
line(519, 167, 519, 407);
line(518, 168, 518, 406);
line(352, 407, 519, 407);
line(353, 406, 519, 406);
line(524, 55, 89, 55);
line(524, 55, 524, 411);
line(89, 411, 524, 411);
line(89, 55, 89, 411);
line(524, 56, 89, 56);
line(525, 55, 525, 411);
line(89, 410, 524, 410);
line(88, 55, 88, 411);
setfillstyle(8, 7);
bar(94, 59, 336, 406);
for(i=0; i<8; i++)
DrawDigital(357+i*20, 65, 0);
for(i=0; i<4; i++)
DrawDigital(431+i*20, 111, 0);
setfillstyle(1, 8);
setcolor(12);
for(i=0; i<4; i++)
{
temp=i+'1';
outtextxy(364, 177+14*i, (char*)&temp);
bar(378, 177+i*14, 508, 184+i*14);
}
setcolor(14);
outtextxy(366, 250, "Next Shape");
setcolor(10);
outtextxy(366, 294, "Current");
outtextxy(382, 309, "Level");
setcolor(6);
outtextxy(366, 334, "Message:");
bar(362, 348, 509, 398);
DrawDigital(466, 293, Speed);
}

void WannaQuit()
{
int choise=0, temp;
setfillstyle(1, 8);
bar(362, 348, 509, 398);
setcolor(15);
outtextxy(378, 355, "Are you sure to");
outtextxy(368, 368, "quit game?");
outtextxy(410, 388, "Yes");
outtextxy(470, 388, "No");
setcolor(14);
circle(399, 392, 4);
while((temp=bioskey(0))!=7181)
{
if(temp==19200)
{
setcolor(8);
circle(459, 392, 4);
choise=0;
setcolor(14);
circle(399, 392, 4);
}
if(temp==19712)
{
setcolor(8);
circle(399, 392, 4);
choise=1;
setcolor(14);
circle(459, 392, 4);
}
}
if(choise==0)
end();
setfillstyle(1, 8);
bar(362, 348, 509, 398);
return;
}

void main()
{
ShowTitle();
unsigned c;
int CurrentShape, x=6, y=0, Status=0;
oldhandler=getvect(INTR);
setvect(INTR, handler);
randomize();
NewShape[0]=rand()%7;
DrawFace();
CurrentShape=CreateNewShape();
show(x, y, CurrentShape, Status);
while(1)
{
if(kbhit())
{
c=getch();
if(c==0)
c=getch();
switch(c)
{
case 's' :Speed=(Speed+1)%10; DrawDigital(466, 293, Speed); break;
case DOWN :GoDown(x, y, CurrentShape, Status); break;
case LEFT :GoLeft(x, y, CurrentShape, Status); break;
case RIGHT :GoRight(x, y, CurrentShape, Status); break;
case CHANGE :ChageShape(x, y, CurrentShape, Status); break;
case ESC :WannaQuit();
}
}
if((counter%=TimeDelay[Speed])==(TimeDelay[Speed]-1))
{
GoDown(x, y, CurrentShape, Status);
counter=0;
}
}
}

#include
#include
#include
int main(void)
{

int random();
int mopai(int shan);
int yourchusha(int shan);
int i,xingcan=0,temp,choice;
int yoursha=0,yourshan=0;
int itssha=0,itsshan=0;
int yourhp=4,itshp=4;

printf("\u4e09\u56fd\u6740\u7b80\u6613\u7248\uff1a\n");
printf("\u5f00\u59cb\u6e38\u620f\uff1a\n");
srand( (unsigned)time( NULL ) );
for(i=1;i<=4;i++)
{
random();//random() \u65b9\u6cd5\u53ef\u8fd4\u56de\u4ecb\u4e8e 0 ~ 1 \u4e4b\u95f4\u7684\u4e00\u4e2a\u968f\u673a\u6570\u3002
if(!random())
yourshan+=1;
else yoursha+=1;
}
for(i=1;i<=4;i++)
{
random();
if(!random())
itsshan+=1;
else itssha+=1;
}
printf("\u4f60\u7684\u624b\u724c\uff1a\u6740%d\u5f20\uff0c\u95ea%d\u5f20\t",yoursha,yourshan);
printf("\u8ba1\u7b97\u673a\u7684\u624b\u724c\uff1a%d\u5f20\n",itssha+itsshan);
printf("\u4f60\u7684\u4f53\u529b\uff1a%d\t",yourhp);
printf("\u8ba1\u7b97\u673a\u7684\u4f53\u529b\uff1a%d\n",itshp);

while(yourhp&&itshp)
{
printf("\n\u4f60\u7684\u884c\u52a8\u5f00\u59cb\uff1a\n");
printf("\n\u6478\u724c\u9636\u6bb5\uff1a\n");
temp=mopai(xingcan);
yourshan+=temp;
yoursha+=(2-temp);
xingcan=0;
printf("\u4f60\u7684\u624b\u724c\uff1a\u6740%d\u5f20\uff0c\u95ea%d\u5f20\n",yoursha,yourshan);
printf("\n\u6309\u4efb\u610f\u952e\u7ee7\u7eed\n");
getch();
system("cls");
printf("\u4f60\u7684\u624b\u724c\uff1a\u6740%d\u5f20\uff0c\u95ea%d\u5f20\t",yoursha,yourshan);
printf("\u8ba1\u7b97\u673a\u7684\u624b\u724c\uff1a%d\u5f20\n",itssha+itsshan);
printf("\u4f60\u7684\u4f53\u529b\uff1a%d\t",yourhp);
printf("\u8ba1\u7b97\u673a\u7684\u4f53\u529b\uff1a%d\n",itshp);

printf("\n\u51fa\u724c\u9636\u6bb5\uff1a\n");
printf("\u8bf7\u9009\u62e9:\n");
printf("1.\u51fa\u6740 2.\u5f03\u724c\n");
while(1)
{
scanf("%d",&choice);
if(choice!=1&&choice!=2)
printf("\u8f93\u5165\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\n");
else break;
}
if(choice==1)
{
if(yoursha)
{
yoursha-=1;
if(yourchusha(itsshan))
itsshan-=1;
else
{
itshp-=1;
}
}
else printf("\u4f60\u6ca1\u6709\u6740\uff0c\u8bf7\u5f03\u724c\n");
}
if(!itshp)
break;
printf("\n\u6309\u4efb\u610f\u952e\u7ee7\u7eed\n");
getch();
system("cls");
printf("\u4f60\u7684\u624b\u724c\uff1a\u6740%d\u5f20\uff0c\u95ea%d\u5f20\t",yoursha,yourshan);
printf("\u8ba1\u7b97\u673a\u7684\u624b\u724c\uff1a%d\u5f20\n",itssha+itsshan);
printf("\u4f60\u7684\u4f53\u529b\uff1a%d\t",yourhp);
printf("\u8ba1\u7b97\u673a\u7684\u4f53\u529b\uff1a%d\n",itshp);

printf("\u5f03\u724c\u9636\u6bb5\uff1a\n");
while(yoursha+yourshan-yourhp>0)
{
printf("\u4f60\u9700\u8981\u5f03\u6389%d\u5f20\u5361\u724c\uff0c\u8bf7\u9010\u5f20\u5f03\u724c\uff1a\n",yoursha+yourshan-yourhp);
printf("1.\u5f03\u4e00\u5f20\u6740 2.\u5f03\u4e00\u5f20\u95ea\n");
while(1)
{
scanf("%d",&choice);
if(choice!=1&&choice!=2)
printf("\u8f93\u5165\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\n");
else break;
}
switch(choice)
{
case 1:
{
if(yoursha)
yoursha-=1;
else printf("\u4f60\u6ca1\u6709\u6740\uff0c\u8bf7\u91cd\u65b0\u9009\u62e9\n");
break;
}
case 2:
{
if(yourshan)
yourshan-=1;
else printf("\u4f60\u6ca1\u6709\u95ea\uff0c\u8bf7\u91cd\u65b0\u9009\u62e9\n");
break;
}
}
}
printf("\u4f60\u7684\u884c\u52a8\u7ed3\u675f\u3002\n");
printf("\n\u6309\u4efb\u610f\u952e\u7ee7\u7eed\n");
getch();
system("cls");
printf("\u4f60\u7684\u624b\u724c\uff1a\u6740%d\u5f20\uff0c\u95ea%d\u5f20\t",yoursha,yourshan);
printf("\u8ba1\u7b97\u673a\u7684\u624b\u724c\uff1a%d\u5f20\n",itssha+itsshan);
printf("\u4f60\u7684\u4f53\u529b\uff1a%d\t",yourhp);
printf("\u8ba1\u7b97\u673a\u7684\u4f53\u529b\uff1a%d\n",itshp);


printf("\u8ba1\u7b97\u673a\u7684\u884c\u52a8\u5f00\u59cb\uff1a\n");
printf("\u6478\u724c\u9636\u6bb5\uff1a\n");
temp=mopai(xingcan);
itsshan+=temp;
itssha+=(2-temp);
xingcan=0;
printf("\u8ba1\u7b97\u673a\u624b\u724c\u6570\uff1a%d\u5f20\n",itssha+itsshan);
printf("\n\u6309\u4efb\u610f\u952e\u7ee7\u7eed\n");
getch();
system("cls");
printf("\u4f60\u7684\u624b\u724c\uff1a\u6740%d\u5f20\uff0c\u95ea%d\u5f20\t",yoursha,yourshan);
printf("\u8ba1\u7b97\u673a\u7684\u624b\u724c\uff1a%d\u5f20\n",itssha+itsshan);
printf("\u4f60\u7684\u4f53\u529b\uff1a%d\t",yourhp);
printf("\u8ba1\u7b97\u673a\u7684\u4f53\u529b\uff1a%d\n",itshp);

printf("\u51fa\u724c\u9636\u6bb5\uff1a\n");
if(itssha)
{
itssha-=1;
printf("\u6740\n");
printf("\u8ba1\u7b97\u673a\u5bf9\u4f60\u51fa\u4e86\u4e00\u5f20\u6740\uff0c\u8bf7\u51fa\u4e00\u5f20\u95ea\n");
printf("1.\u786e\u5b9a 2.\u53d6\u6d88\n");
while(1)
{
scanf("%d",&choice);
if(choice!=1&&choice!=2){
printf("\u8f93\u5165\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\n");
system("cls");
printf("\u4f60\u7684\u624b\u724c\uff1a\u6740%d\u5f20\uff0c\u95ea%d\u5f20\t",yoursha,yourshan);
printf("\u8ba1\u7b97\u673a\u7684\u624b\u724c\uff1a%d\u5f20\n",itssha+itsshan);
printf("\u4f60\u7684\u4f53\u529b\uff1a%d\t",yourhp);
printf("\u8ba1\u7b97\u673a\u7684\u4f53\u529b\uff1a%d\n",itshp);
}
else break;
}
switch(choice)
{
case 1:
{
if(yourshan)
{
yourshan-=1;
printf("\u95ea\n");
break;
}
else printf("\u4f60\u6ca1\u6709\u95ea\n");
}
case 2:
{
yourhp-=1;
printf("\u8ba1\u7b97\u673a\u5bf9\u4f60\u9020\u6210\u4e00\u70b9\u4f24\u5bb3\n");
}
}
}
if(!yourhp)
break;
printf("\u8ba1\u7b97\u673a\u624b\u724c\u6570\uff1a%d\u5f20\n",itssha+itsshan);

printf("\u5f03\u724c\u9636\u6bb5\uff1a\n");
if(itssha+itsshan-itshp>0)
{
if(itshp>itsshan)
{
printf("\u8ba1\u7b97\u673a\u5f03\u6740%d\u5f20\n",itssha+itsshan-itshp);
itssha-=(itssha+itsshan-itshp);
}
else
{
printf("\u8ba1\u7b97\u673a\u5f03\u6740%d\u5f20\uff0c\u95ea%d\u5f20\n",itssha,itsshan-itshp);
itssha=0;
itsshan=itshp;
}
}
printf("\u8ba1\u7b97\u673a\u7684\u884c\u52a8\u7ed3\u675f\u3002\n");
printf("\n\u6309\u4efb\u610f\u952e\u7ee7\u7eed\n");
getch();
system("cls");
printf("\u4f60\u7684\u624b\u724c\uff1a\u6740%d\u5f20\uff0c\u95ea%d\u5f20\t",yoursha,yourshan);
printf("\u8ba1\u7b97\u673a\u624b\u724c\u6570\uff1a%d\u5f20\n",itssha+itsshan);
printf("\u4f60\u7684\u4f53\u529b\uff1a%d\t",yourhp);
printf("\u8ba1\u7b97\u673a\u7684\u4f53\u529b\uff1a%d\n",itshp);
}

if(!yourhp)
printf("\u5f88\u9057\u61be\uff0c\u8ba1\u7b97\u673a\u51fb\u8d25\u4e86\u4f60\n");
else printf("\u606d\u559c\u4f60\uff0c\u4f60\u51fb\u8d25\u4e86\u8ba1\u7b97\u673a\n");
printf("\u6e38\u620f\u7ed3\u675f\uff0c\u6b22\u8fce\u4e0b\u6b21\u518d\u6765\uff01\n");
printf("\n\u6309\u4efb\u610f\u952e\u9000\u51fa\u3002");
getch();
return 0;
}
int random()
{
return rand()%3;
}

int mopai(int shan)
{
int i;
srand( (unsigned)time( NULL ) );
for(i=1;i<=2;i++)
{
random();
if(!random())
shan+=1;
}
return shan;
}

int yourchusha(int shan)
{
printf("\u6740 ");
if(shan)
{
printf("\u95ea\n");
return 1;
}
else
{
printf("\u60a8\u5bf9\u8ba1\u7b97\u673a\u9020\u6210\u4e00\u70b9\u4f24\u5bb3\n");
return 0;
}
}

举五子棋做个例子,第一步做界面,无非就是画几条线,写上行号列号,找个黑棋白棋的位图。第二步写算法,五子棋的算法无非是某方有横的或竖的或斜的的五个子连在一起就赢。
我手头有个下象棋的小程序,写了两天,算法做的差不多了,界面也有一点,但算法和界面还没联系。要有兴趣和我联系,我把代码给你。

使用MFC做,主要是界面UI,规则判断等.如果是人和人交互下比较简单,加入网络接口也不麻烦.如果要编和机器玩就麻烦了,要写算法.
举个五子棋例子,主要是棋盘贴图(手工画用CDC类),判断规则,将旗子放入后 存入位置坐标.满足胜利条件后结束.
编程时采用基于单文档的较为方便.

www.game.com

  • VC++鍒朵綔涓涓皬娓告垙姝ラ
    绛旓細涓句簲瀛愭鍋涓緥瀛愶紝绗竴姝ュ仛鐣岄潰锛屾棤闈炲氨鏄敾鍑犳潯绾匡紝鍐欎笂琛屽彿鍒楀彿锛屾壘涓粦妫嬬櫧妫嬬殑浣嶅浘銆傜浜屾鍐欑畻娉曪紝浜斿瓙妫嬬殑绠楁硶鏃犻潪鏄煇鏂规湁妯殑鎴栫珫鐨勬垨鏂滅殑鐨勪簲涓瓙杩炲湪涓璧峰氨璧傛垜鎵嬪ご鏈変釜涓嬭薄妫嬬殑灏忕▼搴忥紝鍐欎簡涓ゅぉ锛岀畻娉曞仛鐨勫樊涓嶅浜嗭紝鐣岄潰涔熸湁涓鐐癸紝浣嗙畻娉曞拰鐣岄潰杩樻病鑱旂郴銆傝鏈夊叴瓒e拰鎴戣仈绯伙紝...
  • 鎬庝箞鍒朵綔娓告垙?
    绛旓細1銆侀氳繃鍙傝冧笉鍚岀殑娓告垙锛屽啓鍑烘兂瑕佸埗浣滅殑娓告垙鐨勫墽鎯呭拰鑴氭湰銆傛父鎴忕殑绉嶇被鏈夊绉嶏紝鏍规嵁鑷繁鍠滄鐨勬父鎴忕绫伙紝閫氳繃鍙傝冧笉鍚岀殑娓告垙锛屽啓鍑鸿鍒朵綔娓告垙鐨勫墽鎯呫2銆佹牴鎹父鎴忕殑鍓ф儏鍜岃剼鏈紝浣跨敤鎵嬬粯杞欢缁樺埗娓告垙浜虹墿鐨勫浘褰㈠拰鑳屾櫙銆3銆侀氳繃寤烘ā鐨勮蒋浠舵妸骞抽潰鍥惧舰鍒涘缓涓虹珛浣撴ā鍨嬫晥鏋溿傛湁澶氱寤烘ā杞欢锛屽彲浠ラ氳繃寤烘ā鐨勮蒋浠舵妸...
  • 鎬庢牱鑷繁鍒朵綔娓告垙?
    绛旓細1銆佹兂鍑轰竴涓偣瀛愮偣瀛愭槸鍚姩娓告垙鐨勫紩瀛愶紝鏄涓涓父鎴鐨勬簮澶淬傝繖涓偣瀛愰鍏堝湪澶т綋涓婂簲璇ユ槸涓被浼间簬鏁呬簨鐨勪笢瑗裤傜劧鍚庤繖涓晠浜嬮渶瑕佹湁涓涓洰鏍囥2銆佸垎闀滃ご鑴氭湰璁捐鐞嗚В涓涓父鎴忔渶濂界殑鏂规硶鏄娇鐢ㄥ垎闀溾斺斿垱閫犱竴绯诲垪鑳戒綋鐜版父鎴忔瘡涓叧鍗℃垨鑰呬笉鍚岀殑鍦烘櫙涓庣洰鏍囩殑鍥剧墖銆傛瘡涓垎闀滅敤涓涓ゅ箙鍥剧墖鏉ユ弿杩版鍦ㄥ彂鐢熶粈涔堛3銆...
  • 濡備綍鍒涘缓涓涓杞欢?
    绛旓細闂涓:鎬庝箞鍒朵綔涓涓皬杞欢? 缂栧啓灏忚蒋浠剁敤vb濂界偣,閫傚悎蹇熷紑鍙,鐢vc鐨勮瘽浼氬緢鐑,濡傛灉涓嶈冭檻搴旂敤鐣岄潰鐨勮瘽瀹屽叏鍙互鐢═C缂栧啓鎴栬卾c鐨剋in32 application ,姣斿浣犳兂瑕佸疄鐜板鏉傝绠,鍙渶瑕佸紕娓 杈撳叆 鍜 杈撳嚭 鍒嗗埆鏄粈涔,涓棿杩囩▼灏辩湅浣犵殑绠楁硶浜嗐傚緢瀹规槗鐨 闄:鏈绠鍗曠殑灏忚蒋浠跺埗浣: 鏂板缓涓涓浜嬫湰,鍦ㄨ浜嬫湰閲屽啓涓婁綘...
  • 鎴戞兂瀛︿範娓告垙鍒朵綔
    绛旓細瑕佽璁涓涓父鎴,棣栧厛浣犲繀椤昏纭畾鍑犱釜閲嶈鏂归拡,绗竴鏄綘瑕佽璁$殑娓告垙鏄睘鏂奸偅涓绉嶇被鍨,绗簩鏄椂浠h儗鏅,绗笁鏄ā寮,绗洓鏄▼寮忔妧鏈,绗簲鏄〃鐜版墜娉,绗叚鏄競鍦哄畾浣,绗竷鏄爺鍙戞椂闂,鍦ㄦ帉鎻′笂杩颁竷涓柟閽堜箣鍚,浣犲氨鍙互鍐鍋璇︾粏鐨勮鍒掑唴瀹瑰強璋冮厤璧勬簮,閭i航浣曡皳鏄竷椤规柟閽堝憿? 绗旇呬互鑼冧緥鏉ヨ鏄庝箣! 涓銆佺被鍨: 鎵璋...
  • 鍏変細C璇█缂栫▼鑳鍒朵綔娓告垙鍚
    绛旓細鍦ㄥ畠閲岄潰浣犱細鍒涗綔鍑轰綘鐞嗘兂鐨勮蒋浠躲備笉鍙槸娓告垙閭d箞绠鍗曚簡銆傝櫧鐒剁幇鍦ㄧ殑灏忔父鎴鍩烘湰閮芥槸java缂栧啓鐨勶紝锛屼絾鏄VC++鐢ㄩ斿箍娉涳紝娑电洊鑼冨洿鏄痺indows鏈哄埗鐨勫熀纭銆 鎵浠ュ畠鏄案杩滀篃涓嶄細杩囧け鐨勩傚鏋滄ゼ涓昏寰楀彧鏄兂鍒朵綔娓告垙鐨勮瘽锛岋紝浣犱笉浼氫换浣曚竴绉嶈瑷锛屼篃鏄彲浠ョ殑銆傚洜涓烘湁涓撻棬鍒朵綔娓告垙鐨勮蒋浠讹紝锛屽彧鏈変綘鐔熸倝杞欢鐨勪娇鐢ㄣ
  • 鎬庝箞鏍锋墠鑳鍒朵綔娓告垙杞欢
    绛旓細1銆佺幇鍦ㄥ凡缁忔湁姣旇緝绠鍗曠殑娓告垙寮曟搸寮婧愶紝鍙互鐩存帴浣跨敤鍐呯疆鐨勬ā鏉垮拰鍐呯疆鐨勭礌鏉愬簱锛岄氳繃鐩稿绠鍗曠殑璁剧疆灏卞彲浠ュ埗閫涓涓寰堢畝鍗曠殑娓告垙杩愯銆傛瘮濡傝铏氬够寮曟搸锛屽彲浠ラ氳繃鍐呭缓鐨勬ā鏉垮拰绱犳潗搴撴惌寤轰竴涓彲浠ヨ繍琛岀殑娓告垙锛屼絾鎯宠鍒涗綔涓娆炬瘮杈冨鏉傜殑杞欢锛屽厜闈犺繖浜涚礌鏉愭槸涓嶅鐨勶紱2銆佷竴娆剧數鑴戞父鎴忔槸绛栧垝锛屽満鏅璁★紝缇庢湳锛屾枃鏈...
  • 3ds妯℃嫙鍣vc姘存櫠濂戒笉濂
    绛旓細鎵嬫焺 杩樿兘澶熷姞鍏ユ墜鏌勬潵娓告垙锛屾彃鍏ユ墜鏌勶紝棰嗙暐鎵嬫焺鎰忔濓紝鐣呯帺瑙佹晥涔熼渿鎾笺3ds妯℃嫙鍣vc姘存櫠浼樺娍锛1銆侀潪甯稿鐨勫姩鐢绘护闀滐紝鍗佸垎澶ф彁鍗囨父鎴忔覆鏌擄紝灏辫兘鍒朵綔鎸囧畾娓告垙棰樻潗銆2銆侀泦鎴愭父鎴忓鍔憋紝渚濇嵁鍓嶇鎺у埗绔睍绀猴紝鏁翠釜鐢佃剳濂栧姳寰界珷灞曠ず鍦ㄤ綘闈㈠墠銆3銆佸甫鏉ョ綉缁滃崟鎸戣兘鍔涳紝渚濇嵁鍦ㄧ嚎锛屽拰浣犱紮浼翠滑瀹炴柦瀵规垬锛岃穬鍑轰笉鍙兘涓鏍锋父鎴...
  • 濡備綍鍒涘缓涓涓杞欢
    绛旓細闂涓:鎬庝箞鍒朵綔涓涓皬杞欢? 缂栧啓灏忚蒋浠剁敤vb濂界偣,閫傚悎蹇熷紑鍙,鐢vc鐨勮瘽浼氬緢鐑,濡傛灉涓嶈冭檻搴旂敤鐣岄潰鐨勮瘽瀹屽叏鍙互鐢═C缂栧啓鎴栬卾c鐨剋in32 application ,姣斿浣犳兂瑕佸疄鐜板鏉傝绠,鍙渶瑕佸紕娓 杈撳叆 鍜 杈撳嚭 鍒嗗埆鏄粈涔,涓棿杩囩▼灏辩湅浣犵殑绠楁硶浜嗐傚緢瀹规槗鐨 闄:鏈绠鍗曠殑灏忚蒋浠跺埗浣: 鏂板缓涓涓浜嬫湰,鍦ㄨ浜嬫湰閲屽啓涓婁綘...
  • 濡備綍鑷埗娓告垙?
    绛旓細2銆佸垎闀滃ご鑴氭湰璁捐鐞嗚В涓涓父鎴鏈濂界殑鏂规硶鏄娇鐢ㄥ垎闀溾斺斿垱閫犱竴绯诲垪鑳戒綋鐜版父鎴忔瘡涓叧鍗℃垨鑰呬笉鍚岀殑鍦烘櫙涓庣洰鏍囩殑鍥剧墖銆傛瘡涓垎闀滅敤涓涓ゅ箙鍥剧墖鏉ユ弿杩版鍦ㄥ彂鐢熶粈涔堛3銆佽冭檻缁嗚妭鍋氬畬鍒嗛暅澶磋剼鏈璁★紝灏卞彲浠ュ紑濮嬪啓娓告垙璁捐鐨勭粏鑺傘備粠杩欎釜姝ラ灏卞紑濮嬪彉寰楀鏉備簡銆備綘灏嗛渶瑕佹濊冩瘡涓涓彲鑳界殑缁嗚妭锛屽苟璁板綍涓嬫潵銆4銆佹敟...
  • 扩展阅读:免费游戏马上玩游戏 ... 用c++编写小游戏 ... 少儿编程小游戏 ... c++简单小游戏代码 ... 如何自己编程一个软件 ... 如何自己编程做游戏 ... 编程一个最简单游戏 ... 自己制作手机游戏app ... 玩游戏出现c++runtime ...

    本站交流只代表网友个人观点,与本站立场无关
    欢迎反馈与建议,请联系电邮
    2024© 车视网