C#课设报告书游戏五子棋Word文件下载.docx
- 文档编号:20741345
- 上传时间:2023-01-25
- 格式:DOCX
- 页数:20
- 大小:305.95KB
C#课设报告书游戏五子棋Word文件下载.docx
《C#课设报告书游戏五子棋Word文件下载.docx》由会员分享,可在线阅读,更多相关《C#课设报告书游戏五子棋Word文件下载.docx(20页珍藏版)》请在冰豆网上搜索。
控件及相应属性如表1所示。
表1
编辑控件属性
控件名
属性
属性值
Label1
BackColor
ControlDark
Location
12,35
Size
401,401
TabIndex
1
Visible
True
Control
419,52
167,30
Text
当前玩家:
白方
4
419,315
145,30
Label3
剩余用时:
5
Label4
420,365
166,30
7
每轮不得超时30s!
!
Button1
Gray
522,398
99,38
Button2
退出游戏
417,398
panel1
BackgroundImage
System.Drawing.Bitmap
Timer1
enabled
Interval
1000
Modifiers
Private
3.2.4程序功能设计
(1)在gobang类中添加下列数据成员及成员函数。
privatebool[,]chessBoard=newbool[20,20];
//判断棋盘指定坐标是否被绘制
privateint[,]chessColor=newint[20,20];
//用数组记录棋子的颜色,1-白色,2-黑色
privateboolIsWhite=true;
//判断是否是白棋
privateStack<
Point>
last=newStack<
();
//下棋历史记录
(2)画棋盘代码如下:
publicvoidChecker(Graphicsg)
{
PenmyPen=newPen(Color.Black);
for(inti=10;
i<
=400;
i=i+20)
g.DrawLine(myPen,0,i,400,i);
}
g.DrawLine(myPen,i,0,i,400);
}
(3)画棋子代码如下:
publicvoidDrawChess(Graphicsg,Colorcolor,intx,inty)
SolidBrushb=newSolidBrush(color);
if(chessBoard[(x-x%20)/20,(y-y%20)/20]==false)
if(x%20==0&
&
y%20==0)
g.FillEllipse(b,x+2,y+2,16,16);
else
x=x-x%20;
y=y-y%20;
if(IsWhite)
chessColor[(x-x%20)/20,(y-y%20)/20]=1;
chessColor[(x-x%20)/20,(y-y%20)/20]=2;
chessBoard[(x-x%20)/20,(y-y%20)/20]=true;
last.Push(newPoint((x-x%20)/20,(y-y%20)/20));
IsWhite=!
IsWhite;
(4)悔棋一步代码如下:
publicvoidBack(Graphicsg)
if(last.Count>
0)
Pointp=last.Pop();
chessBoard[p.X,p.Y]=false;
chessColor[p.X,p.Y]=0;
SolidBrushsb=newSolidBrush(Color.Gray);
g.FillEllipse(sb,p.X*20,p.Y*20,20,20);
(5)检查游戏结果代码如下:
publicboolCheckGameResult(intx,inty)
//检查横向
x=(x-x%20)/20;
y=(y-y%20)/20;
intsum1=1;
intsum2=1;
intsum3=1;
intsum4=1;
intsearch=chessColor[x,y];
for(inti=x+1;
chessColor.GetLength(0);
i++)
if(chessColor[i,y]==search)
sum1++;
break;
for(inti=x-1;
i>
=0;
i--)
//检查纵向
for(inti=y+1;
chessColor.GetLength
(1);
if(chessColor[x,i]==search)
sum2++;
for(inti=y-1;
//检查主对角线
for(inti=x-1,j=y-1;
=0&
j>
i--,j--)
if(chessColor[i,j]==search)
sum3++;
for(inti=x+1,j=y+1;
chessColor.GetLength(0)&
j<
i++,j++)
//检查副对角线
for(inti=x+1,j=y-1;
i++,j--)
sum4++;
for(inti=x-1,j=y+1;
i--,j++)
//判定结果
if(sum1>
=5||sum2>
=5||sum3>
=5||sum4>
=5)
returntrue;
returnfalse;
(6)输出游戏结果代码如下:
publicvoidOutputResult(intx,inty)
if(chessColor[x,y]==1)
MessageBox.Show("
白棋获胜"
"
比赛结果"
);
黑棋获胜"
(7)判断是否是白棋代码如下:
publicboolPlayWhite()
(8)更换玩家代码如下:
publicvoidChangePlayer()
(9)判断当前一格是否已被绘制代码如下:
publicboolisDraw(intx,inty)
returnchessBoard[(x-x%20)/20,(y-y%20)/20];
4运行结果与分析
(1)游戏界面运行如图2、图3。
图2五子棋运行界面
图3五子棋运行界面
(2)游戏结束如图4所示
图4游戏结束界面
(3)屏保显示如图5所示
图5屏保界面
5心得体会
在这次的C#课程设计中,我负责的是画棋子模块。
当单击棋盘的时候,在棋盘上画出一个圆形带颜色的棋子,画棋子之前首先判断棋盘上的这个位置有没有被画,如果没有被画便可以画上,还要考虑,每次画的都是什么颜色的棋子,这次试验感受颇多,从中无也学到了很多书上没有的知识。
也知道实践只重要性,也加深对C#的更一步了解。
在这次实训中,我对C#有了一个更深的了解认识,也对这个学期学的知识得到巩固,还尝试运行编程,虽然每次运行程序不一定会成功。
通过自己上网查资料编写程序,经过多次的上机调试和上网查资料和修改,最终把最初的理论知识转化基本技能。
通过这次实习,让我们初步有了编写系统的能力,我们对很多的函数有了新的认识,也学会了运用多种函数,也明白了编写软件的基本过程,和基本方法。
编写软件的过程中我们又学到了曾经自己不知道的函数或是自己不会的函数的用法。
这次课程设计课总的来说让我受益匪浅。
这次的实训,使我对C#的学习产生浓厚的兴趣。
在这几天的编写过程中我们对c#有了更进一步的认识和了解。
此次编程过程的经验和知识肯定能促进我以后的学习。
此次课程设计不仅给了我们很多很好的经验,也让我们体会到了失败时的焦急和难受,也体会到了成功时的兴奋与喜悦。
参考文献
[1]罗斌,越飞,等.VisualC#2005编程实例精粹[M].北京:
中国水利水电出版社,2006.10:
10-135
[2]陈哲,戴博,等.VisualC#2005程序设计[M].北京:
清华大学出版社,2007.7:
38-235
[3]耿肇英,等.C#程序设计简明教程[M].北京:
人民邮电出版社,2007.12:
44-156
[4]刘甫迎、刘光会、王蓉.C#程序设计教程[M].北京:
电子工业出版社,2008.9:
32-105
[5]陈佛敏,潘春华,等.C#程序设计简明教程[M].北京:
人民邮电出版社,2008.11:
10-103
[6]李旗.C#.NET程序设计[M]北京:
机械工业出版社,2008.7:
67-234
[7]古万荣.VisualC#轻松入门[M].北京:
人民邮电出版社,2009.5:
22-212
[8]熊壮,宋文强.C#程序设计[M].北京:
高等教育出版社,2010.14:
02-271
[9]ChristianNagel,等.C#高级编程[M],李铭,译.北京:
清华大学出版社,2010.9:
[10]KarliWaston,等.C#高级编程[M].齐立波,译.北京:
清华大学出版社,2010.11:
21-179
6附录(部分源代码)
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespace五子棋
{
publicpartialclassForm1:
Form
gobanggb=newgobang();
//创建对象
privateintSec=30;
//设置游戏时间为30s
privateintstep1=0,step2=0;
//白棋和黑棋下子数
publicForm1()
InitializeComponent();
privatevoid作者WToolStripMenuItem_Click(objectsender,EventArgse)
13计算机专升本F1383136郭轶"
"
版权所有"
privatevoid关于五子棋AToolStripMenuItem_Click(objectsender,EventArgse)
System.Diagnostics.Process.Start("
//参照网上做法
privatevoid退出XToolStripMenuItem_Click(objectsender,EventArgse)
this.Close();
privatevoid重新开局NToolStripMenuItem_Click(objectsender,EventArgse)
Graphicsg=this.label1.CreateGraphics();
gb.ReDrawBorad(g);
step1=step2=0;
privatevoid屏保PToolStripMenuItem_Click(objectsender,EventArgse)
Form2f=newForm2();
f.Show();
privatevoid隐藏时间HToolStripMenuItem_Click(objectsender,EventArgse)
if(this.toolStripStatusLabel2.Visible==true)
this.toolStripStatusLabel2.Visible=false;
this.toolStripStatusLabel2.Visible=true;
privatevoidlabel1_Paint(objectsender,PaintEventArgse)
Graphicsg=e.Graphics;
Penp=newPen(Color.Black);
gb.Checker(g);
privatevoidlabel1_MouseDown(objectsender,MouseEventArgse)
boolisWhite=gb.PlayWhite();
if(isWhite)
gb.DrawChess(g,Color.White,e.X,e.Y);
step1++;
this.toolStripStatusLabel3.Text="
白:
"
+step1.ToString();
this.toolStripStatusLabel1.Text=this.label2.Text="
黑方"
;
gb.DrawChess(g,Color.Black,e.X,e.Y);
step2++;
this.toolStripStatusLabel4.Text="
黑:
+step2.ToString();
白方"
if(gb.CheckGameResult(e.X,e.Y))
gb.OutputResult(e.X,e.Y);
Sec=30;
privatevoidbutton1_Click(objectsender,EventArgse)
gb.Back(g);
if(gb.PlayWhite())
step1--;
privatevoidtimer1_Tick(objectsender,EventArgse)
this.panel1.Refresh();
if(Sec<
=0)
gb.ChangePlayer();
this.label2.Text="
this.toolStripStatusLabel1.Text="
当前玩家"
Drawing();
Stringtime=DateTime.Now.ToString();
this.toolStripStatusLabel2.Text=time;
privatevoidDrawing()
Graphicsg=this.panel1.CreateGraphics();
PenmyPen=newPen(Color.Red,3);
Sec--;
doublemiaozhen1=Math.Sin((Math.PI/180)*((360/60)*Sec));
doublemiaozhen2=Math.Cos((Math.PI/180)*((360/60)*Sec));
miaozhen1=100+90*miaozhen1;
miaozhen2=100-90*miaozhen2;
g.DrawLine(myPen,100,100,(float)miaozhen1,(float)miaozhen2);
this.label3.Text="
+Sec+"
秒"
privatevoidbutton2_Click(objectsender,EventArgse)
退出XToolStripMenuItem_Click(sender,e);
}
publicpartialclassForm2:
staticintpx=0,py=0;
staticintrx=15,ry=10;
publicForm2()
privatevoidForm2_Load(objectsender,EventArgse)
this.Size=newSize(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);
this
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C# 报告书 游戏 五子棋