rpg角色生成器java版本

作业说明:
题目:
1.功能描述
几乎所有的RPG游戏(一种源自《龙与地下城》的游戏类型)在进入游戏时都会让用户自己来创建自己喜欢的角色。本次上机要求编写一个简化的创建游戏角色的程序。

2.游戏角色应有的属性
本题目要求的游戏角色应有以下属性:名字、性别、种族、职业、力量、敏捷、体力、智力、智慧、生命值和魔法值。
名字:不超过50个字符。
性别:可以选择男性和女性。
种族:一共可选五个种族,人类、精灵、兽人、矮人和元素。
职业:可选六种职业,狂战士、圣骑士、刺客、猎手、祭司和巫师。
其余属性均为整数。
本题目要求首先用户输入角色姓名,然后由用户选择角色性别,然后由用户选择种族,然后选择职业,然后自动分配力量、敏捷、体力、智力和智慧属性,并计算生命值和魔法值。
生命值=体力*20。
魔法值=(智力+智慧)*10。
3.职业限制
很多职业会限制某些种族选择,例如兽人不能就职圣骑士等等,种族和职业的限制表如下:
种族/职业 狂战士 圣骑士 刺客 猎手 祭司 巫师
人类 允许 允许 允许 允许 允许 允许
精灵 不允许 不允许 允许 允许 允许 允许
兽人 允许 不允许 不允许 允许 允许 不允许
矮人 允许 允许 不允许 不允许 允许 不允许
元素 不允许 不允许 不允许 不允许 允许 允许
所以在要求用户选择职业时,输出信息里面只能有用户所选择种族可以就职的职业。
4.初始属性
本题目要求力量、敏捷、体力、智力和智慧要求是随机值(利用随机数函数来取得随机数),但是五项属性的总和应该是100,并且应该和职业相关。例如狂战士的体力和力量就要比较高,而巫师需要较高的智力,而祭司则需要较高的智慧。各职业初始属性的大致比例应遵从下表:
职业/属性 力量 敏捷 体力 智力 智慧
狂战士 40 20 30 5 5
圣骑士 25 15 30 20 10
刺客 20 35 20 15 10
猎手 15 40 15 10 20
祭司 15 20 15 35 15
巫师 10 20 10 20 40
例如,前面示意图中的祭司的初始属性,大致满足该比例,但是应该是随机的。
然后利用属性值计算生命值和魔法值。
5.显示信息
最后向用户显示该角色的所有信息,然后询问用户是否满意,如用户不满意则重新创建,若用户满意则程序结束,并将用户创建角色的相关信息写入文件保存。

思路:
用面向对象思路,创建好输入姓名,性别,种族,职业函数,用键盘输入数字,选择信息。根据所选职业随机分配属性,然后询问是否愿意,如果不满意则重新建立,满意则保存在txt文件中。
职业限制的方法:用race_chocie保存种族信息,然后用swtich语句根据race_choice来选择不同的职业。
随机分配属性的办法:用基本属性+Math.random函数分配

运行结果:

在这里插入图片描述

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;

public class rgpCreate  {
	public static String dsex[]={"男","女"};             
	public static String drace[]={"人类","精灵","兽人","矮人","元素"};
	public static String doccuption[]={"狂战士","圣骑士","刺客","猎手","祭司","巫师"};
	public int race_choice;                    //种族选择
	public int occuption_choice;               //职业选择
	public String name;
	public int sex_choice;                    //性别选择
	public int strength;	//力量
	public int agility;	//敏捷
	public int physical;	//体力
    public int intelligence;	//智力
	public int wisdom;	//智慧
	public int HP;	//生命值
	public int MP;	//法力值
	

