@ -1,13 +0,0 @@
|
||||
package com.Drj.Object;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
|
||||
public class GoldMinidrj extends Golddrj{
|
||||
public GoldMinidrj() {
|
||||
this.width=36;
|
||||
this.height =36;//由于图片大小不同重新设置一个宽高
|
||||
this.m=15;//由于质量大小不同重新设置一个质量
|
||||
this.count=2;//设置积分
|
||||
this.img =Toolkit.getDefaultToolkit().getImage("image/gold0.gif");//由于图片不同重新设置一个路径
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
package com.Drj.Object;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
|
||||
public class GoldPlusdrj extends Golddrj{
|
||||
public GoldPlusdrj() {
|
||||
//由于大金矿过大会溢出画面重新设置其坐标
|
||||
this.x=(int)(Math.random()*650);//金矿x轴随机位置的函数
|
||||
this.y=(int)(Math.random()*550+300);//金矿y轴随机位置的函数
|
||||
this.width=105;
|
||||
this.height =105;//由于图片大小不同重新设置一个宽高
|
||||
this.m=60;//由于质量大小不同重新设置一个质量
|
||||
this.count=8;//设置积分
|
||||
this.img =Toolkit.getDefaultToolkit().getImage("image/gold2.gif");//由于图片不同重新设置一个路径
|
||||
}
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package com.Drj.Object;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
|
||||
public class Golddrj extends Objectdrj{
|
||||
boolean f=false;//用于判断是否被抓取
|
||||
public Golddrj() {
|
||||
this.x=(int)(Math.random()*700);//金矿x轴随机位置的函数
|
||||
this.y=(int)(Math.random()*550+300);//金矿y轴随机位置的函数
|
||||
this.width=52;//设置宽
|
||||
this.height =52;//设置高
|
||||
this.f=false;
|
||||
this.m=30;//设置质量
|
||||
this.count=4;//设置积分
|
||||
this.type=1;
|
||||
this.img =Toolkit.getDefaultToolkit().getImage("image/gold1.gif");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
package com.Drj.Object;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
|
||||
public class Rockdrj extends Objectdrj{
|
||||
boolean f=false;//用于判断是否被抓取
|
||||
public Rockdrj() {
|
||||
this.x=(int)(Math.random()*700);//石头x轴随机位置的函数
|
||||
this.y=(int)(Math.random()*550+300);//石头y轴随机位置的函数
|
||||
this.width=71;
|
||||
this.height =71;
|
||||
this.f=false;
|
||||
this.m=50;
|
||||
this.count=1;//设置积分
|
||||
this.type=2;
|
||||
this.img =Toolkit.getDefaultToolkit().getImage("image/rock1.png");
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package com.Drj.shop;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import com.Drj.Bg.Bgdrj;
|
||||
import com.Drj.gameWin.gameWindrj;
|
||||
public class Shopdrj {
|
||||
public void mouseClicked(MouseEvent e,Bgdrj bg) {
|
||||
if(e.getButton()==1) {
|
||||
bg.shop=true;
|
||||
}
|
||||
if(e.getButton()==3) {
|
||||
gameWindrj.state=1;
|
||||
bg.startTime=System.currentTimeMillis();//给开始时间赋值为系统时间
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package com.Sq.phb;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.Drj.gameWin.gameWindrj;
|
||||
|
||||
public class Phb {
|
||||
public void paint(Graphics g,int count) {
|
||||
word(g,30,Color.red,"游戏失败",300,100);
|
||||
word(g,30,Color.BLACK,"排行榜",325,130);
|
||||
if(!UserScores.check(gameWindrj.username,count)) {
|
||||
System.out.print(UserScores.insert(gameWindrj.username,count));
|
||||
}
|
||||
ArrayList<UserScore> us=UserScores.orderBy();
|
||||
int i=0;
|
||||
for(UserScore a:us) {
|
||||
if(i==10)break;
|
||||
word(g,60,Color.BLACK,"第"+(i+1)+"名用户"+a.username+"的积分为"+a.score,50,190+i*60);
|
||||
i++;
|
||||
}
|
||||
word(g,50,Color.red,"点击左键重新开始游戏",100,800);
|
||||
//打印积分
|
||||
word(g,20,Color.red,"此次积分"+count,350,750);
|
||||
}
|
||||
public static void word(Graphics g,int size,Color color,String str,int x,int y) {
|
||||
g.setColor(color);//设置积分颜色
|
||||
g.setFont(new Font("仿宋",Font.BOLD,size));//设置字体和大小
|
||||
g.drawString(str, x, y);//设置输出格式和位置
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package com.Sq.phb;
|
||||
|
||||
public class UserScore {
|
||||
String username;
|
||||
int score;
|
||||
public UserScore() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param username
|
||||
* @param score
|
||||
*/
|
||||
public UserScore(String username,int score) {
|
||||
super();
|
||||
this.username = username;
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
public void setScore(int score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
package com.Sq.phb;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class UserScores {
|
||||
public static boolean insert(String username,int score) {
|
||||
boolean flaguser=false;
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
String url="jdbc:mysql://localhost:3306/gold?userSSL=flase&serverTimezone=Asia/Shanghai";
|
||||
String user="root";
|
||||
String password1="asdasd123";
|
||||
Connection conn =DriverManager.getConnection(url,user,password1);
|
||||
String sql ="Insert into score (username,score) values(?,?)";
|
||||
PreparedStatement prestm=conn.prepareStatement(sql);
|
||||
prestm.setString(1,username);
|
||||
prestm.setLong(2,score);
|
||||
if(prestm.executeUpdate()!=0) {
|
||||
flaguser=true;
|
||||
}
|
||||
prestm.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return flaguser;
|
||||
}
|
||||
public static boolean check(String username,int score) {
|
||||
// TODO 自动生成的方法存根
|
||||
boolean flaguser=false;
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
String url="jdbc:mysql://localhost:3306/gold?userSSL=flase&serverTimezone=Asia/Shanghai";
|
||||
String user="root";
|
||||
String password1="asdasd123";
|
||||
Connection conn =DriverManager.getConnection(url,user,password1);
|
||||
String sql ="select *from score where username=? and score=?";
|
||||
PreparedStatement prestm=conn.prepareStatement(sql);
|
||||
prestm.setString(1,username);
|
||||
prestm.setLong(2,score);
|
||||
ResultSet rs=prestm.executeQuery();
|
||||
if(rs.next()) {
|
||||
flaguser=true;
|
||||
}
|
||||
rs.close();
|
||||
prestm.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return flaguser;
|
||||
}
|
||||
public static ArrayList<UserScore> orderBy() {
|
||||
ArrayList<UserScore> us=new ArrayList<UserScore>();
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
String url="jdbc:mysql://localhost:3306/gold?userSSL=flase&serverTimezone=Asia/Shanghai";
|
||||
String user="root";
|
||||
String password1="asdasd123";
|
||||
Connection conn =DriverManager.getConnection(url,user,password1);
|
||||
String sql = "select *from score order by score desc";
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
ResultSet rs=pstmt.executeQuery();
|
||||
while(rs.next()) {
|
||||
UserScore score=new UserScore();
|
||||
score.setUsername(rs.getString("username"));
|
||||
score.setScore(rs.getInt("score"));
|
||||
us.add(score);
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return us;
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 9.9 KiB |
|
Before Width: | Height: | Size: 9.7 KiB |
|
Before Width: | Height: | Size: 4.1 KiB |