#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int total_diamonds = 0;
int current;
int choice;
int multiplier;
int diamonds_this_round;
int addValue;
int scissors = 0;
int shovels = 0;
int round = 1;
srand(time(0));
printf("欢迎来到西瓜大王游戏!\n");
printf("规则:\n");
printf("1. 初始选择一个1-10之间的数字\n");
printf("2. 每轮会随机增加1或2\n");
printf("3. 每轮有机会乘以一个正整数\n");
printf("4. 达到特定分数可获得钻石:\n");
printf(" 25分 -> 1颗钻石\n");
printf(" 50分 -> 2颗钻石\n");
printf(" 75分 -> 3颗钻石\n");
printf(" 100分 -> 4颗钻石\n");
printf("5. 超过100分游戏结束并结算\n");
printf("6. 在商店中可以用钻石购买道具:\n");
printf(" 剪刀(-5): 5颗钻石\n");
printf(" 铲子(-10): 10颗钻石\n\n");
while(1) {
diamonds_this_round = 0;
printf("\n===== 第 %d 轮游戏开始 =====", round);
printf("\n总钻石: %d | 剪刀: %d | 铲子: %d\n", total_diamonds, scissors, shovels);
do {
printf("\n请输入初始数字(1-10): ");
scanf("%d", &choice);
if(choice < 1 || choice > 10) {
printf("无效输入!请输入1-10之间的数字。\n");
}
} while(choice < 1 || choice > 10);
current = choice;
printf("初始数字: %d\n", current);
if(current == 25 || current == 50 || current == 75 || current == 100) {
int newDiamonds = 0;
if(current == 25) newDiamonds = 1;
else if(current == 50) newDiamonds = 2;
else if(current == 75) newDiamonds = 3;
else if(current == 100) newDiamonds = 4;
diamonds_this_round += newDiamonds;
printf("恭喜!初始值达到%d分,获得%d颗钻石!\n", current, newDiamonds);
}
while(1) {
addValue = rand() % 2 + 1;
current += addValue;
printf("\n本轮增加: %d, 当前数值: %d\n", addValue, current);
int newDiamonds = 0;
if(current == 25) newDiamonds = 1;
else if(current == 50) newDiamonds = 2;
else if(current == 75) newDiamonds = 3;
else if(current == 100) newDiamonds = 4;
if(newDiamonds > 0) {
diamonds_this_round += newDiamonds;
printf("★★★★★ 达到%d分,获得%d颗钻石!★★★★★\n", current, newDiamonds);
}
if(current > 100) {
printf("超过100分!本轮结束!\n");
break;
}
do {
printf("请输入乘数(正整数,输入0跳过): ");
scanf("%d", &multiplier);
if(multiplier < 0) {
printf("请输入正整数或0!\n");
} else if(multiplier == 0) {
printf("跳过乘法操作。\n");
break;
} else if(multiplier == 1) {
printf("乘以1,数值不变。\n");
break;
} else {
int prev = current;
current *= multiplier;
printf("乘以 %d, 当前数值: %d\n", multiplier, current);
newDiamonds = 0;
if(current == 25) newDiamonds = 1;
else if(current == 50) newDiamonds = 2;
else if(current == 75) newDiamonds = 3;
else if(current == 100) newDiamonds = 4;
if(newDiamonds > 0) {
diamonds_this_round += newDiamonds;
printf("★★★★★ 达到%d分,获得%d颗钻石!★★★★★\n", current, newDiamonds);
}
if(current > 100) {
printf("超过100分!本轮结束!\n");
break;
}
break;
}
} while(1);
if(current > 100) {
break;
}
}
total_diamonds += diamonds_this_round;
printf("\n本轮结束!获得钻石: %d | 总钻石: %d\n", diamonds_this_round, total_diamonds);
printf("\n===== 商 店 =====");
printf("\n总钻石: %d\n", total_diamonds);
printf("1. 剪刀(-5) - 5颗钻石\n");
printf("2. 铲子(-10) - 10颗钻石\n");
printf("3. 不购买,继续下一轮\n");
printf("4. 退出游戏\n");
int shop_choice;
do {
printf("请选择操作: ");
scanf("%d", &shop_choice);
if(shop_choice == 1 && total_diamonds >= 5) {
total_diamonds -= 5;
scissors++;
printf("购买剪刀成功!剪刀数量: %d\n", scissors);
break;
} else if(shop_choice == 2 && total_diamonds >= 10) {
total_diamonds -= 10;
shovels++;
printf("购买铲子成功!铲子数量: %d\n", shovels);
break;
} else if(shop_choice == 3) {
printf("不购买道具,继续下一轮。\n");
break;
} else if(shop_choice == 4) {
printf("游戏结束!感谢游玩!\n");
printf("最终统计:\n");
printf("游戏轮次: %d\n", round);
printf("总钻石: %d\n", total_diamonds);
printf("剪刀: %d | 铲子: %d\n", scissors, shovels);
return 0;
} else {
if((shop_choice == 1 && total_diamonds < 5) ||
(shop_choice == 2 && total_diamonds < 10)) {
printf("钻石不足!\n");
} else {
printf("无效选择!请重新输入。\n");
}
}
} while(1);
if(scissors > 0 || shovels > 0) {
printf("\n是否要在下一轮开始前使用道具?\n");
if(scissors > 0) {
printf("1. 使用剪刀(-5) - 当前数量: %d\n", scissors);
}
if(shovels > 0) {
printf("2. 使用铲子(-10) - 当前数量: %d\n", shovels);
}
printf("3. 不使用道具\n");
int use_tool;
do {
printf("请选择: ");
scanf("%d", &use_tool);
if(use_tool == 1 && scissors > 0) {
scissors--;
printf("剪刀已使用!下一轮初始数字将减少5。\n");
break;
} else if(use_tool == 2 && shovels > 0) {
shovels--;
printf("铲子已使用!下一轮初始数字将减少10。\n");
break;
} else if(use_tool == 3) {
printf("不使用道具。\n");
break;
} else {
printf("无效选择!请重新输入。\n");
}
} while(1);
}
round++;
}
return 0;
}