PlayCanvas.java
上传用户:whhzxy
上传日期:2009-12-31
资源大小:269k
文件大小:68k
源码类别:

J2ME

开发平台:

Java

  1. import java.io.*;
  2. import java.util.*;
  3. import javax.microedition.lcdui.*;
  4. import javax.microedition.rms.*;
  5. /**
  6.  * 游戏画板。这是这个游戏最关键的一个类
  7.  * @author SoftStar,嘟嘟熊
  8.  * @version 1.0
  9.  */
  10. public class PlayCanvas extends Canvas
  11.     implements Runnable
  12. {
  13.   /**
  14.    * 画板宽度
  15.    */
  16.   public int canvasWidth;
  17.   /**
  18.    * 画板高度
  19.    */
  20.   public int canvasHeight;
  21.   /**
  22.    * richMan实例
  23.    */
  24.   private KMRichMan richMan;
  25.   /**
  26.    * 地图第1部分
  27.    */
  28.   private Image mapImage1;
  29.   /**
  30.    * 地图第2部分
  31.    */
  32.   private Image mapImage2;
  33.   /**
  34.    * 游戏控制面板
  35.    */
  36.   private Image gamePanelImage;
  37.   /**
  38.    * 线程
  39.    */
  40.   private volatile Thread thread;
  41.   /**
  42.    * 控制面板的选择序号(1-色子,2-卡片,3-其他(玩家信息,股票信息)4-系统
  43.    */
  44.   private static int choiceIndex = 0;
  45.   /**
  46.    * 游戏角色要走的步数
  47.    */
  48.   private static int steps = 0;
  49.   /**
  50.    * 游戏进行的轮数
  51.    */
  52.   private static int turnCount = 0;
  53.   /**
  54.    * 游戏状态(0-进行,2-胜利,3-失败)
  55.    */
  56.   private static int gameStatusGoOrWinOrFail = 0;
  57.   /**
  58.    * 角色特殊状态(10--在公园处,20-在监狱里,30-在睡眠中(睡眠卡)
  59.    */
  60.   private static int status_Park10_Prinson20_Sleep30 = 0;
  61.   /**
  62.    * 现在正在进行的角色
  63.    */
  64.   public static int nowPlayerID = 0;
  65.   /**
  66.    * 现在玩家是否能控制进行游戏(如果是电脑角色在玩,玩家就不能控制)
  67.    */
  68.   private boolean ManControlStatus_CanNotPlay;
  69.   /**
  70.    * 随机函数
  71.    */
  72.   private Random random;
  73.   /**
  74.    * 定时器
  75.    */
  76.   private static Timer timer = null;
  77.   /**
  78.    * 地皮
  79.    */
  80.   private static int groundForBuilding[] = null;
  81.   // 游戏角色变量
  82.   /**
  83.    * 角色在地图上位置(用地皮ID表示)
  84.    */
  85.   private static int player_location[] = null;
  86.   /**
  87.    * 角色卡片
  88.    */
  89.   private static int player_cards[][] = null;
  90.   /**
  91.    * 角色因为进入监狱而不能移动的次数
  92.    */
  93.   private static int player_prinson_canNotMoveNum[] = null;
  94.   /**
  95.    * 角色因为睡眠而不能移动的次数
  96.    */
  97.   private static int player_sleep_canNotMoveNum[] = null;
  98.   /**
  99.    * 角色轮转次序
  100.    */
  101.   public  static int player_sequence[] = null;
  102.   /**
  103.    * 角色的金钱
  104.    */
  105.   public  static int player_money[] = null;
  106.   /**
  107.    * 角色的地皮和房屋的图象
  108.    */
  109.   private static Image player_houseImage[][] = null;
  110.   /**
  111.    * 角色的头像
  112.    */
  113.   private static Image player_faceImage[] = null;
  114.   /**
  115.   * 玩家的股票 [角色ID][股票ID][0]---- 购入数目,[角色ID][股票ID][1]---- 购入价格
  116.   *
  117.   */
  118.   public static int player_stock[][][] = null;
  119.   /**
  120.    * 屏幕图象缓冲
  121.    */
  122.   Image bufferImage;
  123.   /**
  124.    * 空白地皮图象
  125.    */
  126.   Image emptyGround;
  127.   /**
  128.    * 屏幕图象缓冲句柄
  129.    */
  130.   Graphics bufferImageG;
  131.   /**
  132.    * 是否背景灯打开
  133.    */
  134.   private boolean isLightOn = true;
  135.   /**
  136.    * 是否背景音乐打开
  137.    */
  138.   private boolean isMusicOn = true;
  139.   /**
  140.    * 游戏速度
  141.    */
  142.   private int gameSpeed = 3;
  143.   /**
  144.    * 音乐序号
  145.    */
  146.   private int music = 1;
  147.   /**
  148.    * 西门子手机的音乐合成器
  149.    */
  150.   com.siemens.mp.game.MelodyComposer composer;
  151.   /**
  152.    * 地皮的缓冲
  153.    */
  154.   private int[] bufferGroundForBuilding;
  155. // 股票变量
  156.   /**
  157.    * 股票名字
  158.    */
  159.   public String[] stock_name;
  160.   /**
  161.    * 股票的价格
  162.    */
  163.   public int[] stock_price;
  164.   /**
  165.    * 股票的涨幅
  166.    */
  167.   public int[] stock_amplitude;
  168.   /**
  169.    * 股票的分数部分(便于计算)如 2元 涨幅 1%,总要个分数部分吧,不然老是2元
  170.    */
  171.   public int[] stock_price_fraction;
  172.   /**
  173.    * 构造游戏画板
  174.    */
  175.     public PlayCanvas(KMRichMan kmrichman)
  176.     {
  177.       player_faceImage = null;
  178.       richMan = null;
  179.       mapImage1 = null;
  180.       thread = null;
  181.       random = null;
  182.       thread = null;
  183.       richMan = kmrichman;
  184.       ManControlStatus_CanNotPlay = false;
  185.       random = new Random();
  186.       timer = new Timer();
  187.       canvasWidth = getWidth();
  188.       canvasHeight = getHeight();
  189.       bufferImage = Image.createImage(101,80);
  190.       bufferImageG = bufferImage.getGraphics();
  191.       groundForBuilding = new int[56];
  192.       bufferGroundForBuilding = new int[56];
  193.       player_location = new int[3];
  194.       player_money = new int[3];
  195.       player_sequence = new int[3];
  196.       player_cards = new int[3][5];
  197.       player_prinson_canNotMoveNum = new int[3];
  198.       player_sleep_canNotMoveNum = new int[3];
  199.       player_faceImage = new Image[3];
  200.       player_stock = new int[3][4][2];
  201.      // 加载图像
  202.       loadMap();
  203.       loadImage();
  204.       //初始化音乐
  205.       this.initialMusic();
  206.       //初始化游戏
  207.       initialGame();
  208.     }
  209.     /**
  210.      * 加载地图
  211.      */
  212.     void loadMap()
  213.     {
  214.       try
  215.       {
  216.         mapImage1 = Image.createImage(128,160);
  217.         mapImage2 = Image.createImage(128,160);
  218.         Graphics g = mapImage1.getGraphics();
  219.         g.drawImage(com.siemens.mp.ui.Image.createImageWithoutScaling("/res/image/map0bw.png"),0,0,20);
  220.         g = mapImage2.getGraphics();
  221.         g.drawImage(com.siemens.mp.ui.Image.createImageWithoutScaling("/res/image/map1bw.png"),0,0,20);
  222.       }
  223.       catch(Exception exception) { }
  224.     }
  225.     /**
  226.      * 加载图象
  227.      */
  228.     void loadImage()
  229.     {
  230.       Image houseImage = null;
  231.       Graphics g = null;
  232.       try
  233.       {
  234.         houseImage = Image.createImage("/res/image/housebw.png");
  235.         emptyGround = Image.createImage("/res/image/ground.png");
  236.         gamePanelImage = com.siemens.mp.ui.Image.createImageWithoutScaling("/res/image/gamepanelbw.png");
  237.         for(int i = 0; i < 3; i++)
  238.           player_faceImage[i] = Image.createImage(String.valueOf(new StringBuffer("/res/image/h").append(i).append(".png")));
  239.       }
  240.       catch(Exception exception) {
  241.         System.out.println("Err on loading Images");
  242.       }
  243.       // 把地皮和房子的图象分割成一个一个小块
  244.       player_houseImage = new Image[3][4];
  245.       for(int i = 0; i < 3; i++)
  246.       {
  247.         for(int j = 0; j < 4; j++)
  248.         {
  249.           Image image = Image.createImage(16, 16);
  250.           g = image.getGraphics();
  251.           g.drawImage(houseImage, -16 * j, -16 * i, 20);
  252.           player_houseImage[i][j] = image;
  253.         }
  254.       }
  255.       houseImage = null;
  256.       g = null;
  257.     }
  258.     /**
  259.      * 排列角色的次序
  260.      * @param selectedPlayerID 玩家选择的角色ID
  261.      */
  262.     void arragePlayerSecquence(int selectedPlayerID)
  263.     {
  264.         player_sequence[0] = selectedPlayerID;
  265.         int player2 = fetchRandom(2);
  266.         int player3 = fetchRandom(2);
  267.         for(; player2 == selectedPlayerID; player2 = fetchRandom(2));
  268.         player_sequence[1] = player2;
  269.         for(; player3 == selectedPlayerID || player3 == player2; player3 = fetchRandom(2));
  270.         player_sequence[2] = player3;
  271.     }
  272.     /**
  273.      * 转到下一个玩家
  274.      * @param delay 延迟时间
  275.      */
  276.     public void nextPlay(int deplay)
  277.     {
  278.         timer.schedule(new Controlor(this), deplay);
  279.     }
  280.     /**
  281.      * 电脑玩家开始游戏
  282.      * @param delay 延迟时间
  283.      * @param Num_ComputerActor_or_HunmanActor 是电脑还是玩家 (1-电脑 0-玩家)
  284.      */
  285.     public void play_computerActor(int delay, int Num_ComputerActor_or_HumanActor)
  286.     {
  287.         timer.schedule(new Controlor(this, Num_ComputerActor_or_HumanActor), delay);
  288.     }
  289.     /**
  290.      * 开始游戏
  291.      * @param isLoadGameRestart 是否是进行的存储的游戏(继续上次游戏)
  292.      */
  293.     public void play(boolean isLoadGameRestart)
  294.     {
  295.       // siemens special call
  296.       if (this.isIsLightOn())
  297.         com.siemens.mp.game.Light.setLightOn(); //开灯
  298.       else
  299.         com.siemens.mp.game.Light.setLightOff();//关灯
  300.         //siemens special call
  301.       choiceIndex = 0;
  302.       status_Park10_Prinson20_Sleep30 = 0;
  303.       if(isLoadGameRestart)
  304.       {
  305.         nowPlayerID = 2; // 让玩家先开始
  306.       } else {
  307.         repaint();
  308.         serviceRepaints();
  309.         try
  310.         {
  311.           Thread.sleep(600L);
  312.         }
  313.         catch(Exception exception) { }
  314.       }
  315.       // 换游戏角色
  316.       nowPlayerID++;
  317.       nowPlayerID %= 3;
  318.       // 如果是玩家操作,那么保存游戏
  319.       if(nowPlayerID == 0)
  320.       {
  321.         autoSaveGame();
  322.         turnCount++;
  323.         this.changeStock();
  324.       }
  325.       // 如果有游戏角色 钱 < 0
  326.       if(player_money[nowPlayerID] < 0)
  327.       {
  328.         nowPlayerID++;
  329.         nowPlayerID %= 3;
  330.       }
  331.       // 如果 玩家没有钱
  332.       if(player_money[0] < 0)
  333.       {
  334.         gameOver(0);
  335.         return;
  336.       }
  337.       // 如果电脑角色没有钱
  338.       if(player_money[1] < 0 && player_money[2] < 0)
  339.       {
  340.         gameOver(1);
  341.         return;
  342.       }
  343.       repaint();
  344.       serviceRepaints();
  345.       if(player_prinson_canNotMoveNum[nowPlayerID] > 0)
  346.       {
  347.         if(deleteCard(nowPlayerID, 5)) // 使用免罪卡
  348.         {
  349.           player_prinson_canNotMoveNum[nowPlayerID] = 0;
  350.           nextPlay(1000);
  351.         } else
  352.         {
  353.           status_Park10_Prinson20_Sleep30 = 20;
  354.           repaint();
  355.           serviceRepaints();
  356.           nextPlay(1000);
  357.           player_prinson_canNotMoveNum[nowPlayerID]--;
  358.         }
  359.       } else
  360.       if(player_sleep_canNotMoveNum[nowPlayerID] > 0)
  361.       {
  362.         status_Park10_Prinson20_Sleep30 = 30;
  363.         repaint();
  364.         serviceRepaints();
  365.         nextPlay(1000);
  366.         player_sleep_canNotMoveNum[nowPlayerID]--;
  367.       } else
  368.       if(nowPlayerID != 0)
  369.         play_computerActor(1000, 1); // 电脑玩家开始玩
  370.       else
  371.         ManControlStatus_CanNotPlay = false; // 玩家开始玩
  372.     }
  373.     /**
  374.      * 启动移动角色线程
  375.      * @param steps 步数
  376.      */
  377.     public void moveActor(int steps)
  378.     {
  379.         PlayCanvas.steps = steps;
  380.         if(thread == null)
  381.         {
  382.           thread = new Thread(this);
  383.           thread.start();
  384.         }
  385.       }
  386.       /**
  387.        * 移动角色的线程
  388.        */
  389.     public void run()
  390.     {
  391.         Thread thread = Thread.currentThread();
  392.         int stepCount = 0;
  393.         while(thread == this.thread)
  394.           try
  395.           {
  396.             Thread.sleep((long)(gameSpeed*100)); //移动一步休息的时间
  397.             if(stepCount == steps)
  398.             {
  399.               this.thread = null;
  400.               stepOver(); //如果移动完毕
  401.             } else
  402.             {
  403.               stepCount++;
  404.               moveSteps(stepCount); //移动
  405.               repaint();
  406.               serviceRepaints();
  407.             }
  408.           }
  409.           catch(Exception exception) { }
  410.       }
  411.       /**
  412.        * 移动角色
  413.        * @param stepCount 移动步数
  414.        */
  415.     private void moveSteps(int stepCount)
  416.     {
  417.         //System.out.println("Location:" + playerLocation[nowPlayerID]);
  418.         player_location[nowPlayerID]++;
  419.         specialLocationPlusSteps();
  420.         if(player_location[nowPlayerID] == 50)
  421.         { //如果到第50号地皮,就是一圈完毕
  422.             if(stepCount != 1)
  423.             {
  424.                 status_Park10_Prinson20_Sleep30 = 1;
  425.                 player_money[nowPlayerID] += 200; //加200的钱
  426.             }
  427.             player_location[nowPlayerID] = 0;
  428.         }
  429.     }
  430.     /**
  431.      * 到了特别的地方要加走的步数(因为?或飞机场占了几步的位置,但也只能算一步)
  432.      */
  433.     private void specialLocationPlusSteps()
  434.     {
  435.         switch(player_location[nowPlayerID])
  436.         {
  437.         case 5: // '05'
  438.         case 10: // 'n'
  439.         case 14: // '16'
  440.         case 15: // '17'
  441.         case 27: // '33'
  442.         case 36: // '$'
  443.         case 41: // ')'
  444.         case 48: // '0'
  445.             steps++;
  446.             break;
  447.         }
  448.     }
  449.     /**
  450.      * 移动完毕要处理的事情
  451.      */
  452.     private void stepOver()
  453.     {
  454.         //System.out.println("StepOverLocation:" + player_location[nowPlayerID]);
  455.         //playerLocation[nowPlayerID] = 49 ;
  456.         switch(player_location[nowPlayerID])
  457.         {
  458.         case 2: //
  459.         case 20: //
  460.         case 42: // 随机事件
  461.             randomEvent();
  462.             return;
  463.         case 6: //
  464.         case 37: // 飞机场
  465.             showFlyToNextStation();
  466.             return;
  467.         case 11: //
  468.         case 25: //
  469.         case 32: // 卡片
  470.             addCard(10);
  471.             return;
  472.         case 16: // 监狱
  473.             prise();
  474.             return;
  475.         case 28: //
  476.         case 45: // 公园
  477.             status_Park10_Prinson20_Sleep30 = 10;
  478.             repaint();
  479.             serviceRepaints();
  480.             nextPlay(1000);
  481.             return;
  482.         case 49: // '1'
  483.             nextPlay(1000);
  484.             return;
  485.         case 0:
  486.         case 1:
  487.         case 3: // '03'
  488.         case 4: // '04'
  489.         case 5: // '05'
  490.         case 7: // '07'
  491.         case 8: // 'b'
  492.         case 9: // 't'
  493.         case 10: // 'n'
  494.         case 12: // 'f'
  495.         case 13: // 'r'
  496.         case 14: // '16'
  497.         case 15: // '17'
  498.         case 17: // '21'
  499.         case 18: // '22'
  500.         case 19: // '23'
  501.         case 21: // '25'
  502.         case 22: // '26'
  503.         case 23: // '27'
  504.         case 24: // '30'
  505.         case 26: // '32'
  506.         case 27: // '33'
  507.         case 29: // '35'
  508.         case 30: // '36'
  509.         case 31: // '37'
  510.         case 33: // '!'
  511.         case 34: // '"'
  512.         case 35: // '#'
  513.         case 36: // '$'
  514.         case 38: // '&'
  515.         case 39: // '''
  516.         case 40: // '('
  517.         case 41: // ')'
  518.         case 43: // '+'
  519.         case 44: // ','
  520.         case 46: // '.'
  521.         case 47: // '/'
  522.         case 48: // '0'
  523.         default:
  524.             onCommonGround();
  525.             return;
  526.         }
  527.     }
  528.     /**
  529.      * 移动完毕到了一般的地皮上要处理的事情
  530.      */
  531.     private void onCommonGround()
  532.     {
  533.        // 如果是0-空地,-1 -- 财神作用过的土地,-2 --衰神作用过的土地
  534.         if(groundForBuilding[player_location[nowPlayerID]] <= 0)
  535.         {
  536.             if(player_money[nowPlayerID] >= fetchGroundPrice(player_location[nowPlayerID]) && player_money[nowPlayerID] != 0)
  537.                 buildorBuyGround();
  538.             else
  539.                 nextPlay(1000);
  540.         } else
  541.         if(isNowPlayerIDGround()) //如果是自己的地皮
  542.         {   //如果有足够的钱修建
  543.             if(player_money[nowPlayerID] >= fetchGroundPrice(player_location[nowPlayerID]))
  544.             {
  545.                 int actorLevel = 1;
  546.                 for(int i = 0; i < nowPlayerID; i++)
  547.                     actorLevel *= 10;
  548.                     //如果不是最高级建筑就可以修建
  549.                 if(groundForBuilding[player_location[nowPlayerID]] == 4 * actorLevel)
  550.                     nextPlay(1000);
  551.                 else
  552.                     buildorBuyGround();
  553.             } else
  554.             {
  555.                 nextPlay(1000);
  556.             }
  557.         } else //如果土地的所有者处于不能移动状态
  558.         if(player_prinson_canNotMoveNum[fetchNowPlayerLocationGroundBelongtoWho()] > 0 || player_sleep_canNotMoveNum[fetchNowPlayerLocationGroundBelongtoWho()] > 0)
  559.             nextPlay(1000);
  560.         else //减钱,过路费啦:)
  561.             decreaseMoney(fetchNowPlayerLocationGroundBelongtoWho(), fetchConnectedLocationPrice(player_location[nowPlayerID]));
  562.     }
  563.     /**
  564.      * 绘制画板
  565.      */
  566.     protected void paint(Graphics graphics)
  567.     {
  568.       // 如果游戏仍在进行
  569.       if(gameStatusGoOrWinOrFail == 0)
  570.       {
  571.         //清屏
  572.         bufferImageG.setColor(255,255,255);
  573.         bufferImageG.fillRect(0, 0, canvasWidth, canvasHeight);
  574.         int mapX = (40 - computePlayerX(player_location[nowPlayerID])) + -6;
  575.         int mapY = (56 - computePlayerY(player_location[nowPlayerID])) + -16;
  576.         // 画出地皮
  577.         for(int i = 0; i < 50; i++) {
  578.           //如果地皮有所变化
  579.           if (this.groundForBuilding[i] != this.bufferGroundForBuilding[i]) {
  580.             this.bufferGroundForBuilding[i] = this.groundForBuilding[i];
  581.             Graphics g1 = mapImage1.getGraphics();
  582.             Graphics g2 = mapImage2.getGraphics();
  583.             if (groundForBuilding[i] == 0) {
  584.               g1.drawImage(this.emptyGround, computeGroundX(i),
  585.                            computeGroundY(i), 20);
  586.               g2.drawImage(this.emptyGround, -128 + computeGroundX(i),
  587.                            computeGroundY(i), 20);
  588.               continue;
  589.             }
  590.             //财神使用过的土地
  591.             if (groundForBuilding[i] == -1)
  592.               try {
  593.                 g1.drawImage(Image.createImage("/res/image/h3.png"),
  594.                              computeGroundX(i), computeGroundY(i),
  595.                              20);
  596.                 g2.drawImage(Image.createImage("/res/image/h3.png"),
  597.                              -128 + computeGroundX(i), computeGroundY(i),
  598.                              20);
  599.                 continue;
  600.               }
  601.               catch (Exception exception3) {}
  602.             // 衰神卡使用过的土地
  603.             if (groundForBuilding[i] == -2)
  604.               try {
  605.                 g1.drawImage(Image.createImage("/res/image/h4.png"),
  606.                              computeGroundX(i), computeGroundY(i),
  607.                              20);
  608.                 g2.drawImage(Image.createImage("/res/image/h4.png"),
  609.                              -128 + computeGroundX(i), computeGroundY(i),
  610.                              20);
  611.                 continue;
  612.               }
  613.               catch (Exception exception4) {}
  614.             // 玩家1
  615.             if (groundForBuilding[i] < 10) {
  616.               g1.drawImage(player_houseImage[player_sequence[0]][groundForBuilding[
  617.                            i] - 1], computeGroundX(i),
  618.                            computeGroundY(i), 20);
  619.               g2.drawImage(player_houseImage[player_sequence[0]][groundForBuilding[
  620.                            i] - 1], -128 + computeGroundX(i),
  621.                            computeGroundY(i), 20);
  622.               continue;
  623.             }
  624.             //玩家2
  625.             if (groundForBuilding[i] < 100) {
  626.               g1.drawImage(player_houseImage[player_sequence[1]][groundForBuilding[
  627.                            i] / 10 - 1], computeGroundX(i),
  628.                            computeGroundY(i), 20);
  629.               g2.drawImage(player_houseImage[player_sequence[1]][groundForBuilding[
  630.                            i] / 10 - 1], -128 + computeGroundX(i),
  631.                            computeGroundY(i), 20);
  632.               continue;
  633.             }
  634.             //玩家3
  635.             g1.drawImage(player_houseImage[player_sequence[2]][groundForBuilding[
  636.                          i] / 100 - 1], computeGroundX(i), computeGroundY(i), 20);
  637.             g2.drawImage(player_houseImage[player_sequence[2]][groundForBuilding[
  638.                          i] / 100 - 1], -128 + computeGroundX(i),computeGroundY(i), 20);
  639.           }
  640.         }
  641.         //绘制地图
  642.         try
  643.         {
  644.           bufferImageG.drawImage(mapImage1, (34 - computePlayerX(player_location[nowPlayerID])), (40 - computePlayerY(player_location[nowPlayerID])), 20);
  645.           bufferImageG.drawImage(mapImage2, (162 - computePlayerX(player_location[nowPlayerID])), (40 - computePlayerY(player_location[nowPlayerID])), 20);
  646.         }
  647.         catch(Exception exception) { }
  648.         // 画出非当前游戏者的头像
  649.         try
  650.         {
  651.           for(int i = 2; i >= 0; i--)
  652.             if(i != nowPlayerID && player_money[i] >= 0)
  653.               bufferImageG.drawImage(player_faceImage[player_sequence[i]], mapX + computePlayerX(player_location[i]), mapY + computePlayerY(player_location[i]), 20);
  654.         }
  655.         catch(Exception exception5) { }
  656.         // 画出控制条
  657.         try
  658.         {
  659.           Image image = Image.createImage(28,80);
  660.           Graphics g = image.getGraphics();
  661.           g.drawImage(gamePanelImage, 0, -16, 20);
  662.           bufferImageG.drawImage(image, 73, 0, 20);
  663.           g = null;
  664.           image = null;
  665.         }
  666.         catch(Exception exception6) { }
  667.          try
  668.          {
  669.            // 画出控制条上的头像
  670.            bufferImageG.drawImage(player_faceImage[player_sequence[nowPlayerID]], 79, 4, 20);
  671.            // 画出游戏者头像
  672.            if(player_money[nowPlayerID] >= 0)
  673.              bufferImageG.drawImage(player_faceImage[player_sequence[nowPlayerID]], 34, 40, 20);
  674.          }
  675.          catch(Exception exception8) { }
  676.          //画出选择框
  677.          bufferImageG.setColor(255,255,255);
  678.          bufferImageG.drawRect(78, 23 + choiceIndex * 14, 17, 13);
  679.        }
  680.        //如果玩家获胜
  681.        if(gameStatusGoOrWinOrFail == 2)
  682.        {
  683.          try
  684.          {
  685.            bufferImageG.drawImage(Image.createImage("/res/image/start00bw.png"), 0, 0, 20);
  686.            bufferImageG.drawImage(Image.createImage("/res/image/win.png"), 20, 22, 20);
  687.          }
  688.          catch(Exception exception1) { }
  689.        }
  690.        //如果玩家失败
  691.        if(gameStatusGoOrWinOrFail == 3)
  692.        {
  693.          try
  694.          {
  695.            bufferImageG.drawImage(Image.createImage("/res/image/start00bw.png"), 0, 0, 20);
  696.            bufferImageG.drawImage(Image.createImage("/res/image/lost.png"), 17, 22, 20);
  697.          }
  698.          catch(Exception exception2) { }
  699.        }
  700.        //绘制特殊角色状态
  701.        if(status_Park10_Prinson20_Sleep30 == 30)
  702.          drawMessage(bufferImageG, "睡眠");
  703.        else
  704.        if(status_Park10_Prinson20_Sleep30 == 20)
  705.          drawMessage(bufferImageG, "监狱");
  706.        else
  707.        if(status_Park10_Prinson20_Sleep30 == 10)
  708.          drawMessage(bufferImageG, "公园");
  709.        else
  710.        if(status_Park10_Prinson20_Sleep30 > 0)
  711.        {
  712.          drawMessage(bufferImageG, "+ $200");
  713.          status_Park10_Prinson20_Sleep30 = status_Park10_Prinson20_Sleep30 != 4 ? ++status_Park10_Prinson20_Sleep30 : 0;
  714.        }
  715.        //画出缓冲的图
  716.        graphics.drawImage(bufferImage,0,0,20);
  717.     }
  718.     /**
  719.      * 绘制出特殊角色状态
  720.      * @param g 句柄
  721.      * @param s 状态信息
  722.      */
  723.     private void drawMessage(Graphics g, String s)
  724.     {
  725.         g.setColor(0, 0, 0);
  726.         g.fillRect(8, 29, 80, 30);
  727.         g.setColor(255, 255, 255);
  728.         g.fillRect(10, 31, 76, 26);
  729.         g.setColor(255, 0, 0);
  730.         g.setFont(Font.getFont(0, 1, 0));
  731.         g.drawString(s, 48, 48, 65);
  732.     }
  733.     /**
  734.      * 按键处理
  735.      * @param keyInt 键值
  736.      */
  737.     public void keyPressed(int keyInt)
  738.     {
  739.       // 如果玩家失败或是成功
  740.       if (gameStatusGoOrWinOrFail > 1)
  741.         KMRichMan.exitGame();
  742.       // 如果不是玩家进行游戏
  743.       if (nowPlayerID != 0 || ManControlStatus_CanNotPlay)
  744.         return;
  745.       int pressKey = getGameAction(keyInt);
  746.       switch (pressKey) {
  747.         default:
  748.           break;
  749.         case 1: // 上
  750.         case 2:
  751.           choiceIndex--;
  752.           if (choiceIndex == -1)
  753.             choiceIndex = 3;
  754.           repaint();
  755.           serviceRepaints();
  756.           break;
  757.         case 5: // 下
  758.         case 6:
  759.           choiceIndex++;
  760.           if (choiceIndex == 4)
  761.             choiceIndex = 0;
  762.           repaint();
  763.           serviceRepaints();
  764.           break;
  765.         case 8: // 确定
  766.           switch (choiceIndex) {
  767.             default:
  768.               break;
  769.             case 0: // 投色子
  770.               richMan.setDisplayToDiceCanvas();
  771.               ManControlStatus_CanNotPlay = true;
  772.               break;
  773.             case 1: // 卡片
  774.               if (player_cards[nowPlayerID][0] == 16)
  775.                 richMan.showNoCard();
  776.               else
  777.                 richMan.showCards(player_cards[nowPlayerID]);
  778.               break;
  779.             case 2: // 显示
  780.               this.richMan.setDisplayToFucntionList();
  781.               break;
  782.             case 3: // 选项
  783.               this.richMan.setDisplayToOptionList();
  784.               break;
  785.           }
  786.           break;
  787.       }
  788.     }
  789.     /**
  790.      * 随机事件发生(角色走到?处)
  791.      */
  792.     private void randomEvent()
  793.     {
  794.         int random = fetchRandom(9);
  795.         String s = "";
  796.         switch(random)
  797.         {
  798.         case 0: // ''
  799.             player_prinson_canNotMoveNum[nowPlayerID] += 2;
  800.             player_location[nowPlayerID] = 16;
  801.             s = "监狱(连续停留)2天";
  802.             break;
  803.         case 1: // '01'
  804.             player_money[nowPlayerID] += 300;
  805.             s = "抽奖赢得 + $300";
  806.             break;
  807.         case 2: // '02'
  808.             s = "获得财富的 10%n" + " + $".concat(String.valueOf(player_money[nowPlayerID] / 10));
  809.             player_money[nowPlayerID] = (player_money[nowPlayerID] * 110) / 100;
  810.             break;
  811.         case 3: // '03'
  812.             s = "海外投资失利!n损失财产10%n" + " + $".concat(String.valueOf(String.valueOf((player_money[nowPlayerID] * 90) / 100)));
  813.             player_money[nowPlayerID] = (player_money[nowPlayerID] * 90) / 100;
  814.             break;
  815.         case 4: // '04'
  816.             s = "收入税 5%n" + " - $".concat(String.valueOf(String.valueOf(player_money[nowPlayerID] / 20)));
  817.             player_money[nowPlayerID] = (player_money[nowPlayerID] * 95) / 100;
  818.             break;
  819.         case 5: // '05'
  820.             s = "财产税 5%n" + " - $".concat(String.valueOf(String.valueOf(fetchBuildingTax() / 20)));
  821.             player_money[nowPlayerID] -= fetchBuildingTax() / 20;
  822.             break;
  823.         case 6: // '06'
  824.             tricleBroadCast(15);
  825.             s = "地震";
  826.             break;
  827.         case 7: // '07'
  828.             tricleBroadCast(25);
  829.             s = "龙卷风";
  830.             break;
  831.         case 8: // 'b'
  832.             fireGround();
  833.             s = "火警";
  834.             break;
  835.         case 9: // 't'
  836.             player_money[nowPlayerID] += 200;
  837.             s = "地产投资获利n+ $200";
  838.             break;
  839.         }
  840.         if(random != 6 && random != 7 && random != 8)
  841.             richMan.showChance(s);
  842.     }
  843.     /**
  844.      * 进入监狱
  845.      */
  846.     private void prise()
  847.     {
  848.         player_prinson_canNotMoveNum[nowPlayerID] += 3;
  849.         richMan.showInPrisonMessage();
  850.     }
  851.     /**
  852.      * 显示飞到下一个飞机场信息
  853.      */
  854.     private void showFlyToNextStation()
  855.     {
  856.         richMan.showBroadCast("飞到下一个机场.", null, true, "机场");
  857.     }
  858.     /**
  859.      * 飞到下飞机场
  860.      */
  861.     public void fly()
  862.     {
  863.         try
  864.         {
  865.             Thread.sleep(1000L);
  866.         }
  867.         catch(Exception exception) { }
  868.         switch(player_location[nowPlayerID])
  869.         {
  870.         case 6: // '06'
  871.             player_location[nowPlayerID] = 37;
  872.             break;
  873.         case 37: // '%'
  874.             player_location[nowPlayerID] = 6;
  875.             break;
  876.         }
  877.         nextPlay(1000);
  878.     }
  879.     /**
  880.      * 使用卡片
  881.      * @param cardID 卡片的ID
  882.      */
  883.     void useCard(int cardID)
  884.     {
  885.       switch(cardID)
  886.       {
  887.         case 4: // 免罪卡
  888.         default:
  889.           break;
  890.         case 0: // 偷盗卡
  891.           int cardNum = stealCard();
  892.           if(cardNum == -1)
  893.             richMan.showCardUsedMessage("没有卡片可偷.");
  894.           else {
  895.             deleteCard(nowPlayerID, cardID);
  896.             addCard(cardNum);
  897.           }
  898.           break;
  899.         case 1: // 均富卡
  900.           deleteCard(nowPlayerID, cardID);
  901.           int money = 0;
  902.           for(int i = 0; i < 3; i++)
  903.             if(i != nowPlayerID)
  904.             {
  905.               player_money[i] /= 2;
  906.               money += player_money[i];
  907.             }
  908.           player_money[nowPlayerID] += money;
  909.           richMan.showCardUsedMessage("获得 + $".concat(String.valueOf(money)));
  910.           break;
  911.         case 2: // 强占卡
  912.           if(!isNowPlayerIDGround()) {
  913.             occupyGround();
  914.             deleteCard(nowPlayerID, cardID);
  915.           }
  916.           else {
  917.             richMan.showCardUsedMessage("你不能在这用这张卡片.");
  918.           }
  919.           break;
  920.         case 3: // 睡眠卡
  921.           deleteCard(nowPlayerID, cardID);
  922.           int playerID;
  923.           for(playerID = fetchRandom(2); playerID == nowPlayerID; playerID = fetchRandom(2));
  924.           player_sleep_canNotMoveNum[playerID] += 3;
  925.           player_prinson_canNotMoveNum[playerID] = 0;
  926.           richMan.showCardUsedMessage("玩家不能移动三轮.");
  927.           break;
  928.         case 5: // 怪兽卡
  929.           deleteCard(nowPlayerID, cardID);
  930.           tricleBroadCast(5);
  931.           break;
  932.         case 6: // 天使卡
  933.           deleteCard(nowPlayerID, cardID);
  934.           tricleBroadCast(11);
  935.           break;
  936.         case 7: // 现金卡
  937.           deleteCard(nowPlayerID, cardID);
  938.           richMan.setDisplayToDiceForm(player_money, nowPlayerID);
  939.           break;
  940.         case 8: // 财神卡
  941.           if(isEmptyGround(player_location[nowPlayerID]))
  942.           {
  943.             groundForBuilding[player_location[nowPlayerID]] = -1;
  944.             deleteCard(nowPlayerID, cardID);
  945.             nextPlay(1000);
  946.           } else
  947.           {
  948.             richMan.showCardUsedMessage("你不能在这使用.");
  949.           }
  950.           break;
  951.         case 9: // 衰神卡
  952.           if(isEmptyGround(player_location[nowPlayerID]))
  953.           {
  954.             groundForBuilding[player_location[nowPlayerID]] = -2;
  955.             deleteCard(nowPlayerID, cardID);
  956.             nextPlay(1000);
  957.           } else
  958.           {
  959.             richMan.showCardUsedMessage("你不能在这使用.");
  960.           }
  961.           break;
  962.       }
  963.     }
  964.     /**
  965.      * 判断是否是空地
  966.      * @param groundLocation 空地位置
  967.      */
  968.     private boolean isEmptyGround(int groundLocation)
  969.     {
  970.       return groundLocation != 2 && groundLocation != 6 && groundLocation != 11 && groundLocation != 16 && groundLocation != 20 && groundLocation != 25 && groundLocation != 28 && groundLocation != 32 && groundLocation != 37 && groundLocation != 42 && groundLocation != 45 && groundLocation != 49 && groundForBuilding[groundLocation] == 0;
  971.     }
  972.     /**
  973.      * 强占土地
  974.      */
  975.     private void occupyGround()
  976.     {
  977.         for(; groundForBuilding[player_location[nowPlayerID]] > 9; groundForBuilding[player_location[nowPlayerID]] /= 10);
  978.         switch(nowPlayerID)
  979.         {
  980.         case 2: // '02'
  981.             groundForBuilding[player_location[nowPlayerID]] *= 100;
  982.         case 1: // '01'
  983.             groundForBuilding[player_location[nowPlayerID]] *= 10;
  984.         default:
  985.             richMan.showCardUsedMessage("这块地现在是你的了.");
  986.             break;
  987.         }
  988.     }
  989.     /**
  990.      * 删除卡片
  991.      * @param playID 角色ID
  992.      * @param cardID 卡片ID
  993.      */
  994.     private boolean deleteCard(int playID, int cardID)
  995.     {
  996.       boolean flag = false;
  997.       //判断有没有这张卡
  998.       for(int i = 0; i < player_cards[playID].length; i++)
  999.         if(player_cards[playID][i] == cardID)
  1000.           flag = true;
  1001.       if(!flag)
  1002.         return false;
  1003.       for(int i = 0; i < player_cards[playID].length; i++)
  1004.         if(player_cards[playID][i] == cardID)
  1005.         {
  1006.           player_cards[playID][i] = 16;
  1007.           i = 5; // 跳出循环,很奇怪的设置。。呵呵
  1008.         }
  1009.       // 重新排列卡片
  1010.       for(int i = 0; i < 4; i++)
  1011.         if(player_cards[playID][i] == 16)
  1012.         {
  1013.           player_cards[playID][i] = player_cards[playID][i + 1];
  1014.           player_cards[playID][i + 1] = 16;
  1015.         }
  1016.       return true;
  1017.     }
  1018.     /**
  1019.      * 偷卡片
  1020.      */
  1021.     private int stealCard()
  1022.     {
  1023.         if(nowPlayerID == 0 && player_cards[1][0] == 16 && player_cards[2][0] == 16 ||
  1024.            nowPlayerID == 1 && player_cards[0][0] == 16 && player_cards[2][0] == 16 ||
  1025.            nowPlayerID == 2 && player_cards[0][0] == 16 && player_cards[1][0] == 16)
  1026.             return -1;
  1027.         int cardNum = 16;
  1028.         int id = fetchRandomIn0ToMaxNumExceptExcludeNum(2, nowPlayerID);
  1029.         for(; cardNum == 16; cardNum = player_cards[id][fetchRandom(4)])
  1030.             id = fetchRandomIn0ToMaxNumExceptExcludeNum(2, nowPlayerID);
  1031.         deleteCard(id, cardNum);
  1032.         return cardNum;
  1033.     }
  1034.     /**
  1035.      * 增加卡片
  1036.      * @param 卡片ID
  1037.      */
  1038.     private void addCard(int cardID)
  1039.     {
  1040.       if(cardID == 10) // 随机增加卡片
  1041.         cardID = fetchRandom(9);
  1042.       for(int i = 0; i < 5; i++)
  1043.         if(player_cards[nowPlayerID][i] == 16)
  1044.         {
  1045.           player_cards[nowPlayerID][i] = cardID;
  1046.           richMan.showCardMessage(cardID);
  1047.           return;
  1048.         }
  1049.       forceAddCard(cardID);
  1050.     }
  1051.     /**
  1052.      * 强行增加卡片(5张卡片都满的时候)
  1053.      * @param 卡片ID
  1054.      */
  1055.     private void forceAddCard(int cardNum)
  1056.     {
  1057.       for(int i = 0; i < 4; i++)
  1058.         player_cards[nowPlayerID][i] = player_cards[nowPlayerID][i + 1];
  1059.       player_cards[nowPlayerID][4] = cardNum;
  1060.       richMan.showCardMessage(cardNum);
  1061.     }
  1062.     /**
  1063.      * 获的一个随机数(>=0 and <= number)
  1064.      * @param number 最大数(包括)
  1065.      */
  1066.     private int fetchRandom(int number)
  1067.     {
  1068.         return (random.nextInt() % (number + 1) + (number + 1)) % (number + 1);
  1069.     }
  1070.     /**
  1071.      * 获得一个随机数,除去一个数
  1072.      * @param maxNum 最大数
  1073.      * @param excludeNum 排除数
  1074.      */
  1075.     private int fetchRandomIn0ToMaxNumExceptExcludeNum(int maxNum, int excludeNum)
  1076.     {
  1077.         int id;
  1078.         for(id = fetchRandom(maxNum); id == excludeNum; id = fetchRandom(maxNum));
  1079.         return id;
  1080.     }
  1081.     /**
  1082.      * 火灾
  1083.      */
  1084.     private void fireGround()
  1085.     {
  1086.         int groundID = autoFetchNotSpecialGround();
  1087.         int groundID2;
  1088.         for(groundID2 = autoFetchNotSpecialGround(); groundNotConnected(groundID) != groundNotConnected(groundID2) || groundID2 == groundID; groundID2 = autoFetchNotSpecialGround());
  1089.         firedetroyGround(groundID, groundID + 1, 1);
  1090.         firedetroyGround(groundID2, groundID2 + 1, 1);
  1091.         repaint();
  1092.         serviceRepaints();
  1093.         int groundIDs[] = {
  1094.             groundID, groundID2
  1095.         };
  1096.         richMan.showBroadCast("这些区域被火灾摧毁了:", groundIDs, nowPlayerID != 0, "火警");
  1097.     }
  1098.     /**
  1099.      * 破坏地皮(因为火灾)
  1100.      * @param beginIndex 地皮开始序号
  1101.      * @param endIndex 地皮结束序号
  1102.      * @param j1 我都不知道干什么用的。。呵呵。(j1在这里没有用)
  1103.      */
  1104.     private void firedetroyGround(int beginIndex, int endIndex, int j1)
  1105.     {
  1106.         for(int k1 = beginIndex; k1 < endIndex + 1; k1++)
  1107.             if(groundForBuilding[k1] != 0)
  1108.                 groundForBuilding[k1] = groundForBuilding[k1] >= 10 ? groundForBuilding[k1] >= 100 ? 100 : 10 : 1;
  1109.     }
  1110.     /**
  1111.      * 自动获取非特殊地皮。(除去?,飞机场等)
  1112.      */
  1113.     private int autoFetchNotSpecialGround()
  1114.     {
  1115.         int l = fetchRandom(47);
  1116.         if(l == 2 || l == 5 || l == 6 || l == 10 || l == 11 || l == 14 || l == 15 || l == 16 || l == 20 || l == 25 || l == 27 || l == 28 || l == 32 || l == 36 || l == 37 || l == 41 || l == 42 || l == 45)
  1117.             l = autoFetchNotSpecialGround();
  1118.         return l;
  1119.     }
  1120.     /**
  1121.      * 获取不连接的土地
  1122.      * @param groundLocation 地皮位置
  1123.      */
  1124.     private int groundNotConnected(int groundLocation)
  1125.     {
  1126.         return groundLocation >= 2 ? groundLocation >= 5 ? groundLocation >= 10 ? ((int) (groundLocation >= 14 ? ((int) (groundLocation >= 20 ? ((int) (groundLocation >= 25 ? ((int) (groundLocation >= 32 ? ((int) (groundLocation >= 36 ? ((int) (groundLocation >= 41 ? 9 : 8)) : 7)) : 6)) : 5)) : 4)) : 3)) : 2 : 1 : 0;
  1127.     }
  1128.     /**
  1129.      * 激发广播(地震等)
  1130.      * @param broadCastType 广播类型
  1131.      */
  1132.     private void tricleBroadCast(int broadCastType)
  1133.     {
  1134.         int groundIDs[] = null;
  1135.         switch(fetchRandom(8))
  1136.         {
  1137.         case 0: // ''
  1138.             broadCastChangeGround(0, 1, broadCastType);
  1139.             groundIDs = (new int[] {
  1140.                 0, 1
  1141.             });
  1142.             break;
  1143.         case 1: // '01'
  1144.             broadCastChangeGround(3, 4, broadCastType);
  1145.             groundIDs = (new int[] {
  1146.                 3, 4
  1147.             });
  1148.             break;
  1149.         case 2: // '02'
  1150.             broadCastChangeGround(7, 9, broadCastType);
  1151.             groundIDs = (new int[] {
  1152.                 7, 8, 9
  1153.             });
  1154.             break;
  1155.         case 3: // '03'
  1156.             broadCastChangeGround(12, 13, broadCastType);
  1157.             groundIDs = (new int[] {
  1158.                 12, 13
  1159.             });
  1160.             break;
  1161.         case 4: // '04'
  1162.             broadCastChangeGround(17, 19, broadCastType);
  1163.             groundIDs = (new int[] {
  1164.                 17, 18, 19
  1165.             });
  1166.             break;
  1167.         case 5: // '05'
  1168.             broadCastChangeGround(21, 24, broadCastType);
  1169.             groundIDs = (new int[] {
  1170.                 21, 22, 23, 24
  1171.             });
  1172.             break;
  1173.         case 6: // '06'
  1174.             broadCastChangeGround(26, 31, broadCastType);
  1175.             groundForBuilding[27] = 0; //很特别哦。
  1176.             groundForBuilding[28] = 0;//很特别哦,其他CASE都没有
  1177.             groundIDs = (new int[] {
  1178.                 26, 29, 30, 31
  1179.             });
  1180.             break;
  1181.         case 7: // '07'
  1182.             broadCastChangeGround(33, 35, broadCastType);
  1183.             groundIDs = (new int[] {
  1184.                 33, 34, 35
  1185.             });
  1186.             break;
  1187.         case 8: // 'b'
  1188.             broadCastChangeGround(38, 47, broadCastType);
  1189.             groundIDs = (new int[] {
  1190.                 38, 39, 40, 43, 44, 46, 47
  1191.             });
  1192.             break;
  1193.         }
  1194.         if(broadCastType == 11)
  1195.             richMan.showBroadCast("天使祝福:n", groundIDs, nowPlayerID != 0, "新闻");
  1196.         else
  1197.         if(broadCastType == 5)
  1198.             richMan.showBroadCast("怪兽袭击n:", groundIDs, nowPlayerID != 0, "新闻");
  1199.         else
  1200.         if(broadCastType == 15)
  1201.             richMan.showBroadCast("地震摧毁:n", groundIDs, nowPlayerID != 0, "新闻");
  1202.         else
  1203.         if(broadCastType == 25)
  1204.             richMan.showBroadCast("龙卷风毁坏:n", groundIDs, nowPlayerID != 0, "新闻");
  1205.     }
  1206.     /**
  1207.      * 广播改变(地震等)
  1208.      * @param beginID 开始地皮序号
  1209.      * @param endID 结束地皮序号
  1210.      * @param broadCastType 广播类型
  1211.      */
  1212.     private void broadCastChangeGround(int beginID, int endID, int broadCastType)
  1213.     {
  1214.         switch(broadCastType)
  1215.         {
  1216.         case 11: // 天使祝福
  1217.             for(int location = beginID; location < endID + 1; location++)
  1218.             {
  1219.                 if(groundForBuilding[location] >= 100)
  1220.                     groundForBuilding[location] += 100;
  1221.                 else
  1222.                 if(groundForBuilding[location] >= 10)
  1223.                     groundForBuilding[location] += 10;
  1224.                 else
  1225.                 if(groundForBuilding[location] > 0)
  1226.                     groundForBuilding[location]++;
  1227.                 adjustGroundOverBuilding(location);
  1228.             }
  1229.             break;
  1230.         case 15: // 地震摧毁
  1231.             for(int l1 = beginID; l1 < endID + 1; l1++)
  1232.                 groundForBuilding[l1] = 0;
  1233.             break;
  1234.         default: // 龙卷风毁坏,怪兽袭击
  1235.             destroyGround(beginID, endID);
  1236.             break;
  1237.         }
  1238.     }
  1239.     /**
  1240.       * 龙卷风破坏土地
  1241.       * @param beginID 开始地皮序号
  1242.       * @param endID 结束地皮序号
  1243.       */
  1244.     private void destroyGround(int beginID, int endID)
  1245.     {
  1246.         for(int j1 = beginID; j1 < endID + 1; j1++)
  1247.             if(groundForBuilding[j1] != 0)
  1248.                 groundForBuilding[j1] = groundForBuilding[j1] >= 10 ? groundForBuilding[j1] >= 100 ? 100 : 10 : 1;
  1249.     }
  1250.     /**
  1251.      * 调整土地,避免过度建设
  1252.      * @param groundLocation 土地位置
  1253.      */
  1254.     private void adjustGroundOverBuilding(int groundLocation)
  1255.     {
  1256.         groundForBuilding[groundLocation] = groundForBuilding[groundLocation] != 5 ? groundForBuilding[groundLocation] != 50 ? groundForBuilding[groundLocation] != 500 ? groundForBuilding[groundLocation] : 400 : 40 : 4;
  1257.     }
  1258.     /**
  1259.      * 获得财产税
  1260.      */
  1261.     private int fetchBuildingTax()
  1262.     {
  1263.         int tax = 0;
  1264.         int playerBuiding = 1;
  1265.         for(int j1 = 0; j1 < nowPlayerID; j1++)
  1266.             playerBuiding *= 10;
  1267.         for(int i = 0; i < groundForBuilding.length; i++)
  1268.             if(groundForBuilding[i] == 1 * playerBuiding)
  1269.                 tax += fetchGroundPrice(i);
  1270.             else
  1271.             if(groundForBuilding[i] == 2 * playerBuiding)
  1272.                 tax += (fetchGroundPrice(i) * 8 * 5) / 100;
  1273.             else
  1274.             if(groundForBuilding[i] == 3 * playerBuiding)
  1275.                 tax += (fetchGroundPrice(i) * 8 * 15) / 100;
  1276.             else
  1277.             if(groundForBuilding[i] == 4 * playerBuiding)
  1278.                 tax += (fetchGroundPrice(i) * 8 * 125) / 100;
  1279.         return tax;
  1280.     }
  1281.     /**
  1282.      * 判断是否是当前角色的地皮
  1283.      */
  1284.     private boolean isNowPlayerIDGround()
  1285.     {
  1286.         if(groundForBuilding[player_location[nowPlayerID]] == 0)
  1287.             return true;
  1288.         else
  1289.             return nowPlayerID == (groundForBuilding[player_location[nowPlayerID]] >= 10 ? groundForBuilding[player_location[nowPlayerID]] >= 100 ? 2 : 1 : 0);
  1290.     }
  1291.     /**
  1292.      * 买地或是加盖房子
  1293.      */
  1294.     private void buildorBuyGround()
  1295.     {
  1296.         int buildingLevel = groundForBuilding[player_location[nowPlayerID]];
  1297.         for(int i1 = 0; i1 < 2; i1++)
  1298.             if(buildingLevel > 10)
  1299.                 buildingLevel /= 10;
  1300.         richMan.buildorBuyGround(player_location[nowPlayerID], fetchGroundPrice(player_location[nowPlayerID]), nowPlayerID != 0, buildingLevel);
  1301.     }
  1302.     /**
  1303.      * 减钱(走到别人的地皮上)
  1304.      * @param groundBelongtoWho 谁的土地
  1305.      * @param price  过路费
  1306.      */
  1307.     private void decreaseMoney(int groundBelongtoWho, int price)
  1308.     {
  1309.         player_money[nowPlayerID] -= price;
  1310.         player_money[groundBelongtoWho] += price;
  1311.         // 如果角色钱 < 0 把他所有的土地清除
  1312.         if(player_money[nowPlayerID] < 0)
  1313.             switch(nowPlayerID)
  1314.             {
  1315.             default:
  1316.                 break;
  1317.             case 0: // ''
  1318.                 for(int j1 = 0; j1 < groundForBuilding.length; j1++)
  1319.                     if(groundForBuilding[j1] < 10 && groundForBuilding[j1] > 0)
  1320.                         groundForBuilding[j1] = 0;
  1321.                 break;
  1322.             case 1: // '01'
  1323.               for(int j1 = 0; j1 < groundForBuilding.length; j1++)
  1324.                   if(groundForBuilding[j1] < 100 && groundForBuilding[j1] > 10)
  1325.                       groundForBuilding[j1] = 0;
  1326.               break;
  1327.             case 2: // '02'
  1328.                 for(int l1 = 0; l1 < groundForBuilding.length; l1++)
  1329.                     if(groundForBuilding[l1] >= 100)
  1330.                         groundForBuilding[l1] = 0;
  1331.                 break;
  1332.             }
  1333.         richMan.showPaymentExpense(price, nowPlayerID != 0);
  1334.     }
  1335.     /**
  1336.      * 判断当前的当前角色所处地皮是谁的。
  1337.      */
  1338.     private int fetchNowPlayerLocationGroundBelongtoWho()
  1339.     {
  1340.         if(groundForBuilding[player_location[nowPlayerID]] < 10)
  1341.             return 0;
  1342.         else
  1343.             return groundForBuilding[player_location[nowPlayerID]] >= 100 ? 2 : 1;
  1344.     }
  1345.     /**
  1346.      * 获得地皮的价格
  1347.      * @param groundID 地皮ID
  1348.      */
  1349.     private int fetchGroundPrice(int groundID)
  1350.     {
  1351.         switch(groundID)
  1352.         {
  1353.         case 0: // ''
  1354.             return 82;
  1355.         case 1: // '01'
  1356.         case 13: // 'r'
  1357.             return 80;
  1358.         case 3: // '03'
  1359.         case 8: // 'b'
  1360.             return 100;
  1361.         case 4: // '04'
  1362.         case 7: // '07'
  1363.         case 9: // 't'
  1364.         case 31: // '37'
  1365.         case 38: // '&'
  1366.         case 44: // ','
  1367.             return 120;
  1368.         case 12: // 'f'
  1369.         case 29: // '35'
  1370.         case 34: // '"'
  1371.             return 90;
  1372.         case 17: // '21'
  1373.         case 23: // '27'
  1374.         case 24: // '30'
  1375.         case 30: // '36'
  1376.         case 46: // '.'
  1377.         case 47: // '/'
  1378.             return 110;
  1379.         case 18: // '22'
  1380.             return 130;
  1381.         case 19: // '23'
  1382.             return 95;
  1383.         case 21: // '25'
  1384.         case 43: // '+'
  1385.             return 150;
  1386.         case 22: // '26'
  1387.         case 40: // '('
  1388.             return 140;
  1389.         case 26: // '32'
  1390.             return 105;
  1391.         case 33: // '!'
  1392.         case 35: // '#'
  1393.             return 85;
  1394.         case 39: // '''
  1395.             return 125;
  1396.         case 2: // '02'
  1397.         case 5: // '05'
  1398.         case 6: // '06'
  1399.         case 10: // 'n'
  1400.         case 11: // '13'
  1401.         case 14: // '16'
  1402.         case 15: // '17'
  1403.         case 16: // '20'
  1404.         case 20: // '24'
  1405.         case 25: // '31'
  1406.         case 27: // '33'
  1407.         case 28: // '34'
  1408.         case 32: // ' '
  1409.         case 36: // '$'
  1410.         case 37: // '%'
  1411.         case 41: // ')'
  1412.         case 42: // '*'
  1413.         case 45: // '-'
  1414.         default:
  1415.             return 0;
  1416.         }
  1417.     }
  1418.     /**
  1419.      * 获得相连的地皮价格
  1420.      * @param id 地皮ID
  1421.      */
  1422.     private int fetchConnectedLocationPrice(int id)
  1423.     {
  1424.         int price = 0;
  1425.         int groundID = id;
  1426.         byte groundActorID = groundForBuilding[groundID] >= 10 ? (byte)(groundForBuilding[groundID] >= 100 ? 100 : 10) : 1;
  1427.         if(groundID != 0)
  1428.             do
  1429.             {
  1430.                 if(groundForBuilding[groundID - 1] == 0 || groundForBuilding[groundID - 1] < groundActorID || groundForBuilding[groundID - 1] > groundActorID * 4)
  1431.                     break;
  1432.                 price += fetchTheGroundPrice(groundForBuilding[groundID - 1], groundID - 1);
  1433.             } while(--groundID != 0);
  1434.         groundID = groundID;
  1435.         do
  1436.         {
  1437.             if(groundForBuilding[groundID + 1] == 0 || groundForBuilding[groundID + 1] < groundActorID || groundForBuilding[groundID + 1] > groundActorID * 4)
  1438.                 break;
  1439.             price += fetchTheGroundPrice(groundForBuilding[groundID + 1], groundID + 1);
  1440.         } while(++groundID != 49);
  1441.         if(price == 0)
  1442.             price = fetchAddPrice(groundID);
  1443.         else
  1444.             price += fetchTheGroundPrice(groundForBuilding[groundID], groundID);
  1445.         return price;
  1446.     }
  1447.     /**
  1448.      * 获得地皮价格
  1449.      * @param groundBuilding 地皮的级别
  1450.      * @param groudID 地皮ID
  1451.      */
  1452.     private int fetchTheGroundPrice(int groundBuilding, int groundID)
  1453.     {
  1454.         switch(groundBuilding)
  1455.         {
  1456.         case 1: // '01'
  1457.         case 10: // 'n'
  1458.         case 100: // 'd'
  1459.             return fetchGroundPrice(groundID);
  1460.         }
  1461.         return 500;
  1462.     }
  1463.     /**
  1464.      * 获得地皮价格
  1465.      * @param 地皮ID
  1466.      */
  1467.     private int fetchAddPrice(int groundID)
  1468.     {
  1469.         switch(groundForBuilding[groundID])
  1470.         {
  1471.         case 1: // '01'
  1472.         case 10: // 'n'
  1473.         case 100: // 'd'
  1474.             return (fetchGroundPrice(groundID) * 4) / 5;
  1475.         case 2: // '02'
  1476.         case 20: // '24'
  1477.         case 200:
  1478.             return fetchGroundPrice(groundID) * 2;
  1479.         case 3: // '03'
  1480.         case 30: // '36'
  1481.         case 300:
  1482.             return (fetchGroundPrice(groundID) * 14) / 5;
  1483.         case 4: // '04'
  1484.         case 40: // '('
  1485.         case 400:
  1486.             return fetchGroundPrice(groundID) * 4;
  1487.         }
  1488.         return 0;
  1489.     }
  1490.     /**
  1491.      * 计算地皮的数量
  1492.      * @param groundValue 地皮值
  1493.      */
  1494.     public int countPlayerGround(int goundValue)
  1495.     {
  1496.         int count = 0;
  1497.         for(int i = 0; i < groundForBuilding.length; i++)
  1498.             if(groundForBuilding[i] == goundValue)
  1499.                 count++;
  1500.         return count;
  1501.     }
  1502.     /**
  1503.      * 计算角色在地图上的坐标X
  1504.      * @param id 地皮ID
  1505.      */
  1506.     private int computePlayerX(int id)
  1507.     {
  1508.         return id <= 44 && id >= 3 ? id >= 7 ? id >= 12 ? id >= 16 ? id >= 21 ? id >= 25 ? id >= 33 ? id >= 45 ? 0 : 208 - 16 * (id - 33) : 224 : 160 + 16 * (id - 21) : 144 : 96 + 16 * (id - 12) : 80 : 32 + 16 * (id - 3) : 16;
  1509.     }
  1510.     /**
  1511.      * 计算角色在地图上的坐标Y
  1512.      * @param id 地皮ID
  1513.      */
  1514.     private int computePlayerY(int id)
  1515.     {
  1516.         return id >= 3 ? id >= 7 ? id >= 11 ? id >= 16 ? id >= 20 ? id >= 26 ? id >= 32 ? id >= 46 ? id >= 50 ? 0 : 32 + 16 * (id - 46) : 16 : 112 - 16 * (id - 26) : 128 : 64 + 16 * (id - 16) : 48 : 112 - 16 * (id - 7) : 128 : 96 + 16 * id;
  1517.     }
  1518.     /**
  1519.      * 计算地皮在地图上的坐标X
  1520.      * @param id 地皮ID
  1521.      */
  1522.     private int computeGroundX(int id)
  1523.     {
  1524.         return id >= 2 ? id >= 5 ? id >= 10 ? id >= 14 ? id >= 20 ? id >= 25 ? id >= 32 ? id >= 45 ? ((int) (id >= 48 ? -200 : 0)) : 208 - 16 * (id - 33) : 240 : 160 + 16 * (id - 21) : 128 : 96 + 16 * (id - 12) : 64 : 32 + 16 * (id - 3) : 0;
  1525.     }
  1526.     /**
  1527.      * 计算角色在地图上的坐标Y
  1528.      * @param id 地皮ID
  1529.      */
  1530.     private int computeGroundY(int id)
  1531.     {
  1532.         return id >= 2 ? id >= 5 ? id >= 10 ? id >= 14 ? id >= 20 ? id >= 25 ? id >= 32 ? id >= 45 ? id >= 48 ? 0 : 32 + 16 * (id - 46) : 0 : 112 - 16 * (id - 26) : 144 : 80 + 16 * (id - 17) : 64 : 112 - 16 * (id - 7) : 144 : 96 + 16 * id;
  1533.     }
  1534.     /**
  1535.      * 初始化游戏
  1536.      */
  1537.     public void initialGame()
  1538.     {
  1539.       //角色
  1540.       for(int i = 0; i < 3; i++)
  1541.       {
  1542.         player_location[i] = 49;
  1543.         player_money[i] = 3500;
  1544.         player_prinson_canNotMoveNum[i] = 0;
  1545.         player_sleep_canNotMoveNum[i] = 0;
  1546.         for(int j = 0; j < 5; j++)
  1547.           player_cards[i][j] = 16;
  1548.         for(int j = 0; j < 4; j++)
  1549.           for (int k = 0; k < 2; k++)
  1550.             player_stock[i][j][k] = 0;
  1551.       }
  1552.       //股票
  1553.       this.stock_name = new String[4];
  1554.       stock_name[0] = "嘟嘟控股";
  1555.       stock_name[1] = "华西医大";
  1556.       stock_name[2] = "Microsoft";
  1557.       stock_name[3] = "Linux";
  1558.       this.stock_price = new int[4];
  1559.       stock_price[0] = 10;
  1560.       stock_price[1] = 4;
  1561.       stock_price[2] = 12;
  1562.       stock_price[3] = 6;
  1563.       this.stock_amplitude = new int[4];
  1564.       stock_amplitude[0] = 5 - this.fetchRandom(10);
  1565.       stock_amplitude[1] = 5 - this.fetchRandom(10);
  1566.       stock_amplitude[2] = 5 - this.fetchRandom(10);
  1567.       stock_amplitude[3] = 5 - this.fetchRandom(10);
  1568.       this.stock_price_fraction = new int[4];
  1569.       stock_price_fraction[0] = 0;
  1570.       stock_price_fraction[1] = 0;
  1571.       stock_price_fraction[2] = 0;
  1572.       stock_price_fraction[3] = 0;
  1573.       //其他
  1574.       choiceIndex = 0;
  1575.       gameStatusGoOrWinOrFail = 0;
  1576.       turnCount = 0;
  1577.       nowPlayerID = 0;
  1578.       ManControlStatus_CanNotPlay = false;
  1579.     }
  1580.     /**
  1581.      * 控制股票升降
  1582.      */
  1583.     private void changeStock() {
  1584.       for (int i = 0; i < 4; i++ ){
  1585.         stock_amplitude[i] += (7 - this.fetchRandom(14));
  1586.         if (stock_amplitude[i] > 10)
  1587.           stock_amplitude[i] = 10; //涨幅不能大于10%
  1588.         if (stock_amplitude[i] < -10)
  1589.           stock_amplitude[i] = -10; //涨幅不能小于-10%
  1590.         int price = stock_price[i] * 10000 + stock_price_fraction[i];
  1591.         price = price * (100 + stock_amplitude[i]) / 100;
  1592.         stock_price[i] = price / 10000;
  1593.         stock_price_fraction[i] = price - stock_price[i] * 10000;
  1594.         if (stock_price[i] < 2) { //价格不能小于 2块钱
  1595.           stock_price[i] = 2;
  1596.         }
  1597.       }
  1598.     }
  1599.     /**
  1600.      * 游戏结束
  1601.      * @param status 结束标记
  1602.      */
  1603.     private void gameOver(int status)
  1604.     {
  1605.         if(status == 1)
  1606.         {
  1607.             gameStatusGoOrWinOrFail = 2;
  1608.             repaint();
  1609.             serviceRepaints();
  1610.             richMan.freshHighScore(player_sequence[0], turnCount);
  1611.         } else
  1612.         {
  1613.             gameStatusGoOrWinOrFail = 3;
  1614.             repaint();
  1615.             serviceRepaints();
  1616.         }
  1617.     }
  1618.     /**
  1619.      * 自动保存文件
  1620.      */
  1621.     public void autoSaveGame()
  1622.     {
  1623.       try {
  1624.         RecordStore recordstore = RecordStore.openRecordStore("RichMan", true);
  1625.         byte bytes[] = saveGame();
  1626.         if (recordstore.getNumRecords() == 0)
  1627.           recordstore.addRecord(bytes, 0, bytes.length);
  1628.         else {
  1629.           recordstore.setRecord(1, bytes, 0, bytes.length);
  1630.           System.out.print("AutoSetSaveGame Success!");
  1631.         }
  1632.         recordstore.closeRecordStore();
  1633.       }
  1634.       catch (RecordStoreException ex) {
  1635.         System.out.println("AutoSave failed!");
  1636.       }
  1637.     }
  1638.     /**
  1639.      * 获得游戏记录
  1640.      */
  1641.     public boolean fetchRecords()
  1642.     {
  1643.       try {
  1644.         RecordStore recordstore = RecordStore.openRecordStore("RichMan", false);
  1645.         if (recordstore == null)
  1646.           return false;
  1647.         rebuildGame(recordstore.getRecord(1));
  1648.         recordstore.closeRecordStore();
  1649.       }
  1650.       catch (Exception exception) {
  1651.         return false;
  1652.       }
  1653.       play(true);
  1654.       return true;
  1655.     }
  1656.     /**
  1657.      * 保存游戏
  1658.      */
  1659.     public byte[] saveGame()
  1660.     {
  1661.         byte bytes[] = null;
  1662.         try
  1663.         {
  1664.             ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
  1665.             DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
  1666.             // 玩家数据
  1667.             for(int i = 0; i < 3; i++)
  1668.             {
  1669.                 dataoutputstream.writeInt(player_location[i]);
  1670.                 dataoutputstream.writeInt(player_money[i]);
  1671.                 dataoutputstream.writeInt(player_sequence[i]);
  1672.                 dataoutputstream.writeInt(player_prinson_canNotMoveNum[i]);
  1673.                 for (int j = 0; j < 4; j++)
  1674.                   for (int k = 0; k < 2; k++)
  1675.                     dataoutputstream.writeInt(this.player_stock[i][j][k]);
  1676.                 for(int j = 0; j < 5; j++)
  1677.                   dataoutputstream.writeInt(player_cards[i][j]);
  1678.             }
  1679.             // 地皮数据
  1680.             for(int i = 0; i < groundForBuilding.length; i++)
  1681.               dataoutputstream.writeInt(groundForBuilding[i]);
  1682.               // 股票数据
  1683.             for(int i = 0; i < 4; i++) {
  1684.               dataoutputstream.writeInt(this.stock_price[i]);
  1685.               dataoutputstream.writeInt(this.stock_amplitude[i]);
  1686.               dataoutputstream.writeInt(this.stock_price_fraction[i]);
  1687.             }
  1688.             // 其他数据
  1689.             dataoutputstream.writeInt(turnCount);
  1690.             dataoutputstream.writeInt(this.gameSpeed);
  1691.             dataoutputstream.writeBoolean(this.isLightOn);
  1692.             dataoutputstream.writeBoolean(this.isMusicOn);
  1693.             bytes = bytearrayoutputstream.toByteArray();
  1694.             bytearrayoutputstream.close();
  1695.             dataoutputstream.close();
  1696.         }
  1697.         catch(Exception exception) { }
  1698.         return bytes;
  1699.     }
  1700.     /**
  1701.      * 重建游戏(load game)
  1702.      */
  1703.     public void rebuildGame(byte recordData[])
  1704.     {
  1705.         try
  1706.         {
  1707.             ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(recordData);
  1708.             DataInputStream datainputstream = new DataInputStream(bytearrayinputstream);
  1709.             for(int i = 0; i < 3; i++)
  1710.             {
  1711.                 player_location[i] = datainputstream.readInt();
  1712.                 player_money[i] = datainputstream.readInt();
  1713.                 player_sequence[i] = datainputstream.readInt();
  1714.                 player_prinson_canNotMoveNum[i] = datainputstream.readInt();
  1715.                 for (int j = 0; j < 4; j++)
  1716.                   for (int k = 0; k < 2; k++)
  1717.                     player_stock[i][j][k] = datainputstream.readInt();
  1718.                 for(int j = 0; j < 5; j++)
  1719.                   player_cards[i][j] = datainputstream.readInt();
  1720.             }
  1721.             for(int i = 0; i < groundForBuilding.length; i++)
  1722.                 groundForBuilding[i] = datainputstream.readInt();
  1723.               for(int i = 0; i < 4; i++) {
  1724.                 this.stock_price[i] = datainputstream.readInt();
  1725.                 this.stock_amplitude[i] = datainputstream.readInt();
  1726.                 this.stock_price_fraction[i] = datainputstream.readInt();
  1727.               }
  1728.             turnCount = datainputstream.readInt();
  1729.             this.gameSpeed = datainputstream.readInt();
  1730.             this.isLightOn = datainputstream.readBoolean();
  1731.             this.isMusicOn = datainputstream.readBoolean();
  1732.             this.setIsLightOn(this.isLightOn);
  1733.             this.setIsMusicOn(this.isIsMusicOn());
  1734.             bytearrayinputstream.close();
  1735.             datainputstream.close();
  1736.         }
  1737.         catch(Exception exception) { }
  1738.     }
  1739.     /**
  1740.      * 购买土地
  1741.      */
  1742.     public void buyLand()
  1743.     {
  1744.         switch(groundForBuilding[player_location[nowPlayerID]])
  1745.         {
  1746.         case 0: // ''
  1747.             player_money[nowPlayerID] -= fetchGroundPrice(player_location[nowPlayerID]);
  1748.             break;
  1749.         case 1: //
  1750.         case 10: //
  1751.         case 100: //
  1752.             player_money[nowPlayerID] -= (fetchGroundPrice(player_location[nowPlayerID]) * 2) / 5;
  1753.             break;
  1754.         case 2: //
  1755.         case 20: //
  1756.         case 200:
  1757.             player_money[nowPlayerID] -= (fetchGroundPrice(player_location[nowPlayerID]) * 3) / 5;
  1758.             break;
  1759.         case 3: //
  1760.         case 30: //
  1761.         case 300:
  1762.             player_money[nowPlayerID] -= (fetchGroundPrice(player_location[nowPlayerID]) * 4) / 5;
  1763.             break;
  1764.         case -2: //衰神的土地
  1765.             player_money[nowPlayerID] -= fetchGroundPrice(player_location[nowPlayerID]);
  1766.             break;
  1767.         case -1: //财神的土地
  1768.           break;
  1769.         }
  1770.         if(groundForBuilding[player_location[nowPlayerID]] == -2)
  1771.             groundForBuilding[player_location[nowPlayerID]] = 0; // 恢复衰神的土地
  1772.         else
  1773.             groundForBuilding[player_location[nowPlayerID]] += nowPlayerID != 0 ? nowPlayerID != 1 ? 100 : 10 : 1;
  1774.         adjustGroundOverBuilding(player_location[nowPlayerID]);
  1775.     }
  1776.     /**
  1777.      * 处理电脑玩家玩游戏
  1778.      */
  1779.     void dealWithComputerActorPlay()
  1780.     {
  1781.       ManControlStatus_CanNotPlay = true;
  1782.       int cardIndex = -1;
  1783.       //自动获得卡片
  1784.       if(player_cards[nowPlayerID][0] != 16)
  1785.         cardIndex = autoFetchCardIndex();
  1786.       if(cardIndex != -1 &&
  1787.          this.fetchRandom(5) > 3) // 电脑有2/6机会使用卡片
  1788.       {
  1789.         choiceIndex = 1;
  1790.         repaint();
  1791.         serviceRepaints();
  1792.         try
  1793.         {
  1794.           Thread.sleep(1000L);
  1795.         }
  1796.         catch(Exception exception) { }
  1797.         richMan.useCard_ComputerActor(player_cards[nowPlayerID], cardIndex);
  1798.         /*
  1799.         choiceID = 0;
  1800.         repaint();
  1801.         serviceRepaints();
  1802.         try
  1803.         {
  1804.           Thread.sleep(1000L);
  1805.         }
  1806.         catch(Exception exception) { }
  1807.         */
  1808.       }else
  1809.         richMan.setDisplayToDiceCanvas();
  1810.     }
  1811.     /**
  1812.      * 自动获得卡片
  1813.      */
  1814.     private int autoFetchCardIndex()
  1815.     {
  1816.       int cardCount = 0;
  1817.       //计算卡片的数目
  1818.       for(int i1 = 0; i1 < 5; i1++)
  1819.         if(player_cards[nowPlayerID][i1] != 16)
  1820.           cardCount++;
  1821.       for(int index = 0; index < cardCount; index++)
  1822.         switch(player_cards[nowPlayerID][index])
  1823.         {
  1824.           case 4: // 免罪卡
  1825.           default:
  1826.             break;
  1827.           case 2: // 强占卡
  1828.             if(!isNowPlayerIDGround())
  1829.               return index;
  1830.             break;
  1831.           case 8: // 财神卡
  1832.           case 9: // 衰神卡
  1833.             if(groundForBuilding[player_location[nowPlayerID]] == 0 &&
  1834.                player_location[nowPlayerID] != 2 &&
  1835.                player_location[nowPlayerID] != 5 &&
  1836.                player_location[nowPlayerID] != 11 &&
  1837.                player_location[nowPlayerID] != 16 &&
  1838.                player_location[nowPlayerID] != 20 &&
  1839.                player_location[nowPlayerID] != 25 &&
  1840.                player_location[nowPlayerID] != 28 &&
  1841.                player_location[nowPlayerID] != 32 &&
  1842.                player_location[nowPlayerID] != 37 &&
  1843.                player_location[nowPlayerID] != 42 &&
  1844.                player_location[nowPlayerID] != 45 &&
  1845.                player_location[nowPlayerID] != 49)
  1846.               return index;
  1847.             break;
  1848.           case 0: //其他卡片
  1849.           case 1: //
  1850.           case 3: //
  1851.           case 5: //
  1852.           case 6: //
  1853.           case 7: //
  1854.             return index;
  1855.         }
  1856.       return -1;
  1857.     }
  1858.     /**
  1859.      * 设置背景灯
  1860.      * @param isLightOn 是否开灯
  1861.      */
  1862.   public void setIsLightOn(boolean isLightOn) {
  1863.     this.isLightOn = isLightOn;
  1864.     if (this.isLightOn)
  1865.       com.siemens.mp.game.Light.setLightOn();
  1866.     else
  1867.       com.siemens.mp.game.Light.setLightOff();
  1868.   }
  1869.   /**
  1870.    * 设置音乐
  1871.    * @param isMusicOn 是否打开音乐
  1872.    */
  1873.   public void setIsMusicOn(boolean isMusicOn) {
  1874.     this.isMusicOn = isMusicOn;
  1875.     if (this.isMusicOn)
  1876.       this.composer.getMelody().play();
  1877.     else
  1878.       this.composer.getMelody().stop();
  1879.   }
  1880.   /**
  1881.    * 获取背景灯状态
  1882.    */
  1883.   public boolean isIsLightOn() {
  1884.     return isLightOn;
  1885.   }
  1886.   /**
  1887.    * 获取背景音乐状态
  1888.    */
  1889.   public boolean isIsMusicOn() {
  1890.     return isMusicOn;
  1891.   }
  1892.   /**
  1893.    * 获取游戏速度
  1894.    */
  1895.   public int getGameSpeed() {
  1896.     return gameSpeed;
  1897.   }
  1898.   /**
  1899.    * 设置游戏速度
  1900.    */
  1901.   public void setGameSpeed(int gameSpeed) {
  1902.     this.gameSpeed = gameSpeed;
  1903.   }
  1904.   /**
  1905.    * 初始化音乐
  1906.    */
  1907.   public void initialMusic() {
  1908.     if (composer == null)
  1909.       composer = new com.siemens.mp.game.MelodyComposer();
  1910.     else
  1911.       composer.resetMelody();
  1912.     composer.setBPM(240);
  1913.     try {
  1914.       com.siemens.mp.io.File file = new com.siemens.mp.io.File();
  1915.       int musicFile = file.open("music" + this.music +".msc");
  1916.       int length = file.length(musicFile);
  1917.       byte[] bytes = new byte[length];
  1918.       file.read(musicFile,bytes,0,length);
  1919.       for (int i = 0; i < length / 2; i++) {
  1920.         composer.appendNote((int)bytes[i*2], (int)bytes[i*2+1]);
  1921.       }
  1922.       composer.appendNote(composer.TONE_REPEV, 1);
  1923.     }
  1924.     catch (Exception e) {
  1925.       e.printStackTrace();
  1926.     }
  1927.     /*
  1928.     try {
  1929.       composer.appendNote(composer.TONE_E3, composer.TONELENGTH_DOTTED_1_4);
  1930.       composer.appendNote(composer.TONE_D3, composer.TONELENGTH_DOTTED_1_16);
  1931.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1932.       composer.appendNote(composer.TONE_E3, composer.TONELENGTH_DOTTED_1_4);
  1933.       composer.appendNote(composer.TONE_D3, composer.TONELENGTH_DOTTED_1_16);
  1934.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1935.       composer.appendNote(composer.TONE_C3, composer.TONELENGTH_DOTTED_1_16);
  1936.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1937.       composer.appendNote(composer.TONE_H2, composer.TONELENGTH_DOTTED_1_16);
  1938.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1939.       composer.appendNote(composer.TONE_A2, composer.TONELENGTH_1_8);
  1940.       composer.appendNote(composer.TONE_A2, composer.TONELENGTH_DOTTED_1_16);
  1941.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1942.       composer.appendNote(composer.TONE_G2, composer.TONELENGTH_DOTTED_1_16);
  1943.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1944.       composer.appendNote(composer.TONE_A2, composer.TONELENGTH_DOTTED_1_4);
  1945.       composer.appendNote(composer.TONE_G2, composer.TONELENGTH_DOTTED_1_16);
  1946.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1947.       composer.appendNote(composer.TONE_A2, composer.TONELENGTH_DOTTED_1_8);
  1948.       composer.appendNote(composer.TONE_G2, composer.TONELENGTH_DOTTED_1_16);
  1949.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1950.       composer.appendNote(composer.TONE_F2, composer.TONELENGTH_1_8);
  1951.       composer.appendNote(composer.TONE_F2, composer.TONELENGTH_DOTTED_1_16);
  1952.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1953.       composer.appendNote(composer.TONE_E2, composer.TONELENGTH_DOTTED_1_16);
  1954.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1955.       composer.appendNote(composer.TONE_F2, composer.TONELENGTH_DOTTED_1_8);
  1956.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_8);
  1957.       composer.appendNote(composer.TONE_G2, composer.TONELENGTH_DOTTED_1_16);
  1958.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1959.       composer.appendNote(composer.TONE_A2, composer.TONELENGTH_DOTTED_1_16);
  1960.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1961.       composer.appendNote(composer.TONE_C3, composer.TONELENGTH_DOTTED_1_16);
  1962.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1963.       composer.appendNote(composer.TONE_G2, composer.TONELENGTH_DOTTED_1_4);
  1964.       composer.appendNote(composer.TONE_A2, composer.TONELENGTH_DOTTED_1_16);
  1965.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1966.       composer.appendNote(composer.TONE_H2, composer.TONELENGTH_DOTTED_1_8);
  1967.       composer.appendNote(composer.TONE_H2, composer.TONELENGTH_1_16);
  1968.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1969.       composer.appendNote(composer.TONE_C3, composer.TONELENGTH_DOTTED_1_8);
  1970.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_8);
  1971.       composer.appendNote(composer.TONE_D3, composer.TONELENGTH_DOTTED_1_8);
  1972.       composer.appendNote(composer.TONE_G2, composer.TONELENGTH_DOTTED_1_16);
  1973.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1974.       composer.appendNote(composer.TONE_E3, composer.TONELENGTH_DOTTED_1_4);
  1975.       composer.appendNote(composer.TONE_D3, composer.TONELENGTH_DOTTED_1_16);
  1976.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1977.       composer.appendNote(composer.TONE_E3, composer.TONELENGTH_DOTTED_1_4);
  1978.       composer.appendNote(composer.TONE_D3, composer.TONELENGTH_DOTTED_1_16);
  1979.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1980.       composer.appendNote(composer.TONE_C3, composer.TONELENGTH_DOTTED_1_16);
  1981.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1982.       composer.appendNote(composer.TONE_H2, composer.TONELENGTH_DOTTED_1_16);
  1983.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1984.       composer.appendNote(composer.TONE_A2, composer.TONELENGTH_1_8);
  1985.       composer.appendNote(composer.TONE_A2, composer.TONELENGTH_DOTTED_1_16);
  1986.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1987.       composer.appendNote(composer.TONE_G2, composer.TONELENGTH_DOTTED_1_16);
  1988.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1989.       composer.appendNote(composer.TONE_A2, composer.TONELENGTH_DOTTED_1_4);
  1990.       composer.appendNote(composer.TONE_G2, composer.TONELENGTH_DOTTED_1_16);
  1991.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1992.       composer.appendNote(composer.TONE_A2, composer.TONELENGTH_DOTTED_1_8);
  1993.       composer.appendNote(composer.TONE_G2, composer.TONELENGTH_DOTTED_1_16);
  1994.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1995.       composer.appendNote(composer.TONE_F2, composer.TONELENGTH_1_8);
  1996.       composer.appendNote(composer.TONE_F2, composer.TONELENGTH_DOTTED_1_16);
  1997.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  1998.       composer.appendNote(composer.TONE_E2, composer.TONELENGTH_DOTTED_1_16);
  1999.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  2000.       composer.appendNote(composer.TONE_F2, composer.TONELENGTH_DOTTED_1_8);
  2001.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_8);
  2002.       composer.appendNote(composer.TONE_G2, composer.TONELENGTH_DOTTED_1_16);
  2003.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  2004.       composer.appendNote(composer.TONE_A2, composer.TONELENGTH_DOTTED_1_16);
  2005.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  2006.       composer.appendNote(composer.TONE_C3, composer.TONELENGTH_DOTTED_1_16);
  2007.       composer.appendNote(composer.TONE_PAUSE, composer.TONELENGTH_DOTTED_1_16);
  2008.       composer.appendNote(composer.TONE_G2, composer.TONELENGTH_DOTTED_1_8);
  2009.       composer.appendNote(composer.TONE_A2, composer.TONELENGTH_DOTTED_1_8);
  2010.       composer.appendNote(composer.TONE_H2, composer.TONELENGTH_DOTTED_1_8);
  2011.       composer.appendNote(composer.TONE_C3, composer.TONELENGTH_DOTTED_1_8);
  2012.       composer.appendNote(composer.TONE_D3, composer.TONELENGTH_DOTTED_1_8);
  2013.       composer.appendNote(composer.TONE_E3, composer.TONELENGTH_DOTTED_1_8);
  2014.       composer.appendNote(composer.TONE_F3, composer.TONELENGTH_DOTTED_1_8);
  2015.       composer.appendNote(composer.TONE_G3, composer.TONELENGTH_DOTTED_1_8);
  2016.       composer.appendNote(composer.TONE_REPEV, 1);
  2017.     }
  2018.     catch (Exception ex) {
  2019.       ex.printStackTrace();
  2020.     }
  2021.    */
  2022.   }
  2023.   /**
  2024.    * 获取音乐序号
  2025.    */
  2026.   public int getMusic() {
  2027.     return music;
  2028.   }
  2029.   /**
  2030.    * 设置音乐序号
  2031.    * @param music 音乐序号
  2032.    */
  2033.   public void setMusic(int music) {
  2034.     this.music = music;
  2035.     this.initialMusic();
  2036.   }
  2037. }