五子棋游戏设计总结Word格式.docx
- 文档编号:17359255
- 上传时间:2022-12-01
- 格式:DOCX
- 页数:16
- 大小:136.77KB
五子棋游戏设计总结Word格式.docx
《五子棋游戏设计总结Word格式.docx》由会员分享,可在线阅读,更多相关《五子棋游戏设计总结Word格式.docx(16页珍藏版)》请在冰豆网上搜索。
protectedoverridevoidOnPaint(PaintEventArgse)
{
System.Drawing.Graphicsg=this.CreateGraphics();
for(intx=0;
x<
15;
x++)
for(inty=0;
y<
y++)
DrawChess(newPoint(x,y),checkerBoard[y,x]);
}
ReDrawNextPlayerMark();
base.OnPaint(e);
2.重载鼠标按下事件
protectedoverridevoidOnMouseDown(System.Windows.Forms.MouseEventArgse)
{}
3.把鼠标坐标转换成棋盘坐标
第二步:
1.开始新的棋局,所有数据复位并重画棋盘
2.重画棋盘:
privatevoidDrawCheckerBoard()
{
this.BackColor=System.Drawing.SystemColors.Desktop;
this.BackColor=System.Drawing.SystemColors.Control;
}
3.重画下一个选手的标志棋子
privatevoidReDrawNextPlayerMark()
{
System.Drawing.Graphicsg=this.CreateGraphics();
imageList1.Draw(g,2,309,30,30,Player);
4.在棋盘上画一个棋子
privatevoidDrawChess(PointpCoordinates,intiPlayer)
imageList1.Draw(g,15+pCoordinates.X*20,6+pCoordinates.Y*20,20,20,iPlayer);
5.在指定的棋盘坐标位置添加一个棋子
6.判断是否超出边界
if((p.X<
0||p.X>
14)||(p.Y<
0||p.Y>
14))return;
7.判断该位置有无棋子,如果已经有了棋子则退出(这颗棋不能下)
if(checkerBoard[p.Y,p.X]!
=None)return;
第三步:
检查游戏结果
只有先放成5个相连的棋子的一方或剩,所以只要以刚刚下过的那个棋子为中心,检查有没有5个相连的同颜色棋子就好了。
privatevoidCheckGameResult(PointsourcePoint)
intx,y;
intLastPlayer=(Player==White)?
Black:
White;
intn;
1.检查行,列,左斜线,右斜线,是否满足游戏规则
n=1;
y=sourcePoint.Y;
for(x=sourcePoint.X-1;
x>
=0;
x--)
if(checkerBoard[y,x]==LastPlayer)n++;
elsebreak;
for(x=sourcePoint.X+1;
if(n>
=5)
Win(LastPlayer);
return;
}
2.悔棋
privatevoidPenitence()
if(History.Count>
0)
Pointp=(Point)History.Pop();
checkerBoard[p.Y,p.X]=None;
nextPlayer=(Player==White)?
DrawCheckerBoard();
四、程序清单(可附页)
usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceFiveChessPC
{
publicpartialclassForm1:
Form
{
privateconstintNone=2;
//没有棋子
privateconstintWhite=0;
//代表白棋
privateconstintBlack=1;
//代表黑棋
privateint[,]checkerBoard=newint[15,15];
//棋盘(用来保存每一个棋子)
privateintnextPlayer;
//下一个选手
privateintPlayer
get
returnnextPlayer;
set
nextPlayer=value;
privateStackHistory;
//下棋的历史记录
publicForm1()
InitializeComponent();
History=newStack();
Player=White;
//默认设置为白棋先下
Reset();
privatevoidexit_Click(objectsender,EventArgse)
this.Close();
privatevoidForm1_Load(objectsender,System.EventArgse)
//重载重画函数
protectedoverridevoidOnPaint(PaintEventArgse)
//重载鼠标按下事件
base.OnMouseDown(e);
switch(e.Button)
caseMouseButtons.Left:
if((History.Count==0)&
&
(2<
e.X)&
(e.X<
22)&
(309<
e.Y)&
(e.Y<
329))
Player=(Player==White)?
elseAddChess(MToA(newPoint(e.X,e.Y)));
break;
caseMouseButtons.Right:
privatePointMToA(Pointp)//把鼠标坐标转换成棋盘坐标
returnnewPoint((p.X-15)/20,(p.Y-6)/20);
privatevoidReset()
for(inti=0;
i<
i++){
for(intj=0;
j<
j++)
checkerBoard[i,j]=None;
History.Clear();
//清空历史记录
//重画棋盘
privatevoidDrawCheckerBoard()
this.BackColor=System.Drawing.SystemColors.Desktop;
this.BackColor=System.Drawing.SystemColors.Control;
privatevoidReDrawNextPlayerMark()
imageList1.Draw(g,2,309,30,30,Player);
privatevoidDrawChess(PointpCoordinates,intiPlayer)
imageList1.Draw(g,15+pCoordinates.X*20,6+pCoordinates.Y*20,20,20,iPlayer);
privatevoidAddChess(Pointp)
DrawChess(p,Player);
if(Player==White)//该白棋下
checkerBoard[p.Y,p.X]=White;
Player=Black;
else
checkerBoard[p.Y,p.X]=Black;
History.Push(newPoint(p.X,p.Y));
//添加历史记录
CheckGameResult(p);
n=1;
//检查行
//检查列
x=sourcePoint.X;
for(y=sourcePoint.Y-1;
y>
y--)
for(y=sourcePoint.Y+1;
for(x=sourcePoint.X+1,y=sourcePoint.Y-1;
15&
x++,y--)
for(x=sourcePoint.X-1,y=sourcePoint.Y+1;
=0&
x--,y++)
n=1;
//检查右斜线
for(x=sourcePoint.X-1,y=sourcePoint.Y-1;
x--,y--)
//检查右斜线的下半截
for(x=sourcePoint.X+1,y=sourcePoint.Y+1;
x++,y++)
//棋盘满棋,平手
=225)
Win(None);
privatevoidWin(intNPlayer)
switch(NPlayer)
caseNone:
MessageBox.Show("
本局平手!
"
"
恭喜!
);
caseWhite:
本局白棋获胜!
caseBlack:
本局黑棋获胜!
//悔棋1步
privatevoidheiqixian_Click(objectsender,EventArgse)
privatevoidmenuItem1_Popup(objectsender,System.EventArgse)
if(History.Count==0)
heiqixian.Visible=true;
heiqixian.Text=(Player==White)?
"
黑棋先下(&
B)"
:
白棋先下(&
W)"
;
elseheiqixian.Visible=false;
privatevoidmenuItem4_Click_2(objectsender,EventArgse)
privatevoiduse_Click(objectsender,EventArgse)
privatevoidrestart_Click(objectsender,EventArgse)
0)this.Reset();
privatevoidhuiqi_Click(objectsender,EventArgse)
Penitence();
五、上机调试过程及结果
1)游戏前
2)游戏中
3)游戏结束
六、设计总结
本学期开始,老师就给我们下了一个最终任务,开发出一款小游戏,作为期中考试成绩的参考标准,于是我和苏宁通过学习和参考网上相关资料,决定选择五子棋作为自己的开发目标,无论成功与否,希望有一个努力的过程能得到老师的认可。
五子棋是一种简单而又受大众喜爱的游戏,规则易懂,变化多端,有趣味性和消遣性。
全过程介绍五子棋程序的评分规则,胜负判断,悔棋等。
毕竟我和苏宁都挺喜欢玩五子棋的,所以自己能做成功,是一件非常开心事。
所以我们就分工进行,她负责棋盘部分,我负责棋子部分,我们一起努力的去完成它。
最后我和苏宁总结出来,五子棋的难点部分,就是画棋盘和棋盘的背景颜色,我们不管通过什么办法,都改不了棋盘的背景颜色,所以到最后我们都没解决掉。
刚学习C#的时候,感觉很难,做的时候出现很多错误而且我是照着书打代码还有错误,那时的感觉是迷茫的。
在学习的过程中,我还是坚持下来,虽然学的不是很好,但是慢慢就理解了。
我觉得我有以下几方面做不好:
1.在刚上C#时老师叫我们现在就要做项目但我没有,一直等到老师快要检查时才急急忙忙的做。
2.老师上完课,自己做完作业之后,没有好好的复习。
无论是学习还是做项目的过程中,耐心都要非常重要。
有时出现错误,上网查了,自己又想了很久,又找苏宁和其他同学讨论还是不能解决时就会有不想做的念头。
但是当在做项目成功的实现它功能时,心理就特别高兴,就好想再做几个功能。
但是事实不是一下就能成功的实现它的功能所以耐心非常重要。
最重要的一点是我们做项目时,我们要有团队的合作精神。
只有这样我们才能很好的完成一个好的项目,才能完成一个项目。
我最大的愿望就是几个想学习的同学在一起讨论问题,只有这样才能进步更快,才能学到更多的知识。
最后想说:
“一分耕耘,一分收获。
”
项目不是做的很好,但是通过项目学到了更多的知识。
七、答辩纪录
答辩纪录表
组号
学号
姓名
综述(10分)
答题(20分)
总分(30分)
八、成绩汇总
成绩纪录表
组号:
设计成绩
(40分)
上机成绩
(20分)
答辩成绩
(30分)
设计报告成绩(10分)
总成绩
(100分)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 五子棋 游戏 设计 总结