(3)面向对象开发_java石头剪刀布小游戏大厅之游戏大厅-初学

package 剪刀石头布_小游戏;

import java.util.Scanner;
import java.util.concurrent.ConcurrentSkipListMap;

public class Room {
	//属性
	private String judgeName = "裁判媛";
	private String roomName = "LOL英雄_石头剪刀布PK";
	private int humscore=0;
	private int comscore=0;
	private int round=1;//回合制
	
	
	
	//方法
	
	//实例化人类玩家
	HumanPlayer human = new HumanPlayer();
	//实例化电脑玩家
	ComputorPlayer com = new ComputorPlayer();
	
	//初始化游戏
	public void intigame() {
		Scanner in = new Scanner(System.in);
		//模拟加载 game-loading
		for(int i=0;i<145;i++) {
			System.out.print("*");
			try {
				Thread.sleep(50);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		System.out.println("\n-游戏加载完成-\n");
		//输入用户名和密码
		System.out.print("请输入用户名:");
		human.setyhm(in.next());
		System.out.print("请输入密码:");
		human.setmm(in.next());
		if(yzYhmAndMm()!=true) {
			System.exit(0);
		}
		System.out.println("\n欢迎尊敬的VIP用户: \""+human.getyhm()+" \"进入"+"《"+roomName+"》"+"大厅\n");
		//选择你要对阵的AI玩家
		com.setComName();
		System.out.println("Player:"+"\""+human.getHumName()+"\""+"\t VS \t"+"AI:"+"\""+com.getComName()+"\"");
		//各位人物开场白
		System.out.println("【"+human.getHumName()+"】"+human.humanTalk(1));
		System.out.println("【"+com.getComName()+"】"+com.computorTalk(1));
	}
	
	//验证输入的用户名和密码
	public boolean yzYhmAndMm() {
		boolean yz = false;
		if(human.getyhm().equals("admin") && human.getmm().equals("123456")) {
			yz=true;
		}
		return yz;
	}
	//开始游戏
	public void  startGame() {
		
		Scanner in  = new Scanner(System.in);
		System.out.println("\n\t【选择】");
		System.out.print("石头:1\t剪刀:2\t布:3\n请输入你的决定: ");
		human.setFist(in.nextInt());
	}
	
	//结束游戏
	public void endGame() {
		System.out.println("\n欢迎下次光临LOL英雄 石头-剪刀-布游戏大厅,哈撒给~~~~");
	}
	
	//是否要继续判断游戏
	public boolean chioceGame() {
		boolean continueGame=false;
		Scanner in = new Scanner(System.in);
		char chioce;
		System.out.print("\n是否要继续游戏(y/n)");
		chioce = in.nextLine().charAt(0);
		if(chioce =='n') {
		continueGame = true;	
		}
		return continueGame;
	}
	
	//判断输赢
	public void judge() {//石头-1 ,剪刀-2 ,布-3
		int humfist = human.getFist();
		int comfist = com.getFist();
		if((humfist==2 && comfist==1) || (humfist==3 && comfist==2) || (humfist==1 && comfist==3)) {//机器赢的情况
			//裁判台词
			System.out.println("\n\t【"+judgeName+"】\n"+com.getComName()+"-win"+"\t"+human.getHumName()+"-lose\n");
			//机器赢台词
			System.out.println("【"+com.getComName()+"】"+":"+com.computorTalk(2));
			//玩家输台词
			System.out.println("【"+human.getHumName()+"】"+":"+human.humanTalk(3));
			comscore++;
			if(humscore!=0) {
				humscore--;
			}
		}
		else if(humfist==comfist){
			//裁判台词
			System.out.println("\n\t【"+judgeName+"】"+"\n"+"\t不相上下\n");
		}
		else {
			//裁判台词
			System.out.println("\n\t【"+judgeName+"】\n"+human.getHumName()+"-win"+"\t"+com.getComName()+"-lose\n");
			//机器输台词
			System.out.println("【"+com.getComName()+"】"+com.computorTalk(3));
			//玩家赢台词
			System.out.println("【"+human.getHumName()+"】"+human.humanTalk(2));
			humscore++;
			if(comscore!=0) {
				comscore--;
			}
		}
	}
	
	//得到玩家分数
	public int gethumscore() {
		return humscore;
	}
	
	//得到AI分数
	public int getcomscore() {
		return comscore;
	}
	
	//显示分数菜单
	public void showScore() {
		System.out.print("\n\t\t【计分板】\n"+human.getHumName()+":"+humscore+" score  "+"\t"+com.getComName()+":"+comscore+" score  "+"\n");
		if(humscore>comscore) {
		System.out.println("\n\t长路漫漫,AI只是暂时击败而已");
		}
		else if(humscore == comscore) {
			System.out.println("\n你们竟然打成平手"+"----【"+judgeName+"】"+"/拍桌 /拍桌 /拍桌");
		}
		else
		{
			System.out.println("\n你已被"+com.getComName()+"击败,恭喜"+com.getComName()+"获得本次最终胜利");
		}
	}
	
	//构造
	public Room() {
		//初始化游戏
		intigame();
		while(true) {
		//之后开始游戏
		startGame();
		com.setFist();
		//开始皇城PK,胜者为王
		judge();
		//判断是否继续游戏
		if(chioceGame()) {
			break;
		}
		}
		//显示计分榜
			showScore();
		//结束游戏
		endGame();
	}
}

最后使用Room这个类就行了

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值