完整word版斗地主Java课程设计.docx

上传人:b****6 文档编号:3427897 上传时间:2022-11-23 格式:DOCX 页数:56 大小:341.58KB
下载 相关 举报
完整word版斗地主Java课程设计.docx_第1页
第1页 / 共56页
完整word版斗地主Java课程设计.docx_第2页
第2页 / 共56页
完整word版斗地主Java课程设计.docx_第3页
第3页 / 共56页
完整word版斗地主Java课程设计.docx_第4页
第4页 / 共56页
完整word版斗地主Java课程设计.docx_第5页
第5页 / 共56页
点击查看更多>>
下载资源
资源描述

完整word版斗地主Java课程设计.docx

《完整word版斗地主Java课程设计.docx》由会员分享,可在线阅读,更多相关《完整word版斗地主Java课程设计.docx(56页珍藏版)》请在冰豆网上搜索。

完整word版斗地主Java课程设计.docx

完整word版斗地主Java课程设计

《面向对象程序设计》

课程设计报告

 

题目:

斗地主软件设计与实现

院(系):

信息科学与工程学院

专业班级:

计算机科学与技术1201班

学生姓名:

程伟

学号:

20121183011

指导教师:

吴奕

 

2014年12月29日至2015年1月9日

 

华中科技大学武昌分校制

面向对象程序设计课程设计任务书

一、设计(调查报告/论文)题目

斗地主软件设计与实现

二、设计(调查报告/论文)主要内容

内容:

设计一个斗地主游戏,玩家可以通过键盘或鼠标控制游戏区,游戏设定不同级别,级别越高难度越大,玩家可以根据自己的需要自由设定初始游戏级别,当玩家取得的分数到达一定水平时游戏自动进入下一个级别。

游戏以最终玩家获得的分数来判断玩家水平的高低。

基本功能与要求:

使用Eclipse和JDK1.6工具,操作系统为WINDOWS,采用面向对象方法完成,包括总体设计、详细设计、编码实现、测试。

设计要求如下:

①游戏由模块组成:

游戏区模块,游戏控制模块,级别设置模块和帮助模块。

②游戏区模块,为玩家提供主体游戏功能,能够处理玩家的各种游戏操作,显示得分情况,并最终显示游戏结果。

③游戏控制模块,该模块为玩家提供游戏控制功能,应包括开始游戏,暂停游戏和退出游戏三部分功能。

④级别设置模块为玩家提供自行设置游戏的初始级别功能,主要提供初级,中级和高级三个游戏初始级别设置。

三、原始资料

1.《面向对象程序设计课程设计》指导书

2.耿祥义.JAVA大学实用教程.北京:

清华大学出版社,2009.

四、要求的设计(调查/论文)成果

1.课程设计报告

2.课程设计软件

五、进程安排

布置任务,查找资料、需求分析1天

总体设计1天

详细设计1.5天

编制源程序实现3.5天

测试与修改1天

撰写课设报告2天

六、主要参考资料

[1]张广彬.Java课程设计案例精编(第二版).北京:

清华大学出版社,2011.

[2]耿祥义.Java课程设计(第二版).北京:

清华大学出版社,2008.

[3]耿祥义.JAVA大学实用教程.北京:

清华大学出版社,2009.

[4]邹林达.陈国君Java2程序设计基础.北京:

清华大学出版社,2010.

[5]邹林达.Java2程序设计基础实验指导.北京:

清华大学,2010.

 

指导教师(签名):

 

20年月日

1需求与总体设计

1.1需求分析

游戏设计需要用到牌Card的正反面及牌的移动,还有CardType设计出牌种类,还有各种牌的形式,还要设计几个人玩游戏,抢地主的方法,出牌倒计时,出牌和不出牌等等,另外还要设计54张牌,打牌出现的各种结果。

1.2总体设计

本游戏实现了图形界面的设计、游戏区模块,游戏控制模块,级别设置模块和帮助模块。

为玩家提供主体游戏功能,能够处理玩家的各种游戏操作,并最终显示游戏结果。

1.3功能图

1.4类图

 

2详细设计

2.1主类Main

图表说明如下:

创建菜单功能按钮

publicvoidInit()

初始化窗体

publicvoidInit()

发牌洗牌

publicvoidCardInit()

抢地主

publicvoidgetLord()

 

2.2类Card

(1)类图

(2)说明:

该类主要是设计牌面的正反、牌之间的距离、移动(即出牌时向前移动纸牌),其中有:

booleanup;//是否正反面;

booleancanClick=false;//是否可被点击

booleanclicked=false;//是否点击过;

Stringname;//图片url名字

Mainmain;//Main类的引用

2.3类CardType

publicenumCardType列出各种出牌的类型

单牌,对子,不带,炸弹;

3带1、带2,3带2个单、或者一对;

4带2对;

连子、连队;

飞机、飞机带单排.、飞机带对子.

不能出牌

2.4类Common