	public static void main(String[] args) {
		rgpCreate rgp=new rgpCreate();                 //创建一个rgp对象
		int i = 1;
		while(i != 0) {
			rgp.getBaseinformation();
			rgp.getRace();
			rgp.getOccuption();
			rgp.random();
			System.out.println("0愿意,1不愿意");
			Scanner sc=new Scanner(System.in);
			i = sc.nextInt();
		}
		System.out.println("创建成功");
		rgp.outPut();
		rgp.save();

	}
	/*
	 * 姓名性别输入函数 
	 * */
	public int getBaseinformation(){
    	Scanner sc=new Scanner(System.in);
    	
		System.out.println("请输入您的昵称:");
		name=sc.nextLine();	
		while(name.length()>50){
			
			System.out.println("昵称超过50位字符!,请重新输入");
		}
		while(true){ 
			System.out.println("请选择您的性别:0为男性,1为女性。");         
		    sex_choice=sc.nextInt();
			if(sex_choice==0||sex_choice==1){
				break;                                //验证输入正确性,正确则跳出,否则输出提示。
			}
			else
				System.out.println("请输入0或1选择性别");
		}
		return sex_choice;
	}
/*
 * 种族选择函数
 * */
	public int getRace(){
		Scanner sc =new Scanner(System.in);
		System.out.println("请选择种族:0为人类,1为精灵,2为兽人,3为矮人,4为元素");
		race_choice=sc.nextInt();
		while(true){
			if(race_choice>=0&&race_choice<=4){        //验证输入正确性,正确则跳出,否则输出提示。
				break;
			}
			else
				
				System.out.println("请输入0-4的数字选择种族");
		}
		return race_choice;
	  }
	/*
	 * 职业选择函数
	 * */
	  public int getOccuption() {
		Scanner sc=new Scanner(System.in);
		switch(race_choice){
		case 0:
			while(true){
				System.out.println("请选择您的职业:0狂战士,1圣骑士,2刺客,3猎手,4祭司,5巫师");  //人类所选职业
				occuption_choice=sc.nextInt();
				if(occuption_choice>=0&&occuption_choice<=5){      //验证输入正确性,正确则跳出,否则输出提示。
					break;
				}
				else
					System.out.println("请输入0-5之间的数字选择职业!!");
			}
			break;
		case 1:	
			while(true){
				System.out.println("请选择您的职业:2刺客,3猎手,4祭司,5巫师");  //精灵所选职业
				occuption_choice=sc.nextInt();
				if(occuption_choice>=2&&occuption_choice<=5){     //验证输入正确性,正确则跳出,否则输出提示。
					break;
				}
				else
					System.out.println("请输入2-5之间的数字选择职业!!");
			}
			break;
		case 2:
			while(true){
				System.out.println("请选择您的职业:0狂战士,3猎手,4祭司");  //兽人所选职业
				occuption_choice=sc.nextInt();
				if(occuption_choice==0||occuption_choice==3||occuption_choice==4){
					break;                                   //验证输入正确性,正确则跳出,否则输出提示。
				}
				else
					System.out.println("请输入0或3或4来选择职业!!");
			}
			break;
		case 3:
			while(true){
				System.out.println("请选择您的职业:0狂战士,1圣骑士,4祭司");  //矮人所选职业
				occuption_choice=sc.nextInt();
				if(occuption_choice==0||occuption_choice==1||occuption_choice==4){
					break;                                //验证输入正确性,正确则跳出,否则输出提示。
				}
				else
					System.out.println("请输入0或1或4来选择职业!!");
			}
			break;
		case 4:
			while(true){
				System.out.println("请选择您的职业:4祭司,5巫师");  //元素所选职业
				occuption_choice=sc.nextInt();
				if(occuption_choice==4||occuption_choice==5){   //验证输入正确性,正确则跳出,否则输出提示。
					break;
				}
				else
					System.out.println("请输入4或5来选择职业!!");
			}
			break;
		}
		return occuption_choice;
	 }
/*
 * 属性随机分配函数
 * */	  
	public void random(){
			if(occuption_choice==0){                       //人类的属性值分配
				strength=(int)(40+Math.random()*10-5);
				agility=(int)(20+Math.random()*10-5);
				physical=(int)(30+Math.random()*10-5);
				intelligence=(int)(5+Math.random()*10-5);
				wisdom=100-strength-agility-physical-intelligence;
				HP = physical * 20;//生命值为体力的20倍
				MP = (wisdom + intelligence) * 10;//魔法值为智力与智慧的10倍

			}
			else if(occuption_choice==1){                        //圣骑士的属性值分配
				strength=(int)(25+Math.random()*10-5);
				agility=(int)(15+Math.random()*10-5);
				physical=(int)(30+Math.random()*10-5);
				intelligence=(int)(20+Math.random()*10-5);
				wisdom=100-strength-agility-physical-intelligence;
				HP = physical * 20;//生命值为体力的20倍
				MP = (wisdom + intelligence) * 10;//魔法值为智力与智慧的10倍

			}
			else if(occuption_choice==2){                       //刺客的属性值分配
				strength=(int)(20+Math.random()*10-5);
				agility=(int)(35+Math.random()*10-5);
				physical=(int)(20+Math.random()*10-5);
				intelligence=(int)(15+Math.random()*10-5);
				wisdom=100-strength-agility-physical-intelligence;
				HP = physical * 20;//生命值为体力的20倍
				MP = (wisdom + intelligence) * 10;//魔法值为智力与智慧的10倍

			}
			else if(occuption_choice==3){                       //猎手的属性值分配
				strength=(int)(15+Math.random()*10-5);
				agility=(int)(40+Math.random()*10-5);
				physical=(int)(15+Math.random()*10-5);
				intelligence=(int)(10+Math.random()*10-5);
				wisdom=100-strength-agility-physical-intelligence;
				HP = physical * 20;//生命值为体力的20倍
				MP = (wisdom + intelligence) * 10;//魔法值为智力与智慧的10倍

			}
			else if(occuption_choice==4){                       //祭司的属性值分配
				strength=(int)(15+Math.random()*10-5);
				agility=(int)(20+Math.random()*10-5);
				physical=(int)(15+Math.random()*10-5);
				intelligence=(int)(35+Math.random()*10-5);
				wisdom=100-strength-agility-physical-intelligence;
				HP = physical * 20;//生命值为体力的20倍
				MP = (wisdom + intelligence) * 10;//魔法值为智力与智慧的10倍

			}
			else if(occuption_choice==5){                       //巫师的属性值分配
				strength=(int)(10+Math.random()*10-5);
				agility=(int)(20+Math.random()*10-5);
				physical=(int)(10+Math.random()*10-5);
				intelligence=(int)(20+Math.random()*10-5);
				wisdom=100-strength-agility-physical-intelligence;
				HP = physical * 20;//生命值为体力的20倍
				MP = (wisdom + intelligence) * 10;//魔法值为智力与智慧的10倍

			}
		}
	/*
	 * 打印出玩家信息函数
	 * */
		public String outPut(){
			System.out.println("===============================");
			System.out.println("姓名: "+name);
			System.out.println("===============================");
			System.out.println("性别 : "+dsex[sex_choice]);
			System.out.println("===============================");
			System.out.println("种族 : "+drace[race_choice]);
			System.out.println("===============================");
			System.out.println("职业 : "+doccuption[occuption_choice]);
			System.out.println("===============================");
			System.out.println("力量 : "+strength);
			System.out.println("===============================");
			System.out.println("敏捷 : "+agility);
			System.out.println("===============================");
			System.out.println("体力 : "+physical);
			System.out.println("===============================");
			System.out.println("智力 : "+intelligence);
			System.out.println("===============================");
			System.out.println("智慧 : "+wisdom);
			System.out.println("===============================");
			System.out.println("HP: "+HP);
			System.out.println("===============================");
			System.out.println("MP: "+MP);
			System.out.println("===============================");
			return (name+dsex[sex_choice]+drace[race_choice]+doccuption[occuption_choice]+strength+agility+physical+intelligence+wisdom+HP+MP);
		}

/*
 * 将玩家信息储存进文件函数
 * */
public void save(){
	    File file = new File("D://d.txt");			
		try (PrintWriter output = new PrintWriter(file);){
			output.println("姓名: "+name);
			output.println("性别 : "+dsex[sex_choice]);
			output.println("种族 : "+drace[race_choice]);
			output.println("职业 : "+doccuption[occuption_choice]);
			output.println("力量 : "+strength);
			output.println("敏捷 : "+agility);
			output.println("体力 : "+physical);
			output.println("智力 : "+intelligence);
			output.println("智慧 : "+wisdom);
			output.println("HP: "+HP);
			output.println("MP: "+MP);
			output.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();	
		}
		
	}
 
		
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 随着智能手机的普及及其强大的运算能力,越来越多的手机游戏被制作并推出市场。其中,按键手机javarpg游戏是手机游戏类型之一。 按键手机javarpg游戏是指采用Java语言编写的角色扮演游戏,需要使用物理按键进行操作。这一类型的游戏具有丰富的剧情、多样化的任务、多人互动等特点,深受玩家喜爱。 在按键手机javarpg游戏大全中,最经典的莫过于《仙剑奇侠传》系列。该游戏以古代神话传说为背景,收集各种角色、挑战各种副本、完成各种任务等,玩家可以通过游戏中的成长系统提升自己的能力。 除了《仙剑奇侠传》外,还有《仙剑客栈》、《幻想三国志》等精品大作。在这些游戏中,玩家可以选择自己的职业路线,为自己的角色配备最佳装备和技能,与其他玩家进行pk等等。 总之,按键手机javarpg游戏大全涵盖了各种题材和玩法,适合不同喜好的游戏玩家。最重要的是,这些游戏都充满了各种趣味和挑战,给玩家带来了非凡的游戏体验。 ### 回答2: 按键手机Java RPG游戏大全是一个涵盖了各类按键手机游戏的综合性清单。这些游戏主要采用了Java语言开发,以RPG角色扮演)类别为主题。这些游戏在手机上玩家可以通过按键的方式进行控制和操作,使得游戏过程更加流畅和便捷。 这个游戏大全中包含了各种类型的RPG游戏,例如传统的魔幻题材、科幻题材以及历史题材等。每一款游戏都有独特的故事情节和游戏玩法,玩家可以选择自己感兴趣的游戏进行体验。 这些游戏也提供了丰富的角色选择和升级系统,玩家可以根据自己的喜好选择不同的职业和属性进行角色的建立。通过完成任务、战斗和探索,玩家可以获得经验和装备来提升角色的能力和实力。 此外,这些游戏还提供了多人游戏模式,玩家可以与其他玩家一起组队冒险或进行PVP战斗,增加了游戏的互动性和乐趣。 总之,按键手机Java RPG游戏大全是一个为手机用户提供各种类型的RPG游戏的资源清单。玩家可以通过按键的方式控制游戏,体验丰富的故事情节、角色选择和多人模式,带来乐趣和挑战。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值