面向?qū)ο笃谥凶鳂I(yè)-五子棋程序設(shè)計(jì)作業(yè)_第1頁
面向?qū)ο笃谥凶鳂I(yè)-五子棋程序設(shè)計(jì)作業(yè)_第2頁
面向?qū)ο笃谥凶鳂I(yè)-五子棋程序設(shè)計(jì)作業(yè)_第3頁
面向?qū)ο笃谥凶鳂I(yè)-五子棋程序設(shè)計(jì)作業(yè)_第4頁
面向?qū)ο笃谥凶鳂I(yè)-五子棋程序設(shè)計(jì)作業(yè)_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、面向?qū)ο笃谥凶鳂I(yè)五子棋程序設(shè)計(jì)一、五子棋的由來 五子棋是我國古代的、傳統(tǒng)的黑白棋種之一,大約在南北朝時(shí)期隨圍棋一起先后傳入朝鮮、日本等地。五子棋在日本叫“連珠棋”。通過一系列的規(guī)則變化使連珠五子棋這一簡單的游戲復(fù)雜化、規(guī)范化,而最終成為今天的職業(yè)連珠五子棋,同時(shí)也成為一種國際比賽棋。二、五子棋的棋盤 棋盤正中一點(diǎn)為“天元”。棋盤兩端的橫線稱端線。棋盤左右最外邊的兩條縱線稱邊線。從兩條端線和兩條邊線向正中發(fā)展而縱橫交叉在第四條線形成的四個(gè)點(diǎn)稱為“星”。天元和星應(yīng)在棋盤上用小圓點(diǎn)標(biāo)出。 以持黑方為準(zhǔn),棋盤上的縱軸線從左到右用英文字母AO標(biāo)記。橫行線從遠(yuǎn)到近用阿拉伯?dāng)?shù)字115標(biāo)記??v橫軸上的橫縱線交

2、叉點(diǎn)分別用橫縱線標(biāo)記的名稱合寫成。三、五子棋規(guī)則 1、行棋順序 黑先、白后,從天元開始相互順序落子。 2、判斷勝負(fù) 最先在棋盤橫向、豎向、斜向形成連續(xù)的相同色五個(gè)棋子的一方為勝。 黑棋禁手判負(fù)(Lose),白棋無禁手。黑棋禁手包括“三、三”(Double Three)(包括“四、三、三”)、“四、四”(Double Four)(包括“四、四、三”)、“長連”(Overline)。黑棋只能以“四、三”取勝。 如分不出勝負(fù),則定為平局(Draw)。 五連與禁手同時(shí)形成,先五為勝。 黑方禁手形成時(shí),白方應(yīng)立即指出。若白方未發(fā)現(xiàn)或發(fā)現(xiàn)后未指明而繼續(xù)應(yīng)子,則不能判黑方負(fù)。 3、規(guī)則的解釋 術(shù)語介紹: 、

3、陽線和陰線 1、 陽線:棋盤上可見的橫縱直線。 2、 陰線:棋盤上無實(shí)線連接的隱形斜線。 、連:在棋陽線和陰線的任意一條線上形成的有5個(gè)或5個(gè)以上的同色棋子不間隔地緊緊相連。 1、 五連:在棋盤上形成的5個(gè)同色棋子的連。 2、 長連:在棋盤上形成的6個(gè)或6個(gè)以上同色棋子的連。 、四包括活四和沖四。 1、活四:在棋盤某一條陽線或陰線上有同色4子不間隔地緊緊相連,且在此4子兩端延長線上各有一個(gè)無子的交叉點(diǎn)與此4子緊密相連。 2、沖四:除活四外的,再下一著棋便可形成五連,并且存在五連的可能性的局面。 3、 白棋再下一著可形成長連的局面也視為四。 、三指活三,包括連三和跳三。 1、連三:在棋盤某一條陽

