赛马游戏程序Word下载.docx

上传人:b****5 文档编号:21361708 上传时间:2023-01-30 格式:DOCX 页数:12 大小:117.94KB
下载 相关 举报
赛马游戏程序Word下载.docx_第1页
第1页 / 共12页
赛马游戏程序Word下载.docx_第2页
第2页 / 共12页
赛马游戏程序Word下载.docx_第3页
第3页 / 共12页
赛马游戏程序Word下载.docx_第4页
第4页 / 共12页
赛马游戏程序Word下载.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

赛马游戏程序Word下载.docx

《赛马游戏程序Word下载.docx》由会员分享,可在线阅读,更多相关《赛马游戏程序Word下载.docx(12页珍藏版)》请在冰豆网上搜索。

赛马游戏程序Word下载.docx

JMenuItembeginMenuItem,initMenuItem,aboutMenuItem,exitMenuItem;

//子菜单项

JMenufileMenu,systemMenu;

//菜单项

JMenuBarmbar;

//菜单条

JLabeljL1,jl2,jl3;

//用于显示游戏启动界面和游戏版本界面信息

ContainerwinContainer;

//容器对象

staticintbetMoney=10000;

//庄家本金,静态成员属性

staticintmyMoney=1000;

//玩家本金,静态成员属性

staticintbetCount=5;

//竞猜次数,静态成员属性

