资源简介
Java打砖块游戏,可以完美运行!
即使年龄已经开始慢慢的增长,但我还是怀念当初我玩这个游戏时的乐趣!
代码片段和文件信息
package com.fei;
import java.awt.*;
public class Ball {
private double x y;//左上角的位置
private boolean isAlive = true;
private boolean moveToRight = true moveToDown = true;
private int count;
private static int XSpeed = 20;
private static int YSpeed = 15;
public static int R = 4;
public Ball() {
this.x = 0;
this.y = 0;
count = 0;
}
public Ball(int x int y) {
this.x = x;
this.y = y;
}
public void draw(Graphics g) {
if (isAlive) {
Color c = g.getColor();
g.setColor(Color.YELLOW);
g.fillOval((int) x (int) y R + R R + R);
g.setColor(c);
// System.out.println(x+“\t“+y);
}
}
public void move(double dt) {
if (moveToDown)
y += YSpeed * dt;
else
y -= YSpeed * dt;
if (moveToRight)
x += XSpeed * dt;
else
x -= XSpeed * dt;
// System.out.println(x + “\t“ + y);
}
public Rectangle getRect() {
return new Rectangle((int)x - R (int) y - R R + R R + R);// 加法速度比乘法快
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public int getCount() {
return count;
}
public int getXSpeed() {
return XSpeed;
}
public int getYSpeed() {
return YSpeed;
}
public boolean isAlive() {
return isAlive;
}
public void setIsAlive(boolean isAlive) {
this.isAlive = isAlive;
}
public boolean isMoveToDown() {
return moveToDown;
}
public boolean isMoveToRight() {
return moveToRight;
}
public boolean bounceOffVertical(Event e) {
boolean flag = false;
Brick brick = e.getBrick();
if(brick == null){
flag = true;
this.count++;
this.moveToRight = ! this.moveToRight;
}else{
if(brick.isAlive() && this.y+0.1 >= brick.getTop() - R - R && this.y-0.1 <= brick.getBottom() - R) {
flag = true;
this.count++;
this.moveToRight = !this.moveToRight;
brick.setLive(false);
}
}
return flag;
}
public boolean bounceOffHorizontal(Event eWall myWall) {
boolean flag = false;
Brick brick = e.getBrick();
if(brick == null){
if(this.moveToDown && this.x+0.1 >= myWall.getX() - R && this.x-0.1 <= myWall.getX() + Wall.WIDTH - R) {
flag = true;
this.count++;
this.moveToDown = false;
}else if(!this.moveToDown){
flag = true;
this.count++;
this.moveToDown = true;
}
}else{
if(brick.isAlive() && this.x+0.1
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 301 2017-12-27 19:00 xiaoyouxi\.classpath
文件 385 2017-12-27 19:00 xiaoyouxi\.project
文件 598 2017-12-27 19:00 xiaoyouxi\.settings\org.eclipse.jdt.core.prefs
文件 3417 2018-01-04 00:05 xiaoyouxi\bin\com\fei\Ball.class
文件 1951 2018-01-02 20:51 xiaoyouxi\bin\com\fei\Brick.class
文件 962 2018-01-02 20:55 xiaoyouxi\bin\com\fei\DIYArrayList$DIYArrayIterator.class
文件 2656 2018-01-02 20:55 xiaoyouxi\bin\com\fei\DIYArrayList.class
文件 1600 2018-01-02 20:58 xiaoyouxi\bin\com\fei\Event.class
文件 644 2018-01-02 23:49 xiaoyouxi\bin\com\fei\GAME$1.class
文件 913 2018-01-02 23:49 xiaoyouxi\bin\com\fei\GAME$2.class
文件 868 2018-01-02 23:49 xiaoyouxi\bin\com\fei\GAME$KeyMonitor.class
文件 2460 2018-01-02 23:49 xiaoyouxi\bin\com\fei\GAME$PaintThread.class
文件 6901 2018-01-02 23:49 xiaoyouxi\bin\com\fei\GAME.class
文件 1469 2018-01-02 22:23 xiaoyouxi\bin\com\fei\MinPQ$HeapIterator.class
文件 4841 2018-01-02 22:23 xiaoyouxi\bin\com\fei\MinPQ.class
文件 1068 2018-01-02 20:24 xiaoyouxi\bin\com\fei\Wall$Direction.class
文件 2944 2018-01-02 20:24 xiaoyouxi\bin\com\fei\Wall.class
文件 3306 2018-01-04 00:05 xiaoyouxi\src\com\fei\Ball.java
文件 1005 2018-01-02 20:51 xiaoyouxi\src\com\fei\Brick.java
文件 1764 2018-01-02 20:55 xiaoyouxi\src\com\fei\DIYArrayList.java
文件 955 2018-01-02 20:58 xiaoyouxi\src\com\fei\Event.java
文件 8810 2018-01-02 23:49 xiaoyouxi\src\com\fei\GAME.java
文件 9103 2018-01-02 22:23 xiaoyouxi\src\com\fei\MinPQ.java
文件 2290 2018-01-02 20:24 xiaoyouxi\src\com\fei\Wall.java
目录 0 2018-01-07 14:16 xiaoyouxi\bin\com\fei
目录 0 2018-01-07 14:16 xiaoyouxi\src\com\fei
目录 0 2018-01-07 14:16 xiaoyouxi\bin\com
目录 0 2018-01-07 14:16 xiaoyouxi\src\com
目录 0 2018-01-07 14:16 xiaoyouxi\.settings
目录 0 2018-01-07 14:16 xiaoyouxi\bin
............此处省略5个文件信息
- 上一篇:自用webstorm配置setting jar包
- 下一篇:JAVA绘制函数图像工具
评论
共有 条评论