练习-聊天机器人

        此聊天机器人是通过用户输入的语句识别语句中的关键词进行随机回答回答语库中的语句,小天聊天机器人能够回答用户的"小天","在吗","你好","撒娇","挖掘机","音乐","歌","拜拜","再见","不聊了","退出"语句,同时还可以回答用户"时间"并返回实时时间,还可以和用户玩猜数小游戏,同时添加了斗地主功能(注:斗地主的发牌,洗牌,抢地主都已经完成但是人机玩家的未有完成)。

package xiaotian;

import java.util.*;
//import java.util.logging.*;
import java.text.*;
import java.security.*;
import java.util.ArrayList;
import java.util.Collections;
//import org.apache.http.*;


public class Test {
	public static void main(String[] args){

		//创建控制台输入类
		Scanner input = new Scanner(System.in);

		//创建数据处理类
		DataProcessing data = new DataProcessing();

		//创建回答处理算法类
		Handle handle = new Handle();

		//创建人物对象类
		CharacterObject charact = new CharacterObject();

		/*****************************************************************/	 
		//循环运行系统
		while (true)
		{
			charact.empty();
			charact.me();
			//控制台输入
			String str = input.next();
			//传出数据
			data.keyWord(str);
			data.combination();
			//解析处理算法
			handle.anlysis();

			/*****************************************************************/
		}
	}

}

//数据处理类
class DataProcessing
{

	//询问关键词
	boolean start1;
	boolean start2;

	//你好关键词
	boolean hello1;

	//撒娇关键词
	boolean spoiled1;

	//挖掘机广告语
	boolean excavatingMachinery1;

	//斗地主关键词类
	boolean fightAgainstLandlords1;
	boolean fightAgainstLandlords2;

	//音乐关键词
	boolean music1;
	boolean music2;

	//退出关键词
	boolean quit1;
	boolean quit2;
	boolean quit3;

	//猜数游戏关键词
	boolean guessingGame1;

	//时间关键词
	boolean time1;
	boolean time2;
	boolean time3;

	//数据区块
	public static boolean start;//传输询问关键词识别结果
	public static boolean hello;//传输你好关键词识别结果
	public static boolean music;//传输音乐关键词识别结果
	public static boolean quit ;//传输退出关键词识别结果
	public static boolean guessingGame;//传输猜数游戏关键词识别结果
	public static boolean time;//传输时间关键词识别结果
	public static boolean spoiled;//传输撒娇关键词识别结果
	public static boolean fightAgainstLandlords;//传输斗地主关键词识别结果
	public static boolean excavatingMachinery;//传输挖掘机关键词识别结果


	//关键字识别方法
	public void keyWord(String str)
	{

		//询问关键词识别语块
		//**************************************//
		boolean start1 = str.contains("小天");
		this.start1 = start1;
		boolean start2 = str.contains("在吗");
		this.start2 = start2;
		//**************************************//

		//你好关键词识别语块
		//**************************************//
		boolean hello1 = str.contains("你好");
		this.hello1 = hello1;
		//**************************************//

		//撒娇关键词识别语块
		//**************************************//
		boolean spoiled1 = str.contains("撒娇");
		this.spoiled1 = spoiled1;
		//***************************************//

		//挖掘机关键词识别语块
		//***************************************//
		boolean excavatingMachinery1 = str.contains("挖掘机");
		this.excavatingMachinery1 = excavatingMachinery1;
		//***************************************//

		//斗地主关键词识别语块
		//***************************************//
		boolean fightAgainstLandlords1 = str.contains("斗地主");
		boolean fightAgainstLandlords2 = str.contains("打牌");
		this.fightAgainstLandlords1 = fightAgainstLandlords1;
		this.fightAgainstLandlords2 = fightAgainstLandlords2;
		//***************************************//

		//音乐关键词识别语块
		//**************************************//
		boolean music1 = str.contains("音乐");
		this.music1 = music1;
		boolean music2 = str.contains("歌");
		this.music2 = music2;
		//**************************************//

		//退出关键词识别语块
		//**************************************//
		boolean quit1 = str.contains("拜");
		this.quit1 = quit1;
		boolean quit2 = str.contains("退出");
		this.quit2 = quit2;
		boolean quit3 = str.contains("不聊了");
		this.quit3 = quit3;
		//**************************************//

		//猜数游戏
		//**************************************//
		boolean guessingGame1 = str.contains("猜数");
		this.guessingGame1 = guessingGame1;
		//**************************************//

		//时间
		//*************************************//
		boolean time1 = str.contains("时间");
		this.time1 = time1;
		boolean time2 = str.contains("几点");
		this.time2 = time2;
		boolean time3 = str.contains("报时");
		this.time3 = time3;
		//*************************************//

	}
	//关键词组合判断方法
	public void combination()
	{
		//询问关键词语块组合判断
		boolean start = start1 || start2;
		this.start = start;

		//你好关键词语块组合判断
		boolean hello = hello1 || false;
		this.hello = hello;

		//撒娇关键词语块组合判断
		boolean spoiled = spoiled1 || false;
		this.spoiled = spoiled;

		//挖掘机关键词语块组合判断
		boolean excavatingMachinery = excavatingMachinery1 || false;
		this.excavatingMachinery = excavatingMachinery;

		//斗地主关键词语块组合判断
		boolean fightAgainstLandlords = fightAgainstLandlords1 || fightAgainstLandlords2;
		this.fightAgainstLandlords = fightAgainstLandlords;

		//音乐关键词语块组合判断
		boolean music = music1 || music2;
		this.music = music;

		//退出关键词语块组合判断
		boolean quit = quit1 || quit2 || quit3;
		this.quit = quit;

		//猜数游戏关键词语块组合判断
		boolean guessingGame = guessingGame1 || false;
		this.guessingGame = guessingGame;

		//时间关键词语块组合判断
		boolean time = time1 || time2 || time3;
		this.time = time;
	}
}
//回答处理算法类
class Handle
{
	/**********创建对象区**********/

