版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、C#程序設(shè)計(jì)課程設(shè)計(jì)題 目: 拼圖游戲 專 業(yè): 計(jì)算機(jī)科學(xué)與技術(shù) 學(xué) 號(hào): 姓 名: 指導(dǎo)老師: 完成日期: 2012/12/26 C#課程設(shè)計(jì)評(píng)分標(biāo)準(zhǔn)題 目: 拼圖游戲 專 業(yè): 計(jì)算機(jī)科學(xué)與技術(shù) 學(xué) 號(hào): 姓 名: 考察項(xiàng)目評(píng)分依據(jù)完成情況分?jǐn)?shù)報(bào)告(40分)規(guī)范完成設(shè)計(jì)報(bào)告,含光盤報(bào)告能夠反映設(shè)計(jì)思路,并介紹系統(tǒng)功能報(bào)告內(nèi)容比較完整,思路比較清晰,語句比較通順報(bào)告內(nèi)容完整,用語準(zhǔn)確,能夠反映系統(tǒng)開發(fā)過程前臺(tái)開發(fā)工具(10分)能夠使用開發(fā)工具的基本操作完成系統(tǒng)的開發(fā)能夠熟練地運(yùn)用開發(fā)工具來實(shí)現(xiàn)較全面的功能對(duì)開發(fā)工具熟悉,能夠靈活使用各類控件和語句完成系統(tǒng)開發(fā)能夠熟練掌握多種開發(fā)工具,并能夠
2、獨(dú)立解決較復(fù)雜的編程問題。應(yīng)用到多種數(shù)據(jù)庫對(duì)象。系統(tǒng)功能(25分)能夠完成數(shù)據(jù)的輸入輸出和基本查詢功能除了基本信息管理功能外,還可以完成比較復(fù)雜的數(shù)據(jù)查詢和數(shù)據(jù)編輯功能能夠方便地完成數(shù)據(jù)操作功能具有較復(fù)雜的數(shù)據(jù)管理功能系統(tǒng)界面設(shè)計(jì)(20分)具有一般的Window窗口界面功能比較全,操作也比較方便界面美觀,功能全面,操作方便界面美觀,功能設(shè)計(jì)有創(chuàng)新教師簽字:成績(jī):目 錄1 前言42 需求分析42.1要求42.2任務(wù)42.3運(yùn)行環(huán)境42.4開發(fā)工具43 概要設(shè)計(jì)與詳細(xì)設(shè)計(jì)53.1系統(tǒng)流程圖53.2結(jié)構(gòu)功能圖54 編碼與實(shí)現(xiàn)64.1編碼分析64.2具體代碼實(shí)現(xiàn)(附源代碼)95 課程設(shè)計(jì)總結(jié)18參考文
3、獻(xiàn)191.前言拼圖游戲一款非常經(jīng)典的小游戲,因?yàn)樗容^簡(jiǎn)單有趣,無論老少都比較適合。拼圖的設(shè)計(jì)對(duì)每一個(gè)C#語言設(shè)計(jì)者進(jìn)行語言提高和進(jìn)階都是一個(gè)很好的鍛煉機(jī)會(huì)。 拼圖游戲的設(shè)計(jì)比較復(fù)雜,它涉及面廣、牽涉方面多,如果不好好考慮和設(shè)計(jì),將難以成功開發(fā)出這個(gè)游戲。在這個(gè)游戲的設(shè)計(jì)中,牽涉到圖形界面的顯示與更新、數(shù)據(jù)的收集與更新,并且在這個(gè)游戲的開發(fā)中,還要應(yīng)用類的繼承機(jī)制以及一些設(shè)計(jì)模式。因此,如何設(shè)計(jì)和開發(fā)好這個(gè)拼圖游戲,對(duì)于提高C#開發(fā)水平和系統(tǒng)的設(shè)計(jì)能力有極大的幫助。在設(shè)計(jì)開發(fā)過程中,需要處理好各個(gè)類之間的繼承關(guān)系,還要處理各個(gè)類相應(yīng)的封裝,并且還要協(xié)調(diào)好各個(gè)模塊之間的邏輯依賴關(guān)系和數(shù)據(jù)通信關(guān)系
4、。一個(gè)3×3的魔板,有一個(gè)格子是空的,其他格子內(nèi)隨機(jī)放置1-8共8個(gè)編號(hào)的方塊,通過單擊任意一個(gè)與空格子相鄰的方塊可以把該方塊移入空格子,不斷的移動(dòng)方塊,直到方塊按照?qǐng)D片的原來的順序排好。2 需求分析2.1要求(1)用C#語言實(shí)現(xiàn)程序設(shè)計(jì);(2)利用PictureBox控件來實(shí)現(xiàn)圖片的移動(dòng)(3)超過200步提示重新來(4)界面友好(良好的人機(jī)互交),程序要有注釋。2.2任務(wù)(1)制作流程圖(2)編寫代碼;(3)程序分析與調(diào)試。2.3運(yùn)行環(huán)境(1)WINDOWS2000/XP/win7系統(tǒng)(2)TurboC2.0編譯環(huán)境2.4開發(fā)工具C#語言3 概要設(shè)計(jì)與詳細(xì)設(shè)計(jì)3.1系統(tǒng)流程圖如圖3
5、.1所示。游戲開始操作游戲200步內(nèi)完成游戲游戲完成圖3.1 系統(tǒng)流程圖3.2功能結(jié)構(gòu)圖如圖3.2所示。拼圖游戲游戲開始游戲復(fù)位游戲結(jié)束游戲退出圖3.2功能結(jié)構(gòu)圖這個(gè)游戲主要分為四個(gè)模塊,分別是游戲開始、游戲復(fù)位、游戲結(jié)束和游戲退出。這四個(gè)摸塊的功能各不一樣,游戲開始的模塊就不用多介紹了,我們?cè)谶@里主要說說重新開始的模塊,如果玩家對(duì)自己本次的成績(jī)不滿意,可以通過重新開始模塊來重完游戲4 編碼與實(shí)現(xiàn)4.1分析說明游戲開始:界面如圖4-1圖4-1在程序開頭定義變量,實(shí)例化數(shù)組;代碼如下圖游戲進(jìn)行中 :當(dāng)游戲運(yùn)行的時(shí)候,桌面上會(huì)出現(xiàn)圖上的圖形界面。有一個(gè)文本框和一個(gè)圖形界面。其中通過點(diǎn)擊鼠標(biāo)移動(dòng)圖片
6、,游戲就正式開始,且此游戲是通過計(jì)算鼠標(biāo)點(diǎn)擊的次數(shù),而不是計(jì)算時(shí)間,所以玩游戲的人可以有充分的時(shí)間考慮。游戲中見圖4-2圖4-2左右圖片對(duì)照方便有游戲的進(jìn)行,左下角有顯示有戲進(jìn)行的步數(shù),復(fù)位時(shí)直接把右邊的圖相應(yīng)的賦給左邊,代碼實(shí)現(xiàn)如下圖:這里從第一個(gè)到第九個(gè)PictureBox都有相應(yīng)賦值和命令這里只截取Box1的圖片對(duì)應(yīng)的代碼游戲時(shí)本段代碼主要運(yùn)用的c#知識(shí)是二維數(shù)組和ifelse語句,通過判斷box1游戲復(fù)位:如果覺得自己的成績(jī)不夠好,可以選擇復(fù)位重新開始。復(fù)位時(shí)直接把右邊的圖相應(yīng)的賦給左邊,復(fù)位后效果和剛開始一樣。代碼實(shí)現(xiàn)如下游戲完成:當(dāng)玩家在200步以內(nèi)完成拼圖則提示"恭喜你
7、已經(jīng)完成拼圖!"如圖4-3 ;否則將提玩家重新來過如圖4-4圖4-44.2具體代碼實(shí)現(xiàn)附源代碼using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace 拼圖游戲2 public partial class Form1 : Form public static int aa; public static int
8、bb; private System.Windows.Forms.PictureBox, t; public Form1() InitializeComponent(); /實(shí)例化數(shù)組 private void Form1_Load(object sender, EventArgs e) t = new PictureBox3, 3pictureBox1 ,pictureBox2 ,pictureBox3 , pictureBox4 ,pictureBox5 ,pictureBox6 , pictureBox7 ,pictureBox8 ,pictureBox9 ; for (int i =
9、0; i <= 2; i+) for (int j = 0; j <= 2; j+) ti, j.Enabled = false; /圖片的移動(dòng) private void pictureBox1_Click(object sender, EventArgs e) bb+; label2.Text = bb.ToString(); if (pictureBox2.Image = null) pictureBox2.Image = pictureBox1.Image; pictureBox1.Image = null; else if (pictureBox4.Image = null
10、) pictureBox4.Image = pictureBox1.Image; pictureBox1.Image = null; private void pictureBox2_Click(object sender, EventArgs e) bb+; label2.Text = bb.ToString(); if (pictureBox1.Image = null) pictureBox1.Image = pictureBox2.Image; pictureBox2.Image = null; else if (pictureBox3.Image = null) pictureBox
11、3.Image = pictureBox2.Image; pictureBox2.Image = null; else if (pictureBox5.Image = null) pictureBox5.Image = pictureBox2.Image; pictureBox2.Image = null; private void pictureBox3_Click(object sender, EventArgs e) bb+; label2.Text = bb.ToString(); if (pictureBox2.Image = null) pictureBox2.Image = pi
12、ctureBox3.Image; pictureBox3.Image = null; else if (pictureBox6.Image = null) pictureBox6.Image = pictureBox3.Image; pictureBox3.Image = null; private void pictureBox4_Click(object sender, EventArgs e) bb+; label2.Text = bb.ToString(); if (pictureBox1.Image = null) pictureBox1.Image = pictureBox4.Im
13、age; pictureBox4.Image = null; else if (pictureBox5.Image = null) pictureBox5.Image = pictureBox4.Image; pictureBox4.Image = null; else if (pictureBox7.Image = null) pictureBox7.Image = pictureBox4.Image; pictureBox4.Image = null; private void pictureBox5_Click(object sender, EventArgs e) bb+; label
14、2.Text = bb.ToString(); if (pictureBox2.Image = null) pictureBox2.Image = pictureBox5.Image; pictureBox5.Image = null; else if (pictureBox4.Image = null) pictureBox4.Image = pictureBox5.Image; pictureBox5.Image = null; else if (pictureBox6.Image = null) pictureBox6.Image = pictureBox5.Image; picture
15、Box5.Image = null; else if (pictureBox8.Image = null) pictureBox8.Image = pictureBox5.Image; pictureBox5.Image = null; private void pictureBox6_Click(object sender, EventArgs e) bb+; label2.Text = bb.ToString(); if (pictureBox5.Image = null) pictureBox5.Image = pictureBox6.Image; pictureBox6.Image =
16、 null; else if (pictureBox3.Image = null) pictureBox3.Image = pictureBox6.Image; pictureBox6.Image = null; else if (pictureBox9.Image = null) pictureBox9.Image = pictureBox6.Image; pictureBox6.Image = null; private void pictureBox7_Click(object sender, EventArgs e) bb+; label2.Text = bb.ToString();
17、if (pictureBox4.Image = null) pictureBox4.Image = pictureBox7.Image; pictureBox7.Image = null; else if (pictureBox8.Image = null) pictureBox8.Image = pictureBox7.Image; pictureBox7.Image = null; private void pictureBox8_Click(object sender, EventArgs e) bb+; label2.Text = bb.ToString(); if (pictureB
18、ox5.Image = null) pictureBox5.Image = pictureBox8.Image; pictureBox8.Image = null; else if (pictureBox7.Image = null) pictureBox7.Image = pictureBox8.Image; pictureBox8.Image = null; else if (pictureBox9.Image = null) pictureBox9.Image = pictureBox8.Image; pictureBox8.Image = null; private void pict
19、ureBox9_Click(object sender, EventArgs e) bb+; label2.Text = bb.ToString(); if (pictureBox6.Image = null) pictureBox6.Image = pictureBox9.Image; pictureBox9.Image = null; else if (pictureBox8.Image = null) pictureBox8.Image = pictureBox9.Image; pictureBox9.Image = null; /設(shè)置游戲最大步數(shù) private void label2
20、_TextChanged(object sender, EventArgs e) try if (int.Parse(label2.Text) >=200) MessageBox.Show("你已經(jīng)超過了游戲所限定的最大步數(shù),歡迎再來!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Information); catch private void button1_Click(object sender, EventArgs e) button2.Enabled = true; pictureBox9.Im
21、age = null; aa = aa + 1; for (int m = 0; m <= 2; m+) for (int n = 0; n <= 2; n+) tm, n.Enabled = true; ss: switch (aa) /對(duì)圖片進(jìn)行隨機(jī)的分割 case 1: Clipboard.SetImage(pictureBox1.Image); pictureBox1.Image = pictureBox5.Image; pictureBox5.Image = Clipboard.GetImage(); Clipboard.Clear(); Clipboard.SetIma
22、ge(pictureBox2.Image); pictureBox2.Image = pictureBox4.Image; pictureBox4.Image = Clipboard.GetImage(); Clipboard.Clear(); Clipboard.SetImage(pictureBox3.Image); pictureBox3.Image = pictureBox8.Image; pictureBox8.Image = Clipboard.GetImage(); Clipboard.Clear(); button1.Enabled = false; break; case 2
23、: Clipboard.SetImage(pictureBox1.Image); pictureBox1.Image = pictureBox6.Image; pictureBox6.Image = Clipboard.GetImage(); Clipboard.Clear(); Clipboard.SetImage(pictureBox2.Image); pictureBox2.Image = pictureBox8.Image; pictureBox8.Image = Clipboard.GetImage(); Clipboard.Clear(); Clipboard.SetImage(p
24、ictureBox3.Image); pictureBox3.Image = pictureBox5.Image; pictureBox5.Image = Clipboard.GetImage(); Clipboard.Clear(); button1.Enabled = false; break; case 3: Clipboard.SetImage(pictureBox2.Image); pictureBox2.Image = pictureBox5.Image; pictureBox5.Image = Clipboard.GetImage(); Clipboard.Clear(); Cl
25、ipboard.SetImage(pictureBox4.Image); pictureBox4.Image = pictureBox6.Image; pictureBox6.Image = Clipboard.GetImage(); Clipboard.Clear(); Clipboard.SetImage(pictureBox3.Image); pictureBox3.Image = pictureBox8.Image; pictureBox8.Image = Clipboard.GetImage(); Clipboard.Clear(); button1.Enabled = false;
26、 break; case 4: Clipboard.SetImage(pictureBox1.Image); pictureBox1.Image = pictureBox8.Image; pictureBox8.Image = Clipboard.GetImage(); Clipboard.Clear(); Clipboard.SetImage(pictureBox3.Image); pictureBox3.Image = pictureBox5.Image; pictureBox5.Image = Clipboard.GetImage(); Clipboard.Clear(); Clipbo
27、ard.SetImage(pictureBox6.Image); pictureBox6.Image = pictureBox9.Image; pictureBox9.Image = Clipboard.GetImage(); Clipboard.Clear(); button1.Enabled = false; break; default: aa = 1; goto ss; /對(duì)數(shù)組賦值 private void button2_Click(object sender, EventArgs e) pictureBox1.Image = pictureBox10.Image; picture
28、Box2.Image = pictureBox12.Image; pictureBox3.Image = pictureBox15.Image; pictureBox4.Image = pictureBox13.Image; pictureBox5.Image = pictureBox14.Image; pictureBox6.Image = pictureBox16.Image; pictureBox7.Image = pictureBox17.Image; pictureBox8.Image = pictureBox18.Image; pictureBox9.Image = null; l
29、abel2.Text = "" bb = 0; button2.Enabled = false; button1.Enabled = true; for (int m = 0; m <= 2; m+) for (int n = 0; n <= 2; n+) tm, n.Enabled = false; /對(duì)游戲完成進(jìn)行判斷 private void Form1_Activated(object sender, EventArgs e) if (pictureBox1.Image = pictureBox10.Image && pictureBox
30、2.Image = pictureBox12.Image && pictureBox3.Image = pictureBox13.Image && pictureBox4.Image = pictureBox14.Image && pictureBox5.Image = pictureBox15.Image && pictureBox6.Image = pictureBox16.Image && pictureBox7.Image = pictureBox17.Image && pictureBox8.Image = pictureBox18.Image && pict
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度柴油發(fā)動(dòng)機(jī)銷售與培訓(xùn)服務(wù)合同4篇
- 2025年度私立學(xué)校后勤保障服務(wù)及安全管理合同
- 2025版心臟病學(xué)生入學(xué)生活照料與免責(zé)服務(wù)協(xié)議3篇
- 二零二五年度中草藥種植技術(shù)輸出合同3篇
- 二零二五年度基礎(chǔ)設(shè)施維護(hù)承包勞務(wù)公司合作協(xié)議4篇
- 2025年智能制造成套裝備項(xiàng)目可行性分析報(bào)告
- 二零二五年度輪胎行業(yè)市場(chǎng)調(diào)研與分析合同8篇
- 二零二五年度大師傅非遺傳承用工協(xié)議3篇
- 2025年度私人商鋪?zhàn)赓U合同范本:定制化商業(yè)培訓(xùn)與指導(dǎo)
- 二零二五年度外匯借款合同爭(zhēng)議解決機(jī)制合同
- 第22單元(二次函數(shù))-單元測(cè)試卷(2)-2024-2025學(xué)年數(shù)學(xué)人教版九年級(jí)上冊(cè)(含答案解析)
- 安全常識(shí)課件
- 河北省石家莊市2023-2024學(xué)年高一上學(xué)期期末聯(lián)考化學(xué)試題(含答案)
- 小王子-英文原版
- 新版中國食物成分表
- 2024年山東省青島市中考生物試題(含答案)
- 河道綜合治理工程技術(shù)投標(biāo)文件
- 專題24 短文填空 選詞填空 2024年中考英語真題分類匯編
- 再生障礙性貧血課件
- 產(chǎn)后抑郁癥的護(hù)理查房
- 2024年江蘇護(hù)理職業(yè)學(xué)院高職單招(英語/數(shù)學(xué)/語文)筆試歷年參考題庫含答案解析
評(píng)論
0/150
提交評(píng)論