package?pokergame;
import?java.util.ArrayList;
import?java.util.Collections;
import?java.util.HashMap;
import?java.util.InputMismatchException;
import?java.util.Scanner;
public?class?bidaxiao?{
static?boolean?flag?=?true;
static?HashMap<Integer,?String>?poker?=?new?HashMap<Integer,?String>();//?放撲克
static?ArrayList<Integer>?xuhao?=?new?ArrayList<Integer>();//?放排序
static?HashMap<Integer,?String>?player?=?new?HashMap<Integer,?String>();
static?String[]?dianshu?=?{?"2",?"A",?"K",?"Q",?"J",?"10",?"9",?"8",?"7",?"6",?"5",?"4",?"3"?};
static?String[]?huase?=?{?"?",?"?",?"?",?"?"?};
static?ArrayList<Integer>?player1?=?new?ArrayList<Integer>();//玩家1的牌
static?ArrayList<Integer>?player2?=?new?ArrayList<Integer>();//玩家2的牌
static?ArrayList<Integer>?number?=?new?ArrayList<Integer>();//存放玩家序號
public?static?void?main(String[]?args)?{
int?index?=?0;
for?(String?ds?:?dianshu)?{
for?(String?hs?:?huase)?{
poker.put(index,?hs?+?ds);
xuhao.add(index);
index++;
}
}//做牌
Collections.shuffle(xuhao);//打亂牌序
System.out.println("------------創(chuàng)建玩家------------");
startgame();//進入游戲
fapai();//開始發(fā)牌
start();//開始游戲比大小
lookpoker(player.get(number.get(0)),?player1,?poker);//看牌
lookpoker(player.get(number.get(1)),?player2,?poker);//看牌
}
public?static?void?startgame()?{
int?i?=?1;
while?(flag)?{
try?{
Scanner?input?=?new?Scanner(System.in);
System.out.println("請輸入第"?+?i?+?"位玩家的ID和姓名:");
System.out.println("輸入ID:");
int?a?=?input.nextInt();
number.add(a);
System.out.println("輸入姓名:");
String?name?=?input.next();
player.put(a,?name);
i++;
}?catch?(InputMismatchException?e)?{
System.out.println("請輸入整數(shù)類型的ID!");
}
if?(i?==?3)?{
flag?=?false;
}
}
for?(Integer?Key?:?player.keySet())?{
System.out.println("----歡迎玩家:"?+?player.get(Key));
}
}
public?static?void?fapai()?{
System.out.println("---------開始發(fā)牌...---------");
for?(int?o?=?0;?o?<?4;?o++)?{
if?(o?%?2?==?0)?{
player1.add(xuhao.get(o));
System.out.println("---玩家:"?+?player.get(number.get(0))?+?"-拿牌");
}?else?if?(o?%?2?==?1)?{
player2.add(xuhao.get(o));
System.out.println("---玩家:"?+?player.get(number.get(1))?+?"-拿牌");
}
}
System.out.println("---------發(fā)牌結束!---------");
}
public?static?void?start()?{
System.out.println("---------開始游戲...---------");
Collections.sort(player1);
Collections.sort(player2);
System.out.println(player.get(number.get(0))?+?"最大的手牌為:"?+?poker.get(player1.get(0)));
System.out.println(player.get(number.get(1))?+?"最大的手牌為:"?+?poker.get(player2.get(0)));
if?(player1.get(0)?>?player2.get(0))?{
System.out.println("---------玩家:"?+?player.get(2)?+?"獲勝!---------");
}?else?{
System.out.println("---------玩家:"?+?player.get(1)?+?"獲勝!---------");
}
}
public?static?void?lookpoker(String?name,?ArrayList<Integer>?playernum,?HashMap<Integer,?String>?poker)?{
System.out.println("玩家各自的手牌為: ");
System.out.print(name?+?":");
for?(Integer?key?:?playernum)?{
String?value?=?poker.get(key);
System.out.print(value?+?"?");
}
System.out.println();
}
}運行效果如下圖
添加回答
舉報
0/150
提交
取消