码农小Q仔 2022-08-23 23:49 采纳率: 100%
浏览 28
已结题

java斗地主地主牌不能全加进手牌

java斗地主抢地主的时候
1、明牌按钮只有在发牌的时候才有作用
2、抢三分的 时候地主牌按一次只加两张,得按两次三张才会全加进去

public class GamePokerCallListener implements ActionListener{
GamePokerMainJPanel mainJPanel;
public GamePokerCallListener(GamePokerMainJPanel mainJPanel) {
    this.mainJPanel = mainJPanel;
}

@Override
public void actionPerformed(ActionEvent e) {
    boolean flag = false;
    if(e.getActionCommand().equals("2分")) {
        System.out.println("2分");
    }
    if(e.getActionCommand().equals("3分")) {
        for(int i = 0;i < mainJPanel.getSendDipaiList().size();i++){
            mainJPanel.falseTurn(mainJPanel.getSendDipaiList().get(i),mainJPanel.getSendDipaiList().get(i).getColorValue(),mainJPanel.getSendDipaiList().get(i).getPointValue());
            mainJPanel.getSendP2List().add(mainJPanel.getSendDipaiList().get(i));
            mainJPanel.getSendDipaiList().remove(mainJPanel.getSendDipaiList().get(i));
            
        }
        System.out.println(mainJPanel.getSendDipaiList());
        mainJPanel.sortCards(mainJPanel.getSendP2List());
        mainJPanel.repaint();
    }
    if(e.getActionCommand().equals("明牌")) {

// for (int i = 0; i < mainJPanel.getSendP1List().size(); i++) {
// mainJPanel.falseTurn(mainJPanel.getSendP1List().get(i),mainJPanel.getSendP1List().get(i).getColorValue(),
// mainJPanel.getSendP1List().get(i).getPointValue());
// }
// for(int j = 0;j < mainJPanel.getSendP3List().size();j++ ) {
// mainJPanel.falseTurn(mainJPanel.getSendP3List().get(j),mainJPanel.getSendP3List().get(j).getColorValue(),mainJPanel.getSendP3List().get(j).getPointValue());
// }
for (int i = 0; i < mainJPanel.getCardList().size(); i++) {
mainJPanel.falseTurn(mainJPanel.getCardList().get(i), mainJPanel.getCardList().get(i).getColorValue(), mainJPanel.getCardList().get(i).getPointValue());
}
}
}

}

我想要达到的结果

明牌正常运行,抢三分的时候能把所有地主牌都加进去

  • 写回答

2条回答 默认 最新

  • 於黾 2022-08-24 07:12
    关注

    关键代码没放,鬼知道是怎么写的
    无非就是各种getList函数里写错了,没有获取全部的list呗

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • 码农小Q仔 2022-08-24 11:56
    关注

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

    }

    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月1日
  • 已采纳回答 8月24日
  • 创建了问题 8月23日

悬赏问题

  • ¥15 Erasure Code纠删码表
  • ¥15 用vite创建的vue3项目,404重定向不起作用??
  • ¥15 关于#c语言#的问题:一个球从80米高度自由落下,每次落地后反弹的高度为原高度的一半计算6次小球反弹的高度.(反弹结果取整,使用走走for循环结构)
  • ¥15 SurfaceControl的screenshot问题
  • ¥15 基于51单片机的oled菜单代码,要C语言,模块化编程!
  • ¥15 JAVAswing,设计一个扑克牌什么的
  • ¥50 python ctypes调用dll实现分析
  • ¥40 用python解决数据统计问题
  • ¥100 是否有方案能通过抓包分析得到移动应用的名称和包名信息?
  • ¥15 opencv检测不到轮廓