Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 编程/算法/API  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:发桥牌 [Re:cainiao025]
lisliefor





发贴: 287
积分: 7
于 2006-06-08 14:51 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
这个题目比较有意思,小做一下,仅供参考:
桥牌类:
package bridge;

public class Bridge {
  String name;
//花色与点数
  int Colors = -1;
  int Count = -1;
  
  public Bridge(String name){
    this.name = name;
  }
  
}
发牌类:
package bridge;

public class BridgeDeal {
  
  static Bridge player1,player2,player3,player4;
  
  //发牌
  public void Deal(){
    player1.Colors = (int)(Math.random()*4);
    player1.Count = (int)(Math.random()*13);
    player2.Colors = (int)(Math.random()*4);
    player2.Count = (int)(Math.random()*13);
    player3.Colors = (int)(Math.random()*4);
    player3.Count = (int)(Math.random()*13);
    player4.Colors = (int)(Math.random()*4);
    player4.Count = (int)(Math.random()*13);
    
    //第二个玩家的牌不能和第一个玩家牌一样
    while(!Check(player1,player2)){
      player2.Colors = (int)(Math.random()*4);
      player2.Count = (int)(Math.random()*13);
    }
    
    //同理
    while(!Check(player1,player3) && !Check(player2,player3)){
      player2.Count = (int)(Math.random()*13);
      player3.Colors = (int)(Math.random()*4);
    }
    
    while(!Check(player1,player4) &&!Check(player2,player4) && !Check(player3,player4)){
      player4.Colors = (int)(Math.random()*4);
      player4.Count = (int)(Math.random()*13);
    }
  }
  
  //检查花色、点数是否一致
  public boolean Check(Bridge b,Bridge c){
    boolean Flag = false;
    if(b.Colors!=c.Colors && b.Count!=c.Count)
      Flag = true;
    return Flag;
  }
  
  public void ShowBridge(Bridge b){
    String cor = "",cot = "";
    
    switch(b.Colors){
    case 0:
      cor = "梅花(C)";
      break;
    case 1:
      cor = "方块(D)";
      break;
    case 2:
      cor = "黑桃(S)";
      break;
    case 3:
      cor = "红心(H)";
      break;
      default:
        break;
    }
    
    switch(b.Count){
    case 0:
      cot = "A";
      break;
    case 1:
      cot = "2";
      break;
    case 2:
      cot = "3";
      break;
    case 3:
      cot = "4";
      break;
    case 4:
      cot = "5";
      break;
    case 5:
      cot = "6";
      break;
    case 6:
      cot = "7";
      break;
    case 7:
      cot = "8";
      break;
    case 8:
      cot = "9";
      break;
    case 9:
      cot = "T";
      break;
    case 10:
      cot = "J";
      break;
    case 11:
      cot = "Q";
      break;
    case 12:
      cot = "K";
      break;
      default:
        break;
    }
    System.out.println("玩家"+b.name+"得到的牌为:"+cor+cot);
  }
  
  public static void main(String args[]){
    player1 = new Bridge("player1");
    player2 = new Bridge("player2");
    player3 = new Bridge("player3");
    player4 = new Bridge("player4");
    
    BridgeDeal bd = new BridgeDeal();
    bd.Deal();
    bd.ShowBridge(player1);
    bd.ShowBridge(player2);
    bd.ShowBridge(player3);
    bd.ShowBridge(player4);
  }
}




话题树型展开
人气 标题 作者 字数 发贴时间
8917 发桥牌 cainiao025 102 2006-06-08 10:18
7034 Re:发桥牌 lisliefor 2611 2006-06-08 14:51
6935 Re:发桥牌 why 240 2006-06-08 18:43
7152 Re:发桥牌 cainiao025 17 2006-06-08 23:10
6969 Re:发桥牌 why 1768 2006-06-08 23:50
7717 Re:发桥牌 lisliefor 124 2006-06-09 11:00

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923