1)判断牌型

publicstaticCardTypejugdeType()

2)移动效果的函数,用于发牌

publicstaticvoidmove()

3)对牌的排序

publicstaticvoidorder()

4)重新定位flag代表电脑1,2或者是我

publicstaticvoidrePosition()

5)地主牌权值,看是否抢地主

publicstaticintgetScore()

6)返回花色

publicstaticintgetColor()

7)得到最大相同数

publicstaticvoidgetMax()

8)拆牌

publicstaticModelgetModel()各种对子、顺子、飞机、炸弹

9)拆连子

publicstaticvoidget123()

10)拆双顺

publicstaticvoidgetTwoTwo()

11)拆飞机

publicstaticvoidgetPlane()

12)拆炸弹

publicstaticvoidgetBoomb()

13)拆3带

publicstaticvoidgetThree()

14)拆对子

publicstaticvoidgetTwo()

15)拆单牌

publicstaticvoidgetSingle()

16)隐藏之前出过的牌

publicstaticvoidhideCards()

17)检查牌的是否能出

publicstaticintcheckCards()

2.5类Model

各种牌型publicclassModel

Lista1=newArrayList();//单张

Lista2=newArrayList();//对子

Lista3=newArrayList();//3带

Lista123=newArrayList();//连子

Lista112233=newArrayList();//连牌

Lista111222=newArrayList();//飞机

Lista4=newArrayList();//炸弹

2.6类Time

//等待i秒publicvoidsecond(inti)

//时间如何走publicvoidrun()

if(i==-1)//正常终结,说明超时

//开始游戏根据地主不同顺序不同main.turn=main.dizhuFlag;

//出牌按钮--我出牌turnOn(true);

//我自己的定时器timeWait(30,1);

//选完关闭turnOn(false);

3编码实现

3.1JAVA编码实现

(1)Main.java主要代码

publicclassMainextendsJFrameimplementsActionListener

