用C语言做一个简单的原神抽卡小游戏

运行的过程

        • 💥开始的界面💥
          • 📓输入1
            • 🎸没中🎸
            • 🎸中了🎸
          • 📓输入10
          • 📓输入0
        • 💥代码💥
          • 📓test4.26.c
          • 📓许愿.c
          • 📓game.h
      • 下载


💥开始的界面💥

请添加图片描述


📓输入1
🎸没中🎸

请添加图片描述


🎸中了🎸

请添加图片描述


📓输入10

请添加图片描述

📓输入0

请添加图片描述


💥代码💥

我创建了两个.c源文件,一个.h头文件


📓test4.26.c
#define _CRT_SECURE_NO_WARNINGS#include"game.h"int main(){	srand((unsigned)time(NULL));//随机赋值	while (1)	{		int choose = 0;		choose = Cho();				switch (choose)		{		   case 1:		   {			   num1:			   //许愿进行			   wish();			   break;		   }		   case 0:		   {			   num2:			   goto over;//结束程序		   }		   case 10:		   {			   num3:			   int i = 0;			   for (i = 0; i < 10; i++)			   {				   wish();			   }			   break;		   }		   default:		   {		   swi:			   //未能识别选项,请重新输入			   printf("未能识别选项,请重新输入nn");			   int again = 0;			   again = Cho();			 if (again == 1)				goto num1;//返回case 1			 else if (again == 0)				goto num2;//返回case 0			 else if (again == 10)				 goto num3;//返回case 10			 else			    goto swi;//重复default		   }		}	}	over:	return 0;}

📓许愿.c
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <time.h>#include <stdlib.h>void wish(){	int random_num = rand() % 440 ;	//修改它可以改变概率,当前概率是1/100	if (1 == random_num)	{		printf("★☆★☆★刻晴n");	}	else if (2 == random_num)	{		printf("★☆★☆★胡桃n");	}	else if (3 == random_num)	{		printf("★☆★☆★七七n");	}	else if (4 == random_num)	{		printf("★☆★☆★钟离n");	}	else if (5 == random_num)	{		printf("★☆★☆★卢老爷n");	}	else if (6 == random_num)	{		printf("★☆★☆★宵宫n");	}	else if (7 == random_num)	{		printf("★☆★☆猫猫n");	}	else if (8 == random_num)	{		printf("★☆★☆★琴n");	}	else if (9 == random_num)	{		printf("★☆★☆安柏n");	}	else if (10 == random_num)	{		printf("★☆★☆丽莎n");	}	else if (11 == random_num)	{		printf("★☆★☆凯亚n");	}	else if (12 == random_num)	{		printf("★☆★☆芭芭拉n");	}	else if (13 == random_num)	{		printf("★☆★☆班尼特n");	}	else if (14 == random_num)	{		printf("★☆★☆★不干正事的巴巴托斯n");	}	else if (15 == random_num)	{		printf("★☆★☆★小可莉n");	}	else if (16 == random_num)	{		printf("★☆★☆雷泽n");	}	else if (17 == random_num)	{		printf("★☆★☆★莫娜n");	}	else if (18 == random_num)	{		printf("★☆★☆砂糖n");	}	else if (19 == random_num)	{		printf("★☆★☆菲谢尔n");	}	else if (20 == random_num)	{		printf("★☆★☆诺艾尔n");	}	else if (21 == random_num)	{		printf("★☆★☆★阿贝多n");	}	else if (22 == random_num)	{		printf("★☆★☆★优菈n");	}	else if (23 == random_num)	{		printf("★☆★☆罗莎莉亚n");	}	else if (24 == random_num)	{		printf("★☆★☆★魈n");	}	else if (25 == random_num)	{		printf("★☆★☆北斗n");	}	else if (26 == random_num)	{		printf("★☆★☆凝光n");	}	else if (27 == random_num)	{	     printf("★☆★☆香菱n");	}	else if (28 == random_num)	{	printf("★☆★☆重云n");	}	else if (29 == random_num)	{	printf("★☆★☆行秋n");	}	else if (30 == random_num)	{	printf("★☆★☆★达达利亚n");	}	else if (31 == random_num)	{	printf("★☆★☆辛焱n");	}	else if (32 == random_num)	{	printf("★☆★☆★雷电将军n");	}	else if (33 == random_num)	{	printf("★☆★☆★神里绫华n");	}	else if (34 == random_num)	{	printf("★☆★☆★枫原万叶n");	}	else if (35 == random_num)	{	printf("★☆★☆早柚n");	}	else if (36 == random_num)	{	printf("★☆★☆九条裟罗n");	}	else if (37 == random_num)	{	printf("★☆★☆★心海n");	}	else if (38 == random_num)	{	printf("★☆★☆托马n");	}	else if (39 == random_num)	{	printf("★☆★☆五郎n");	}	else if (40 == random_num)	{	printf("★☆★☆★荒泷一斗n");	}	else if (41 == random_num)	{	printf("★☆★☆★八重神子n");	}	else if (42 == random_num)	{	printf("★☆★☆★神里绫人n");	}	else if (43 == random_num)	{	printf("★☆★☆久岐忍n");	}	else if (44 == random_num)	{	printf("★☆★☆夜兰n");	}	else		printf("非酋n");}int Cho(){	int a = 0;	printf("n|-----------------|n");	printf("|输入1开始单抽    |n");	printf("|输入10开始十连抽 |n");	printf("|输入0结束游戏    |n");	printf("|-----------------|n");	printf("是否开始许愿:>");	scanf("%d", &a);	return a;}

📓game.h
#pragma once#include<stdio.h>#include <time.h>#include <stdlib.h>void wish();//许愿运行int Cho();//输入是否进行游戏

🌟我写的这个小游戏还很粗糙goto用的太多了,显得有点乱,可读性不太好,不过才开始学,进步空间还是很大的,我们继续加油,未来可期

下载

exe存在了百度网盘
有提取码的话就是1111

代码就上传到我的gitee了

 
友情链接
鄂ICP备19019357号-22