求用C语言写的小游戏源码,不管什么小游戏,源码都比较简单,适合初学者,3Q。

/*21点游戏*/

# include & ltstdio.h & gt

# include & lttime.h & gt

# include & ltstdlib.h & gt

int main(void)

{

int a,b,c,d,s,x,t,I,n,k;

s=200,k = 1000;

x=t=i=1,a = b = c = d = n = 0;

srand((int)time(0));

Printf(" 21点游戏

★游戏规则:\ n游戏开始后,系统会随机产生1到10之间的数字并累加。

1.当点数不超过21时,点数最多者获胜,点数相等计算平局;

2.一方点数大于21,一方点数小于21,小于21的一方获胜;

3.如果双方都大于21,则视为平局;

4.胜者获得相应的下注金币,当金币达到零时,游戏结束。\n(注意:继续加分选择1,不继续加分选择1以外的任何数字)\ n \ n # # # # # # # # # # # # # # # # # # #

做{

while(x==1)

{

如果(t==1)

{

c = rand()% 8+3;

a = rand()% 10+1;

}

如果(t==2)

{

a = rand()% 5+1;

c = rand()% 4+1;

}

如果(t==3)

{

c = rand()% 3+1;

a = rand()% 3+1;

}

如果(t==4)

{

a = rand()% 2+1;

c = rand()% 3+1;

}

如果(t==5)

a = rand()% 8+1;

如果(t==6)

a = rand()% 3+1;

b+=a,d+= c;

if(d & gt;16)

t = 2;

if(d = = 19 & amp;& ampb==19)

t = 3;

if(d = = 20 & amp;& ampb==20)

t = 3;

if(b = = 20 & amp;& ampd==19)

t = 4;

if(d = = 19 & amp;& amp(d-b)>3)

t = 5;

if(d = = 20 & amp;& ampd & gtb)

t = 6;

如果(d==21)

t = 6;

if(i==1)

{

{

Printf("你还有%d金币,系统有%d,请输入赌注:",s,k);

scanf("%d ",& ampn);

}

while(s & lt;n);

i++;

}

如果(b & gt21。& ampd & lt22)

{

Printf("你%d点,系统%d点,你输了!\n\n\n\n ",b,d);

s-= n;

k+= n;

t=i=1,b = d = 0;

打破;

}

if(d & gt;21。& ampb & lt22)

{

Printf("你%d,系统%d,你赢了!\n\n\n\n ",b,d);

s+= n;

k-= n;

t=i=1,b = d = 0;

打破;

}

if(d & gt;21。& ampb & gt21)

{

Printf("你%d,系统%d,平局!

\n\n\n ",b,d);

t=i=1,b = d = 0;

打破;

}

Printf("你加%d分,系统加%d分!\ n您现在有%d个积分,系统现在有%d个积分!\n是否要添加更多的“”,a,c,b,d);

scanf(" %d ",& ampx);

a = c = 0;

如果(x!=1)

{

if(d & lt;b & amp& ampd & lt18)

{

c = rand()% 4+2;

d = d+c;

Printf("不加分,系统会加%d分",c);

}

if(d & lt;b & amp& ampd==20)

{

c = rand()% 2+1;

d = d+c;

Printf("不加分,系统会加%d分",c);

}

if(d & lt;b & amp& ampd==19)

{

c = rand()% 4+1;

d = d+c;

Printf("不加分,系统会加%d分",c);

}

if(d & lt;b & amp& ampd==18)

{

c = rand()% 5+1;

d = d+c;

Printf("不加分,系统会加%d分",c);

}

if(d & gt;b)

Printf("不加,系统不加");

if(d & lt;22 & amp& ampd & gtb)

{

Printf("你%d点,系统%d点,你输了!\n\n\n\n ",b,d);

s-= n;

k+= n;

t=x=i=1,b = d = 0;

打破;

}

如果(b & gtd & amp& ampb & lt22 | | b & lt22 & amp& ampd & gt21)

{

Printf("你%d,系统%d,你赢了!\n\n\n\n ",b,d);

s+= n;

k-= n;

t=x=i=1,b = d = 0;

打破;

}

如果(b==d)

{

Printf("你%d,系统%d,平局!

\n\n\n\n ",b,d);

t=x=i=1,b = d = 0;

打破;

}

}

}

}

while(s & gt;0 & amp& ampk & gt0);

Printf("你有%d金币,系统有%d金币!\n\n ",s,k);

if(s & gt;k)

Printf("太好了,你打败了系统!!!\ n ");else if(k & gt;s)

Printf("你的金币不足,挑战系统失败!\ n ");

返回0;

}