【发布时间】:2020-12-04 07:46:19
【问题描述】:
我正在尝试做一个纸牌游戏(用户对电脑),首先获得 7.5 分的人获胜。为此,我创建了一套有 4 套套装,每套 10 张牌的套牌。卡片从 1 到 10,卡片的价值从 1 到 7,他们看重他们拥有的数字。卡片 8,9 和 10 值 0.5 分。
我创建了一个数组来存储卡片,并创建了一个数组来在选择时将卡片标记为已删除
int deck[40] = {1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10};
int draw[40] = {0}; //array to "delete" a card. Mark a card as "deleted", e.g., by setting it to 1,
// then if the card chosen has been deleted, it choose again.
问题是我不知道在 draw[ ] = 1 中的方括号之间放什么才能正常工作
查看我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int main()
{
srand( time(NULL) );
int key, card, cardpc;
int deck[40]={1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10};
int draw[40] = {0}; //array to "delete" a card. Mark a card as "deleted", e.g., by setting it to 1,
// then if the card chosen has been deleted, it choose again.
float points, points_pc;
printf("Press 1 to play or 0 to not!\t");
scanf("%d", &key);
printf("\n");
if (key ==0){
printf("BYE\n");
}else if (key==1){
while(key==1){
card = deck[rand()% 40];
if (draw[] == 1){
card = deck[rand()% 40];
}
if(card==8 || card==9 || card==10){
printf("You got 0.5 points");
points = points + 0.5;
}else{
printf("You got %d points",card);
points = points + card;
}
printf("\n");
printf("Your score is: %0.1f \n", points);
draw[]=1
cardpc = deck[rand()% 40];
if (draw[] == 1){
card = deck[rand()% 40];
}
if(cardpc==8 || cardpc==9 || cardpc==10){
printf("The PC got 0.5 points");
points_pc = points_pc + 0.5;
}else{
printf("The PC got %d points", cardpc);
points_pc = points_pc + cardpc;
}
printf("\n");
printf("The PC score is: %0.1f \n", points_pc);
draw[]=1;
printf("Do you want another card? (Press 1 if you want it)\t");
scanf("%d", &key);
printf("\n");
}
}
【问题讨论】: