谁能用C语言帮我设计一个小小的游戏- -。。(C++)
4个回答
展开全部
#include<stdio.h>
#define N 10
void welcome();
void initqipan();
void showqi(int i);
void save(int p);
void panduan(int p);
void heqi();
void over();
int zouqihang();
int zouqilie();
/******************结构体 *****************/ struct zuobiao
{
int x[N * N];
int y[N * N];
} weizhi[N * N]; /******************主函数 *****************/
int main()
{
int p = 0;
welcome();
initqipan();
for (p = 1; p <= N * N; p++)
{
weizhi[p].x[p] = zouqihang();
weizhi[p].y[p] = zouqilie();
save(p);
showqi(p);
panduan(p);
}
if (p == N * N)
heqi();
over();
} /******************建立棋盘 *****************/
void initqipan()
{
int i, j;
for (i = 0; i < N; i++)
{
printf("%d", i);
printf(" ");
}
printf("\n");
for (i = 1; i < N; i++)
{
for (j = 0; j < N; j++)
{
if (j == 0)
printf("%d", i);
else
printf("·");
}
printf("\n");
}
} /******************显示棋子 *****************/
void showqi(int p)
{
int i, j, k, m;
int a[N * N], b[N * N];
FILE *fp;
fp = fopen("wuzi_list", "rb");
for (i = 1; i <= N * N; i++)
{
fread(&weizhi[i], sizeof(struct zuobiao), 1, fp);
a[i] = weizhi[i].x[i];
b[i] = weizhi[i].y[i];
} for (m = 1; m < p; m++)
{
while(weizhi[p].x[p] == a[m] && weizhi[p].y[p] == b[m])
{
printf("error!\n");
weizhi[p].x[p] = zouqihang();
weizhi[p].y[p] = zouqilie();
m = 1;
}
}
for (i = 0; i < N; i++)
{
printf("%d", i);
printf(" ");
}
printf("\n");
for (i = 1; i < N; i++)
{
for (j = 1; j < N; j++)
{
if (j == 1)
printf("%d", i);
for (k = 1; k <= p; k++)
{
if (i == weizhi[k].x[k] && j == weizhi[k].y[k])
{
if (k % 2 == 1)
{
printf("○");
break;
}
else if (k % 2 == 0)
{
printf("●");
break;
}
}
}
if (k > p)
printf("·");
else
continue;
}
printf("\n");
}
} /******************走棋行 *****************/
int zouqihang()
{
int x;
printf("请输入要走棋子所在行 数!\n");
printf("x=");
scanf("%d", &x);
while (x > N - 1 || x < 1)
{
printf("error!\n");
printf("请输入要走棋子所在行 数!\n");
printf("x=");
scanf("%d", &x);
}
return x;
} /******************走棋列 *****************/
int zouqilie()
{
int y;
printf("请输入要走棋子所在列 数!\n");
printf("y=");
scanf("%d", &y);
while (y > N - 1 || y < 1)
{
printf("error!\n");
printf("请输入要走棋子所在列 数!\n");
printf("y=");
scanf("%d", &y);
}
return y;
} /******************文件保存 *****************/
void save(int i)
{
FILE *fp;
fp = fopen("wuzi_list", "wb");
fwrite(&weizhi[i], sizeof(struct zuobiao), 1, fp);
} /****************判断输赢 *******************/ void panduan(int p)
{
int i, j, k[8] = { 1, 1, 1, 1, 1, 1, 1, 1, };
int a[N * N], b[N * N];
FILE *fp;
fp = fopen("wuzi_list", "rb");
for (i = 1; i <= p; i++)
{
fread(&weizhi[i], sizeof(struct zuobiao), 1, fp);
a[i] = weizhi[i].x[i];
b[i] = weizhi[i].y[i];
} /*****************判断行 ******************/ for (i = 1; i <= p; i++)
{
if (i % 2 == 1)
{
for (j = 1; j <= p; j = j + 2)
{
if ((a[i] == a[j]) && (b[i] == b[j] - 1))
{
k[0]++;
continue;
}
else if ((a[i] == a[j]) && (b[i] == b[j] - 2))
{
k[0]++;
continue;
}
else if ((a[i] == a[j]) && (b[i] == b[j] - 3))
{
k[0]++;
continue;
}
else if ((a[i] == a[j]) && (b[i] == b[j] - 4))
{
k[0]++;
continue;
}
else if (k[0] == 5)
{
printf("Player 1 wins!!!\n");
}
else
continue;
}
if (k[0] == 5)
break;
k[0] = 1;
}
else if (k[0] == 5)
break;
else if (i % 2 == 0)
{
for (j = 2; j <= p; j = j + 2)
{
if ((a[i] == a[j]) && (b[i] == b[j] - 1))
{
k[1]++;
continue;
}
else if ((a[i] == a[j]) && (b[i] == b[j] - 2))
{
k[1]++;
continue;
}
else if ((a[i] == a[j]) && (b[i] == b[j] - 3))
{
k[1]++;
continue;
}
else if ((a[i] == a[j]) && (b[i] == b[j] - 4))
{
k[1]++;
continue;
}
else if (k[1] == 5)
{
printf("Player 2 wins!!!\n");
}
else
continue;
}
if (k[1] == 5)
break;
k[1] = 1;
}
} /**********************判断列 ************************/
for (i = 1; i <= p; i++)
{
if (k[0] == 5 || k[1] == 5)
break;
else if (i % 2 == 1)
{
for (j = 1; j <= p; j = j + 2)
{
if ((a[i] == a[j] - 1) && (b[i] == b[j]))
{
k[2]++;
continue;
}
else if ((a[i] == a[j] - 2) && (b[i] == b[j]))
{
k[2]++;
continue;
}
else if ((a[i] == a[j] - 3) && (b[i] == b[j]))
{
k[2]++;
continue;
}
else if ((a[i] == a[j] - 4) && (b[i] == b[j]))
{
k[2]++;
continue;
}
else if (k[2] == 5)
{
printf("Player 1 wins!!!\n");
}
else
continue;
}
if (k[2] == 5)
break;
k[2] = 1;
}
else if (k[2] == 5)
break;
else if (i % 2 == 0)
{
for (j = 2; j <= p; j = j + 2)
{
if ((a[i] == a[j] - 1) && (b[i] == b[j]))
{
k[3]++;
continue;
}
else if ((a[i] == a[j] - 2) && (b[i] == b[j]))
{
k[3]++;
continue;
}
else if ((a[i] == a[j] - 3) && (b[i] == b[j]))
{
k[3]++;
continue;
}
else if ((a[i] == a[j] - 4) && (b[i] == b[j]))
{
k[3]++;
continue;
}
else if (k[3] == 5)
{
printf("Player 2 wins!!!\n");
}
else
continue;
}
if (k[3] == 5)
break;
k[3] = 1;
}
} /****************判断对角(左 上-右下)******************/
for (i = 1; i <= p; i++)
{
if (k[0] == 5 || k[1] == 5 || k[2] == 5 || k[3] == 5)
break;
else if (i % 2 == 1)
{
for (j = 1; j <= p; j = j + 2)
{
if ((a[i] == a[j] - 1) && (b[i] == b[j] - 1))
{
k[4]++;
continue;
}
else if ((a[i] == a[j] - 2) && (b[i] == b[j] - 2))
{
k[4]++;
continue;
}
else if ((a[i] == a[j] - 3) && (b[i] == b[j] - 3))
{
k[4]++;
continue;
}
else if ((a[i] == a[j] - 4) && (b[i] == b[j] - 4))
{
k[4]++;
continue;
}
else if (k[4] == 5)
{
printf("Player 1 wins!!!\n");
}
else
continue;
}
if (k[4] == 5)
break;
k[4] = 1;
}
else if (k[2] == 5)
break;
else if (i % 2 == 0)
{
for (j = 2; j <= p; j = j + 2)
{
if ((a[i] == a[j] - 1) && (b[i] == b[j] - 1))
{
k[5]++;
continue;
}
else if ((a[i] == a[j] - 2) && (b[i] == b[j] - 2))
{
k[5]++;
continue;
}
else if ((a[i] == a[j] - 3) && (b[i] == b[j] - 3))
{
k[5]++;
continue;
}
else if ((a[i] == a[j] - 4) && (b[i] == b[j] - 4))
{
k[5]++;
continue;
}
else if (k[5] == 5)
{
printf("Player 2 wins!!!\n");
}
else
continue;
}
if (k[5] == 5)
break;
k[5] = 1;
}
} /**********判断对角(左下-右 上)************/
for (i = 1; i <= p; i++)
{
if (k[0] == 5 || k[1] == 5 || k[2] == 5 || k[3] == 5 || k[4] == 5
|| k[5] == 5)
break;
else if (i % 2 == 1)
{
for (j = 1; j <= p; j = j + 2)
{
if ((a[i] == a[j] + 1) && (b[i] == b[j] - 1))
{
k[6]++;
continue;
}
else if ((a[i] == a[j] + 2) && (b[i] == b[j] - 2))
{
k[6]++;
continue;
}
else if ((a[i] == a[j] + 3) && (b[i] == b[j] - 3))
{
k[6]++;
continue;
}
else if ((a[i] == a[j] + 4) && (b[i] == b[j] - 4))
{
k[6]++;
continue;
}
else if (k[6] == 5)
{
printf("Player 1 wins!!!\n");
}
else
continue;
}
if (k[6] == 5)
break;
k[6] = 1;
}
else if (k[6] == 5)
break;
else if (i % 2 == 0)
{
for (j = 2; j <= p; j = j + 2)
{
if ((a[i] == a[j] + 1) && (b[i] == b[j] - 1))
{
k[7]++;
continue;
}
else if ((a[i] == a[j] + 2) && (b[i] == b[j] - 2))
{
k[7]++;
continue;
}
else if ((a[i] == a[j] + 3) && (b[i] == b[j] - 3))
{
k[7]++;
continue;
}
else if ((a[i] == a[j] + 4) && (b[i] == b[j] - 4))
{
k[7]++;
continue;
}
else if (k[7] == 5)
{
printf("Player 2 wins!!!\n");
}
else
continue;
}
if (k[7] == 5)
break;
k[7] = 1;
}
}
} /****************和棋 *******************/
void heqi()
{
printf("************************** **********\n");
printf(" Tie!!!\n");
printf("************************** **********\n");
} /****************游戏结束 *******************/ void over()
{
printf("************************** **********\n");
printf(" game over!!!\n");
printf("************************** **********\n");
} /****************游戏开始 *******************/ void welcome()
{
printf("************************** **********\n");
printf(" Welcome!!!\n");
printf("************************** **********\n");
}
以上为五子棋代码
#define N 10
void welcome();
void initqipan();
void showqi(int i);
void save(int p);
void panduan(int p);
void heqi();
void over();
int zouqihang();
int zouqilie();
/******************结构体 *****************/ struct zuobiao
{
int x[N * N];
int y[N * N];
} weizhi[N * N]; /******************主函数 *****************/
int main()
{
int p = 0;
welcome();
initqipan();
for (p = 1; p <= N * N; p++)
{
weizhi[p].x[p] = zouqihang();
weizhi[p].y[p] = zouqilie();
save(p);
showqi(p);
panduan(p);
}
if (p == N * N)
heqi();
over();
} /******************建立棋盘 *****************/
void initqipan()
{
int i, j;
for (i = 0; i < N; i++)
{
printf("%d", i);
printf(" ");
}
printf("\n");
for (i = 1; i < N; i++)
{
for (j = 0; j < N; j++)
{
if (j == 0)
printf("%d", i);
else
printf("·");
}
printf("\n");
}
} /******************显示棋子 *****************/
void showqi(int p)
{
int i, j, k, m;
int a[N * N], b[N * N];
FILE *fp;
fp = fopen("wuzi_list", "rb");
for (i = 1; i <= N * N; i++)
{
fread(&weizhi[i], sizeof(struct zuobiao), 1, fp);
a[i] = weizhi[i].x[i];
b[i] = weizhi[i].y[i];
} for (m = 1; m < p; m++)
{
while(weizhi[p].x[p] == a[m] && weizhi[p].y[p] == b[m])
{
printf("error!\n");
weizhi[p].x[p] = zouqihang();
weizhi[p].y[p] = zouqilie();
m = 1;
}
}
for (i = 0; i < N; i++)
{
printf("%d", i);
printf(" ");
}
printf("\n");
for (i = 1; i < N; i++)
{
for (j = 1; j < N; j++)
{
if (j == 1)
printf("%d", i);
for (k = 1; k <= p; k++)
{
if (i == weizhi[k].x[k] && j == weizhi[k].y[k])
{
if (k % 2 == 1)
{
printf("○");
break;
}
else if (k % 2 == 0)
{
printf("●");
break;
}
}
}
if (k > p)
printf("·");
else
continue;
}
printf("\n");
}
} /******************走棋行 *****************/
int zouqihang()
{
int x;
printf("请输入要走棋子所在行 数!\n");
printf("x=");
scanf("%d", &x);
while (x > N - 1 || x < 1)
{
printf("error!\n");
printf("请输入要走棋子所在行 数!\n");
printf("x=");
scanf("%d", &x);
}
return x;
} /******************走棋列 *****************/
int zouqilie()
{
int y;
printf("请输入要走棋子所在列 数!\n");
printf("y=");
scanf("%d", &y);
while (y > N - 1 || y < 1)
{
printf("error!\n");
printf("请输入要走棋子所在列 数!\n");
printf("y=");
scanf("%d", &y);
}
return y;
} /******************文件保存 *****************/
void save(int i)
{
FILE *fp;
fp = fopen("wuzi_list", "wb");
fwrite(&weizhi[i], sizeof(struct zuobiao), 1, fp);
} /****************判断输赢 *******************/ void panduan(int p)
{
int i, j, k[8] = { 1, 1, 1, 1, 1, 1, 1, 1, };
int a[N * N], b[N * N];
FILE *fp;
fp = fopen("wuzi_list", "rb");
for (i = 1; i <= p; i++)
{
fread(&weizhi[i], sizeof(struct zuobiao), 1, fp);
a[i] = weizhi[i].x[i];
b[i] = weizhi[i].y[i];
} /*****************判断行 ******************/ for (i = 1; i <= p; i++)
{
if (i % 2 == 1)
{
for (j = 1; j <= p; j = j + 2)
{
if ((a[i] == a[j]) && (b[i] == b[j] - 1))
{
k[0]++;
continue;
}
else if ((a[i] == a[j]) && (b[i] == b[j] - 2))
{
k[0]++;
continue;
}
else if ((a[i] == a[j]) && (b[i] == b[j] - 3))
{
k[0]++;
continue;
}
else if ((a[i] == a[j]) && (b[i] == b[j] - 4))
{
k[0]++;
continue;
}
else if (k[0] == 5)
{
printf("Player 1 wins!!!\n");
}
else
continue;
}
if (k[0] == 5)
break;
k[0] = 1;
}
else if (k[0] == 5)
break;
else if (i % 2 == 0)
{
for (j = 2; j <= p; j = j + 2)
{
if ((a[i] == a[j]) && (b[i] == b[j] - 1))
{
k[1]++;
continue;
}
else if ((a[i] == a[j]) && (b[i] == b[j] - 2))
{
k[1]++;
continue;
}
else if ((a[i] == a[j]) && (b[i] == b[j] - 3))
{
k[1]++;
continue;
}
else if ((a[i] == a[j]) && (b[i] == b[j] - 4))
{
k[1]++;
continue;
}
else if (k[1] == 5)
{
printf("Player 2 wins!!!\n");
}
else
continue;
}
if (k[1] == 5)
break;
k[1] = 1;
}
} /**********************判断列 ************************/
for (i = 1; i <= p; i++)
{
if (k[0] == 5 || k[1] == 5)
break;
else if (i % 2 == 1)
{
for (j = 1; j <= p; j = j + 2)
{
if ((a[i] == a[j] - 1) && (b[i] == b[j]))
{
k[2]++;
continue;
}
else if ((a[i] == a[j] - 2) && (b[i] == b[j]))
{
k[2]++;
continue;
}
else if ((a[i] == a[j] - 3) && (b[i] == b[j]))
{
k[2]++;
continue;
}
else if ((a[i] == a[j] - 4) && (b[i] == b[j]))
{
k[2]++;
continue;
}
else if (k[2] == 5)
{
printf("Player 1 wins!!!\n");
}
else
continue;
}
if (k[2] == 5)
break;
k[2] = 1;
}
else if (k[2] == 5)
break;
else if (i % 2 == 0)
{
for (j = 2; j <= p; j = j + 2)
{
if ((a[i] == a[j] - 1) && (b[i] == b[j]))
{
k[3]++;
continue;
}
else if ((a[i] == a[j] - 2) && (b[i] == b[j]))
{
k[3]++;
continue;
}
else if ((a[i] == a[j] - 3) && (b[i] == b[j]))
{
k[3]++;
continue;
}
else if ((a[i] == a[j] - 4) && (b[i] == b[j]))
{
k[3]++;
continue;
}
else if (k[3] == 5)
{
printf("Player 2 wins!!!\n");
}
else
continue;
}
if (k[3] == 5)
break;
k[3] = 1;
}
} /****************判断对角(左 上-右下)******************/
for (i = 1; i <= p; i++)
{
if (k[0] == 5 || k[1] == 5 || k[2] == 5 || k[3] == 5)
break;
else if (i % 2 == 1)
{
for (j = 1; j <= p; j = j + 2)
{
if ((a[i] == a[j] - 1) && (b[i] == b[j] - 1))
{
k[4]++;
continue;
}
else if ((a[i] == a[j] - 2) && (b[i] == b[j] - 2))
{
k[4]++;
continue;
}
else if ((a[i] == a[j] - 3) && (b[i] == b[j] - 3))
{
k[4]++;
continue;
}
else if ((a[i] == a[j] - 4) && (b[i] == b[j] - 4))
{
k[4]++;
continue;
}
else if (k[4] == 5)
{
printf("Player 1 wins!!!\n");
}
else
continue;
}
if (k[4] == 5)
break;
k[4] = 1;
}
else if (k[2] == 5)
break;
else if (i % 2 == 0)
{
for (j = 2; j <= p; j = j + 2)
{
if ((a[i] == a[j] - 1) && (b[i] == b[j] - 1))
{
k[5]++;
continue;
}
else if ((a[i] == a[j] - 2) && (b[i] == b[j] - 2))
{
k[5]++;
continue;
}
else if ((a[i] == a[j] - 3) && (b[i] == b[j] - 3))
{
k[5]++;
continue;
}
else if ((a[i] == a[j] - 4) && (b[i] == b[j] - 4))
{
k[5]++;
continue;
}
else if (k[5] == 5)
{
printf("Player 2 wins!!!\n");
}
else
continue;
}
if (k[5] == 5)
break;
k[5] = 1;
}
} /**********判断对角(左下-右 上)************/
for (i = 1; i <= p; i++)
{
if (k[0] == 5 || k[1] == 5 || k[2] == 5 || k[3] == 5 || k[4] == 5
|| k[5] == 5)
break;
else if (i % 2 == 1)
{
for (j = 1; j <= p; j = j + 2)
{
if ((a[i] == a[j] + 1) && (b[i] == b[j] - 1))
{
k[6]++;
continue;
}
else if ((a[i] == a[j] + 2) && (b[i] == b[j] - 2))
{
k[6]++;
continue;
}
else if ((a[i] == a[j] + 3) && (b[i] == b[j] - 3))
{
k[6]++;
continue;
}
else if ((a[i] == a[j] + 4) && (b[i] == b[j] - 4))
{
k[6]++;
continue;
}
else if (k[6] == 5)
{
printf("Player 1 wins!!!\n");
}
else
continue;
}
if (k[6] == 5)
break;
k[6] = 1;
}
else if (k[6] == 5)
break;
else if (i % 2 == 0)
{
for (j = 2; j <= p; j = j + 2)
{
if ((a[i] == a[j] + 1) && (b[i] == b[j] - 1))
{
k[7]++;
continue;
}
else if ((a[i] == a[j] + 2) && (b[i] == b[j] - 2))
{
k[7]++;
continue;
}
else if ((a[i] == a[j] + 3) && (b[i] == b[j] - 3))
{
k[7]++;
continue;
}
else if ((a[i] == a[j] + 4) && (b[i] == b[j] - 4))
{
k[7]++;
continue;
}
else if (k[7] == 5)
{
printf("Player 2 wins!!!\n");
}
else
continue;
}
if (k[7] == 5)
break;
k[7] = 1;
}
}
} /****************和棋 *******************/
void heqi()
{
printf("************************** **********\n");
printf(" Tie!!!\n");
printf("************************** **********\n");
} /****************游戏结束 *******************/ void over()
{
printf("************************** **********\n");
printf(" game over!!!\n");
printf("************************** **********\n");
} /****************游戏开始 *******************/ void welcome()
{
printf("************************** **********\n");
printf(" Welcome!!!\n");
printf("************************** **********\n");
}
以上为五子棋代码
更多追问追答
追问
五子棋不可以弄。。。
追答
什么意思?我没听懂你的意思!五子棋可以啊。
展开全部
// 打字母的游戏
// 编译代码请先安装 VC 绘图库(V20091123),贴吧里有下载:http://tieba.baidu.com/f?kz=730592608
// 最后修改日期: 2010-3-28
//
#include <graphics.h>
#include <conio.h>
#include <time.h>
// 欢迎界面
void welcome()
{
// 输出屏幕提示
cleardevice();
setcolor(YELLOW);
setfont(64, 0, "黑体");
outtextxy(200, 50, "打字游戏");
setcolor(WHITE);
setfont(24, 0, "宋体");
outtextxy(100, 200, "根据掉下的字母按下相应的按键来消除字母");
outtextxy(100, 240, "暂时处于实验阶段");
outtextxy(100, 280, "只写程序不恋爱");
outtextxy(100, 320, "终身无缘高富帅");
// 实现闪烁的“按任意键继续”
int c=255;
while(!kbhit())
{
setcolor(RGB(c, 0, 0));
outtextxy(280, 400, "按任意键继续");
c-=8;
if (c<0) c=255;
Sleep(20);
}
getch();
cleardevice();
}
// 退出界面
void goodbye()
{
cleardevice();
setcolor(YELLOW);
setfont(48, 0, "黑体");
outtextxy(110, 150, "只写程序不恋爱");
outtextxy(110, 250, "终身无缘高富帅");
getch();
}
// 主函数
void main()
{
// 初始化屏幕为 640x480
initgraph(640, 480);
welcome(); // 显示欢迎界面
srand(time(NULL)); // 设置随机种子
setfont(16, 0, "Arial"); // 设置字母的字体和大小
char target[2] = " "; // 定义字母字符串
char key; // 定义用户按键变量
outtextxy(480,20,"生命:");
outtextxy(550,20,"分数:00");
// 主循环
while(true)
{
target[0] = 65 + rand() % 26; // 产生任意大写字母
int x = rand()%630;
for (int y=0; y<460; y++)
{
setcolor(WHITE); // 设置字母的颜色
outtextxy(x, y, target); // 显示字母
if(kbhit())
{
key = getch();
if((key == target[0]) || (key == target[0] + 32))
{
// 设置清除
setcolor(BLACK);
outtextxy(x, y, target); // 清除原字符
/// int i++;
break; // 跳出循环,进行下一个字符
}
else if (key == 27)
{
goto EXIT; // 如果按 ESC,退出游戏主循环
}
int a;
// sprintf(i, "%d", a);
/// outtextxy(520,20,i);
}
// 延时,并清除原字符
Sleep(10);
setcolor(BLACK);
outtextxy(x, y, target);
}
}
EXIT:
// 退出部分
goodbye();
// 关闭图形界面
closegraph();
}
// 编译代码请先安装 VC 绘图库(V20091123),贴吧里有下载:http://tieba.baidu.com/f?kz=730592608
// 最后修改日期: 2010-3-28
//
#include <graphics.h>
#include <conio.h>
#include <time.h>
// 欢迎界面
void welcome()
{
// 输出屏幕提示
cleardevice();
setcolor(YELLOW);
setfont(64, 0, "黑体");
outtextxy(200, 50, "打字游戏");
setcolor(WHITE);
setfont(24, 0, "宋体");
outtextxy(100, 200, "根据掉下的字母按下相应的按键来消除字母");
outtextxy(100, 240, "暂时处于实验阶段");
outtextxy(100, 280, "只写程序不恋爱");
outtextxy(100, 320, "终身无缘高富帅");
// 实现闪烁的“按任意键继续”
int c=255;
while(!kbhit())
{
setcolor(RGB(c, 0, 0));
outtextxy(280, 400, "按任意键继续");
c-=8;
if (c<0) c=255;
Sleep(20);
}
getch();
cleardevice();
}
// 退出界面
void goodbye()
{
cleardevice();
setcolor(YELLOW);
setfont(48, 0, "黑体");
outtextxy(110, 150, "只写程序不恋爱");
outtextxy(110, 250, "终身无缘高富帅");
getch();
}
// 主函数
void main()
{
// 初始化屏幕为 640x480
initgraph(640, 480);
welcome(); // 显示欢迎界面
srand(time(NULL)); // 设置随机种子
setfont(16, 0, "Arial"); // 设置字母的字体和大小
char target[2] = " "; // 定义字母字符串
char key; // 定义用户按键变量
outtextxy(480,20,"生命:");
outtextxy(550,20,"分数:00");
// 主循环
while(true)
{
target[0] = 65 + rand() % 26; // 产生任意大写字母
int x = rand()%630;
for (int y=0; y<460; y++)
{
setcolor(WHITE); // 设置字母的颜色
outtextxy(x, y, target); // 显示字母
if(kbhit())
{
key = getch();
if((key == target[0]) || (key == target[0] + 32))
{
// 设置清除
setcolor(BLACK);
outtextxy(x, y, target); // 清除原字符
/// int i++;
break; // 跳出循环,进行下一个字符
}
else if (key == 27)
{
goto EXIT; // 如果按 ESC,退出游戏主循环
}
int a;
// sprintf(i, "%d", a);
/// outtextxy(520,20,i);
}
// 延时,并清除原字符
Sleep(10);
setcolor(BLACK);
outtextxy(x, y, target);
}
}
EXIT:
// 退出部分
goodbye();
// 关闭图形界面
closegraph();
}
更多追问追答
追问
开不了。。。
追答
不是吧。。。我用的VC++6.0是可以打开的
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
比如这个21点游戏,代码挺简单的,适合初学者:
http://www.oschina.net/code/snippet_997483_20343
这个挺多的。推荐你去个地方吧
http://www.oschina.net/code/list/2/cpp?lang=cpp&catalog=game-development&show=time
里面有更多的小游戏,自己选选也推荐自己顺便认真学习下,如何?
http://www.oschina.net/code/snippet_997483_20343
这个挺多的。推荐你去个地方吧
http://www.oschina.net/code/list/2/cpp?lang=cpp&catalog=game-development&show=time
里面有更多的小游戏,自己选选也推荐自己顺便认真学习下,如何?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询