#S0018. 物品合成与配方验证
物品合成与配方验证
1. Description
🎮 In-Game Crafting
Games like Zelda require players to craft items using recipes:
- Recipe: e.g., "Fire Arrow = Wooden Arrow×3 + Ruby×1"
- Rules: Deduct materials if sufficient, else fail
- Dynamic Recipes: Allow adding new recipes at runtime
🛠️ Task
Implement a crafting system with commands:
add_recipe recipe_name material1×count ...collect player material countcraft player recipe_nameendto finish
Rules:
- Check material availability before crafting
- Output success/failure immediately
2. Input & Output
Input:
- Multiple commands ending with
end
Output:
- Immediate result for each craft attempt
- Final inventories sorted by player name
Example
# Input:
add_recipe FireArrow WoodenArrow×3 Ruby×1
collect Link WoodenArrow 10
collect Link Ruby 2
craft Link FireArrow
craft Link FireArrow
end
# Process Output:
[Success] Link crafted FireArrow
[Success] Link crafted FireArrow
# Final Output:
Link: WoodenArrow×4, Ruby×0, FireArrow×2
# Input:
add_recipe Potion Herb×2 Water×1
collect Zelda Herb 1
craft Zelda Potion
end
# Process Output:
[Failed] Not enough materials
# Final Output:
Zelda: Herb×1, Water×0