编辑代码

#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) {
            // 随机增加1或2
            addValue = rand() % 2 + 1; // 生成1或2
            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);
            }
            
            // 检查是否超过100
            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);
                    }
                    
                    // 乘法后检查是否超过100
                    if(current > 100) {
                        printf("超过100分!本轮结束!\n");
                        break;
                    }
                    break;
                }
            } while(1);
            
            // 如果当前值超过100,结束本轮
            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;
}