




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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("2
7、012914244 黄舜尧");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, Borde
8、rLayout.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("游戏已结束,请重新开
9、始");else if (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();
10、sa = 1; );3.2 .按钮设置:congxin.addActionListener(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
11、ActionListener() public void actionPerformed(ActionEvent arg0) 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(Action
12、Event arg0) if(arg0.getSource()=back) System.exit(0););setSize(500, 500);setVisible(true);3.3 .鼠标单击事件设置: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 < 300; i += 10
13、0) 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, 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.drawLi
14、ne(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, 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
15、(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 (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 =
16、 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 = 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;i
17、f (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, 325, 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.setTe
18、xt("红队下棋");dd();3.4 .胜负事件判断: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")
19、; 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 =
20、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(Col
21、or.RED);jl.setText("红方获胜,连接线2,5,8"); yin = true;if (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&quo
22、t;); yin = true;if (jj4 = 2 && jj5 = 2 && jj6 = 2) jl.setForeground(Color.RED);jl.setText("蓝方获胜,连接线4,5,6"); yin = true;if (jj7 = 2 && jj8 = 2 && jj9 = 2) jl.setForeground(Color.RED);jl.setText("蓝方获胜,连接线7,8,9"); yin = true;if (jj1 = 2 && jj5
23、 = 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 = 2 && jj4 = 2 && jj7 = 2) jl.setForegroun
24、d(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
25、,9"); yin = true;if (s1 = 1 && 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设计的摘要J
26、AVA设计的目录结构JAVA设计的概要和详细设计JAVA设计的版权意识JAVA设计需要编译的环境JAVA设计的实用性3.6 .程序流程图J*11rf 判断限负是否重新开始刷新图3绘制井字过三关游戏方法PAD图4运行结果图4运行结果显示5测试分析5.1 程序运行情况:程序能够正常运行,并没有出现异常状况,能正常判断胜负。5.2 程序异常处理:若下棋的位置原来已经存在棋,则会处理如下:addMouseListener( new MouseAdapter() public void mousePressed(MouseEvent event) if (event.isAltDown() repain
27、t();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 .setText("此位置有棋子,请另选位置重新下棋");else fa = false ;if (a = 1)a1 = 1;if (a = 2)a2 = 1;if (a = 3) a
28、3 = 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;);6程序清单:package黄舜尧;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.FlowLayout;import java.awt.Graphics
29、;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.*;import .URL;import java.sql.Date;import java.applet.*;import javax.swing.*;import java.awt.event.*;import java.text.*;import javax.swing.JButt
30、on;import javax.swing.JFrame;import javax.swing.JLabel;SuppressWarnings("unused") public class zjt extends JFrame /*/private static final long serialVersionUID = -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 =
31、 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("2012914244 黄舜尧");Container c = getContentPane();c.setLayout(new FlowLayout();congxin = new
32、 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(" 退出");c.add(back);addMouseListener(new MouseAdapte
33、r() 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.setText("此位置有棋子,请另选位置重新下棋"
34、); 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.addActionListener(new ActionListener() public void actionPerformed(
35、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;
36、 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);setVisible(true);
37、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 < 300; i += 100) g.drawRect(x + i, y, c - i, k);else jl.setForeground(Color.black);if (huatu) g.setColor(Color.red);
38、 if (a1 = 1) g.drawLine(120, 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, 22
39、0, 180, 280);g.drawLine(180, 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,
40、 120, 380);a7 = 0;jj7 = 1;if (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(1
41、25, 125, 50, 50);a1 = 0;jj1 = 2;if (a2 = 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
42、= 0;jj6 = 2;if (a7 = 1) g.drawOval(125, 325, 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();public int mm(int x, int y) if (x >= 100 && x < 200 &&
43、amp; y >= 100 && y < 200)a = 1;else if (x >= 200 && x < 300 && y >= 100 && y < 200) a = 2;else if (x >= 300 && x < 400 && y >= 100 && y < 200) a = 3;else if (x >= 100 && x < 200 && y >= 200
44、 && y < 300) a = 4;else if (x >= 200 && x < 300 && y >= 200 && y < 300) a = 5;else if (x >= 300 && x < 400 && y >= 200 && y < 300) a = 6;else if (x >= 100 && x < 200 && y >= 300 && y &
45、lt; 400) a = 7;else if (x >= 200 && x < 300 && y >= 300 && y < 400) a = 8;else if (x >= 300 && x < 400 && y >= 300 && y < 400) a = 9;elsea = 0;return a;public void dd() if (jj1 = 1 && jj2 = 1 && jj3 = 1) jl.setFo
46、reground(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("红方获胜,连接
47、线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.setText("红方获胜,连接线3,5,7");yin = true;if (jj1 = 1 &&
48、amp; 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 (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(C
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 加盟保洁公司合同范本
- 2024年盐城市滨海县招聘教师考试真题
- 农村房屋共建合同范例
- 2024年梧州市龙圩区招录公益性岗位人员考试真题
- 公司之间供货合同范本
- 动产转让合同范本
- 2024年普洱市墨江县教体系统所属事业单位紧缺招聘考试真题
- 2024年绵阳市投资控股有限公司招聘笔试真题
- 第12课 宋元时期的都市和文化(教学设计)七年级历史下册同步备课系列(部编版)
- 做代理合同范本
- CJ/T 124-2016 给水用钢骨架聚乙烯塑料复合管件
- YDT 4560-2023-5G数据安全评估规范
- 浙教版(2023)四下信息科技第1课《初探数字化》教学设计
- 双J管置入术后护理
- 2024年青岛酒店管理职业技术学院单招综合素质考试题库及答案(新)
- 安全帽的佩戴
- JJG 365-2008电化学氧测定仪
- 2024年江苏太仓市产业投资发展集团有限公司招聘笔试参考题库含答案解析
- 医院食堂计划方案
- 河北传统医学师承关系合同书
- (附件条款版)电话销售员员工保密协议
评论
0/150
提交评论