using system;
using system.drawing;
using system.threading;
using system.windows.forms;
private
void
show_can_position()
}}}//統計可以落子的位置數
private
intshow_can_num()
}}return n;
//可以落子的位置個數
}private
void
cls_can_position()
= cint(x) & y }}
private
bool
checkdirect
(int x1,
int y1,
int dx,
int dy)if(
inboard
(x, y)
&ismychess
(x, y)
& flag ==
true
)return
false;}
private
void
directreverse
(int x1,
int y1,
int dx,
int dy)if(
inboard
(x, y)
&ismychess
(x, y)
& flag ==
true
)while
((x != x1 || y != y1));
}}private
bool
inboard
(int x,
int y)
private
bool
can_go
(int x1,
int y1)
private
void
picturebox1_mousedown
(object sender,
mouseeventargs e)
if(mycolor ==1)
else
//(x1,y1)處原色處理
graphics g =
this
.picturebox1.
creategraphics()
;bitmap bitmap =
newbitmap
("whitestone.png");
if(mycolor ==2)
if(mycolor ==1)
//從左,左上,上,右上,右,右下,下,左下八個方向翻轉 if(
checkdirect
(x1, y1,-1
,0)==
true
)//向左方向形成夾擊之勢
directreverse
(x1, y1,-1
,0);
if(checkdirect
(x1, y1,-1
,-1)
==true
)//向左上方向形成夾擊之勢
directreverse
(x1, y1,-1
,-1)
;if(checkdirect
(x1, y1,0,
-1)==
true
)//向上方向形成夾擊之勢
directreverse
(x1, y1,0,
-1);
if(checkdirect
(x1, y1,1,
-1)==
true
)//向右上方向形成夾擊之勢
directreverse
(x1, y1,1,
-1);
if(checkdirect
(x1, y1,1,
0)==true
)directreverse
(x1, y1,1,
0);if
(checkdirect
(x1, y1,1,
1)==true
)directreverse
(x1, y1,1,
1);if
(checkdirect
(x1, y1,0,
1)==true
)directreverse
(x1, y1,0,
1);if
(checkdirect
(x1, y1,-1
,1)==
true
)directreverse
(x1, y1,-1
,1);
cls_can_position()
;//清除提示
if(mycolor ==1)
else
show_can_position()
;//顯示提示 if(
show_can_num()
==0)else
show_can_position()
;//顯示提示
}//判斷遊戲是否結束
int whitenum =0;
int blacknum =0;
for(x =
1; x <=
8; x++)}
}if(n ==64)
//在棋盤下滿時,
else
picturebox1.enabled =
false
;//遊戲結束,不能走棋
button1.enabled =
true
;//"開始遊戲"按鈕有效
return;}
//在棋盤還沒有下滿時
if(whitenum ==0)
if(blacknum ==0)
}private
void
fanqi
(int x,
int y)
else
thread.
sleep
(200);
//延時0.2秒
listbox1.items.
add(
" ("
+ convert.
tochar
(x +64)
.tostring()
+","
+ y +
")處被反色");
}private
bool
ismychess
(int x,
int y)
private
void
button1_click
(object sender,
eventargs e)
} listbox1.items.
clear()
;//棋盤上畫初始4個棋子
x =4;
y =4;
g.drawimage
(bitmap,
(x -1)
*45+22
,(y -1)
*45+22
,45,45
);x =5;
y =5;
g.drawimage
(bitmap,
(x -1)
*45+22
,(y -1)
*45+22
,45,45
);bitmap =
newbitmap
("blackstone.png");
x =5;
y =4;
g.drawimage
(bitmap,
(x -1)
*45+22
,(y -1)
*45+22
,45,45
);x =4;
y =5;
g.drawimage
(bitmap,
(x -1)
*45+22
,(y -1)
*45+22
,45,45
);map[4,
4]=2
;//0無子 1黑色 2白色
map[5,
5]=2
; map[4,
5]=1
; map[5,
4]=1
; mycolor =1;
//自己棋子顏色為黑色
toolstripstatuslabel1.text =
"黑色棋子先走"
;this
.text =
"黑白棋遊戲"
;show_can_position()
;}private
void
button2_click
(object sender,
eventargs e)
private
void
button3_click
(object sender,
eventargs e)
private
void
button4_click
(object sender,
eventargs e)
}}
C 黑白棋(落子)
時限 1000ms 記憶體限制 10000k 總時限 3000ms 描述 經過前3題的熱身相信大家已經對黑白棋有了一定的認識,下面我們來編寫稍微複雜一點的模組。黑白棋並不像5子棋或者圍棋一樣可以在任意空白處下子,那麼檢測某個位置是否可以下子 如對規則還不是很了解,請參照前3題的規則介紹 也是我們黑白...
黑白棋遊戲
黑白棋遊戲 time limit 10000ms memory limit 65536k total submit 9 accepted 5 case time limit 1000ms description 問題描述 黑白棋遊戲的棋盤由4 4方格陣列構成。棋盤的每一方格中放有1枚棋子,共有8枚白...
黑白棋遊戲
用c 封裝了一下,只完成了乙個雛形,有很多功能沒有新增上,但 的行數已經縮短了很多了。include include include includeusing namespace std class chess int counter 計數器,計算棋子個數 const friend void dra...