java井字过三关游戏软件设计_计算机软件及应用_it计算机_专业资料.docx

上传人:scccc 文档编号:13574394 上传时间:2022-01-17 格式:DOCX 页数:23 大小:102.41KB
返回 下载 相关 举报
java井字过三关游戏软件设计_计算机软件及应用_it计算机_专业资料.docx_第1页
第1页 / 共23页
java井字过三关游戏软件设计_计算机软件及应用_it计算机_专业资料.docx_第2页
第2页 / 共23页
java井字过三关游戏软件设计_计算机软件及应用_it计算机_专业资料.docx_第3页
第3页 / 共23页
java井字过三关游戏软件设计_计算机软件及应用_it计算机_专业资料.docx_第4页
第4页 / 共23页
java井字过三关游戏软件设计_计算机软件及应用_it计算机_专业资料.docx_第5页
第5页 / 共23页
点击查看更多>>
资源描述

《java井字过三关游戏软件设计_计算机软件及应用_it计算机_专业资料.docx》由会员分享,可在线阅读,更多相关《java井字过三关游戏软件设计_计算机软件及应用_it计算机_专业资料.docx(23页珍藏版)》请在三一文库上搜索。

1、佛山科学技术学院可视化编程技术课程设计报告并字过三关游戏软件设计学生姓名:黄舜尧学 号: 2012914244年级专业:12级教育技术学指导老师:容汝佳学 院:教育科学学院广东佛山提交日期:2014年6月1 .前言 22 .概要设计 22.1 开发环境 22.2 井字过三关游戏功能 32.3 界面设计 33 .详细设计 43.1 界面设计 43.2 按钮设计 53.3 鼠标单击事件设计 63.4 胜负判断设计 93.5 设计总体认识 123.6 程序流程图124 .运行结果 135 .测试分析 145.1 程序运行情况 145.2 程序异常处理 146 .源程序 14参考文献 24设计总结 2

2、4摘要:该程序是一个图形界面的简单的java井宇过三关小游戏程序,具有简 洁易懂的界面,使用人员能快速理解操作。支持两个人对玩,增添了娱乐性,在 玩完一局游戏后可以选择重来,在游戏过程中也可以选择重新开始,可玩性高。关键字:java井字过关游戏,游戏类,井字过三关1前言随着科学技术的不断发展,计算机已经成为我们工作学习和生活中不可缺少 的工具。文本编辑器是个人计算机最司空见惯的应用程序了,在学习了Java语言之后,我决定使用Java语言编写一个简单的小游戏,可以实现简单的运算功 能,满足日常基本的工作学习和娱乐需要。Java是由Sun公司开发的新一代纯面向对象的网络编程语言。其目标是建立一种在

