为了账号安全,请及时绑定邮箱和手机立即绑定

自己构思出来的方法,可能比较绕

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Collections;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Scanner;


public class TestPuke {

List <Puke> testList;

List <Puke> newTestList=new ArrayList<Puke>();

Scanner console=new Scanner(System.in);

Map<Integer,Player> ms=new HashMap<Integer,Player>();

public TestPuke() {

testList=new ArrayList<Puke>();

}

public void testListAdd() {

System.out.println("---------------创建扑克牌------");

Puke []puke = {new Puke("方片","2"),new Puke("方片","3"),new Puke("方片","4"),

new Puke("方片","5"),new Puke("方片","6"),new Puke("方片","7"),new Puke("方片","8"),

new Puke("方片","9"),new Puke("方片","10"),new Puke("方片","J"),new Puke("方片","Q"),

new Puke("方片","K"),new Puke("方片","A"),new Puke("黑桃","2"),new Puke("黑桃","3"),new Puke("黑桃","4"),

new Puke("黑桃","5"),new Puke("黑桃","6"),new Puke("黑桃","7"),new Puke("黑桃","8"),new Puke("黑桃","9"),new Puke("黑桃","10"),new Puke("黑桃","J"),new Puke("黑桃","Q"),

new Puke("黑桃","K"),new Puke("黑桃","A"),new Puke("红桃","2"),new Puke("红桃","3"),new Puke("红桃","4"),

new Puke("红桃","5"),new Puke("红桃","6"),new Puke("红桃","7"),new Puke("红桃","8"),

new Puke("红桃","9"),new Puke("红桃","10"),new Puke("红桃","J"),new Puke("红桃","Q"),

new Puke("红桃","K"),new Puke("红桃","A"),new Puke("梅花","2"),new Puke("梅花","3"),new Puke("梅花","4"),

new Puke("梅花","5"),new Puke("梅花","6"),new Puke("梅花","7"),new Puke("梅花","8"),

new Puke("梅花","9"),new Puke("梅花","10"),new Puke("梅花","J"),new Puke("梅花","Q"),

new Puke("梅花","K"),new Puke("梅花","A") };

testList.addAll(Arrays.asList(puke));

System.out.println("------------扑克牌创建成功------------");

System.out.print("扑克牌为:");

for(Puke p:testList) {

System.out.print(p.floor+p.pokeID);

System.out.println();

}System.out.println("---------开始洗牌-------------");

Collections.shuffle(testList);

System.out.println("---------洗牌结束-------------");

System.out.println("---------创建玩家-------------");



}

public void testPlayer() {

    

for(int i=0;i<2;) {

try{System.out.println("请输入第"+(i+1)+"位玩家的id和姓名:");

System.out.println("输入ID");

int ID=console.nextInt();

System.out.println("输入玩家姓名:");

String name=console.next();

ms.put(ID, new Player(ID,name));

i++;}

catch(Exception e) {

System.out.println("输入有误,请重新输入");

console = new Scanner(System.in);

continue;

}

}


}

public void goGo() {

Player play1=ms.get(1);

Player play2=ms.get(2);

System.out.println("欢迎"+play1.name);

System.out.println("欢迎"+play2.name);

for(int i=0;i<4;i++) {

if(i%2==0) {

System.out.println("玩家:"+play1.name+"抓牌");

play1.playOfPuke.add(testList.get(i));}

else {

System.out.println("玩家:"+play2.name+"抓牌");

play2.playOfPuke.add(testList.get(i));

}

newTestList.add(testList.get(i));

}System.out.println("-------------------------发牌结束");

System.out.println("-------------------------开始游戏");

Collections.sort(play1.playOfPuke);

System.out.println("玩家"+play1.name+"的最大手牌为"+play1.playOfPuke.get(0).floor+play1.playOfPuke.get(0).pokeID);

Collections.sort(play2.playOfPuke);

System.out.println("玩家"+play1.name+"的最大手牌为"+play2.playOfPuke.get(0).floor+play2.playOfPuke.get(0).pokeID);

Collections.sort(newTestList);

if(!(play1.playOfPuke.get(0).pokeID.equals(play2.playOfPuke.get(0).pokeID)))

if(play1.playOfPuke.get(0).equals(newTestList.get(0))) {

System.out.println("玩家"+play1.name+"获胜");

}else {

System.out.println("玩家"+play2.name+"获胜");

}

else {

String huase="黑桃红桃梅花方片";

int index1=huase.indexOf(play1.playOfPuke.get(0).floor);

int index2=huase.indexOf(play2.playOfPuke.get(0).floor);

if(index1>index2) {

System.out.println("玩家"+play1.name+"获胜");

}else {

System.out.println("玩家"+play2.name+"获胜");

}

}

System.out.println("玩家各自的手牌为:"+play1.playOfPuke.get(0).floor+play1.playOfPuke.get(0).pokeID+","+play1.playOfPuke.get(1).floor+play1.playOfPuke.get(1).pokeID);

System.out.println("玩家各自的手牌为:"+play2.playOfPuke.get(0).floor+play2.playOfPuke.get(0).pokeID+","+play2.playOfPuke.get(1).floor+play2.playOfPuke.get(1).pokeID);

}




public static void main(String[] args) {

TestPuke tp=new TestPuke();

tp.testListAdd();

tp.testPlayer();

tp.goGo();


}

}


正在回答

举报

0/150
提交
取消

自己构思出来的方法,可能比较绕

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信