主頁 >  其他 > 練習-聊天機器人

練習-聊天機器人

2021-12-20 08:54:09 其他

此聊天機器人是通過用戶輸入的陳述句識別陳述句中的關鍵詞進行隨機回答回答語庫中的陳述句,小天聊天機器人能夠回答用戶的"小天","在嗎","你好","撒嬌","挖掘機","音樂","歌","拜拜","再見","不聊了","退出"陳述句,同時還可以回答用戶"時間"并回傳實時時間,還可以和用戶玩猜數小游戲,同時添加了斗地主功能(注:斗地主的發牌,洗牌,搶地主都已經完成但是人機玩家的未有完成),

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;
				}

			}
		}
	}
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/386732.html

標籤:其他

上一篇:Unity制作一套自定義選擇題試卷

下一篇:狀態模式——紙牌游戲

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more