package com.hjf.fishGame0112;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringBufferInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.print.attribute.standard.MediaSize.Other;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class ThreadFish implements Runnable {
Graphics g;
JPanel j;
ImageIcon imgi1;
threadotherfishlist todl;
List<AllFish> otherfish;
AllFish mf;
collision cl = new collision();
int score = 0;
public int myfishsize;
boolean bo = false;
int n,i=0,date;
File f;
private int jilu;
String str;
String name;
// HashMap<String, Integer> DataMap = new HashMap<>();
public ThreadFish(Graphics g, JPanel j, List<AllFish> otherfish, AllFish mf) {
this.g = g;
this.j = j;
this.otherfish = otherfish;
this.mf = mf;
imgi1 = new ImageIcon(this.getClass().getResource("海洋.png"));
f = new File("F:\\Java\\io\\top.txt");
}
// 控制不断画其他鱼和画自己的鱼的线程
public void run() {
while (true) {
try {
Thread.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
// 创建缓冲区
BufferedImage bf = new BufferedImage(j.getWidth(), j.getHeight(),
BufferedImage.TYPE_3BYTE_BGR);
// 从缓冲区获取画笔
Graphics bg = bf.getGraphics();
// 画背景
bg.drawImage(imgi1.getImage(), 0, 0, j.getWidth(), j.getHeight(),
null);
// 在缓冲区里画自己的鱼
mf.drawmyfish(bg);
bg.setFont(new Font("宋体", 50, 50));
bg.setColor(Color.black);
bg.drawString("得分:" + score, 50, 50);
// 按暂停键时暂停线程
if (bo) {
continue;
}
// 当被鱼吃掉的时候停止线程
if (n == 1) {
continue;
}
for (int i = 0; i < otherfish.size(); i++) {
// 在缓冲区里画其他的鱼
otherfish.get(i).drawotherfish(bg);
}
for (int i = 0; i < otherfish.size(); i++) {
// 移除已经出界的鱼
if (otherfish.get(i).getX1() < 0
|| otherfish.get(i).getX2() > 1400) {
otherfish.remove(i);
}
if (otherfish.get(i).getFish() % 2 == 1) {
// 吃鱼的判断
if ((mf.getY() + mf.getMyfishsize() >= otherfish.get(i)
.getPosition() && mf.getY() <= otherfish.get(i)
.getPosition())
&& (mf.getX() + mf.getMyfishsize() > otherfish.get(
i).getX1() && (mf.getX() < otherfish.get(i)
.getX1()))) {
// 测试是否运行到这一步
// System.out.println("已运行");
if (cl.cillisionfish(otherfish, mf.getMyfishsize(), i) == 1) {
mf.setMyfishsize(mf.getMyfishsize() + 10);
score++;
otherfish.remove(i);
break;
}
}
// 被鱼吃的判断
if ((mf.getY() <= otherfish.get(i).getPosition()
+ otherfish.get(i).getfishh() && mf.getY() >= otherfish
.get(i).getPosition())
&& (mf.getX() <= otherfish.get(i).getX1()
+ otherfish.get(i).getfishw() && mf.getX() >= otherfish
.get(i).getX1())) {
// 测试是否运行到这一步
// System.out.println("已运行");
if (cl.cillisionfish(otherfish, mf.getMyfishsize(), i) == 2) {
// 停止线程并gameover
jilu = JOptionPane.showConfirmDialog(null,
"请问您要保存记录吗", "保存",
JOptionPane.YES_NO_OPTION);
n = 1;
if (jilu == 0) {
name=JOptionPane.showInputDialog(null,"请输入你的名字:\n","你的名字",JOptionPane.PLAIN_MESSAGE);
if(i<2){
i++;
}
try {
fileOutput(f);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
bg.setFont(new Font("宋体", 250, 250));
bg.setColor(new Color(255, 215, 0));
bg.drawString("GAME OVER", 50, 400);
}
}
}
if (otherfish.get(i).getFish() % 2 == 0) {
// 吃鱼的判断
if ((mf.getY() + mf.getMyfishsize() >= otherfish.get(i)
.getPosition() && mf.getY() <= otherfish.get(i)
.getPosition())
&& (mf.getX() + mf.getMyfishsize() > otherfish.get(
i).getX2() && (mf.getX() < otherfish.get(i)
.getX2()))) {
// 测试是否运行到这一步
// System.out.println("已运行");
if (cl.cillisionfish(otherfish, mf.getMyfishsize(), i) == 1) {
mf.setMyfishsize(mf.getMyfishsize() + 10);
score++;
otherfish.remove(i);
break;
}
}
// 被鱼吃的判断
if ((mf.getY() <= otherfish.get(i).getPosition()
+ otherfish.get(i).getfishh() && mf.getY() >= otherfish
.get(i).getPosition())
&& (mf.getX() <= otherfish.get(i).getX2()
+ otherfish.get(i).getfishw() && mf.getX() >= otherfish
.get(i).getX2())) {
if (cl.cillisionfish(otherfish, mf.getMyfishsize(), i) == 2) {
// 停止线程并gameover
jilu = JOptionPane.showConfirmDialog(null,
"请问您要保存记录吗", "保存",
JOptionPane.YES_NO_OPTION);
n = 1;
if (jilu == 0) {
name=JOptionPane.showInputDialog(null,"请输入你的名字:\n","你的名字",JOptionPane.PLAIN_MESSAGE);
if(i<2){
i++;
}
try {
fileOutput(f);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
bg.setFont(new Font("宋体", 250, 250));
bg.setColor(new Color(255, 215, 0));
bg.drawString("GAME OVER", 50, 400);
}
}
}
}
// 把缓冲图片画在面板上
g.drawImage(bf, 0, 0, null);
}
}
//排行榜的界面
public void phb(String name,int score){
javax.swing.JFrame jf = new javax.swing.JFrame();
jf.setSize(400, 800);
jf.setTitle("排行榜");
jf.setLocationRelativeTo(null);
jf.setDefaultCloseOperation(2);
FlowLayout fl = new FlowLayout();
jf.setLayout(fl);
Dimension di=new Dimension(300,200);
// if(score>score1&&score1>score2){
// javax.swing.JLabel jlb1=new javax.swing.JLabel(name+": "+score);
// jlb1.setPreferredSize(di);
// jf.add(jlb1);
// javax.swing.JLabel jlb2=new javax.swing.JLabel(name1+": "+score1);
// jlb2.setPreferredSize(di);
// jf.add(jlb2);
// javax.swing.JLabel jlb3=new javax.swing.JLabel(name2+": "+score2);
// jlb3.setPreferredSize(di);
// jf.add(jlb3);
// }
// if(score1>score&&score>score2){
// javax.swing.JLabel jlb2=new javax.swing.JLabel(name1+": "+score1);
// jlb2.setPreferredSize(di);
// jf.add(jlb2);
// javax.swing.JLabel jlb1=new javax.swing.JLabel(name+": "+score);
// jlb1.setPreferredSize(di);
// jf.add(jlb1);
// javax.swing.JLabel jlb3=new javax.swing.JLabel(name2+": "+score2);
// jlb3.setPreferredSize(di);
// jf.add(jlb3);
// }
// if(score2>score&&score>score1){
// javax.swing.JLabel jlb3=new javax.swing.JLabel(name2+": "+score2);
// jlb3.setPreferredSize(di);
// jf.add(jlb3);
// javax.swing.JLabel jlb1=new javax.swing.JLabel(name+": "+score);
// jlb1.setPreferredSize(di);
// jf.add(jlb1);
// javax.swing.JLabel jlb2=new javax.swing.JLabel(name1+": "+score1);
// jlb2.setPreferredSize(di);
// jf.add(jlb2);
// }
// if(score>score1&&score2>score1&&score>score2){
// javax.swing.JLabel jlb1=new javax.swing.JLabel(name+": "+score);
// jlb1.setPreferredSize(di);
// jf.add(jlb1);
// javax.swing.JLabel jlb3=new javax.swing.JLabel(name2+": "+score2);
// jlb3.setPreferredSize(di);
// jf.add(jlb3);
// javax.swing.JLabel jlb2=new javax.swing.JLabel(name1+": "+score1);
// jlb2.setPreferredSize(di);
// jf.add(jlb2);
// }
// if(score1>score&&score2>score&&score1>score2){
// javax.swing.JLabel jlb2=new javax.swing.JLabel(name1+": "+score1);
// jlb2.set
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计
资源推荐
资源详情
资源评论
收起资源包目录
java线程小游戏,大鱼吃小鱼,实现了大体的模式,可以给想做小游戏的朋友一点参考.zip (31个子文件)
project_code_0719
.classpath 295B
.settings
org.eclipse.jdt.core.prefs 587B
src
com
hjf
fishGame0112
otherfish3_副本.png 88KB
Myfish.png 115KB
海洋.png 370KB
ThreadFish.java 11KB
otherfishi1_副本.png 430KB
collision.java 375B
threadotherfishlist.java 689B
AllFish.java 4KB
otherfish2.png 302KB
otherfish3.png 90KB
FishUI.java 4KB
otherfish2_副本.png 307KB
Myfish2.png 107KB
otherfishi1.png 428KB
bin
com
hjf
fishGame0112
FishUI.class 5KB
otherfish3_副本.png 88KB
Myfish.png 115KB
threadotherfishlist.class 1KB
ThreadFish.class 8KB
海洋.png 370KB
otherfishi1_副本.png 430KB
otherfish2.png 302KB
otherfish3.png 90KB
otherfish2_副本.png 307KB
collision.class 884B
Myfish2.png 107KB
AllFish.class 4KB
otherfishi1.png 428KB
.project 367B
共 31 条
- 1
资源评论
- 2301_809046342023-12-19怎么能有这么好的资源!只能用感激涕零来形容TAT...
辣椒种子
- 粉丝: 3414
- 资源: 5723
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功