	Random random = new Random();     /*创建随机数类对象*/
	Answer an = new Answer();         /*创建回答语句语块类对象*/
	CharacterObject character = new CharacterObject();/*创建人物对象*/
	DataProcessing data = new DataProcessing();//创建数据处理类
	/****************************/

	//创建解析算法方法
	public void anlysis()
	{
		/***接受数据区块***/
		boolean music = data.music;//音乐
		boolean quit = data.quit;//退出
		boolean start = data.start;//询问
		boolean guessingGame= data.guessingGame;//猜数游戏
		boolean time = data.time;//时间
		boolean hello = data.hello;//你好
		boolean spoiled = data.spoiled;//撒娇
		boolean excavatingMachinery = data.excavatingMachinery;
		boolean fightAgainstLandlords = data.fightAgainstLandlords;//斗地主
		/****************/
		switch (1)
		{
			case 1:
				//基础语句区******************************/
				/*音乐关键词识别*/
				if (music == true)
				{
					int digit = random.nextInt(an.music.length);
					character.smallDay();
					System.out.println(an.music[digit]);
					break;
				}
				/*退出关键词识别*/
				if (quit == true)
				{
					int digit = random.nextInt(an.music.length);
					character.smallDay();
					System.out.println(an.quit[digit]);
					break;
				}
				/*你好关键词识别*/
				if (hello == true)
				{
					int digit = random.nextInt(an.hello.length);
					character.smallDay();
					System.out.println(an.hello[digit]);
					break;
				}
				/*撒娇关键词识别*/
				if (spoiled == true)
				{
					int digi = random.nextInt(an.spoiled.length);
					character.smallDay();
					System.out.println(an.spoiled[digi]);
					break;
				}
				/*挖掘机关键词识别*/
				if (excavatingMachinery == true)
				{
					int digi = random.nextInt(an.excavatingMachinery.length);
					character.smallDay();
					System.out.println(an.excavatingMachinery[digi]);
					break;
				}
				//扩展功能区*****************************/
				//猜数游戏关键词识别
				if (guessingGame == true)
				{
					character.smallDay();
					int digi = random.nextInt(an.guessingGame1.length);
					System.out.println(an.guessingGame1[digi]);
					//创建猜数游戏算法类
					GuessingGame guessing = new GuessingGame();
					guessing.rule();
					guessing.algorithm();
					break;
				}
				/*时间关键词识别*/
				if (time == true)
				{
					character.smallDay();
					int digi = random.nextInt(an.time.length);
					System.out.println(an.time[digi]);
					//创建时间类
					Time timeDate = new Time();
					timeDate.date();
					break;
				}
				/*斗地主关键词识别*/
				if (fightAgainstLandlords == true)
				{
					START_GAME START_GAME = new START_GAME();
					START_GAME.START_GAME();
					break;

				}
				//低级处理关键词区**************************/
				/*询问关键词识别*/
				if (start == true)
				{
					int digit = random.nextInt(an.start.length);
					character.smallDay();
					System.out.println(an.start[digit]);
					break;
				}
			default:
				/*没有识别到关键词*/
				int digit = random.nextInt(an.no.length);
				character.smallDay();
				System.out.println(an.no[digit]);
		}
	}
}
//回答语句语块
class Answer
{
	//基础回答语句
	String music[] = {"想听什么音乐🎶","哦,好啊👌","播放什么呢🎧","我喜欢听邓紫棋的歌,你呢😃"};  /*音乐回答语块*/

