目录
头文件内容
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h> //包含srand、rand函数声明
#include<time.h> //包含time函数声明
源文件内容
#程序主体
主菜单循环
int main()
{
int input = 0;
do //采用do……while循环,保证菜单能直接打印出来(至少打印一次)
{
menu(); //【菜单函数】
printf("Please select[Input: 1/0]:>\n");
scanf("%d", &input);
switch (input)
{
输入1开始抽卡
case 1:
printf("*DRAW CARDs*\n");
tarot(); //【抽卡函数】
break;
输入0直接退出
case 0:
printf("EXIT:<\n");
break;
输入其他数报错
default:
printf("Error, please reselect:>\n");
}
} while (input);//抽完一次或输错数自动跳回主菜单 //输0直接跳出
return 0;
}
#内部函数
1.菜单函数
打印菜单
void menu()
{
printf("***************************\n");
printf(" \n");
printf(" 1. DRAW CARDs\n");
printf(" \n");
printf(" 0. EXIT\n");
printf(" \n");
printf(" \n");
printf("***************************\n");
}
2.抽卡函数
void tarot()
{
//part 1/
//确定抽几张牌
int cardnum = 0;
printf("The number of cards drawn:");
scanf("%d", &cardnum);
//part 2/
//初始化数组card[]
int card[79] = { 0 };
for (int i = 0; i < 79; i++)
{
card[i] = i;
}
//随机打乱数组card[]
for (int i = 0; i < 79; i++)
{
srand(time(NULL)); //初始化随机数种子
for (int i = 78; i > 0; i--)
{
int j = rand() % (i + 1); //打乱范围逐步缩小,后面已经打乱过的数不变
int temp = card[i];
card[i] = card[j];
card[j] = temp;
}
}
//part 3/
const char* tarotcard[79] = {
"Fool", "Magician", "High Priestess", "Empress", "Emperor",
"Hierophant", "Lovers", "Chariot", "Strength", "Hermit",
"Wheel of Fortune", "Justice", "Hanged Man", "Death", "Temperance",
"Devil", "Tower", "Star", "Moon", "Sun",
"Judgement", "World", "King of Swords", "Queen of Swords", "Knight of Swords",
"Page of Swords", "Ace of Swords", "Two of Swords", "Three of Swords", "Four of Swords",
"Five of Swords", "Six of Swords", "Seven of Swords", "Eight of Swords", "Nine of Swords",
"Ten of Swords", "King of Wands", "Queen of Wands", "Knight of Wands", "Page of Wands",
"Ace of Wands", "Two of Wands", "Three of Wands", "Four of Wands", "Five of Wands",