




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
package practice;import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.awt.Color; public class WuZhiqi extends Applet implements ActionListener, MouseListener, MouseMotionListener, ItemListener int color = 0;/ 旗子的颜色标识 0:白子 1:黑子 boolean isStart = false;/ 游戏开始标志 int bodyArray = new int1616; / 设置棋盘棋子状态 0 无子 1 白子 2 黑子 Button b1 = new Button(游戏开始); Button b2 = new Button(重置游戏); Label lblWin = new Label( ); Checkbox ckbHB = new Checkbox2; CheckboxGroup ckgHB = new CheckboxGroup(); public void init() setLayout(null); addMouseListener(this); add(b1); b1.setBounds(330, 50, 80, 30); b1.addActionListener(this); add(b2); b2.setBounds(330, 90, 80, 30); b2.addActionListener(this); ckbHB0 = new Checkbox(白子先, ckgHB, false); ckbHB0.setBounds(320, 20, 60, 30); ckbHB1 = new Checkbox(黑子先, ckgHB, false); ckbHB1.setBounds(380, 20, 60, 30); add(ckbHB0); add(ckbHB1); ckbHB0.addItemListener(this); ckbHB1.addItemListener(this); add(lblWin); lblWin.setBounds(330, 130, 80, 30); gameInit(); this.resize(new Dimension(450,350); public void itemStateChanged(ItemEvent e) if (ckbHB0.getState() / 选择黑子先还是白子先 color = 0; else color= 1; public void actionPerformed(ActionEvent e) if (e.getSource() = b1) gameStart(); else reStart(); public void mousePressed(MouseEvent e) public void mouseClicked(MouseEvent e) int x1, y1; x1 = e.getX(); y1 = e.getY(); if (e.getX() 300 | e.getY() 300) return; if (x1 % 20 10) x1 += 20; if (y1 % 20 10) y1 += 20; x1 = x1 / 20 * 20; y1 = y1 / 20 * 20; setDown(x1, y1); public void mouseEntered(MouseEvent e) public void mouseExited(MouseEvent e) public void mouseReleased(MouseEvent e) public void mouseDragged(MouseEvent e) public void mouseMoved(MouseEvent e) public void paint(Graphics g) g.setColor(Color.lightGray); g.fill3DRect(10, 10, 300, 300, true); g.setColor(Color.black); for (int i = 1; i 16; i+) g.drawLine(20, 20 * i, 300, 20 * i); g.drawLine(20 * i, 20, 20 * i, 300); public void setDown(int x, int y) / 落子 if (!isStart) / 判断游戏未开始 return; if (bodyArrayx / 20y / 20 != 0) return; Graphics g = getGraphics(); if (color = 1)/ 判断黑子还是白子 g.setColor(Color.black); color = 0; else g.setColor(Color.white); color = 1; g.fillOval(x - 10, y - 10, 20, 20); bodyArrayx / 20y / 20 = color + 1; if (gameWin1(x / 20, y / 20) / 判断输赢 lblWin.setText(startColor(color) + 赢了!); isStart = false; if (gameWin2(x / 20, y / 20) / 判断输赢 lblWin.setText(startColor(color) + 赢了!); isStart = false; if (gameWin3(x / 20, y / 20) / 判断输赢 lblWin.setText(startColor(color) + 赢了!); isStart = false; if (gameWin4(x / 20, y / 20) / 判断输赢 lblWin.setText(startColor(color) + 赢了!); isStart = false; public String startColor(int x) if (x = 0) return 黑子; else return 白子; public void gameStart() / 游戏开始 isStart = true; enableGame(false); b2.setEnabled(true); public void gameInit() / 游戏开始初始化 isStart = false; enableGame(true); b2.setEnabled(false); ckbHB0.setState(true); for (int i = 0; i 16; i+) for (int j = 0; j 16; j+) bodyArrayij = 0; lblWin.setText(); public void reStart() / 游戏重新开始 repaint(); gameInit(); public void enableGame(boolean e) / 设置组件状态 b1.setEnabled(e); b2.setEnabled(e); ckbHB0.setEnabled(e); ckbHB1.setEnabled(e); public boolean gameWin1(int x, int y) / 判断输赢 横 int x1, y1, t = 1; x1 = x; y1 = y; for (int i = 1; i 15) break; if (bodyArrayx1 + iy1 = bodyArrayxy) t += 1; else break; for (int i = 1; i 5; i+) if (x1 4) return true; else return false; public boolean gameWin2(int x, int y) / 判断输赢 竖 int x1, y1, t = 1; x1 = x; y1 = y; for (int i = 1; i 15) break; if (bodyArrayx1y1 + i = bodyArrayxy) t += 1; else break; for (int i = 1; i 5; i+) if (x1 4) return true; else return false; public boolean gameWin3(int x, int y) / 判断输赢 左斜 int x1, y1, t = 1; x1 = x; y1 = y; for (int i = 1; i 15) break; if (bodyArrayx1 + iy1 - i = bodyArrayxy) t += 1; else break; for (int i = 1; i 5; i+) if (x1 4) return true; else return false; public boolean gameWin4(int x, int y
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025湖北武汉江夏区第一人民医院(协和江南医院)招聘35人考前自测高频考点模拟试题及一套完整答案详解
- 2025春季中国核工业二四建设有限公司校园招聘正式启动模拟试卷及答案详解(考点梳理)
- 2025江西南昌市自然资源和规划局高新分局招聘辅助工作人员1人考前自测高频考点模拟试题及参考答案详解
- 2025年度吉林大学公开招聘教师(1号)(105人)模拟试卷及答案详解(名师系列)
- 2025广州医科大学校本部招聘工作人员9人(第二次)模拟试卷及答案详解(网校专用)
- 2025《抗菌药物临床应用指导原则》培训试题及答案(院外补考)
- 2025春季北京师范大学保定实验学校(第32届)教师招聘66人考前自测高频考点模拟试题及答案详解(易错题)
- 2025福建厦门大学学院水声通信课题组嵌入式工程师招聘1人考前自测高频考点模拟试题附答案详解(模拟题)
- 2025年春季上海华二松江实验教师招聘模拟试卷及答案详解(网校专用)
- 2025湖北天门市城市社区专职工作人员招聘59人考前自测高频考点模拟试题及答案详解(易错题)
- (2024版)小学六年级数学考试命题趋势分析
- 脑肿瘤的症状和早期诊断方法
- 中级注册安全工程师-其他安全历年真题
- 小学生自己修改作文能力的培养研究课题结题报告.文档
- CREO基础培训教程
- 食品保质期检测记录表
- 诗化小说示范课
- (17)-第三节 反抗外国武装侵略的斗争
- 04质量奖(现场)评审报告
- 《罗织经》全文及翻译
- 《中药商品学》考试复习题库(含答案)
评论
0/150
提交评论