	String hello[] = {"你好啊,我是小天","你好*٩(๑´∀`๑)ง"};/*你好回答语块*/

	String spoiled[] = {"宝宝生气了😡","气死宝宝了😠","宝宝好开心啊😋","宝宝要抱抱(ˊ˘ˋ*)♡","亲亲^3^"};/*撒娇回答语块*/

	String excavatingMachinery[] = {"中国山东找找蓝翔😂😂","山东蓝翔😎"};

	String quit[] = {"嗯,再见😃","拜拜ノBye~!😋","别忘了我啊,拜👌"};   /*退出回答语块*/

	String start[] = {"你好啊!😃","嗯,在的!😋","想我了吗😍"};  /*询问回答语块*/

	String no[] = {"你说什么,我没明白🙄","能再说一遍吗😳","没听清楚😭"};     /*没有找到关键词默认回答语块*/

	//扩展功能回答语句
	/******猜数游戏******/
	String guessingGame1[] = {"准备好了吗,要开始了","开始了哦"};//开始语句
	String guessingGame2[] = {"有点大了哦😃","您猜的数太大了,再猜猜😉"};//数大了回答语句
	String guessingGame3[] = {"有点小了哦😃","您猜的数太小了,再猜猜😉"};//数小了回答语句
	String guessingGame4[] = {"太棒了,猜对了😘","你真厉害👍"};
	//斗地主回答语句
	String pokerGame1[] = {"准备好了吗,开始了","开始了哦","游戏开始"};
	/******时间**********/
	String time[] = {"现在的时间是","亲^3^,以下是中国区时间","好的👌,现在给您报时"};

}
//人物对象
class CharacterObject
{
	public void empty()
	{
		System.out.println();
	}
	public void me()
	{
		System.out.print("我:");
	}
	public void smallDay()
	{
		System.out.print("小天:");
	}
	public void tips()
	{
		System.out.print("小天提示:");
	}
	public void erNi()
	{
		System.out.print("二妮:");
	}
}
/*********************************************************************/
//猜数游戏算法类
class GuessingGame
{
	//生成人物对象类
	CharacterObject chara = new CharacterObject();
	//游戏规则
	public void rule()
	{
		chara.tips();
		System.out.println("系统已经随机生成一个0~99的整数,猜猜看是多少,你只有10次机会哦,加油^0^~");
	}
	//生成游戏算法
	public void algorithm()
	{
		/************************************/
		//创建随机数类
		Random random = new Random();
		//创建随机数
		int randomNumber = random.nextInt(100);
		/************************************/
		//创建控制台输入类
		Scanner input = new Scanner(System.in);
		/****************************?*******/
		//创建回答语句语块类
		Answer an = new Answer();
		for (int i = 1;i <= 10;i++)
		{
			//控制台输入
			chara.tips();
			System.out.println("您的数值是:");
			chara.me();
			int str = input.nextInt();
			//判断数值是否在可选范围内
			while (true)
			{
				if (str > 0)
				{
					if (str < 100)
					{
						//数值在可选择范围内
						break;
					}
					else
					{
						//数值不在可选择范围内
						chara.tips();
						System.out.println("亲您的数值不在可选性择范围内,请重新输入");
						System.out.println("您的数值是");
						chara.me();
						str = input.nextInt();
					}
				}
				else
				{
					//数值不在可选择范围内
					chara.tips();
					System.out.println("亲您的数值不在可选性择范围内,请重新输入");
					System.out.println("您的数值是");
					chara.me();
					str = input.nextInt();
				}
			}
			if (str < randomNumber)
			{
				if (i != 10)
				{
					chara.tips();
					int digit = random.nextInt(an.guessingGame3.length);
					System.out.println(an.guessingGame3[digit]);
				}
				else
				{
					chara.tips();
					System.out.println("抱歉游戏失败!");
				}
			}
			if (str > randomNumber)
			{
				if (i != 10)
				{
					chara.tips();
					int digit = random.nextInt(an.guessingGame2.length);
					System.out.println(an.guessingGame2[digit]);
				}
				else
				{
					chara.tips();
					System.out.println("抱歉游戏失败!");
				}
			}
			if (str == randomNumber)
			{
				if (i != 10)
				{
					chara.tips();
					int digit = random.nextInt(an.guessingGame4.length);
					System.out.println(an.guessingGame4[digit]);
					break;
				}
				else
				{
					chara.tips();
					System.out.println("抱歉游戏失败!");
				}
			}
		}

	}
}
/*********************************************************************/
//时间类
class Time
{
	//创建时间类
	Date date = new Date();
	public void date()
	{
		DateFormat df1 = new SimpleDateFormat("yyyy年MM月dd日  hh时mm分ss秒  EE", Locale.CHINA);
		System.out.println(df1.format(date));
	}
}
/*********************************************************************/
//***********斗地主*********//
//初始化数据
class InitializationData
{
	//初始化数据模块
	TreeSet<Integer> initializationData_1 = new TreeSet<Integer>();
	ArrayList<String> initializationData_2= new ArrayList<String>();

