package cc.glsn.v15; import java.awt.GridBagConstraints; import java.awt.image.BufferedImage; import java.io.File; import java.net.URL; import java.util.LinkedList; import java.util.Random; import javax.imageio.ImageIO; import javax.swing.JFrame; import javax.swing.JPanel; import cc.glsn.ConfigFile; public class test { ConfigFile MatchSettings; /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub new test(); } public test() throws Exception { MatchSettings=new ConfigFile("c:/clash/com/fireduck/robowars/config/match.conf"); JFrame Frame=new JFrame("Battlefield"); FancyImageZ FImage=new FancyImageZ(800,800); Frame.setContentPane(new JPanel(new java.awt.GridBagLayout())); { GridBagConstraints c=new GridBagConstraints(); c.gridheight=1; c.gridwidth=1; c.fill=GridBagConstraints.NONE; c.insets=new java.awt.Insets(0,0,0,0); c.anchor=GridBagConstraints.WEST; Frame.getContentPane().add(FImage,c); } Frame.pack(); Frame.setVisible(true); Random R=new Random(); LinkedList L=new LinkedList(); for(int i=0; i<200; i++) { BufferedImage I=readImage("robot32x32.png"); OD od=new OD(); od.x=R.nextInt(800); od.y=R.nextInt(800); od.dx=R.nextInt(6)-3; od.dy=R.nextInt(6)-3; od.Name="hat" + i; od.I=I; L.add(od); } while(true) { for(OD od : L) { FImage.addImage(0,od.Name,od.I,od.x,od.y); od.update(); } FImage.repaint(); Thread.sleep(20); } } private class OD { String Name; int x; int y; int dx; int dy; public void update() { x+=dx; if (x>=800) x=0; if (x<0) x=800; y+=dy; if (y>=800) y=0; if (y<0) y=800; } BufferedImage I; } private BufferedImage readImage(String name) { BufferedImage BI=null; //try the file File F=new File(MatchSettings.getString("MediaPath") + "/" + name); if (F.canRead()) { try { BI=ImageIO.read(F); } catch(java.io.IOException e) { BI=null; } } //If we dont have it yet, try the internet if (BI==null) { try { URL U=new URL(MatchSettings.getString("MediaURL") + "/" + name); BI=ImageIO.read(U); } catch(java.net.MalformedURLException e2) { System.out.println("Joe is incompetent."); e2.printStackTrace(); } catch(java.io.IOException e) { BI=null; } } return BI; } }