本帖最后由 墨眉无锋 于 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;
}
モンブラン 发表于 2014-2-3 01:38那个...为什么这段代码总有一个错误啊...
for(i=0;i
card是数组阿,这么用数组名的话,是地址阿。
而且for{}后面跟分号无作用。,。。阿
[查看全文]
モンブラン 发表于 2014-2-3 01:38那个...为什么这段代码总有一个错误啊...
for(i=0;i
card=rand()%10; 换成 card【i】=rand()%10;
就行了,粗心了吧!
[查看全文]
修改了下,看看是不是要这种结果
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
int main()
{
int point=10;
int bet=0;
int get=0;
int card[3];
int play, i, beat;
do
{
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] == bet && card[1] == bet && card[2] == bet)
{
point = point + 5 * beat + beat;
}
else
{
if((card[0] == bet && card[1] == bet) || (card[1] ==bet && card[2] == bet) || (card[2] == bet && card[0] == bet))
{
point=point+2*bet;
}
}
//特殊情况
for(i = 0;i <= 2;i++)
{
if(card == 1)
{
point = point + 5 + beat;
}
}
//评语
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 for continus,0 for stop)");
scanf("%d",&play);
/*if(point == 0)
{
play = 0;
}*/
}while(play == 1);
printf("Game End!");
return 0;
}
[查看全文]