千里冰封
          JAVA 濃香四溢
          posts - 151,comments - 2801,trackbacks - 0
          下面我們再來看看ClientModel類,這個類負責保存游戲中的一些數據,這些數據可能需要Control類去更改然后需要由View類去呈現的,說白了,它就是一個包含有很多setter/getter的類.它的代碼如下:

          /*
           * ClientModel.java
           *
           * Created on 2007年10月2日, 下午2:02
           * 此類封裝了一些公共的數據,為視圖類提供模型
           * To change this template, choose Tools | Template Manager
           * and open the template in the editor.
           
          */

          package com.hadeslee.apple.client;

          /**
           *
           * 
          @author lbf
           
          */

          import com.hadeslee.apple.common.Bet;
          import com.hadeslee.apple.common.INFO;
          import java.awt.Image;
          import java.util.Vector;
          import static com.hadeslee.apple.common.Constants.*;
          public class ClientModel {
              
          private Image bg;//表示背景圖片的對象
              private Image table;//表示下注桌面的對象
              
          //private Image runA,runB;//表示跑動的圖像,A表示正在跑的,B表示跑停了的,僅當火車的時候B才有用,其余為null
              
          // private PP[] p;//表示當前的位置枚舉表現形式,當長度為一時,則為普通情況,其余為特殊情況
              private Vector<PP> v;//表示當前的位置枚舉表現形式,當長度為一時,則為普通情況,其余為特殊情況
              private Bet bet;//表示當前或者上一局下注的對象
              private INFO info;//表示當前的INFO對象,里面封裝了要全速走的步數,大彩金,小彩金數
              private int allMoney,winMoney;//表示當前用戶所有的錢和本局贏的錢
              private int id;//表示當前用戶的ID號
              private Image[] number,winNumber;//表示數字的圖像普通數組和贏了的數組
              private volatile boolean Running,Betting,hasRunB;//表示現在是否正在跑或者正在加時賭,是否有RunB
              private Image pkA,pkB;//表示兩張正在PK的圖
              private int ratioA,ratioB;//表示A和B國的陪率
              private RatioA ra;//表增添A或B的枚舉
              private RatioB rb;
              
          private Image pk;//表示PK的背景圖
              private String infos;//表示跑馬燈的文字信息
              /** Creates a new instance of ClientModel */
              
          public ClientModel() {
                  v
          =new Vector<PP>();
                  ra
          =RatioA.A_20;
                  rb
          =RatioB.B_10;
              }
              
          public Image getPKBG(){
                  
          return pk;
              }
              
          public void setPKBG(Image bg){
                  pk
          =bg;
              }
              
          public Image getBg() {
                  
          return bg;
              }
              
          public int getRatioA(){
                  
          return ratioA;
              }
              
          public int getRatioB(){
                  
          return ratioB;
              }
              
          public void setRatioA(int a){
                  ratioA
          =a;
              }
              
          public void setRatioB(int b){
                  ratioB
          =b;
              }
              
          public void setBg(Image bg) {
                  
          this.bg = bg;
              }
              
              
          public Image getTable() {
                  
          return table;
              }
              
              
          public void setTable(Image table) {
                  
          this.table = table;
              }
              
             
          /* public Image getRunA() {
                  return runA;
              }
              
              
              public void setRunA(Image run) {
                  this.runA = run;
              }
              
              public Image getRunB(){
                  return runB;
              }
              public void setRunB(Image run){
                  runB=run;
              }
              
          */
              
              
          public Vector<PP> getP() {
                  Vector
          <PP> vec=new Vector<PP>();
                  
          for(PP p: v){
                      vec.add(p);
                  }
                  
          return vec;
              }
              
              
          public void addP(PP p){
                  v.add(p);
              }
              
          public void setP(PP p){
                  
          if(v.size()>0){
                      v.remove(v.size()
          -1);
                  }
                  v.add(p);
              }
              
          public void clearP(){
                  v.removeAllElements();
              }
              
              
          public Bet getBet() {
                  
          return bet;
              }
              
              
          public void setBet(Bet bet) {
                  
          this.bet = bet;
              }
              
              
          public INFO getInfo() {
                  
          return info;
              }
              
              
          public void setInfo(INFO info) {
                  
          this.info = info;
              }
              
              
          public int getAllMoney() {
                  
          return allMoney;
              }
              
              
          public void setAllMoney(int allMoney) {
                  
          this.allMoney = allMoney;
              }
              
              
          public int getWinMoney() {
                  
          return winMoney;
              }
              
              
          public void setWinMoney(int winMoney) {
                  
          this.winMoney = winMoney;
              }
              
              
          public int getId() {
                  
          return id;
              }
              
              
          public void setId(int id) {
                  
          this.id = id;
              }
              
              
          public Image[] getNumber() {
                  
          return number;
              }
              
              
          public void setNumber(Image[] number) {
                  
          this.number = number;
              }
              
          public Image getNumber(int i){
                  
          return number[i];
              }
              
          public void setWinNumber(Image[] winNumber){
                  
          this.winNumber=winNumber;
              }
              
          public Image getWinNumber(int i){
                  
          return winNumber[i];
              }
              
          public Image[] getWinNumber(){
                  
          return winNumber;
              }
              
              
          public boolean isRunning() {
                  
          return Running;
              }
              
              
          public void setRunning(boolean Running) {
                  
          this.Running = Running;
              }
              
              
          public boolean isBetting() {
                  
          return Betting;
              }
              
              
          public void setBetting(boolean Betting) {
                  
          this.Betting = Betting;
              }
              
          public void setHasRunB(boolean b){
                  hasRunB
          =b;
              }
              
          public boolean getHasRunB(){
                  
          return hasRunB;
              }
              
              
          public Image getPkA() {
                  
          return pkA;
              }
              
              
          public void setPkA(Image pkA) {
                  
          this.pkA = pkA;
              }
              
              
          public Image getPkB() {
                  
          return pkB;
              }
              
              
          public void setPkB(Image pkB) {
                  
          this.pkB = pkB;
              }

              
          public RatioA getRa() {
                  
          return ra;
              }

              
          public void setRa(RatioA ra) {
                  
          this.ra = ra;
              }

              
          public RatioB getRb() {
                  
          return rb;
              }

              
          public void setRb(RatioB rb) {
                  
          this.rb = rb;
              }
              
          //得到A國是否中獎
              public boolean isAWin(){
                  
          for(PP p:v){
                      
          if(p.country==COUNTRY_A)
                          
          return true;
                  }
                  
          return false;
              }
              
          public boolean isBWin(){
                  
          for(PP p:v){
                      
          if(p.country==COUNTRY_B)
                          
          return true;
                  }
                  
          return false;
              }
          }

          多它的好處就是,一個改一個呈現,分工明確,并且它里面也可以包含一些簡單的邏輯,這一點就是仁者見仁了:)





          盡管千里冰封
          依然擁有晴空

          你我共同品味JAVA的濃香.
          posted on 2007-11-12 09:31 千里冰封 閱讀(1489) 評論(0)  編輯  收藏 所屬分類: JAVASE
          主站蜘蛛池模板: 鹤庆县| 东港市| 南安市| 西和县| 蒲江县| 上饶县| 留坝县| 凌源市| 古丈县| 筠连县| 兴海县| 东平县| 葫芦岛市| 南京市| 汝阳县| 潜江市| 平利县| 绥宁县| 丹棱县| 泰和县| 如皋市| 周至县| 马山县| 襄汾县| 湘西| 南阳市| 乾安县| 贞丰县| 宁都县| 昌江| 黄浦区| 永善县| 民和| 云浮市| 宁陕县| 和田县| 康平县| 崇义县| 荆门市| 商洛市| 祥云县|