{

publicContainercontainer=null;//定义容器

JMenuItemstart,exit,about;//定义菜单按钮

JButtonlandlord[]=newJButton[2];//抢地主按钮

JButtonpublishCard[]=newJButton[2];//出牌按钮

intdizhuFlag;//地主标志

intturn;

JLabeldizhu;//地主图标

ListcurrentList[]=newArrayList[3];//当前的出牌

ListplayerList[]=newArrayList[3];//定义3个玩家表

ListlordList;//地主牌

Cardcard[]=newCard[56];//定义54张牌

JTextFieldtime[]=newJTextField[3];//计时器

Timet;//定时器(线程)

booleannextPlayer=false;//转换角色

publicMain()

{

Init();//初始化

SetMenu();//创建菜单按钮(抢地主,发牌,计时器)

this.setVisible(true);

CardInit();//发牌

getLord();//发完牌开始抢地主

time[1].setVisible(true);

//线程安全性,把非主线程的UI控制放到里面

SwingUtilities.invokeLater(newNewTimer(this,10));

}

publicvoidgetLord()//抢地主

{

//System.out.println(CardType.c0.toString());

for(inti=0;i<2;i++)//当没有人抢地主时或者一个人和当前的人抢地主时

landlord[i].setVisible(true);

}

//初始化牌

//发牌洗牌

publicvoidCardInit()//初始化牌

{

intcount=1;

for(inti=1;i<=5;i++)

{

for(intj=1;j<=13;j++)

{

if((i==5)&&(j>2))

break;

else{

card[count]=newCard(this,i+"-"+j,false);

card[count].setLocation(350,50);

container.add(card[count]);

count++;

}

}

}

//打乱顺序

for(inti=0;i<100;i++){

Randomrandom=newRandom();

inta=random.nextInt(54)+1;

intb=random.nextInt(54)+1;

Cardk=card[a];//赋值语句,打乱牌序

card[a]=card[b];

card[b]=k;

}

//开始发牌

for(inti=0;i<3;i++)//三张底牌

playerList[i]=newArrayList();//玩家牌

lordList=newArrayList();//地主牌三张

intt=0;

for(inti=1;i<=54;i++)//进行发牌

{

if(i>=52)//地主牌

{

Common.move(card[i],card[i].getLocation(),newPoint(300+(i-52)*80,10));

lordList.add(card[i]);

continue;

}

switch((t++)%3){

case0:

//显示各边的玩家,这是左边玩家

Common.move(card[i],card[i].getLocation(),newPoint(50,60+i*5));

playerList[0].add(card[i]);

break;

case1:

//玩家:

Common.move(card[i],card[i].getLocation(),newPoint(180+i*7,450));

playerList[1].add(card[i]);

card[i].turnFront();//显示正面

break;

case2:

//右边玩家

Common.move(card[i],card[i].getLocation(),newPoint(700,60+i*5));

playerList[2].add(card[i]);

break;

}

//card[i].turnFront();//显示正面

container.setComponentZOrder(card[i],0);

}

//发完牌排序,从大到小

for(inti=0;i<3;i++)

{

Common.order(playerList[i]);

Common.rePosition(this,playerList[i],i);//重新定位

}

dizhu=newJLabel(newImageIcon("images/dizhu.gif"));//地主最后要加入底牌

dizhu.setVisible(false);

dizhu.setSize(40,40);

container.add(dizhu);

}

//初始化窗体

publicvoidInit()

{

this.setTitle("斗地主游戏---by程宵");

this.setSize(830,620);

setResizable(false);

setLocationRelativeTo(getOwner());//屏幕居中

container=this.getContentPane();

container.setLayout(null);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

container.setBackground(newColor(0,112,26));//背景为绿色

}

//创建菜单功能按钮

publicvoidSetMenu()

{

JMenuBarjMenuBar=newJMenuBar();

JMenugame=newJMenu("游戏");

JMenuhelp=newJMenu("帮助");

start=newJMenuItem("新游戏");

exit=newJMenuItem("退出");

about=newJMenuItem("关于");

start.addActionListener(this);

exit.addActionListener(this);

about.addActionListener(this);

game.add(start);

game.add(exit);

help.add(about);

jMenuBar.add(game);

jMenuBar.add(help);

this.setJMenuBar(jMenuBar);

landlord[0]=newJButton("抢地主");

landlord[1]=newJButton("不抢");

publishCard[0]=newJButton("出牌");

publishCard[1]=newJButton("不要");

for(inti=0;i<2;i++)

{

publishCard[i].setBounds(320+i*100,400,60,20);

landlord[i].setBounds(320+i*100,400,75,20);

container.add(landlord[i]);

landlord[i].addActionListener(this);

landlord[i].setVisible(false);

container.add(publishCard[i]);

publishCard[i].setVisible(false);

publishCard[i].addActionListener(this);

}

for(inti=0;i<3;i++){

time[i]=newJTextField("倒计时:

");

time[i].setVisible(false);

container.add(time[i]);

}

time[0].setBounds(140,230,60,20);

time[1].setBounds(374,360,60,20);

time[2].setBounds(620,230,60,20);

for(inti=0;i<3;i++)

{

currentList[i]=newArrayList();

}

}

@Override

publicvoidactionPerformed(ActionEvente){

//TODOAuto-generatedmethodstub

if(e.getSource()==exit){

this.dispose();

}

if(e.getSource()==about){

JOptionPane.showMessageDialog(this,"20121183026,程宵");

}

if(e.getSource()==start){

//this.restart();

}

if(e.getSource()==landlord[0])

{

time[1].setText("抢地主");

t.isRun=false;//时钟终结

}

if(e.getSource()==landlord[1])

{

time[1].setText("不抢");

t.isRun=false;//时钟终结

}

//如果是不要

if(e.getSource()==publishCard[1])

{

this.nextPlayer=true;

currentList[1].clear();

time[1].setText("不要");

}

//如果是出牌按钮

if(e.getSource()==publishCard[0])

{

Listc=newArrayList();

//点选出牌

for(inti=0;i

{

Cardcard=playerList[1].get(i);

if(card.clicked)

{

c.add(card);

}

}

intflag=0;

//如果我主动出牌

if(time[0].getText().equals("不要")&&time[2].getText().equals("不要"))

{

if(Common.jugdeType(c)!

=CardType.c0)

flag=1;//表示可以出牌

}//如果我跟牌

else{

flag=Common.checkCards(c,currentList);

}

//判断是否符合出牌

if(flag==1)

{

currentList[1]=c;

playerList[1].removeAll(currentList[1]);//移除走的牌

//定位出牌

Pointpoint=newPoint();

point.x=(770/2)-(currentList[1].size()+1)*15/2;;

point.y=300;

for(inti=0,len=currentList[1].size();i

{

Cardcard=currentList[1].get(i);

Common.move(card,card.getLocation(),point);

point.x+=15;

}

//抽完牌后重新整理牌

Common.rePosition(this,playerList[1],1);

time[1].setVisible(false);

this.nextPlayer=true;

}

}

}

publicstaticvoidmain(Stringargs[])

{

newMain();

}

}

classNewTimerimplementsRunnable

{

Mainmain;

inti;

publicNewTimer(Mainm,inti)

{

this.main=m;

this.i=i;

}

@Override

publicvoidrun()

{

//TODOAuto-generatedmethodstub

main.t=newTime(main,10);//从10开始倒计时

main.t.start();

}

}

(2)Card.java主要代码如下:

publicclassCardextendsJLabelimplementsMouseListener

{

Mainmain;//Main类的引用

Stringname;//图片url名字

booleanup;//是否正反面

booleancanClick=false;//是否可被点击

booleanclicked=false;//是否点击过

publicCard(Mainm,Stringname,booleanup)

{

this.main=m;

this.name=name;

this.up=up;

if(this.up)

this.t

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1