用c语言编写一个2048 游戏,求c语言编写的2048游戏代码,尽量功能完善一些
正在編寫中,請稍后!
追答 : 代碼來了!有點急,沒做界面。
追答 : 2048_launcher。c
:
#include
#include
#include
void main()
{
printf("正在啟動中,請稍后!
");
Sleep(1000);
system("bin\Version\games\0。
1\0。1。exe");
}
追答 : 0。1。
c
:
#include
#include
#include
#include
#define WIN 256 // 可以修改決定游戲輸贏的值
// 矩陣數(shù)組
int num[4][4]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int t[5]={0,0,0,0,0}; // 輔助數(shù)組
int move=0; // 記錄移動步數(shù)
int score=0; // 記錄得分情況
int max=0; // max表示游戲輸贏,max=WIN時贏
int change=1;
// 產(chǎn)生一個隨機位置和隨機數(shù)
void Srand()
{
int i,j;
do// 產(chǎn)生一個隨機位置,如果產(chǎn)生的位置有數(shù)據(jù),就繼續(xù)隨機生成一個新位置
{
i=((unsigned)rand())%4;
j=((unsigned)rand())%4;
}while(num[i][j]!=0);
if(((unsigned)rand())%4==0)
{ // 產(chǎn)生一個隨機數(shù),如果該數(shù)對4取余=0,則填充為4
num[i][j]=4;
}
else
{
num[i][j]=2;
}
move ;
}
void Print()
{
int j,i;
system("CLS");
printf("*~~~~~~~~2048~~~~~~~*
");
printf("*author: 亞威 *
");
printf("*得分: %d 步數(shù): %d
",score,move);
printf("*~~~~~~~~~~~~~~~~~~~*
");
for(i=0;i=3)
break;
}
}
// 合并操作
void hebing()
{
int i;
for(i=0;i=WIN)
{
printf("你贏了!
");
printf("你很牛啊!!!
");
}
else
{
printf("游戲結(jié)束!
");
printf("努力啊!!!
");
}
getch();
return 0;
}
展開剩余1條追問追答收起。
全部
總結(jié)
以上是生活随笔為你收集整理的用c语言编写一个2048 游戏,求c语言编写的2048游戏代码,尽量功能完善一些的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python treeview底部加个按
- 下一篇: IMX462 Sensor 对接HI35