<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      HTML5+JS 《五子飛》游戲?qū)崿F(xiàn)(四)夾一個(gè)和挑一對(duì)

      在第一章我們已經(jīng)說了怎么才能“夾一個(gè)”以及怎樣才能挑一對(duì),但那畢竟只是書面上的,對(duì)碼農(nóng)來講,我們還是用代碼講解起來會(huì)更容易了解。

       

      為了更容易對(duì)照分析,我們先把路線再次貼出來:

          // 可走的路線
          this.lines = [
              [ 0,  1,  2,  3,  4],
              [ 5,  6,  7,  8,  9],
              [10, 11, 12, 13, 14],
              [15, 16, 17, 18, 19],
              [20, 21, 22, 23, 24],
              [ 0,  5, 10, 15, 20],
              [ 1,  6, 11, 16, 21],
              [ 2,  7, 12, 17, 22],
              [ 3,  8, 13, 18, 23],
              [ 4,  9, 14, 19, 24],
              [ 0,  6, 12, 18, 24],
              [ 4,  8, 12, 16, 20],
              [ 2,  6, 10],
              [ 2,  8, 14],
              [10, 16, 22],
              [14, 18, 22]
          ];              

       

      一、夾一個(gè):

      根據(jù)上面給出的有限路線中,要實(shí)現(xiàn)“夾一個(gè)”,首頁這顆棋子的index得在[0,1,2...24]之中,我們循環(huán)搜索每條路線,只要找出符合條件的路線和位置就可把對(duì)方的棋子給吃掉。

      首先我們找出棋子的目標(biāo)位置是在哪條路線中:

      int index = $.inArray(chess.point.index, this.lines[i]);//chess被移動(dòng)的棋子,下同
      if(index!=-1)//...

      然后再找出該條線上能被吃掉的棋子是哪一個(gè)。如果按照水平方向來看,被吃掉的棋子有可能在左邊,也有可能在右邊,如果在左邊,那么該方還有一個(gè)棋子應(yīng)該在被吃掉的棋子的左邊

      var p1 = index > 1 ? this.chesses[this.lines[i][index - 1]].player : Player.None;
          if (p1 != Player.None && p1 != chess.player) {
              if (this.chesses[this.lines[i][index - 2]].player == chess.player) {
                  //...找到符合條件的路線

      同理,如果被吃掉的棋子在右邊,那么該方還有一個(gè)棋子應(yīng)該在被吃掉的棋子的右邊:

      var p2 = index < this.lines[i].length - 2 ? this.chesses[this.lines[i][index + 1]].player : Player.None;
          if (p2 != Player.None && p2 != chess.player) {
              if (this.chesses[this.lines[i][index + 2]].player == chess.player) {
                  //...找到符合條件的路線

      不過,因?yàn)?span style="color: #ff0000;">按照規(guī)則,能夾對(duì)方棋子的同時(shí),該條路徑上僅且只能有三顆棋子,已方兩顆,對(duì)方一顆,其他位置上是不能有棋子存在的:

      對(duì)于在左邊的情況:

      var bfind = true;// 是否找到能被吃的棋子
      for (j = 0; j < index - 2; j++) {
          if (this.chesses[this.lines[i][j]].player != Player.None) { bfind = false; break; }
      }
      if (!bfind) return;
      bfind = true;
      for (j = index + 1; j < this.lines[i].length; j++) {
          if (this.chesses[this.lines[i][j]].player != Player.None) { bfind = false; break; }
      }
      if (!bfind) return;
      chessArray.push([this.chesses[this.lines[i][index - 1]]]);// 找到了

      對(duì)于在右邊的情況:

      var bfind = true;
      for (j = 0; j < index; j++) {
          if (this.chesses[this.lines[i][j]].player != Player.None) { bfind = false; break; }
      }
      if (!bfind) return;
      bfind = true;
      for (j = index + 3; j < this.lines[i].length; j++) {
          if (this.chesses[this.lines[i][j]].player != Player.None) { bfind = false; break; }
      }
      if (!bfind) return;
      chessArray.push([this.chesses[this.lines[i][index + 1]]]);// 找到了

       對(duì)于找到可以被夾掉的棋子我們記錄下來,存到 chessArray 里面,以便進(jìn)行其他操作。

      二、挑一對(duì):

      同樣,我們先找出棋子在哪條路徑中:

      index = $.inArray(chess.point.index, this.lines[i]);
      if (index > 0 && index < this.lines[i].length - 1) {

      然后相對(duì)于夾一個(gè)來說簡單很多,我們只要找出該棋子左右相鄰的兩個(gè)棋子是對(duì)方的棋子,且該條直線上其他位置都是空位就行了。

      先找出左右相鄰的兩顆棋子:

      var p1 = this.chesses[this.lines[i][index - 1]].player;
      var p2 = this.chesses[this.lines[i][index + 1]].player;
      if (p1 != chess.player && p2 != chess.player && p1 != Player.None && p2 != Player.None) {

      再判斷其他位置是空位:

      var bfind = true;
      for (j = 0; j < index - 1; j++) {
          if (this.chesses[this.lines[i][j]].player != Player.None) { bfind = false; break; }
      }
      if (!bfind) return;
      bfind = true;
      for (j = this.lines[i].length - 1; j > index + 1; j--) {
          if (this.chesses[this.lines[i][j]].player != Player.None) { bfind = false; break; }
      }
      if (!bfind) return;
      chessArray.push([this.chesses[this.lines[i][index - 1]], this.chesses[this.lines[i][index + 1]]]);// 找到了

       

      現(xiàn)在實(shí)現(xiàn)了兩個(gè)基本的函數(shù),下一章里沃特再跟大家分析移動(dòng)棋子。本章實(shí)現(xiàn)的兩個(gè)函數(shù)歸納如下:

          // 是否可“挑一對(duì)”
          this.canCarry = function (chess) {
              var p1, p2, j, index, bfind, chessArray = [];
              for (var i = 0; i < this.lines.length; i++) {
                  index = $.inArray(chess.point.index, this.lines[i]);
                  if (index > 0 && index < this.lines[i].length - 1) {
                      p1 = this.chesses[this.lines[i][index - 1]].player;
                      p2 = this.chesses[this.lines[i][index + 1]].player;
                      if (p1 != chess.player && p2 != chess.player && p1 != Player.None && p2 != Player.None) {
                          bfind = true;
                          for (j = 0; j < index - 1; j++) {
                              if (this.chesses[this.lines[i][j]].player != Player.None) { bfind = false; break; }
                          }
                          if (!bfind) continue;
                          bfind = true;
                          for (j = this.lines[i].length - 1; j > index + 1; j--) {
                              if (this.chesses[this.lines[i][j]].player != Player.None) { bfind = false; break; }
                          }
                          if (!bfind) continue;
                          chessArray.push([this.chesses[this.lines[i][index - 1]], this.chesses[this.lines[i][index + 1]]]);
                      }
                  }
              }
              return chessArray.length == 0 ? false : chessArray;
          };
          // 是否可“夾一個(gè)”
          this.canClip = function (chess) {
              var p1, p2, j, index, bfind, chessArray = [];
              for (var i = 0; i < this.lines.length; i++) {
                  index = $.inArray(chess.point.index, this.lines[i]);
                  if (index != -1) {
                      p1 = index > 1 ? this.chesses[this.lines[i][index - 1]].player : Player.None;
                      p2 = index < this.lines[i].length - 2 ? this.chesses[this.lines[i][index + 1]].player : Player.None;
                      if (p1 != Player.None && p1 != chess.player) {
                          if (this.chesses[this.lines[i][index - 2]].player == chess.player) {
                              bfind = true;
                              for (j = 0; j < index - 2; j++) {
                                  if (this.chesses[this.lines[i][j]].player != Player.None) { bfind = false; break; }
                              }
                              if (!bfind) continue;
                              bfind = true;
                              for (j = index + 1; j < this.lines[i].length; j++) {
                                  if (this.chesses[this.lines[i][j]].player != Player.None) { bfind = false; break; }
                              }
                              if (!bfind) continue;
                              chessArray.push([this.chesses[this.lines[i][index - 1]]]);
                          }
                      } else if (p2 != Player.None && p2 != chess.player) {
                          if (this.chesses[this.lines[i][index + 2]].player == chess.player) {
                              bfind = true;
                              for (j = 0; j < index; j++) {
                                  if (this.chesses[this.lines[i][j]].player != Player.None) { bfind = false; break; }
                              }
                              if (!bfind) continue;
                              bfind = true;
                              for (j = index + 3; j < this.lines[i].length; j++) {
                                  if (this.chesses[this.lines[i][j]].player != Player.None) { bfind = false; break; }
                              }
                              if (!bfind) continue;
                              chessArray.push([this.chesses[this.lines[i][index + 1]]]);
                          }
                      }
                  }
              }
              return chessArray.length == 0 ? false : chessArray;
          };
      View Code

       

      HTML5+JS 《五子飛》游戲?qū)崿F(xiàn)(一)規(guī)則

      HTML5+JS 《五子飛》游戲?qū)崿F(xiàn)(二)路線分析和資源準(zhǔn)備

      HTML5+JS 《五子飛》游戲?qū)崿F(xiàn)(三)頁面和棋盤棋子

      HTML5+JS 《五子飛》游戲?qū)崿F(xiàn)(五)移動(dòng)棋子

      HTML5+JS 《五子飛》游戲?qū)崿F(xiàn)(六)鼠標(biāo)響應(yīng)與多重選擇

      posted @ 2015-01-12 07:32  里沃特  閱讀(1664)  評(píng)論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 国产乱人伦AV在线麻豆A| 猫咪AV成人永久网站在线观看 | 国色天香中文字幕在线视频| 网友偷拍视频一区二区三区| 国产成人人综合亚洲欧美丁香花| 濮阳市| 婷婷99视频精品全部在线观看 | 国产国产人免费人成免费| 国产色无码专区在线观看| 长腿校花无力呻吟娇喘的视频| 亚洲人成网站免费播放| 久久人妻精品国产| 亚洲成av人片在www鸭子| 亚洲 欧美 影音先锋| 日本无码欧美一区精品久久| 天堂www在线中文| 在线视频一区二区三区色| 亚洲av无码成人影院一区| 在线a亚洲v天堂网2018| 久久天天躁狠狠躁夜夜婷| 久久精品国产99国产精品澳门| 久久综合免费一区二区三区| 蜜桃av色偷偷av老熟女| 久久精品国产久精国产| 国产精品啪| 动漫精品中文无码卡通动漫| 午夜DY888国产精品影院| 国产中文字幕在线精品| 高潮潮喷奶水飞溅视频无码| 阳泉市| 麻豆蜜桃伦理一区二区三区| 久久久亚洲精品无码| 乱中年女人伦av三区| 无码国模国产在线观看免费| 久久综合精品成人一本| 国产免费午夜福利757| 激情五月日韩中文字幕| 国产精品中文字幕自拍| 宝贝腿开大点我添添公视频免| 九九热在线免费播放视频| 灵山县|