4、線或陰線上有同色三子相連,且在此三子兩端延長線上有一端至少有一個(gè),另一端至少有兩個(gè)無子的交叉點(diǎn)與此三子緊密相連。 2、跳三:中間僅間隔一個(gè)無子交叉點(diǎn)的連三,但兩端延長線均至少有一個(gè)無子的交叉點(diǎn)與此三子相連。 、禁手:對局中禁止使用的著法。 1、黑棋禁手包括三三、四四和長連。 1.1 三三:由于黑方走一著在無子交叉點(diǎn)上同時(shí)形成二個(gè)或二個(gè)以上黑方活的局面。 1.2 四四:由于黑方走一著在無子交叉點(diǎn)上同時(shí)形成二個(gè)或二個(gè)以上黑方四的局面。 2、白棋無禁手。 、四三:指某一方同時(shí)具備兩個(gè)先手,其中一個(gè)是四,一個(gè)是活三。 先手:對方必須應(yīng)答的著法,其中沖四稱為絕對先手。 、三手可交換:是指黑棋下盤面第3著

5、棋后,白方在應(yīng)白之前,如感覺黑方棋形不利于己方,可提出交換,即執(zhí)白棋一方變?yōu)閳?zhí)黑棋一方,而黑方不可以不換。 、五手兩打:是指黑棋在下盤面上關(guān)鍵的第5手棋時(shí),必須下兩步棋,讓白棋在這兩步棋中任選一步,然后再繼續(xù)對弈。一般說來,白棋肯定拿掉對白方不利的一點(diǎn),而保留對黑方較為不利的那點(diǎn)讓黑方行棋。四、UML圖五、功能介紹開始:游戲設(shè)置,點(diǎn)擊開始或選擇新游戲菜單方能開始游戲。暫停和繼續(xù):是用時(shí)間計(jì)數(shù)器來規(guī)定沒有棋手有15秒鐘的下棋思考時(shí)間,期間可以暫停時(shí)間和繼續(xù)時(shí)間,15秒倒計(jì)時(shí)結(jié)束,還未下棋系統(tǒng)將其至為自動放棄,系統(tǒng)判定此局為負(fù)。歷史記錄:歷史紀(jì)錄中記錄了棋手每次下棋,所落子的位置,這樣是棋手可查詢

6、本盤棋所有落子的位置?;谄澹涸诟杏X落子有誤時(shí),方可使用悔棋功能,每執(zhí)行一次,系統(tǒng)將把執(zhí)行前所下的一步棋,將其清除,使得下棋更人性化。六、代碼及注釋using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Net;using System.Net.Sockets;using System.Text;using System.IO;using System.Thread

7、ing;namespace game/ / fivechess 的摘要說明。/ public class fivechess : System.Windows.Forms.Formprivate System.Windows.Forms.MainMenu mainMenu1;private System.Windows.Forms.MenuItem menuItem1;private System.Windows.Forms.MenuItem menuItem5;private System.Windows.Forms.MenuItem menuItem6;private System.Com

8、ponentModel.IContainer components;private System.Windows.Forms.ImageList imageList1;private const int None = -1;/沒有棋子private const int White = 0;/代表白棋private const int Black = 1;/代表黑棋private int timecount=15;private int ,checkerBoard = new int 15, 15;/棋盤(用來保存每一個(gè)棋子)private int nextPlayer;/下一個(gè)選手bool s

9、j = true;bool start = false;private int Playergetreturn nextPlayer;setnextPlayer = value;ReDrawNextPlayerMark();private System.Windows.Forms.MenuItem menuItem9;/下一次該黑棋還是白棋下private Stack History;/下棋的歷史記錄private System.Windows.Forms.MenuItem menuItem2;private System.Windows.Forms.GroupBox groupBox2;pr

10、ivate System.Windows.Forms.ListBox lstHistory;private System.Windows.Forms.GroupBox groupBox1;private System.Windows.Forms.TextBox Time;private System.Windows.Forms.Button stop;private System.Windows.Forms.Button goon;private System.Windows.Forms.Label lb;private System.Windows.Forms.Button startBT;

11、private System.Windows.Forms.Timer timer1;public fivechess()/ Required for Windows Form Designer support/InitializeComponent();/ TODO: Add any constructor code after InitializeComponent call/checkerBoard = new int 15,15;History = new Stack();Player = White;/默認(rèn)設(shè)置為白棋先下Reset();/ / 清理所有正在使用的資源。/ protect

