Java小游戏《皇帝后妃》

package com.yongsheng.second;

import java.util.Calendar;
import java.util.Scanner;
/**
 * 控制台版本
 * @author Yongsheng
 * @version 1.0
 * 创建时间:2018年5月20日 下午2:26:24
 */
public class EmperorTest {
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		int count = 5;//表示存放人物个数
		int currDay = 0; //表示当前的天数
		final int DAY_COUNT = 10; //一共的天数
		int choice; //用户的选择
		int index = Integer.MIN_VALUE; //索引
		String[] names = {"小乔","西施","貂蝉","不知火舞","陈圆圆",""};
		String[] levelNames = {"贵人","嫔妃","贵妃","皇贵妃","皇后",""};
		int level[] = {0,1,0,0,0,-1};
		String name;
		int loves[] = {100,100,100,100,100,-1};
		do{
			++currDay;
			System.out.println("**************************");
			System.out.println("游戏进行第"+currDay+"天");
			System.out.println("**************************");
			System.out.println("1、皇帝下旨选妃!\t\t(增加)");
		    System.out.println("2、翻牌宠幸\t\t\t(修改状态)");
		    System.out.println("3、打入冷宫!\t\t(删除)");
		    System.out.println("4、朕的爱妃呢?\t\t(查找)");
			System.out.printf("-----------------------\n");
			System.out.printf("姓名\t等级\t好感度\n");
		    System.out.printf("-----------------------\n");
		    for(int i = 0; i < count; i++){
		        System.out.printf("%s\t%s\t%d\n", names[i], levelNames[level[i]], loves[i]);

		    }
		    System.out.println("请陛下选择:");
			choice = input.nextInt();
			switch (choice) {
			case 1:  //新增妃子数量  其它好感度-10
				if(count >= level.length){
					System.out.println("\n人数已经满了,陛下还是请注意身体");
				break;
				}
				System.out.println("请陛下填上自己喜欢的娘娘姓名:");
				name = input.next();
				names[count] = name;
				level[count] = 0;
				loves[count] = 100;
				System.out.println("新增妃子后,其它人的好感度-10\n");
				for (int i = 0; i < count; i++) {
					loves[i] -= 10;
				}
				count ++;
				break;
			case 2: //翻牌宠幸  宠幸的妃子好感度+20  其他-10
				System.out.println("请陛下输入想要宠幸的妃子:");
				name = input.next();
				for (int i = 0; i < count; i++) {
					 if(name.equals(names[i])){
						 index = i;
						 continue;
					 }
					loves[i] -= 10;
				}
				if(index == Integer.MIN_VALUE){
					System.out.println("宫中没有这个姓名!!!");
				}
				else{
					loves[index] += 20;
					if(level[index] == 4){
						level[index] = 4;
					}else{
						level[index] ++;
					}
					System.out.println(names[index]+"的等级提升为"+levelNames[level[index]]);
					System.out.println("其它娘娘的好感度-10");
				}
				 index = Integer.MIN_VALUE;
				 break;
			case 3:  //打入冷宫   删除操作  其它妃子的好感度+10
				System.out.println("陛下请输入要打入冷宫的娘娘的姓名");
				name = input.next();
				for (int i = 0; i < count; i++) {
					if(name.equals(names[i])){
						index = i;
						break;
					}
				}
				if(index == Integer.MIN_VALUE){
					System.out.println("真是虚惊一场");
					break;
				}
				for (int i = index; i < count-1; i++) {
					names[i] = names[i+1];
					level[i] = level[i+1];
					loves[i] = loves[i+1];
				}
				count -- ; //总人数减一
				index = Integer.MIN_VALUE; //方便下次使用
				System.out.println(name+"被打入冷宫,而其它的娘娘好感度+10");
				for (int i = 0; i < count; i++) {
					loves[i] += 10;
				} 
				break;
			case 4://根据姓名查找   好感度+10
				System.out.println("请陛下输入要查找的姓名:");
				name = input.next();
				for (int i = 0; i < count; i++) {
					if(name.equals(names[i])){
						System.out.println("由于陛下十分喜欢"+name+",多以其好感度+10");
						loves[i] += 10;
						break;
					}
				} 
				break;
			 
			}
			System.out.printf("-----------------------\n");
			System.out.printf("姓名\t等级\t好感度\n");
		    System.out.printf("-----------------------\n");
		    for(int i = 0; i < count; i++){
		        System.out.printf("%s\t%s\t%d\n", names[i], levelNames[level[i]], loves[i]);

		    }
		    for (int i = 0; i <count; i++) {
				if(loves[i] < 60){
					System.out.println("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
					 System.out.printf("由于妃子们的好感度低于60,决定组队刷皇上去!!\n");
			            //时间函数的固定用法
			            Calendar cal = Calendar.getInstance();	 //日历类          
			            System.out.printf("公元%d年%d月%d日,皇帝卒!共执政%d天\n", 
			            		cal.get(Calendar.YEAR), 
			            		cal.get(Calendar.MONTH) + 1, 
			            		cal.get(Calendar.DATE), 
			            		currDay
			            );
			            System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
			            System.exit(0);
				}
			}
		    
		    
		    
		}while(currDay < DAY_COUNT);
		
		
		
		
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值