纸牌游戏-在方括号[]之间放什么? [英] card game - what to put between the square brackets [ ]?

查看:51
本文介绍了纸牌游戏-在方括号[]之间放什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一个纸牌游戏(用户对个人电脑),该游戏首先获得7.5分.为此,我创建了一个甲板,该甲板有4套西装,每套10张.卡的数量从1到10,卡的值1-7表示他们拥有的数量.纸牌8,9和10得0.5分.

Im trying to do a card game (user vs pc) where the first to get 7.5 points win. For that I created a deck that have 4 suits with 10 cards each one. The cards go from 1 to 10, and the value of the cards 1-7 they value the number they have. Cards 8,9 and 10 value 0.5 points.

我创建了一个存储卡的数组,并创建了一个数组,以在选择时将其标记为已删除

I created an array to store the cards and another to mark a card as deleted when chosen

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的方括号之间应该放什么

The thing is that I dont know what to put between the square brackets in draw[ ] = 1 for it to work

查看我的代码:

#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");
   }
}

推荐答案

您需要一个单独的变量:

You need a separate variable:

int n = rand()% 40;
card = deck[n];
if (draw[n] == 1){

这篇关于纸牌游戏-在方括号[]之间放什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