	GamePlayer gamePlayer = new GamePlayer();//玩家类
	TransmissionPoker transmissionPoker = new TransmissionPoker();//创建传输数据类
	public void initializationData()
	{
		//初始化提示语
		System.out.println("初始化数据中.......................");
		System.out.println("初始化数据中.......................");
		System.out.println("初始化数据中.......................");
		System.out.println("初始化进度:     0%");
		//储存扑克牌索引初始化
		try
		{
			for (Integer i: gamePlayer.gamePlayer_1)
			{
				initializationData_1.add(i);
			}
			for (Integer i : initializationData_1)
			{
				gamePlayer.gamePlayer_1.remove(i);
			}
			System.out.println("初始化进度:     11.11%");
		}
		catch (Exception e )
		{
			System.out.println("初始化数据失败!!!");
		}
		try
		{
			for (Integer i: gamePlayer.gamePlayer_2)
			{
				initializationData_1.add(i);
			}
			for (Integer i : initializationData_1)
			{
				gamePlayer.gamePlayer_2.remove(i);
			}
			System.out.println("初始化进度:     23%");
		}
		catch (Exception e )
		{
			System.out.println("初始化数据失败!!!");
		}
		try
		{
			for (Integer i: gamePlayer.gamePlayer_3)
			{
				initializationData_1.add(i);
			}
			for (Integer i : initializationData_1)
			{
				gamePlayer.gamePlayer_3.remove(i);
			}
			System.out.println("初始化进度:     24.11%");
		}
		catch (Exception e )
		{
			System.out.println("初始化数据失败!!!");
		}
		try
		{
			for (Integer i: gamePlayer.dipai)
			{
				initializationData_1.add(i);
			}
			for (Integer i : initializationData_1)
			{
				gamePlayer.dipai.remove(i);
			}
			System.out.println("初始化进度:     50%");
		}
		catch (Exception e )
		{
			System.out.println("初始化数据失败!!!");
		}
		//储存扑克牌初始化
		try
		{
			for (String i : gamePlayer.gamePlayer_4)
			{
				initializationData_2.add(i);
			}
			for (String i : initializationData_2)
			{
				gamePlayer.gamePlayer_4.remove(i);
			}
			System.out.println("初始化进度:     61.11%");
		}
		catch (Exception e )
		{
			System.out.println("初始化数据失败!!!");
		}
		try
		{
			for (String i : gamePlayer.gamePlayer_5)
			{
				initializationData_2.add(i);
			}
			for (String i : initializationData_2)
			{
				gamePlayer.gamePlayer_5.remove(i);
			}
			System.out.println("初始化进度:     70%");
		}
		catch (Exception e )
		{
			System.out.println("初始化数据失败!!!");
		}
		try
		{
			for (String i : gamePlayer.gamePlayer_6)
			{
				initializationData_2.add(i);
			}
			for (String i : initializationData_2)
			{
				gamePlayer.gamePlayer_6.remove(i);
			}
			System.out.println("初始化进度:     87.5%");
		}
		catch (Exception e )
		{
			System.out.println("初始化数据失败!!!");
		}
		try
		{
			for (String i : gamePlayer.dipai_p)
			{
				initializationData_2.add(i);
			}
			for (String i : initializationData_2)
			{
				gamePlayer.dipai_p.remove(i);
			}
			System.out.println("初始化进度:     93%");
		}
		catch (Exception e )
		{
			System.out.println("初始化数据失败!!!");
		}
		//带索引扑克牌初始化

		//索引对象初始化
		try
		{
			for (Integer i: transmissionPoker.lndexCard)
			{
				initializationData_1.add(i);
			}
			for (Integer i : initializationData_1)
			{
				transmissionPoker.lndexCard.remove(i);
			}
			System.out.println("初始化进度:     100%");
		}
		catch (Exception e )
		{
			System.out.println("初始化数据失败!!!");
		}
		System.out.println("初始化数据成功!!!");
	}
}