3、任意种机器、任一种操作系统的网络环境中运行的软件,实行所谓的“程序写一次,到处运行”的目标。正因为如此,Java已成为当今Internet上最流行、最受欢迎的一种程序开发语言。Java开发小组把Java按特性分为基本版、移动版、企业版,每个版本有一 个软件开发包。Java基本版本叫Java 2标准版(Java 2 Standard Edition,J2SE ), 它包含建立Java应用程序或者是Applet所需的应用程序编程接口 (API)。Java 2移动版(The Java 2 Mobile Edition , J2MB包含创建无线Java应用程序的 API。还有 Java 2 企业版(T

4、he Java 2 Enterprise , J2EE)是 J2SE的增强版本, 包含建立多层架构应用程序API。Java语言是由C+1言发展起而来的,是一种彻底的面向对象的程序设计语 言。作为一种纯面向对象的程序设计语言,它非常适合大型软件的开发。Java语言去掉了 C+邮言的一些容易引起错误的特性。Java语言的特点有:面向对象、 跨平台、安全性、多线程和图形功能强。2概要设计2.1 开发环境开发平台:Microsoft Windows XP Professional Service Pack 2开发工具:JBuilder 2007 + JDK 1.6.0_022.2 井字过三关游戏程序功

5、能功能1:按下“重新开始红方先下”按钮和重新开始蓝方先下”按钮可以开始游戏,并选择游戏顺序。功能2:在游戏过程中会提示轮到哪一方下棋。功能3:当鼠标点击选择下棋的地方已经存在其他棋的时候,会提示此处已有棋子, 请另选位置下棋。功能4:点击退出按钮可退出程序。功能5:当游戏结束时会提示游戏结束。2.3 界面设计图2.3井字过三关游戏程序面板3详细设计3.1. 界面设计:public class zjt extends JFrame /*/private static final long serialVersionUID = -9031161752105489191L;int x = 0, y

6、= 0;int a = 0;int x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0, x4 = 0, y4 = 0;boolean fa = true, huatu = true, yin = false;int al = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0, a7 = 0, a8 = 0, a9 = 0;int s = new int10, jj = new int10;JButton congxin, huanse,back;JLabel jl;public zjt() super(2012914

7、244 黄舜尧);Container c = getContentPane();c.setLayout(new FlowLayout();congxin = new JButton(重新开始红队先下); congxin.setBackground (Color.red);c.add(congxin);huanse = new JButton(重新开始蓝队先下 );huanse.setBackground (Color.blue);c.add(huanse);jl = new JLabel();c.add(jl, BorderLayout.SOUTH);back = new JButton(退出

8、);c.add(back);addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent event) if (event.isAltDown() repaint();x = event.getPoint().x;y = event.getPoint().y;int a = mm(x, y);if (yin) jl.setForeground(Color.RED);jl.setText(游戏已结束,请重新开始);else if (sa = 1) );jl.setForeground(Color.RED);jl.s

9、etText( 此位置有棋子,请另选位置重新下棋else fa = false;if (a = 1)al = 1;if (a = 2)a2 = 1;if (a = 3)a3 = 1;if (a = 4)a4 = 1;if (a = 5)a5 = 1;if (a = 6)a6 = 1;if (a = 7)a7 = 1;if (a = 8)a8 = 1;if (a = 9)a9 = 1;jl.setText();repaint();sa = 1; );3.2 .按钮设置:congxin.addActionListener(new ActionListener() public void actio

10、nPerformed(ActionEvent arg0) for (int i = 0; i s.length; i+) si = 0;jji = 0;fa = true;repaint();yin = false;huatu = true;jl.setForeground(Color.black);jl.setText(红队先下););huanse.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) for (int i = 0; i s.length; i+) si = 0

11、;jji = 0;fa = true;repaint();yin = false;huatu = false;jl.setForeground(Color.black);jl.setText(蓝队先下););back.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) if(arg0.getSource()=back) System.exit(0););setSize(500, 500);setVisible(true);3.3 .鼠标单击事件设置:public void pa

12、int(Graphics g) if (fa) super.paint(g);int x = 100, y = 100, c = 300, k = 300;for (int i = 0; i 300; i += 100) g.drawRect(x, y + i, c, k - i);for (int i = 0; i 300; i += 100) g.drawRect(x + i, y, c - i, k);else jl.setForeground(Color.black);if (huatu) g.setColor(Color.red);if (a1 = 1) g.drawLine(120

13、, 120, 180, 180);g.drawLine(180, 120, 120, 180);a1 = 0;jj1 = 1;if (a2 = 1) g.drawLine(220, 120, 280, 180);g.drawLine(280, 120, 220, 180);a2 = 0;jj2 = 1;if (a3 = 1) g.drawLine(320, 120, 380, 180);g.drawLine(380, 120, 320, 180);a3 = 0;jj3 = 1;if (a4 = 1) g.drawLine(120, 220, 180, 280);g.drawLine(180,

14、220, 120, 280);a4 = 0;jj4 = 1;if (a5 = 1) g.drawLine(220, 220, 280, 280);g.drawLine(280, 220, 220, 280);a5 = 0;jj5 = 1;if (a6 = 1) g.drawLine(320, 220, 380, 280);g.drawLine(380, 220, 320, 280);a6 = 0;jj6 = 1;if (a7 = 1) g.drawLine(120, 320, 180, 380);g.drawLine(180, 320, 120, 380);a7 = 0;jj7 = 1;if

15、(a8 = 1) g.drawLine(220, 320, 280, 380);g.drawLine(280, 320, 220, 380);a8 = 0;jj8 = 1;if (a9 = 1) g.drawLine(320, 320, 380, 380);g.drawLine(380, 320, 320, 380);a9 = 0;jj9 = 1;huatu = false;jl.setText(蓝队下棋); else g.setColor(Color.blue);if (a1 = 1) g.drawOval(125, 125, 50, 50);a1 = 0;jj1 = 2;if (a2 =

16、1) g.drawOval(225, 125, 50, 50);a2 = 0;jj2 = 2;if (a3 = 1) g.drawOval(325, 125, 50, 50);a3 = 0;jj3 = 2;if (a4 = 1) g.drawOval(125, 225, 50, 50);a4 = 0;jj4 = 2;if (a5 = 1) g.drawOval(225, 225, 50, 50);a5 = 0;jj5 = 2;if (a6 = 1) g.drawOval(325, 225, 50, 50);a6 = 0;jj6 = 2;if (a7 = 1) g.drawOval(125, 3

17、25, 50, 50);a7 = 0;jj7 = 2;if (a8 = 1) g.drawOval(225, 325, 50, 50);a8 = 0;jj8 = 2;if (a9 = 1) g.drawOval(325, 325, 50, 50);a9 = 0;jj9 = 2;huatu = true;jl.setText(红队下棋);dd();3.4 .胜负事件判断:public void dd() if (jj1 = 1 & jj2 = 1 & jj3 = 1) jl.setForeground(Color.RED);jl.setText(红方获胜,连接线1,2,3); yin = tru

18、e;if (jj4 = 1 & jj5 = 1 & jj6 = 1) jl.setForeground(Color.RED);jl.setText(红方获胜,连接线4,5,6); yin = true;if (jj7 = 1 & jj8 = 1 & jj9 = 1) jl.setForeground(Color.RED);jl.setText(红方获胜,连接线7,8,9); yin = true;if (jj1 = 1 & jj5 = 1 & jj9 = 1) jl.setForeground(Color.RED);jl.setText(红方获获胜连接线1,5,9); yin = true;i

19、f (jj3 = 1 & jj5 = 1 & jj7 = 1) jl.setForeground(Color.RED);jl.setText(红方获胜,连接线3,5,7); yin = true;if (jj1 = 1 & jj4 = 1 & jj7 = 1) jl.setForeground(Color.RED);jl.setText(红方获胜,连接线1,4,7); yin = true;if (jj2 = 1 & jj5 = 1 & jj8 = 1) jl.setForeground(Color.RED);jl.setText(红方获胜,连接线2,5,8); yin = true;if (

20、jj3 = 1 & jj6 = 1 & jj9 = 1) jl.setForeground(Color.RED);jl.setText(红方获胜,连接线3,6,9); yin = true;if (jj1 = 2 & jj2 = 2 & jj3 = 2) jl.setForeground(Color.RED);jl.setText(蓝方获胜,连接线1,2,3); yin = true;if (jj4 = 2 & jj5 = 2 & jj6 = 2) jl.setForeground(Color.RED);jl.setText(蓝方获胜,连接线4,5,6); yin = true;if (jj7

21、 = 2 & jj8 = 2 & jj9 = 2) jl.setForeground(Color.RED);jl.setText(蓝方获胜,连接线7,8,9); yin = true;if (jj1 = 2 & jj5 = 2 & jj9 = 2) jl.setForeground(Color.RED);jl.setText(蓝方获胜,连接线1,5,9 ); yin = true;if (jj3 = 2 & jj5 = 2 & jj7 = 2) jl.setForeground(Color.RED);jl.setText(蓝方获胜,连接线3,5,7 ); yin = true;if (jj1

22、= 2 & jj4 = 2 & jj7 = 2) jl.setForeground(Color.RED);jl.setText(蓝方获胜,连接线1,4,7 ); yin = true;if (jj2 = 2 & jj5 = 2 & jj8 = 2) jl.setForeground(Color.RED);jl.setText(蓝方获胜,连接线2,5,8); yin = true;if (jj3 = 2 & jj6 = 2 & jj9 = 2) jl.setForeground(Color.RED);jl.setText(蓝方获胜,连接线3,6,9); yin = true;if (s1 = 1

23、 & s2 = 1 & s3 = 1 & s4 = 1 & s5 = 1 & s6 = 1 & s7 = 1 & s8 = 1 & s9 = 1) jl.setForeground(Color.RED);jl.setText(双方都没获胜,游戏结束); yin = true;System.out.println(jj2);3.5 .设计的总体认识JAVA设计的摘要JAVA设计的目录结构JAVA设计的概要和详细设计JAVA设计的版权意识JAVA设计需要编译的环境JAVA设计的实用性3.6 .程序流程图J*11rf 判断限负是否重新开始刷新图3绘制井字过三关游戏方法PAD图4运行结果图4运行结果显

24、示5测试分析5.1 程序运行情况:程序能够正常运行,并没有出现异常状况,能正常判断胜负。5.2 程序异常处理:若下棋的位置原来已经存在棋,则会处理如下:addMouseListener( new MouseAdapter() public void mousePressed(MouseEvent event) if (event.isAltDown() repaint();x = event.getPoint().x;y = event.getPoint().y;int a = mm( x, y);if ( yin ) jl .setForeground(Color. RED);jl.setT

25、ext( 游戏已结束,请重新开始); else if ( sa = 1) jl .setForeground(Color. RED);jl .setText(此位置有棋子,请另选位置重新下棋);else fa = false ;if (a = 1)a1 = 1;if (a = 2)a2 = 1;if (a = 3) a3 = 1;if (a = 4) a4 = 1;if (a = 5) a5 = 1;if (a = 6)a6 = 1;if (a = 7)a7 = 1;if (a = 8)a8 = 1;if (a = 9)a9 = 1;jl .setText();repaint();sa = 1

26、;);6程序清单:package黄舜尧;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.FlowLayout;import java.awt.Graphics;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.

27、awt.*;import .URL;import java.sql.Date;import java.applet.*;import javax.swing.*;import java.awt.event.*;import java.text.*;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;SuppressWarnings(unused) public class zjt extends JFrame /*/private static final long serialVersi

28、onUID = -9031161752105489191L;int x = 0, y = 0;int a = 0;int x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0, x4 = 0, y4 = 0;boolean fa = true, huatu = true, yin = false;int al = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0, a7 = 0, a8 = 0, a9=0;int s口 = new int10, jj = new int10;JButton congxin, huanse

29、,back;JLabel jl;public zjt() super(2012914244 黄舜尧);Container c = getContentPane();c.setLayout(new FlowLayout();congxin = new JButton( 重新开始红队先下);congxin.setBackground (Color.red);c.add(congxin);huanse = new JButton(重新开始蓝队先下);huanse.setBackground (Color.blue);c.add(huanse);jl = new JLabel();c.add(jl,

30、BorderLayout.SOUTH);back = new JButton( 退出);c.add(back);addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent event) if (event.isAltDown() repaint();x = event.getPoint().x;y = event.getPoint().y;int a = mm(x, y);if (yin) jl.setForeground(Color.RED);jl.setText( 游戏已结束,请重新开始);else if

31、(sa = 1) jl.setForeground(Color.RED);jl.setText(此位置有棋子,请另选位置重新下棋); else fa = false; if (a = 1) al = 1; if (a = 2) a2 = 1; if (a = 3) a3 = 1; if (a = 4) a4 = 1;if (a = 5)a5 = 1;if (a = 6)a6 = 1;if (a = 7)a7 = 1;if (a = 8)a8 = 1;if (a = 9)a9 = 1;jl.setText(); repaint();sa = 1;);congxin.addActionListen

32、er(new ActionListener() public void actionPerformed(ActionEvent arg0) for (int i = 0; i s.length; i+) si = 0;jji = 0;fa = true;repaint();yin = false;huatu = true;jl.setForeground(Color.black);jl.setText(红队先下););huanse.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg

33、0) for (int i = 0; i s.length; i+) si = 0;jji = 0;fa = true; repaint(); yin = false; huatu = false;jl.setForeground(Color.black);jl .setText(蓝队先下); );back.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) if(arg0.getSource()=back)System.exit(0); );setSize(500, 500)