12、ed override void Dispose( bool disposing )if( disposing )if(components != null)components.Dispose();base.Dispose( disposing );#region Windows Form Designer generated code/ / Required method for Designer support - do not modify/ the contents of this method with the code editor./ private void Initiali

13、zeComponent()ponents = new System.ComponentModel.Container();System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(fivechess);this.menuItem9 = new System.Windows.Forms.MenuItem();this.menuItem5 = new System.Windows.Forms.MenuItem();this.menuItem6 = new System.Windo

14、ws.Forms.MenuItem();this.menuItem1 = new System.Windows.Forms.MenuItem();this.mainMenu1 = new System.Windows.Forms.MainMenu();this.menuItem2 = new System.Windows.Forms.MenuItem();this.imageList1 = new System.Windows.Forms.ImageList(ponents);this.groupBox2 = new System.Windows.Forms.GroupBox();this.l

15、stHistory = new System.Windows.Forms.ListBox();this.groupBox1 = new System.Windows.Forms.GroupBox();this.lb = new System.Windows.Forms.Label();this.Time = new System.Windows.Forms.TextBox();this.stop = new System.Windows.Forms.Button();this.goon = new System.Windows.Forms.Button();this.timer1 = new

16、System.Windows.Forms.Timer(ponents);this.startBT = new System.Windows.Forms.Button();this.groupBox2.SuspendLayout();this.groupBox1.SuspendLayout();this.SuspendLayout();/ / menuItem9/ this.menuItem9.Index = 1;this.menuItem9.Text = -;/ / menuItem5/ this.menuItem5.Index = 0;this.menuItem5.Text = 新游戲;th

17、is.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);/ / menuItem6/ this.menuItem6.Index = 2;this.menuItem6.Text = 退出;this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);/ / menuItem1/ this.menuItem1.Index = 0;this.menuItem1.MenuItems.AddRange(new System.Windows.Form

18、s.MenuItem this.menuItem5, this.menuItem9, this.menuItem6);this.menuItem1.Text = 游戲;/ / mainMenu1/ this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem this.menuItem1, this.menuItem2);/ / menuItem2/ this.menuItem2.Index = 1;this.menuItem2.Text = 悔棋;this.menuItem2.Click += new System.E