/*身份牌类*/
class Identity
{
	RobLandlord robLandlord = new RobLandlord();//创建抢地主类

	//平民身份
	public void identity(int gamePlayer)
	{
		switch (gamePlayer)
		{
			case 1:
				System.out.print("(地主)");
				break;
			case 2:
				System.out.print("(平民)");
		}
	}
	public void aHand()
	{
		System.out.print("(底牌)");
	}
}
//玩家类
class GamePlayer
{
	//存储扑克牌索引
	public static TreeSet<Integer> gamePlayer_1 = new TreeSet<Integer>();//玩家1
	public static TreeSet<Integer> gamePlayer_2 = new TreeSet<Integer>();//玩家2
	public static TreeSet<Integer> gamePlayer_3 = new TreeSet<Integer>();//玩家3
	public static TreeSet<Integer> dipai = new TreeSet<Integer>();//底牌
	//存储扑克牌
	public static ArrayList<String> gamePlayer_4 = new ArrayList<String>();//玩家1
	public static ArrayList<String> gamePlayer_5 = new ArrayList<String>();//玩家2
	public static ArrayList<String> gamePlayer_6 = new ArrayList<String>();//玩家3
	public static ArrayList<String> dipai_p = new ArrayList<String>();//底牌
}
//生成扑克牌
class Poker
{
	//创建扑克
	String poker_p[] = {"3","3","3","3","4","4","4","4","5","5","5","5","6","6","6","6","7","7","7","7","8","8","8","8","9","9","9","9","S","S","S","S","J","J","J","J","Q","Q","Q","Q","K","K","K","K","A","A","A","A","2","2","2","2","小","大"};
	//索引扑克
	String poker[] = {"3","4","5","6","7","8","9","S","J","Q","K","A","2","小王","大王"};
}
//创建传输数据
class TransmissionPoker
{
	//*******************************************//
	//创建扑克
	Poker poker = new Poker();
	//创建带索引的扑克
	public static HashMap<Integer,String> allCards = new HashMap<Integer,String>();
	//创建索引集合对象
	public static ArrayList<Integer> lndexCard =new ArrayList<Integer>();
	//******************************************//
	//装牌
	public void packUp()
	{
		//创建索引值
		int index = 0;

		for (String tpoker_p :poker.poker_p)
		{
			//传输索引
			allCards.put(index, tpoker_p);
			//记录索引
			lndexCard.add(index);
			//索引递增
			index++;
		}
	}
}
//洗牌
class ShuffleTheCards
{
	TransmissionPoker transmissionPoker =new TransmissionPoker();
	public void ShuffleTheCards()
	{
		//洗牌(打乱索集合中的元素)
		Collections.shuffle(transmissionPoker.lndexCard);//洗牌一次
		Collections.shuffle(transmissionPoker.lndexCard);//洗牌两次
		Collections.shuffle(transmissionPoker.lndexCard);//洗牌三次
		Collections.shuffle(transmissionPoker.lndexCard);//洗牌四次
		Collections.shuffle(TransmissionPoker.lndexCard);//洗牌五次
	}

}
//发牌器
class LicensingDevice
{
	//创建玩家
	GamePlayer gamePlayer = new GamePlayer();
	//传输数据
	TransmissionPoker transmissionPoker = new TransmissionPoker();
	//洗牌
	ShuffleTheCards shuffleTheCards = new ShuffleTheCards();
	//****************************************************//
	public void licensingDevice()
	{
		for (int i = 0;i < transmissionPoker.lndexCard.size();i++)
		{
			if (i >= transmissionPoker.lndexCard.size() - 3)
			{
				//预留底牌
				gamePlayer.dipai.add(transmissionPoker.lndexCard.get(i));
			}
			else if (i % 3 == 0)
			{
				//发牌给玩家1
				gamePlayer.gamePlayer_1.add(transmissionPoker.lndexCard.get(i));
			}
			else if (i % 3 == 1)
			{
				//发牌给玩家2
				gamePlayer.gamePlayer_2.add(transmissionPoker.lndexCard.get(i));
			}
			else
			{
				//发牌给玩家3
				gamePlayer.gamePlayer_3.add(transmissionPoker.lndexCard.get(i));
			}
		}
		/**************************************************/
		//玩家1的牌
		for (Integer i : gamePlayer.gamePlayer_1)
		{
			gamePlayer.gamePlayer_4.add(transmissionPoker.allCards.get(i));
		}
		//玩家2的牌
		for (Integer i : gamePlayer.gamePlayer_2)
		{
			gamePlayer.gamePlayer_5.add(transmissionPoker.allCards.get(i));
		}
		//玩家3的牌
		for (Integer i : gamePlayer.gamePlayer_3)
		{
			gamePlayer.gamePlayer_6.add(transmissionPoker.allCards.get(i));
		}
		//底牌
		for (Integer i : gamePlayer.dipai)
		{
			gamePlayer.dipai_p.add(transmissionPoker.allCards.get(i));

		}
	}
}
//抢地主提示
class Tips
{
	public void tips1()
	{
		System.out.println("提示语音:  是否抢地主     是1    否2");
	}
}
//抢地主
class RobLandlord
{

