Java实现的饥荒控制台游戏代码示例如何添加技能和魔法系统
import java.util.Scanner;
public class HungerGame {
private int food;
private int health;
private int sanity;
private int daysSurvived;
public HungerGame() {
this.food = 10;
this.health = 100;
this.sanity = 100;
this.daysSurvived = 0;
}
public void startGame() {
System.out.println("欢迎来到饥荒控制台游戏!");
System.out.println("你需要努力生存,尽可能多的吃饭、保持健康和内心平衡。");
System.out.println("每天你可以选择不同的行动,但是要注意资源的管理和分配。");
System.out.println("现在,游戏开始了!");
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("-------------------------------------------");
System.out.println("第 " + daysSurvived + " 天");
System.out.println("状态: 饱食度 - " + food + " 健康度 - " + health + " 精神值 - " + sanity);
System.out.println("请选择你的行动:");
System.out.println("1. 采集食物");
System.out.println("2. 狩猎动物");
System.out.println("3. 准备晚餐");
System.out.println("4. 发现新的区域");
System.out.println("5. 查看技能");
System.out.println("6. 使用魔法");
System.out.println("7. 结束游戏");
int choice = Int();
switch (choice) {
case 1:
collectFood();
break;
case 2:
huntAnimal();
break;
case 3:
prepareDinner();
break;
case 4:
discoverNewArea();
break;
简单的java游戏代码 case 5:
showSkills();
break;
case 6:
useMagic();
break;
case 7:
finishGame();
return;
default:
System.out.println("无效的选择,请重新选择。");
}
updateGameState();
if (!isAlive()) {
System.out.println("你没能在饥荒中生存下来,游戏结束!");
return;
}
}
}
private void collectFood() {
int collectedFood = 3 + (int) (Math.random() * 5);
food += collectedFood;
System.out.println("你采集到了 " + collectedFood + " 份食物。");
}
private void huntAnimal() {
int huntedFood = 5 + (int) (Math.random() * 10);
food += huntedFood;
System.out.println("你成功狩猎到了一只动物,获得 " + huntedFood + " 份食物。");
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论