Sat Mar 10, 2012 1:04 pm
import java.awt.*;
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import java.util.Map;
import java.util.Random;
import java.awt.image.ImageObserver;
import java.awt.event.*;
import java.awt.Window;
import java.awt.DisplayMode;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import java.awt.GraphicsDevice;
public class Screen{
public GraphicsDevice vc;
public Screen(){
GraphicsEnvironment evn=GraphicsEnvironment.getLocalGraphicsEnvironment();
vc=evn.getDefaultScreenDevice();
}
public void setFullScreen(DisplayMode dm,JFrame window){
window.setUndecorated(false);
window.setResizable(true);
vc.setFullScreenWindow(window);
if(dm!=null && vc.isDisplayChangeSupported()){
try{
vc.setFullScreenWindow(window);
}catch(Exception ex){}
}
}
public Window getFullScreen(){
return vc.getFullScreenWindow();
}
public void restoreScreen(){
Window w=vc.getFullScreenWindow();
if(w!=null){
w.dispose();
}
}
}
/////////////////////////////////
public class Tank extends JFrame{
static Screen s;
public Tank(){
}
public static void main(String[] args){
DisplayMode dm=new DisplayMode(200,200,8,DisplayMode.REFRESH_RATE_UNKNOWN);
Tank t=new Tank();
Screen s =new Screen();
Tank_thread ab=new Tank_thread(dm);
Tank_thread ab1=new Tank_thread(dm);
ab1.start();
ab.start();
}
}
////////////////////////////////
public class Tank_thread extends Tank implements Runnable{
DisplayMode dm;
private Image bg;
private Image TANK_OPP;
private boolean loaded;
int mov_time,direction,xx=100,yy=100,width,height,scr_Width=700,scr_Height=700;
Random r=new Random();
Screen s=new Screen();
Thread thread;
Tank_thread(DisplayMode dm){
this.dm=dm;
//this.s=s;
s.setFullScreen(dm,this);
thread =new Thread(this);
thread.start();
}
public void run(){
loaded=false;
repaint();
}
public void start(){
thread.start();
}
public void stop(){
thread.stop();
}
public void paint(Graphics g){
//Window w=s.getFullScreen();
int n=0;
while(n<10){
n++;
int x=0;
direction=r.nextInt(4);
loadPics(direction);
mov_time=r.nextInt(250);
if(loaded==true){
while(x<(mov_time)){
if(direction==0){
yy--;
}else if(direction==1){
xx++;
}else if(direction==2){
yy++;
}else{
xx--;
}
width=TANK_OPP.getWidth(null);
height=TANK_OPP.getHeight(null);
if(xx<20 || (xx+width)>scr_Width || yy<20 || (yy+height)>scr_Height){
direction=r.nextInt(4);
loadPics(direction);
continue;
}
g.drawImage(bg,0,0,null);
g.drawImage(TANK_OPP,xx,yy,null);
try{
Thread.sleep(20);
}catch(Exception ex){}
x++;
}
}
}
dispose();
}
public void loadPics(int x){
bg=new ImageIcon("C:\\A BATTLE\\WHITE_BG.JPG").getImage();
if(x==0){
TANK_OPP=new ImageIcon("C:\\A BATTLE\\P1.JPG").getImage();
}else if(x==1){
TANK_OPP=new ImageIcon("C:\\A BATTLE\\P2.JPG").getImage();
}else if(x==2){
TANK_OPP=new ImageIcon("C:\\A BATTLE\\P3.JPG").getImage();
}else{
TANK_OPP=new ImageIcon("C:\\A BATTLE\\P4.JPG").getImage();
}
loaded=true;
}
}
Sat Mar 10, 2012 10:40 pm
Tank_thread ab=new Tank_thread(dm);
Tank_thread ab1=new Tank_thread(dm);
ab1.start();
ab.start();
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.