34、;setVisible(true);public void paint(Graphics g) if (fa) super.paint(g); int x = 100, y = 100, c = 300, k = 300; for (int i = 0; i 300; i += 100) g.drawRect(x, y + i, c, k - i);for (int i = 0; i = 100 & x = 100 & y = 200 & x = 100 & y = 300 & x = 100 & y = 100 & x = 200 & y = 200 & x = 200 & y = 300

35、& x = 200 & y = 100 & x = 300 & y = 200 & x = 300 & y = 300 & x = 300 & y 400) a = 9;elsea = 0;return a;public void dd() if (jj1 = 1 & jj2 = 1 & jj3 = 1) jl.setForeground(Color.RED);jl.setText(红方获胜,连接线1,2,3);yin = true;if (jj4 = 1 & jj5 = 1 & jj6 = 1) jl.setForeground(Color.RED);jl.setText(红方获胜,连接线4,5,6);yin = true;if (jj7 = 1 & jj8 = 1 & jj9 = 1) jl.setForeground(Color.RED);jl.setText(红方获胜,连接线7,8,9);yin = true;if (jj1 = 1 & jj5 = 1 & jj9 = 1) jl.setForeground(Color.RED);jl.setText(红方获获胜,连接线1,5,9);yin = true;if (jj3 = 1 & jj5 = 1 & jj7 = 1) jl.setForeground(Color.RED);jl.setTex

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

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1