public class GamePokerMainJPanel extends JPanel{
public Container container;
GamePokerCardType gamePokerCardType = new GamePokerCardType();
List cardList = new ArrayList();
List sendP1List = new ArrayList();
List sendP2List = new ArrayList();
List sendP3List = new ArrayList();
List sendDipaiList = new ArrayList();
Image ima;
boolean isDeal = false;
int x = 0;
int y = 0;
public GamePokerMainJPanel() {
//s设置边框大小
this.setBounds(0, 0, GamePokerTools.WIDTH, GamePokerTools.HEIGHT);
//更新牌组
initCards();
}
//让扑克牌显示出来
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
for(int i = 0;i < gamePokerCardType.getCount();i++) {
g.drawImage(cardList.get(i).getImage(), cardList.get(i).getStartX(), cardList.get(i).getStartY(), 100, 120, null);
}
for (int i = 0; i < sendP1List.size(); i++) {
g.drawImage(sendP1List.get(i).getImage(), x+200, y+100+i*30, 100, 120, null);
}
for (int i = 0; i < sendP2List.size(); i++) {
g.drawImage(sendP2List.get(i).getImage(), x+500+i*30, y+800, 100, 120, null);
}
for (int i = 0; i < sendP3List.size(); i++) {
g.drawImage(sendP3List.get(i).getImage(), x+900, y+100+i*30, 100, 120, null);
}
for (int i = 0; i < sendDipaiList.size(); i++) {
g.drawImage(sendDipaiList.get(i).getImage(), x+500+i*30, y+100, 100, 120, null);
}
}
//更新牌组
String path = "C:\\Users\\admin\\eclipse-workspace\\PokerGame\\image\\pokerImages\\";
private void initCards() {
//设置牌组类型
for(int i = 1; i <= 4 ; i++) {
for(int j = 3; j <= 15; j++) {
GamePokerCardType cardType = new GamePokerCardType();
//设置单张牌的花色值
cardType.setColorValue(i);
//设置花色
setColor(cardType.getColorValue(), cardType);
//设置单张牌的点数值
cardType.setPointValue(j);
//设置点数值
setPoint(cardType.getPointValue(), cardType);
// //设置图片是否翻面 true为是, 为反面 false为否,为正面
// trueTurn(cardType);
falseTurn(cardType, i, j);
//设置位置
cardType.setStartX(-500);
cardType.setStartY(-500);
// cardType.setLocation(0, 0);
//把牌加入到卡组之中
cardList.add(cardType);
}
}
//添加小王
GamePokerCardType cardType1 = new GamePokerCardType("小王",5,"小王",16,false);
//设置图片是否翻面 true为是, 为反面 false为否,为正面
// trueTurn(cardType1);
falseTurn(cardType1, 5, 16);
//设置小王的位置
// cardType1.setLocation(0, 0);
cardType1.setStartX(-500);
cardType1.setStartY(-500);
cardList.add(cardType1);
//添加大王
GamePokerCardType cardType2 = new GamePokerCardType("大王",5,"大王",17,false);
//设置图片是否翻面 true为是, 为反面 false为否,为正面
// trueTurn(cardType2);
falseTurn(cardType2, 5, 17);
//设置大王的位置
// cardType2.setLocation(0, 0);
cardType2.setStartX(-500);
cardType2.setStartY(-500);
cardList.add(cardType2);
}
//设置图片为正面
public void falseTurn(GamePokerCardType cardType, int i, int j) {
// //设置图片路径
String pokerPath;
pokerPath = path+i+"-"+j+".gif";
cardType.setImaPath(pokerPath);
//放置图片
try {
ima = ImageIO.read(new File(cardType.getImaPath()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
cardType.setImage(ima);
cardType.setIsturn(false);
}
//设置图片为反面
public void trueTurn(GamePokerCardType cardType) {
// //设置图片路径
String pokerPath;
pokerPath = "C:\Users\admin\eclipse-workspace\PokerGame\image\i1.jpg";
cardType.setImaPath(pokerPath);
//放置图片
try {
ima = ImageIO.read(new File(cardType.getImaPath()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
cardType.setImage(ima);
cardType.setIsturn(true);
}
//设置点数值
private void setPoint(int pointValue, GamePokerCardType cardType) {
switch (pointValue) {
case 11:
cardType.setPoint("J");
break;
case 12:
cardType.setPoint("Q");
break;
case 13:
cardType.setPoint("K");
break;
case 14:
cardType.setPoint("A");
break;
case 15:
cardType.setPoint("2");
break;
default:
cardType.setPoint(pointValue+"");
break;
}
}
//放置花色
public void setColor(int colorValue,GamePokerCardType cardType) {
switch (colorValue) {
case 1:
cardType.setColor("黑桃");
break;
case 2:
cardType.setColor("红心");
break;
case 3:
cardType.setColor("梅花");
break;
case 4:
cardType.setColor("方块");
break;
default:
break;
}
}
//排序方法
public void sortCards(List<GamePokerCardType> list) {
Collections.sort(list, (o1,o2)->{
//花色值
int a1 = o1.getColorValue();
int a2 = o2.getColorValue();
//点数值
int b1 = o1.getPointValue();
int b2 = o2.getPointValue();
int flag = 0;
//降序排列
flag = b2 - b1;
if (flag == 0)
return a2 - a1;
else {
return flag;
}
});
}
//get 和 set 方法
public List<GamePokerCardType> getSendP1List() {
return sendP1List;
}
public List<GamePokerCardType> getCardList() {
return cardList;
}
public void setCardList(List<GamePokerCardType> cardList) {
this.cardList = cardList;
}
public void setSendP1List(List<GamePokerCardType> sendP1List) {
this.sendP1List = sendP1List;
}
public List<GamePokerCardType> getSendP2List() {
return sendP2List;
}
public void setSendP2List(List<GamePokerCardType> sendP2List) {
this.sendP2List = sendP2List;
}
public List<GamePokerCardType> getSendP3List() {
return sendP3List;
}
public void setSendP3List(List<GamePokerCardType> sendP3List) {
this.sendP3List = sendP3List;
}
public List<GamePokerCardType> getSendDipaiList() {
return sendDipaiList;
}
public void setSendDipaiList(List<GamePokerCardType> sendDipaiList) {
this.sendDipaiList = sendDipaiList;
}
public boolean isDeal() {
return isDeal;
}
public void setDeal(boolean isDeal) {
this.isDeal = isDeal;
}
}