19、ventHandler(this.menuItem2_Click);/ / imageList1/ this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;this.imageList1.ImageSize = new System.Drawing.Size(20, 20);this.imageList1.ImageStream = (System.Windows.Forms.ImageListStreamer)(resources.GetObject(imageList1.ImageStream);thi

20、s.imageList1.TransparentColor = System.Drawing.Color.Transparent;/ / groupBox2/ this.groupBox2.Controls.Add(this.lstHistory);this.groupBox2.Cursor = System.Windows.Forms.Cursors.Hand;this.groupBox2.Font = new System.Drawing.Font(宋體, 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUni

21、t.Point, (System.Byte)(0);this.groupBox2.ImeMode = System.Windows.Forms.ImeMode.Off;this.groupBox2.Location = new System.Drawing.Point(5, 116);this.groupBox2.Name = groupBox2;this.groupBox2.Size = new System.Drawing.Size(212, 204);this.groupBox2.TabIndex = 5;this.groupBox2.TabStop = false;this.group

22、Box2.Text = 歷史記錄;/ / lstHistory/ this.lstHistory.ItemHeight = 14;this.lstHistory.Location = new System.Drawing.Point(12, 19);this.lstHistory.Name = lstHistory;this.lstHistory.Size = new System.Drawing.Size(187, 172);this.lstHistory.TabIndex = 0;/ / groupBox1/ this.groupBox1.Controls.Add(this.startBT

23、);this.groupBox1.Controls.Add(this.lb);this.groupBox1.Controls.Add(this.Time);this.groupBox1.Controls.Add(this.stop);this.groupBox1.Controls.Add(this.goon);this.groupBox1.Controls.Add(this.groupBox2);this.groupBox1.Cursor = System.Windows.Forms.Cursors.Hand;this.groupBox1.Font = new System.Drawing.F

24、ont(宋體, 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (System.Byte)(0);this.groupBox1.ImeMode = System.Windows.Forms.ImeMode.Off;this.groupBox1.Location = new System.Drawing.Point(321, 0);this.groupBox1.Name = groupBox1;this.groupBox1.Size = new System.Drawing.Size(231,

25、 338);this.groupBox1.TabIndex = 0;this.groupBox1.TabStop = false;/ / lb/ this.lb.Location = new System.Drawing.Point(20, 37);this.lb.Name = lb;this.lb.Size = new System.Drawing.Size(93, 18);this.lb.TabIndex = 9;this.lb.Text = 思考倒計(jì)時(shí):;/ / Time/ this.Time.Location = new System.Drawing.Point(112, 32);th

26、is.Time.Name = Time;this.Time.Size = new System.Drawing.Size(76, 23);this.Time.TabIndex = 8;this.Time.Text = ;/ / stop/ this.stop.Location = new System.Drawing.Point(146, 70);this.stop.Name = stop;this.stop.Size = new System.Drawing.Size(48, 27);this.stop.TabIndex = 7;this.stop.Text = 暫停;this.stop.C

27、lick += new System.EventHandler(this.stop_Click);/ / goon/ this.goon.Location = new System.Drawing.Point(87, 73);this.goon.Name = goon;this.goon.Size = new System.Drawing.Size(46, 27);this.goon.TabIndex = 6;this.goon.Text = 繼續(xù);this.goon.Click += new System.EventHandler(this.goon_Click);/ / timer1/ t

28、his.timer1.Interval = 1000;this.timer1.Tick += new System.EventHandler(this.timer1_Tick);/ / startBT/ this.startBT.Location = new System.Drawing.Point(28, 72);this.startBT.Name = startBT;this.startBT.Size = new System.Drawing.Size(45, 26);this.startBT.TabIndex = 10;this.startBT.Text = 開始;this.startB

29、T.Click += new System.EventHandler(this.startBT_Click);/ / fivechess/ this.AccessibleDescription = ;this.AllowDrop = true;this.AutoScale = false;this.AutoScaleBaseSize = new System.Drawing.Size(10, 25);this.BackgroundImage = (System.Drawing.Image)(resources.GetObject($this.BackgroundImage);this.Clie

30、ntSize = new System.Drawing.Size(549, 331);this.Controls.Add(this.groupBox1);this.Cursor = System.Windows.Forms.Cursors.Hand;this.Font = new System.Drawing.Font(Microsoft Sans Serif, 16F);this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;this.ImeMode = System.Windows.Forms.ImeM

31、ode.Off;this.MaximizeBox = false;this.Menu = this.mainMenu1;this.Name = fivechess;this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;this.Text = 五子棋;this.groupBox2.ResumeLayout(false);this.groupBox1.ResumeLayout(false);this.ResumeLayout(false);#endregion/ / The main entry point

32、 for the application./ STAThread/ / 應(yīng)用程序的主入口點(diǎn)。/ /STAThreadstatic void Main() Application.Run(new fivechess();/退出菜單private void menuItem6_Click(object sender, System.EventArgs e)this.Close();/新游戲菜單private void menuItem5_Click(object sender, System.EventArgs e)if(History.Count 0) this.Reset();timer1.S

33、top();this.Time.Text = ;if(this.lstHistory.Items.Count != 0)this.lstHistory.Items.Clear();start = true;this.timer1.Start();if(this.lstHistory.Items.Count != 0)this.lstHistory.Items.Clear();/重載重畫函數(shù)protected override void OnPaint(PaintEventArgs e)System.Drawing.Graphics g = this.CreateGraphics();for(i

34、nt x = 0; x 15; x+)for(int y= 0; y 15; y+)if(checkerBoard y, x != None)DrawChess(new Point(x, y), checkerBoard y, x );ReDrawNextPlayerMark();base.OnPaint(e);/重載鼠標(biāo)按下事件protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) base.OnMouseDown(e);if(start)if(sj)switch( e.Button )/take

35、left button downcase MouseButtons.Left:if( (History.Count = 0) & (2 e.X) & (e.X 22) & (309 e.Y) & (e.Y 329) ) Player = (Player = White)? Black: White;elseAddChess( MToA( new Point(e.X, e.Y) ) );break;/take right button downcase MouseButtons.Right:/OnRButtonDown(new Point(e.X,e.Y);break;elseMessageBo

36、x.Show(請選擇“開始!”);/把鼠標(biāo)坐標(biāo)轉(zhuǎn)換成棋盤坐標(biāo)private Point MToA(Point p)return new Point( (p.X - 15) / 20, (p.Y - 6) / 20);/開始新的棋局,所有數(shù)據(jù)復(fù)位并重畫棋盤private void Reset()for( int i = 0; i 15; i+ )for( int j = 0; j 15; j+)checkerBoardi,j = None;History.Clear();/清空歷史記錄DrawCheckerBoard();/重畫棋盤/重畫棋盤private void DrawCheckerBoa

37、rd()this.BackColor = System.Drawing.SystemColors.Desktop;this.BackColor = System.Drawing.SystemColors.Control;/重畫下一個(gè)選手的標(biāo)志棋子private void ReDrawNextPlayerMark()System.Drawing.Graphics g = this.CreateGraphics();imageList1.Draw(g, 2, 309, 20, 20, Player);/在棋盤上畫一個(gè)棋子private void DrawChess(Point pCoordinat

38、es,int iPlayer)System.Drawing.Graphics g = this.CreateGraphics();imageList1.Draw(g, 15 + pCoordinates.X * 20, 6 + pCoordinates.Y * 20, 20, 20, iPlayer);/在指定的棋盤坐標(biāo)位置添加一個(gè)棋子private void AddChess(Point p)/判斷是否超出邊界if( (p.X 14) | (p.Y 14) ) return;/判斷該位置有無棋子if( checkerBoard p.Y, p.X != None ) return;/如果已經(jīng)有

39、了棋子則退出(這顆棋不能下)DrawChess( p,Player );if(Player = White)/該白棋下checkerBoard p.Y, p.X = White;this.lstHistory.Items.Add(白棋:+橫:+(p.X+1).ToString()+,縱:+(15-p.Y).ToString();Player = Black;timer1.Stop();timecount=15;timer1.Start();elsecheckerBoard p.Y, p.X = Black;this.lstHistory.Items.Add(黑棋:+橫:+(p.X+1).ToS

40、tring()+,縱:+(15-p.Y).ToString();Player = White;timer1.Stop();timecount=15;timer1.Start();History.Push( new Point(p.X, p.Y) );/添加歷史記錄CheckGameResult( p );/棋手悔棋/private void menuItem2_Click(object sender, System.EventArgs e)if(History.Count 0)this.timer1.Stop();Point p = (Point)History.Pop();checkerBo

41、ard p.Y, p.X = None;nextPlayer = (Player = White)? Black: White;int x = this.lstHistory.Items.Count;this.lstHistory.Items.RemoveAt(x-1);DrawCheckerBoard();this.timer1.Start();elsethis.timer1.Stop();MessageBox.Show(請下棋吧,已經(jīng)沒有可悔的棋子了!);/棋手思考時(shí)間的限定/private void timer1_Tick(object sender, System.EventArgs

42、e)Time.Text = timecount.ToString();if(timecount 0) this.Reset();timer1.Stop();timecount=15;this.Time.Text = ;start = false;if(Player = Black)timer1.Stop();MessageBox.Show(時(shí)間到,白方勝!);if(History.Count 0) this.Reset();timer1.Stop();timecount=15;this.Time.Text = ;start = false;elsetimecount-;/開始按鈕private

43、 void startBT_Click(object sender, System.EventArgs e)if(History.Count 0) this.Reset();timer1.Stop();this.Time.Text = ;if(this.lstHistory.Items.Count != 0)this.lstHistory.Items.Clear();start = true;this.timer1.Start();if(this.lstHistory.Items.Count != 0)this.lstHistory.Items.Clear();/時(shí)間繼續(xù)/private void goon_Click(object sender, System.EventArgs e)timer1.Start();sj = true;/時(shí)間暫停/private vo

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論