	Tips tips = new Tips();//创建提示
	GamePlayer gamePlayer = new GamePlayer();
	LicensingDevice LicensingDevice = new LicensingDevice();//创建发牌器
	Random random = new Random();     /*创建随机数类对象*/
	Scanner input = new Scanner(System.in);//创建控制台输入
	//初始化身份牌


	public static int gamePlayer_1 = 2;//定义玩家1的身份
	public static int gamePlayer_2 = 2;//定义玩家2的身份
	public static int gamePlayer_3 = 2;//定义玩家3的身份


	public void robLandlord()
	{
		tips.tips1();//提示
		int str = input.nextInt();//输入
		switch (str)
		{
			case 1:
				//把底牌给玩家1
				for (String i : gamePlayer.dipai_p)
				{
					gamePlayer.gamePlayer_4.add(i);
				}
				this.gamePlayer_1 = 1;//切换身份牌
				System.out.println("我是地主牌");
				break;
			case 2:
				//选择地主
				int choice = random.nextInt(2);
				switch (choice)
				{
					case 0:
						//把底牌给玩家2
						for (String i : gamePlayer.dipai_p)
						{
							gamePlayer.gamePlayer_5.add(i);
						}
						this.gamePlayer_2 = 1;
						System.out.println("小天是地主牌");
						break;
					case 1:
						for (String i : gamePlayer.dipai_p)
						{
							gamePlayer.gamePlayer_6.add(i);
						}
						this.gamePlayer_3 = 1;
						System.out.println("二妮是地主牌");
						break;
				}
				break;
		}
	}

}
//开始游戏类
class START_GAME
{
	CharacterObject CharacterObject = new CharacterObject();//创建人物对象
	Random random = new Random();//创建随机数
	Answer Answer = new Answer();//基础回答语句
	public void START_GAME()
	{
		/***************************************************/
		/*初始化*/
		InitializationData initializationData = new InitializationData();//创建初始化
		initializationData.initializationData();
		/*开始提示语*/
		CharacterObject.smallDay();
		int digi = random.nextInt(Answer.pokerGame1.length);//生成随机数
		System.out.println(Answer.pokerGame1[digi]);//打印随机提示语
		/***************************************************/
		/*传输数据*/
		TransmissionPoker transmissionPoker = new TransmissionPoker();//创建传输数据
		transmissionPoker.packUp();//调用
		/***************************************************/
		/*洗牌*/
		ShuffleTheCards shuffleTheCards = new ShuffleTheCards();//洗牌
		shuffleTheCards.ShuffleTheCards();//调用洗牌
		/***************************************************/
		/*发牌*/
		LicensingDevice licensingDevice = new LicensingDevice();//创建发牌器
		licensingDevice.licensingDevice();//调用
		/***************************************************/
		/*打牌*/
		MyPlayCards mYplayCards = new MyPlayCards();//创建发牌类
		mYplayCards.playCards();//调用


	}
}
//我出牌类
class MyPlayCards
{


