欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當前位置:主頁 > 軟件編程 > C#教程 >

winform實現(xiàn)五子棋游戲

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點擊: 次

本文實例為大家分享了winform實現(xiàn)五子棋游戲的具體代碼,供大家參考,具體內(nèi)容如下

利用數(shù)組,根據(jù)新舊數(shù)組值的不同,獲取那個點是什么棋子;

說明:

棋盤:15*15;

定義4個全局變量:

string[,] stroldlist = new string[15, 15];//初始的List
    public string[,] strlist = new string[15, 15]; //0 :未下,1:黑子 2:白子
     int icount = 0;//五子連線算贏
     string abc = "";//獲取是白子還是黑子,1=黑子 2=白子 0=無子


自我感覺這種方法好笨,但是實在想不到什么好方法了。

代碼如下:

#region 判斷輸贏
    public void PanDuan() {
      //賦值
      for (int i = 0; i < 225; i++) {
        strlist[i / 15, i % 15] = sandwich[i].btn.Text;
        if (stroldlist[i / 15, i % 15] != strlist[i / 15, i % 15]) {
          stroldlist[i / 15, i % 15] = strlist[i / 15, i % 15];//把新數(shù)組賦值給舊數(shù)組
          icount = i;
          abc = strlist[i / 15, i % 15];       
        }
      }


      //檢查輸贏,共有四中情況,橫、豎、左斜、右斜
      int ix = icount / 15;//X軸
      int iy = icount % 15;//y軸
     // PublicClass.ShowMessage(ix+"--------"+iy);
      int count = 0;//五個點相連為贏
      // int kstart = 0;//五子連開始的點
      //四種情況,橫、豎、左斜、右斜


      //橫(左上角坐標為0,0)    "|"
      int k_shu_min = ix - 4 < 0 ? 0 : ix - 4;
      int k_shu_max = ix + 4 < 15 ? ix + 4 : 14;
      for (int k = k_shu_min; k <= k_shu_max; k++) {
        if (strlist[k, iy] == abc) {
          count++;
          if (count >= 5) {
            if (abc == "1") {
              PublicClass.ShowMessage("黑子勝!");
            }
            if (abc == "2") {
              PublicClass.ShowMessage("白子勝!");
            }
            return;
          }
        }else {
          count = 0;
        }
      }
      count = 0;//count值清0


      //豎      "一"
      int k_heng_min = iy - 4 < 0 ? 0 : iy - 4;
      int k_heng_max = iy + 4 < 15 ? iy + 4 : 14;
      for (int k = k_heng_min; k <= k_heng_max; k++) {
        if (strlist[ix, k] == abc) {
          count++;
          if (count >= 5) {
            if (abc == "1") {
              PublicClass.ShowMessage("黑子勝!");
            }
            if (abc == "2") {
              PublicClass.ShowMessage("白子勝!");
            }
            return;
          }
        }else {
          count = 0;
        }
      }     
      count = 0;


      //左斜     "/"
      int k_left_min = ix - 4 < 0 ? 0 : ix - 4;
      int k_left_max = ix + 4 < 15 ? ix + 4 : 14;
      for (int k = k_left_min; k <= k_left_max; k++) {
        int ky = 0;
        if (ix + iy > 14) {
          ky = ix + iy - k >= 14 ? 14 : ix + iy - k;
        } else {
          ky = ix + iy - k <= 0 ? 0 : ix + iy - k;
        }
        if (strlist[k, ky] == abc) {
          count++;
          if (count >= 5) {
            if (abc == "1") {
              PublicClass.ShowMessage("黑子勝!");
            }
            if (abc == "2") {
              PublicClass.ShowMessage("白子勝!");
            }
            return;
          }
        }else {
          count = 0;
        }
      }
      count = 0;


      //右斜      "\"
      int k_right_min = iy - 4 < 0 ? 0 : iy - 4;
      int k_right_max = iy + 4 < 15 ? iy + 4 : 14;
      for (int k = k_right_min; k <= k_right_max; k++) {
        int kx = 0;
        if (ix < iy) {         
          kx = ix - iy + k <= 0 ? 0 : ix - iy + k;  
        } else {
          kx = ix - iy + k >= 14 ? 14 : ix - iy + k;      
        }
        // PublicClass.ShowMessage(kx+"---"+k);
        if (strlist[kx, k] == abc) {
          count++;
          if (count >= 5) {
            if (abc == "1") {
              PublicClass.ShowMessage("黑子勝!");
            }
            if (abc == "2") {
              PublicClass.ShowMessage("白子勝!");
            }
            return;
          }
        }else {
          count = 0;
        }
      }
      count = 0;
    }
    #endregion

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持我們。

上一篇:C#實現(xiàn)BBcode轉(zhuǎn)為Markdown的方法

欄    目:C#教程

下一篇:C#實現(xiàn)簡單加減乘除計算器

本文標題:winform實現(xiàn)五子棋游戲

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/5271.html

網(wǎng)頁制作CMS教程網(wǎng)絡編程軟件編程腳本語言數(shù)據(jù)庫服務器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有