五子棋介面
package wjc.kotlintest
import android.content.context
import android.graphics.canvas
import android.graphics.color
import android.graphics.paint
import android.util.attributeset
import android.view.view
/** * created by wjc on 2019/12/9.
*/class
mycustomview
: view
constructor
(context: context)
:this
(context, null)
constructor
(context: context, attr: attributeset?):
this
(context, attr,0)
constructor
(context: context, attr: attributeset?
, defstyleattr: int)
:super
(context, attr, defstyleattr)
override fun onmeasure
(widthmeasurespec: int, heightmeasurespec: int)
else
if(widthmode == measurespec.at_most)
else
if(heightmode == measurespec.at_most)
} override fun draw
(canvas: canvas?
)for
(j in 0.
.v)if
(listw.size !=0)
}if(listb.size !=0)
}}fun adddata
(data: data)if(
!select
(data)
)else}}
fun select
(data: data)
: boolean
return
false
} fun issuccess
(data: data, arry: list
): boolean
//橫向遍歷
fun horizontalergodic
(data: data, arry: list
): boolean }}
if(_rn != rn)
}//一方獲勝,遊戲結束
if(rn ==4)
//向左遍歷,y相同,x遞減
for(i in 1..5)
}if(_ln != ln)
}//一方獲勝,遊戲結束
if(ln ==4)
//向左向右
return ln + rn >=4}
//縱向遍歷
fun verticalergodic
(data: data, arry: list
): boolean }if
(_tn != tn)
}//一方獲勝,遊戲結束
if(tn ==4)
//向下遍歷,x相同,y遞減
for(i in 1..5)
}if(_bn != bn)}if
(bn ==4)
//向左向右
return bn + tn >=4}
//對角遍歷
fun acrossergodic
(data: data, arry: list
): boolean }if
(_rb != rb)}if
(rb ==4)
//左上方向遍歷
for(i in 1..5)
}if(_lt != lt)}if
(lt ==4)
//左上右下這條對角線
if(lt + rb >=4)
//右上遍歷
for(i in 1..5)
}if(_rt != rt)}if
(rt ==4)
//左下遍歷
for(i in 1..5)
}if(_lb != lb)}if
(lb ==4)
//左下右上這條對角線
return lb + rt >=4}
fun reset()
}
主介面
package wjc.kotlintest
import android.graphics.point
import android.os.bundle
import android.view.motionevent
import android.widget.toast
import kotlinx.android.synthetic.main.activity_main.*
class
mainactivity:(
)else
if(custom_view.bsuccess)}}
return
@setontouchlistener
true
} reset.setonclicklistener
}}
資料類
五子棋小案例
include include include define max 20 using namespace std bool flag true int temp 1 為了實現黑白棋子的交替,使用全域性變數 void qizi int array2 max int array3 max int ar...
Java實現五子棋
一定義常量類 public class constant二定義我們的棋盤類 public class chess private void playchess 錯誤輸入 if str.length 2 正常輸入的情況 判斷是否越界 if isoverstep str else end if 判斷是否...
C 實現五子棋
自己寫了一下午,但是還是除錯的時候存在很多問題 繼續改善繼續調整 game.h define game h define row 5 define col 5 void displayboard char board row col int row,int col void gameplayer c...