羡慕那些省选进二轮不用期中考试的人
4.25
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Main implements Runnable{
JFrame jf;
MyPanel mp;
Main(){
jf = new JFrame();
jf.setSize(1024, 768);
mp = new MyPanel();
jf.add(mp);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
mp.init_star();
Thread t = new Thread(this);
t.start();
}
public static void main(String[] agrs){
new Main();
}
public void run() {
while(true){
try {
Thread.sleep(25);
this.mp.update();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class obj{
int va,vb;
void setValue(int _va,int _vb){
this.va = _va;
this.vb = _vb;
}
obj(int _va,int _vb){
this.setValue(_va, _vb);
}
obj(){
this.va = this.vb = 0;
}
}
class MyPanel extends JPanel{
private LinkedList<obj> vlink;
private Random vrd;
private final int cnt = 120;
private int vwidth,vheight;
public MyPanel(){
this.setBackground(Color.BLACK);
this.vlink = new LinkedList<obj>();
this.vrd = new Random();
this.vwidth = this.getHeight();
this.vheight = this.getWidth();
// System.out.println(this.vheight + " "+this.vwidth );
}
private void change(obj _buf){
_buf.setValue(vrd.nextInt(this.vheight),this.vrd.nextInt(this.vwidth));
}
public void init_star(){
this.vwidth = this.getHeight();
this.vheight = this.getWidth();
for(int i=1;i<=cnt;i++)
vlink.add(new obj(vrd.nextInt(this.vheight),this.vrd.nextInt(this.vwidth)));
}
private void update_star(){
this.vwidth = this.getHeight();
this.vheight = this.getWidth();
// System.out.println(this.vheight + " "+this.vwidth );
for(obj _buf : this.vlink){
_buf.setValue(_buf.va + vrd.nextInt(2), _buf.vb + vrd.nextInt(2));
if(_buf.va < 0 || _buf.va > this.vheight || _buf.vb<0||_buf.vb>this.vwidth){
change(_buf);
}
}
}
public void update(){
this.vwidth = this.getHeight();
this.vheight = this.getWidth();
update_star();
this.repaint();
}
public void paintComponent(Graphics g){
this.vwidth = this.getHeight();
this.vheight = this.getWidth();
super.paintComponent(g);
g.setColor(Color.WHITE);
for(obj _buf : vlink){
g.drawString("*", _buf.va, _buf.vb);
}
}
}
4.26 没写完。。。
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Main implements Runnable{
private final int Height = 768;
private final int Width = 1024;
JFrame jf;
MyPanel mp;
Main(){
jf = new JFrame();
jf.setSize(Width, Height);
mp = new MyPanel();
jf.add(mp);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
mp.init_star();
Thread t = new Thread(this);
t.start();
}
public static void main(String[] agrs){
new Main();
}
public void run() {
while(true){
try {
Thread.sleep(10);
this.mp.update();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class obj{
int va,vb;
void setValue(int _va,int _vb){
this.va = _va;
this.vb = _vb;
}
obj(int _va,int _vb){
this.setValue(_va, _vb);
}
obj(){
this.va = this.vb = 0;
}
public obj clone(){
obj _re = new obj();
_re.va = this.va;
_re.vb = this.vb;
return _re;
}
public static obj make(int _va,int _vb){
return new obj(_va,_vb);
}
public obj copy(int _va,int _vb){
return new obj(this.va + _va , this.vb + _vb);
}
}
class MyPanel extends JPanel{
private LinkedList<obj> vlink;
private LinkedList<obj> vrlink;
private Random vrd;
private final int cnt = 200;
private final int sizeBall = 4;
private final int bolckSize = 1;
private final int downSeekLenght = 1;
private final int leftSeekLenght = 1;
private int vwidth,vheight;
public MyPanel(){
this.setBackground(Color.BLACK);
this.vlink = new LinkedList<obj>();
this.vrlink = new LinkedList<obj>();
this.vrd = new Random();
this.updateValue();
}
private synchronized void updateValue(){
this.vwidth = this.getWidth()-1;
this.vheight = this.getHeight()-1;
}
private synchronized void change(obj _buf){
_buf.setValue(vrd.nextInt(this.vwidth),this.vrd.nextInt(this.vwidth));
}
private synchronized void push(obj _buf){
vrlink.add(_buf);
}
private int Range(int l,int r){
return vrd.nextInt(r-l+1)+l;
}
public synchronized void init_star(){
this.updateValue();
for(int i=1;i<=cnt;i++)
vlink.add(new obj(vrd.nextInt(this.vwidth),this.vrd.nextInt(this.vheight)));
}
private synchronized boolean checkIfBlock(obj _buf){
int cnt=0;
for(obj i : vrlink){
boolean _f=false,_g=false;
if(_buf.va>=i.va - bolckSize && _buf.va<=i.va + bolckSize){
_f = true;
}
if(_buf.vb>=i.vb - bolckSize && _buf.vb<=i.vb + bolckSize){
_g = true;
}
if(_f && _g ){
if(i.va == _buf.va &&i.vb == _buf.vb-1){
cnt++;
if(cnt>1){
return true;
}else{
continue;
}
}
return true;
}
}
return false;
}
private synchronized boolean checkIfOutMap(obj _buf){
return (_buf.va <= 0 || _buf.va >= this.vwidth || _buf.vb<=0||_buf.vb>=this.vheight);
}
private synchronized boolean checkIfEmpty(obj _buf){
return (!checkIfOutMap(_buf)) && (!checkIfBlock(_buf));
}
private synchronized void update_star(){
this.updateValue();
for(obj _buf : this.vlink){
int _buf_va = Range(-leftSeekLenght,leftSeekLenght);
int _buf_vb = Range(0,downSeekLenght);
_buf.setValue(_buf.va + _buf_va, _buf.vb + _buf_vb);
if(this.checkIfBlock(_buf)){
push(_buf.copy(-_buf_va,-_buf_vb));
change(_buf);
continue;
}
if(this.checkIfOutMap(_buf)){
push(_buf.copy(-_buf_va,-_buf_vb));
change(_buf);
}
}
for(obj i : vrlink){
while(this.checkIfEmpty(i.copy(0,1))){
i.setValue(i.va, i.vb+1);
}
}
}
public synchronized void update(){
this.updateValue();
update_star();
this.repaint();
}
public synchronized void paintComponent(Graphics g){
this.updateValue();
super.paintComponent(g);
g.setColor(Color.WHITE);
for(obj _buf : vlink){
g.fillOval(_buf.va, _buf.vb, sizeBall, sizeBall);
}
for(obj _buf:vrlink){
g.fillOval(_buf.va, _buf.vb, sizeBall, sizeBall);
}
}
}
4.27
package test;
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
public class Main {
JFrame jf;
JPanel jp;
Main(){
jf = new JFrame("fsd");
p mp = new p();
jf.add(mp);
jf.setSize(433, 755);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}
public static void main(String[] args){
new Main();
}
}
class p extends JPanel{
public void paintComponent(Graphics g){
MyImage mg = new MyImage(this.getWidth(),this.getHeight(),0,0,0);
mg.drawOval(4, 4);
g.drawImage(mg.getImage(), 0, 0, null);
}
}
class MyImage{
private BufferedImage mi;
/*奇数*/
private int ballHeight;
private int ballWidth;
private int red;
private int green;
private int blue;
private int width;
private int height;
public MyImage(int _width,int _height,int _r,int _g,int _b){
this.width = _width;
this.height = _height;
this.blue = _b;
this.red = _r;
this.green = _g;
this.mi = new BufferedImage(_width,_height,BufferedImage.TYPE_4BYTE_ABGR);
}
/*not used*/
public void setBallSize(int _width,int _height){
this.ballHeight = _height;
this.ballWidth = _width;
}
public void setColor(int _r,int _g,int _b){
this.red = _r;
this.green = _g;
this.blue = _b;
}
public void setColor(Color _co){
this.red = _co.getRed();
this.green = _co.getGreen();
this.blue = _co.getBlue();
}
public void setPoint(int _x,int _y,Color _co){
this.mi.setRGB(_x, _y, _co.getRGB());
}
public Color getPoint(int _x,int _y){
return new Color(this.mi.getRGB(_x, _y));
}
public void clear(){
this.mi = new BufferedImage(this.width,this.height,BufferedImage.TYPE_4BYTE_ABGR);
}
public BufferedImage getImage(){
return this.mi;
}
public void drawOval(int _x,int _y){
int bx = _x-1>0?_x-1:0;
int ex = _x+1<this.width?_x+1:this.width;
int by = _y-1>0?_y-1:0;
int ey = _y+1<this.height?_y+1:this.height;
for(int i=bx;i<=ex;i++){
for(int j=by;j<=ey;j++){
this.setPoint(i, j, new Color(this.red,this.green,this.blue));
}
}
if(_x>0 && _x<this.width && _y-2>0 && _y-2<this.height){
this.setPoint(_x, _y-2, new Color(this.red,this.green,this.blue));
}
if(_x>0 && _x<this.width && _y+2>0 && _y+2<this.height){
this.setPoint(_x, _y+2, new Color(this.red,this.green,this.blue));
}
if(_x-2>0 && _x-2<this.width && _y>0 && _y<this.height){
this.setPoint(_x-2, _y, new Color(this.red,this.green,this.blue));
}
if(_x+2>0 && _x+2<this.width && _y>0 && _y<this.height){
this.setPoint(_x+2, _y, new Color(this.red,this.green,this.blue));
}
}
}
class obj{
private int x;
private int y;
public obj(int _x,int _y){
this.x = _x;
this.y = _y;
}
public int getX(){
return this.x;
}
public int getY(){
return this.y;
}
public void setX(int _x){
this.x = _x;
}
public void setY(int _y){
this.y = _y;
}
public boolean equals(obj _b){
return (this.x == _b.x && this.y == _b.y);
}
public obj clone(){
return new obj(this.x,this.y);
}
public String toString(){
return ("obj x="+this.x+" y="+this.y);
}
}
class Map{
private LinkedList<obj> aviList;
private LinkedList<obj> deathList;
private boolean[][] mp;
public Map(){
this.mp = new boolean[2000][2000];
this.aviList = new LinkedList<obj>();
this.deathList = new LinkedList<obj>();
}
public boolean isEmpty(int _x,int _y){
return (!mp[_x][_y]);
}
}