墨眉无锋
C语言小游戏

本帖最后由 墨眉无锋 于 2013-12-2 17:37 编辑

游戏要求:Create a simple video game.The user starts the game with 10 points. The user chooses how many points he wants to bet ( minimum

1, maximum the current amount of points ).

Then, the computer randomly choose three numbers ( between 0 and 9 ).

The program first checks if :

• two numbers are equal : the user wins 2 times the bet amount

• three numbers are equal : the user wins 5 times the bet amount

The program then check the number of number “1” in the result. Each time there is a “1” between the

three random numbers, 5 points are given to the player.

For example : if the result is 155 ( the player wins 2 times the amount of points and also 5 bonus

points ). If the result is 111 ( the player wins 5 times the amount of points and also 15 bonus points ).

If one time the player wins more than 50 points, the program will say “Not bad !”. If in one time the

player wins more than 100 points, the program will say “Very Good !”.

When it is finish, the user can bet again or stop the program.

代码

#include <stdio.h>

#include <stdlib.h>

#include<time.h>

int main()

{

int point=10;

int bet=0,beat;

int get=0;

int card[2],i=0;

int play=1;

while(play==1){

while(get==0){

printf("bet?\n");

scanf("%d",&bet);

beat=bet;

if(bet > point){

printf("Sorry,your bet is bigger than the point you have.\n");

}else{point = point-bet;break;};

};

//生成随机数;

srand((unsigned int)time(NULL));

for(i=0;i<=2;i++){

card=rand()%10;

};

//显示随机数

//card[0]=0;

//card[1]=0; 这三个赋值是测试时用的,运行时无视

//card[2]=0;

printf("Random nuber:");

for(i=0;i<=2;i++){

printf("%d ",card);

};

//判断是否有相同数

if(card[0]==card[1] && card[1]==card[2]){

point=point + 5*beat; 未知原因,当三个数相同时,bet会变的与card值相同,哪里有大神能帮个忙

}else{

if(card[0]==card[1] || card[1]==card[2] || card[2]==card[0]){

point=point+2*bet;

};

};

//特殊情况

for(i=0;i<=2;i++){

if(card==1){

point=point+5;

}

};

//评语

printf("\nYour point:%d\n",point);

if(point>=100){

printf("Very good!\n");

}else{

if(point>=50){

printf("Not bad!\n");

};

};

printf("Do you want to continue?(1 fot continus,0 for stop)");

scanf("%d",&play);

if(point==0){play=0;};

};

return 0;

}

幻想夏乡
数组那里就有问题了
展开Biu

是card[3]不是card[2],数组那里就有问题了= =

[查看全文]
lzy199228
拿来试试看
展开Biu

拿来试试看

[查看全文]
自闭的人
人表示现在完全看不懂
展开Biu

个·人表示现在完全看不懂~49!

[查看全文]
听风镇
我是来做任务的
展开Biu

我是来做任务的

[查看全文]
爱来不来
楼主好厉害
展开Biu

楼主好厉害

[查看全文]
墨眉无锋
为什么这段代码总有一个错误啊
展开Biu

モンブラン 发表于 2014-2-3 01:38

那个...为什么这段代码总有一个错误啊...

for(i=0;i

报错提示是什么??

[查看全文]
モンブラン
为什么这段代码总有一个错误啊
展开Biu

那个...为什么这段代码总有一个错误啊...

for(i=0;i<=2;i++){

card=rand()%10;

};

就这段...小白一个...无从下手啊

[查看全文]
燃烧的指环
我才不承认我想念你了呢
展开Biu

hatecrew 发表于 2013-12-9 19:04

我才不承认我想念你了呢。

啊,头像不错吧哈哈~

最近要考试啊,烦

[查看全文]