毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 论文 >> 正文

java蜘蛛纸牌游戏设计 第3页

更新时间:2008-11-17:  来源:毕业论文

java蜘蛛纸牌游戏源代码
        
  int x = 20;
        for (int i = 0; i < 10; i++)
        {
            groundLabel[i] = new JLabel();
            groundLabel[i]
                    .setBorder(javax.swing.BorderFactory
                            .createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
            groundLabel[i].setBounds(x, 25, 71, 96);
            x += 101;
            this.pane.add(groundLabel[i]);
        }
       
  this.setVisible(true);
        this.deal();
       
  this.addKeyListener(new KeyAdapter(){
            class Show extends Thread{
                public void run(){
                    Spider.this.showEnableOperator();
                }
            }

            public void keyPressed(KeyEvent e){
                if (finish != 8) if (e.getKeyCode() == KeyEvent.VK_D && c < 60){
                    Spider.this.deal();
                }
                else if (e.getKeyCode() == KeyEvent.VK_M){
                    new Show().start();
                }
            }
        });
    }

    /**
  **开始新游戏
  */
 public void newGame(){
        this.randomCards();
        this.setCardsLocation();
        this.setGroundLabelZOrder();
        this.deal();
    }

    /**
  **返回值:int
  **返回牌的数量
   */
 public int getC(){
        return c;
    }

    /**
  **设置等级
  */
 public void setGrade(int grade){
        this.grade = grade;
    }

    /**
  **纸牌初始化
  */
 public void initCards(){
        //如果纸牌已被赋值,即将其从框架的面板中移去
  if (cards[0] != null){
            for (int i = 0; i < 104; i++){
                pane.remove(cards[i]);
            }
        }
       
  int n = 0;
        //通过难度等级,为n赋值
  if (this.grade == Spider.EASY){
            n = 1;
        }
        else if (this.grade == Spider.NATURAL){
            n = 2;
        }
        else{
            n = 4;
        }
      //为card赋值 
  for (int i = 1; i <= 8; i++){
            for (int j = 1; j <= 13; j++){
                cards[(i - 1) * 13 + j - 1] = new PKCard((i % n + 1) + "-" + j,
                        this);
            }
        }
       
  //随机纸牌初始化
  this.randomCards();
    }

    /**
  **纸牌随机分配
  */
 public void randomCards(){
        PKCard temp = null;
        //随机生成牌号
  for (int i = 0; i < 52; i++){
            int a = (int) (Math.random() * 104);
            int b = (int) (Math.random() * 104);
            temp = cards[a];
            cards[a] = cards[b];
            cards[b] = temp;
        }
    }

    /**
  **设置还原
  */
 public void setNA(){
        a = 0;
        n = 0;
    }

    /**
  **设置纸牌的位置
  */
 public void setCardsLocation(){
        table = new Hashtable();
        c = 0;
        finish = 0;
        n = 0;
        a = 0;
        int x = 883;
        int y = 580;
  //初始化待展开的纸牌
        for (int i = 0; i < 6; i++){
            for (int j = 0; j < 10; j++){
                int n = i * 10 + j;
                pane.add(cards[n]);
                //将card转向背面
    cards[n].turnRear();
                //将card放在固定的位置上
    cards[n].moveto(new Point(x, y));
                //将card的位置及相关信息存入
    table.put(new Point(x, y), cards[n]);
            }
            x += 10;
        }
  
  x = 20;
        y = 45;
        //初始化表面显示的纸牌
  for (int i = 10; i > 5; i--){
            for (int j = 0; j < 10; j++){
                int n = i * 10 + j;
                if (n >= 104) continue;
                pane.add(cards[n]);
                cards[n].turnRear();
                cards[n].moveto(new Point(x, y));
                table.put(new Point(x, y), cards[n]);
                x += 101;
            }
            x = 20;

上一页  [1] [2] [3] [4] 下一页

java蜘蛛纸牌游戏设计 第3页下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©751com.cn 辣文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。