	GamePlayer gamePlayer = new GamePlayer();//创建玩家类
	CharacterObject characterObject = new CharacterObject();//人物对象类
	RobLandlord robLandlord = new RobLandlord();//创建抢地主
	Identity identity = new Identity();//身份牌

	/********//*数据块*/
	boolean number1;
	boolean number2;
	boolean number3;
	/********//*******/
	public void playCards()
	{
		/****************************************************/
		/*打印我的牌*/
		identity.identity(robLandlord.gamePlayer_1);//身份牌
		System.out.println(gamePlayer.gamePlayer_4);
		/****************************************************/
		/*抢地主*/
		robLandlord.robLandlord();//调用

		/****************************************************/
		//确认出牌顺序
		Order order = new Order();
		order.order();
		/****************************************************/
		Use use = new Use();

		while (true)
		{
			//查找一手牌
			/*玩家1*/
			switch (order.order1)
			{
				case 1:
					use.use();
					number1 = gamePlayer.gamePlayer_4.isEmpty();
					break;
			}
			if (number1 == true)
			{
				System.out.println("我的牌已经出完,我胜出");
				break;
			}
			/*玩家2*/
			switch (order.order2)
			{
				case 1:
					use.manMachine_1();
					number2 = gamePlayer.gamePlayer_5.isEmpty();
					break;
			}
			if (number2 == true)
			{
				System.out.println("小天的牌已经出完,小天胜出");
				break;
			}
			/*玩家3*/
			switch (order.order3)
			{
				case 1:
					use.manMachine_2();
					number3 = gamePlayer.gamePlayer_6.isEmpty();
					break;
			}
			if (number3 == true)
			{
				System.out.println("二妮的牌已经出完,二妮胜出");
				break;
			}
			//查找二手牌
			/*玩家1*/
			switch (order.order1)
			{
				case 2:
					use.use();
					number1 = gamePlayer.gamePlayer_4.isEmpty();
					break;
			}
			if (number1 == true)
			{
				System.out.println("我的牌已经出完,我胜出");
				break;
			}
			/*玩家2*/
			switch (order.order2)
			{
				case 2:
					use.manMachine_1();
					number2 = gamePlayer.gamePlayer_5.isEmpty();
					break;
			}
			if (number2 == true)
			{
				System.out.println("小天的牌已经出完,小天胜出");
				break;
			}
			/*玩家3*/
			switch (order.order3)
			{
				case 2:
					use.manMachine_2();
					number3 = gamePlayer.gamePlayer_6.isEmpty();
					break;
			}
			if (number3 == true)
			{
				System.out.println("二妮的牌已经出完,二妮胜出");
				break;
			}
			//查找三手牌
			/*玩家1*/
			switch (order.order1)
			{
				case 3:
					use.use();
					number1 = gamePlayer.gamePlayer_4.isEmpty();
					break;
			}

			if (number1 == true)
			{
				System.out.println("我的牌已经出完,我胜出");
				break;
			}
			/*玩家2*/
			switch (order.order2)
			{
				case 3:
					use.manMachine_1();
					number2 = gamePlayer.gamePlayer_5.isEmpty();
					break;
			}
			if (number2 == true)
			{
				System.out.println("小天的牌已经出完,小天胜出");
				break;
			}
			/*玩家3*/
			switch (order.order3)
			{
				case 3:
					use.manMachine_2();
					number3 = gamePlayer.gamePlayer_6.isEmpty();
					break;
			}

			if (number3 == true)
			{
				System.out.println("二妮的牌已经出完,二妮胜出");
				break;
			}
		}


	}
}
//用户出牌
class Use
{
	int poker_1;
	int poker_2;
	int poker_3;
	/***********/
	Random random = new Random();//随机数
	Eliminate eliminate = new Eliminate();//清除数据
	CharacterObject CharacterObject = new CharacterObject();//人物对象
	Scanner input = new Scanner(System.in);//输入
	GamePlayer gamePlayer = new GamePlayer();//玩家类
	RobLandlord robLandlord = new RobLandlord();//抢地主类
	Transformation transformation = new Transformation();//转换数据
	Identity identity = new Identity();//身份牌
	public static ArrayList<String> out_1= new ArrayList<String>();//存储
	public static ArrayList<String> out_2 = new ArrayList<String>();//存储桥
	//人
	public void use()
	{

		System.out.println();
		identity.identity(robLandlord.gamePlayer_1);//打印身份牌
		System.out.println(gamePlayer.gamePlayer_4);
		/******************************************/
		/***********************************/
		System.out.println("请选择要出的牌");
		CharacterObject.me();
		String str_1 = input.next();//选择要出的牌
		System.out.println("出牌1    不出2");
		int str_2 = input.nextInt();//是否出牌
		switch (str_2)//判断是否出牌
		{
			case 1:
			    int s = 0;
				int size = str_1.length();
				for (int i = 0 ; i < size;i++)
				{
				    char brand = str_1.charAt(i);//分离字符串
					String brand_s = String.valueOf(brand);//转换数据类型
					if (gamePlayer.gamePlayer_4.contains(brand_s))//是否属于手牌
					{
					}
					else
					{
						s = 1;
						System.out.println("出牌错误,下家出牌");
						break;
					}
					out_2.add(brand_s);//转换出的牌
					gamePlayer.gamePlayer_4.remove(brand_s);//移除出的牌
				}
				eliminate.eliminate_1(out_1);//初始化数据1
				transformation.transformation(out_1, out_2);//转换数据
				eliminate.eliminate_2(out_2);//初始化数据2
				if (s == 1)
				{
					break;
				}

		}
	}
	//人机
	public void manMachine_1()
	{
		//人机出牌
		System.out.println();
		identity.identity(robLandlord.gamePlayer_2);
		CharacterObject.smallDay();
		System.out.println("小天出牌     过!");
	}
	public void manMachine_2()
	{
		//人机出牌
		System.out.println();
		identity.identity(robLandlord.gamePlayer_3);
		CharacterObject.erNi();
		System.out.println("二妮出牌    过!");
	}

}
//清除数据
class Eliminate
{
	ArrayList<String> initializationData= new ArrayList<String>();
	public void eliminate_1(ArrayList<String> out_1)
	{
		for (String i: out_1)
		{
			initializationData.add(i);
		}
		for (String i : initializationData)
		{
			out_1.remove(i);
		}
	}
	public void eliminate_2(ArrayList<String> out_2)
	{
		for (String i: out_2)
		{
			initializationData.add(i);
		}
		for (String i : initializationData)
		{
			out_2.remove(i);
		}
	}
}
//转换数据
class Transformation
{
	public void transformation(ArrayList<String> out_1, ArrayList<String> out_2)
	{

		for (String i: out_2)
		{
			out_1.add(i);
		}
	}
}


//出牌顺序
class Order
{
	public static int order1;//玩家1
	public static int order2;//玩家2
	public static int order3;//玩家3
	RobLandlord robLandlord = new RobLandlord();
	public void order()
	{
		if (robLandlord.gamePlayer_1 == 1)
		{
			int order1 = 1;//玩家1[一手]
			this.order1 = order1;
			int order2 = 2;//玩家2[二手]
			this.order2 = order2;
			int order3 = 3;//玩家3[三手]
			this.order3 = order3;
		}
		else
		{
			if (robLandlord.gamePlayer_2 == 1)
			{
				int order2 = 1;//玩家2[一手]
				this.order2 = order2;
				int order3 = 2;//玩家3[二手]
				this.order3 = order3;
				int order1 = 3;//玩家1[三手]
				this.order1 = order1;
			}
			else
			{
				if (robLandlord.gamePlayer_3 == 1)
				{
					int order3 = 1;//玩家3[一手]
					this.order3 = order3;
					int order1 = 2;//玩家1[二手]
					this.order1 = order1;
					int order2 = 3;//玩家2[三手]
					this.order2 = order2;
				}

			}
		}
	}
}

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>