publicMybetExample(){//构造方法,组建菜单和开始界面

super("

赛马游戏林情出品"

);

beginMenuItem=newJMenuItem("

游戏开场"

beginMenuItem.addActionListener(this);

initMenuItem=newJMenuItem("

制定规则"

initMenuItem.addActionListener(this);

aboutMenuItem=newJMenuItem("

游戏信息"

aboutMenuItem.addActionListener(this);

exitMenuItem=newJMenuItem("

退出游戏"

exitMenuItem.addActionListener(this);

fileMenu=newJMenu("

游戏控制"

systemMenu=newJMenu("

系统信息"

mbar=newJMenuBar();

fileMenu.add(beginMenuItem);

fileMenu.add(initMenuItem);

systemMenu.add(aboutMenuItem);

systemMenu.addSeparator();

systemMenu.add(exitMenuItem);

mbar.add(fileMenu);

mbar.add(systemMenu);

this.setJMenuBar(mbar);

jL1=newJLabel("

欢迎来到赛马世界!

"

jl2=newJLabel("

林情出品"

jl3=newJLabel("

1006003209"

jL1.setFont(newFont("

微软雅黑"

Font.BOLD,25));

jl2.setFont(newFont("

Font.BOLD,18));

jl3.setFont(newFont("

Font.BOLD,15));

jL1.setForeground(Color.BLUE);

jl2.setForeground(Color.RED);

jl3.setForeground(Color.black);

jL1.setBounds(50,30,300,100);

jl2.setBounds(230,80,300,100);

jl3.setBounds(230,100,300,100);

winContainer=this.getContentPane();

winContainer.setLayout(null);

winContainer.add(jL1);

winContainer.add(jl2);

winContainer.add(jl3);

this.setSize(340,250);

this.setVisible(true);

}

publicstaticvoidmain(String[]args){

MybetExamplemmenu=newMybetExample();

publicvoidactionPerformed(ActionEvente){//子菜单的事件处理

if(e.getSource()==beginMenuItem){//选择"

菜单项

BetPanelp1=newBetPanel();

//实例化游戏开始界面

p1.setBounds(0,0,340,250);

//设置该实例的空间大小

winContainer.removeAll();

//移除当前容器中的所有内容

winContainer.add(p1);

//将游戏开始界面添加到当前容器

winContainer.repaint();

//调用repaint()方法,更新界面显示

}elseif(e.getSource()==initMenuItem){//选择"

InitPanelp1=newInitPanel();

winContainer.removeAll();

winContainer.add(p1);

winContainer.repaint();

}elseif(e.getSource()==aboutMenuItem){//选择"

jL1.setText("

林情出品必属精品"

}else

System.exit(0);

}

/*参数设置界面类*/

classInitPanelextendsJPanelimplementsActionListener{

intbetMoney,myMoney,betCount;

JLabeljL1,jL2,jL3;

JTextFieldjT1,jT2,jT3;

JButtonjB1,jB2;

publicInitPanel(){

this.betMoney=MybetExample.betMoney;

//将主界面的成员属性传递到本类

this.myMoney=MybetExample.myMoney;

this.betCount=MybetExample.betCount;

this.setLayout(null);

panelInit();

}//调用界面设计方法

voidpanelInit(){//界面设计方法,完成界面设计

jL1=newJLabel("

庄家本金"

jL1.setBounds(60,20,80,30);

jT1=newJTextField(betMoney+"

jT1.setBounds(160,20,80,30);

jL2=newJLabel("

玩家本金"

jL2.setBounds(60,60,80,30);

jT2=newJTextField(myMoney+"

jT2.setBounds(160,60,80,30);

jL3=newJLabel("

竞猜次数"

jL3.setBounds(60,100,80,30);

jT3=newJTextField(betCount+"

jT3.setBounds(160,100,80,30);

jB1=newJButton("

确定"

jB1.setBounds(60,140,80,30);

jB1.addActionListener(this);

jB2=newJButton("

恢复"

jB2.setBounds(160,140,80,30);

jB2.addActionListener(this);

this.add(jL1);

this.add(jT1);

this.add(jL2);

this.add(jT2);

this.add(jL3);

this.add(jT3);

this.add(jB1);

this.add(jB2);

publicvoidactionPerformed(ActionEvente){//按钮的事件处理方法

if(e.getSource()==jB1)//"

按钮

{betMoney=Integer.parseInt(jT1.getText());

//获得当前的设定值

myMoney=Integer.parseInt(jT2.getText());

betCount=Integer.parseInt(jT3.getText());

if(betMoney-myMoney<

5000)

JOptionPane.showMessageDialog(this,"

庄家没你有钱!

"

提示"

2);

else{if(myMoney==0)

你没钱就别玩!

警告"

else{if(betCount==0)

你的局数不合要求"

else{//满足参数设置要求

MybetExample.betMoney=betMoney;

//设置庄家本金

MybetExample.myMoney=myMoney;

//设置玩家本金

MybetExample.betCount=betCount;

//设置竞猜次数

showSuccess();

}}}}//调用参数设置成功界面显示方法

else{//"

按钮

jT1.setText(MybetExample.betMoney+"

//恢复默认参数显示

jT2.setText(MybetExample.myMoney+"

jT3.setText(MybetExample.betCount+"

}

publicvoidshowSuccess(){//制定规则成功界面显示方法

JLabeljshow=newJLabel("

制定规则完毕,请开始游戏"

jshow.setFont(newFont("

jshow.setForeground(Color.BLUE);

jshow.setBounds(40,40,300,100);

this.removeAll();

this.add(jshow);

this.repaint();

 

/*游戏进行时*/

classBetPanelextendsJPanelimplementsActionListener{

JLabeljL1,jL2,jL3,jL4,jL5,jT1,jT2,jT3;

JTextFieldjT4,jT5;

publicBetPanel(){

jL1.setBounds(60,20,80,15);

jT1=newJLabel(MybetExample.betMoney+"

jT1.setBounds(160,20,80,15);

jL2.setBounds(60,45,80,15);

jT2=newJLabel(MybetExample.myMoney+"

jT2.setBounds(160,45,80,15);

jL3.setBounds(60,70,80,25);

jT3=newJLabel(MybetExample.betCount+"

jT3.setBounds(160,70,80,25);

jL4=newJLabel("

下注金额"

jL4.setBounds(60,95,80,25);

jT4=newJTextField("

0"

jT4.setBounds(160,95,80,25);

jL5=newJLabel("

竞赛马号"

jL5.setBounds(60,125,80,25);

jT5=newJTextField("

1"

jT5.setBounds(160,125,80,25);

jB1.setBounds(60,155,80,30);

重置"

jB2.setBounds(160,155,80,30);

this.add(jL4);

this.add(jT4);

this.add(jL5);

this.add(jT5);

publicvoidactionPerformed(ActionEvente){//按钮事件处理方法

if(e.getSource()==jB1){//"

intbetMoney=Integer.parseInt(jT1.getText());

//获取当前庄家本金

intmyMoney=Integer.parseInt(jT2.getText());

//获取当前玩家本金

intbetCount=Integer.parseInt(jT3.getText());

//获取当前剩余精彩次数

intmybetMoney=Integer.parseInt(jT4.getText());

//获取当前赌资

intmybet=Integer.parseInt(jT5.getText());

//获取当前竞猜马号

if((myMoney-mybetMoney<

0)){//赌资不够

没有那么多钱就不要装大爷!

return;

}elseif(mybetMoney==0){

你会不会玩啊?

怎么不下注!

intnum=(int)(Math.random()*6+1);

//随即生成1~7之间的马号

if(num==mybet){//竞猜成功

MybetExample.betMoney-=mybetMoney;

//庄家本金减少

MybetExample.myMoney+=mybetMoney;

//玩家本金增加

MybetExample.betCount--;

}//竞猜次数减1

else{//竞猜失败

MybetExample.betMoney+=mybetMoney;

//庄家本金增加

MybetExample.myMoney-=mybetMoney;

//玩家本金减少

if(MybetExample.betCount>

0&

&

MybetExample.myMoney>

0){

/*竞猜次数未完,并且玩家仍有本金,则更新显示,继续游戏*/

jT1.setText(MybetExample.betMoney+"

jT2.setText(MybetExample.myMoney+"

}else

showEnd();

//显示游戏结束界面

}

///////////////////////////////////重置

else{MybetExample.betMoney=10000;

MybetExample.myMoney=1000;

MybetExample.betCount=5;

if(MybetExample.betCount>

0)

{

}

///////////////////////////////////////

publicvoidshowEnd(){//游戏结束界面方法

JLabeljshow1=newJLabel("

游戏结束,欢迎再来!

JLabeljshow2=newJLabel("

庄家余额:

"

+MybetExample.betMoney);

JLabeljshow3=newJLabel("

玩家余额:

+MybetExample.myMoney);

jshow1.setFont(newFont("

jshow1.setForeground(Color.RED);

jshow2.setFont(newFont("

jshow2.setForeground(Color.RED);

jshow3.setFont(newFont("

jshow3.setForeground(Color.RED);

jshow1.setBounds(40,5,300,100);

jshow2.setBounds(40,35,300,100);

jshow3.setBounds(40,65,300,100);

this.add(jshow1);

this.add(jshow2);

this.add(jshow3);

程序运行截图

致谢

在本文的撰写过程中,感谢指导老师对我的指导和帮助,同时也要感谢他一直支持我.他严谨细致、一丝不苟的作风一直是我工作、学习中的榜样,他循循善诱的教导和不拘一格的思路给予我无尽的启迪。

使我在对JAVA程序的编写能力方面有了很大的提高。

结束语

通过这次的赛马游戏的程序设计让我们更加地了解如何用JAVA语言进行程序的设计,懂得如何运用所学的知识来完成这次的设计。

本次通过实例介绍了JAVA程序设计。

其分析问题方法,解决问题步骤具有一般性,对程序设计具有一定参考价值。

通过这次的实践,使我了解JAVA程序设计的原理。

参考材料

1.XX百科

2.聂晢.java面向对象程序设计(第二版).北京:

高等教育出版社

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

当前位置:首页 > 总结汇报 > 学习总结

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

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