# Zeitschleife will net



## Maddog (11. Nov 2004)

```
import java.applet.*;
import java.awt.*;
import java.awt.event.*; 


public class Main extends Applet implements Runnable
{	

	//public int zahler;
	
	// variables
	private Thread th;
	
	private Thread th2;
	private Player player;
	private Player2 player2;
	private Shot [] shots;
	private Shot2 [] shots2;
	


	// speed constants
	private final int shotSpeed = -2;
	private final int playerLeftSpeed = -2;
	private final int playerRightSpeed = 2;
	private final int playerLeftSpeed2 = -2;
	private final int playerRightSpeed2 = 2;
	
	
	
	
	// move flags
	private boolean playerMoveLeft;
	private boolean playerMoveRight;
	public boolean schutzschild;
	public boolean schutzschild2;
	private boolean playerMoveLeft2;
	private boolean playerMoveRight2;
	// double buffering
	private Image dbImage;
	private Graphics dbg;

	public void init()
	{
		System.out.println("PLAYER1");
		System.out.println("");
		System.out.println("LINKS: A");
		System.out.println("RECHTS: D");
		System.out.println("SCHUSS: S");
		System.out.println("SCHUTZSCHILD: F");
		System.out.println("");
		System.out.println("PLAYER2");
		System.out.println("");
		System.out.println("LINKS:  K");
		System.out.println("RECHTS: H");
		System.out.println("SCHUSS: J");
		System.out.println("SCHUTZSCHILD: M");
		System.out.println("");
		System.out.println("");
		addKeyListener(new MeinKeyListener());
		setBackground (Color.black);
		player = new Player(40,20);
		player2 = new Player2(200,20);
		shots = new Shot[5];
		shots2 = new Shot2[5];
	
	}

	public void start ()
	{
		th = new Thread(this);
		th.start ();
		
	}

	public void stop()
	{
		th.stop();
	}

	public void destroy()
	{
		th.stop();
	}
	public int zeit()
	{
		
         //Zeitschleife (10sec)      
         int zahler=0;
         for(int i=0;i<6;i++)
         {
         
         zahler++;
         System.out.println(zahler);
         
            try
            {
            th2.sleep(500);
            }
            catch(Exception e)
            {
            th2.interrupt();
            }
         }
         return zahler;  	
	}

	public void run ()
	{
		Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
		
/*		int zeit;
		zeit=zeit();
		System.out.println(zeit);
*/		
		while (true)
		{		
.. ab hier geht nix mehr
```


GreeTz Maddog


----------



## Gast (11. Nov 2004)

```
import java.applet.*;
import java.awt.*;
import java.awt.event.*;


public class Main extends Applet implements Runnable
{
   // variables
   private Thread th;
   private Thread th2;
   private Player player;
   private Player2 player2;
   private Shot [] shots;
   private Shot2 [] shots2;

   // speed constants
   private final int shotSpeed = -2;
   private final int playerLeftSpeed = -2;
   private final int playerRightSpeed = 2;
   private final int playerLeftSpeed2 = -2;
   private final int playerRightSpeed2 = 2;
   
   
   
   
   // move flags
   private boolean playerMoveLeft;
   private boolean playerMoveRight;
   public boolean schutzschild;
   public boolean schutzschild2;
   private boolean playerMoveLeft2;
   private boolean playerMoveRight2;
   // double buffering
   private Image dbImage;
   private Graphics dbg;

   public void init()
   {
      System.out.println("PLAYER1");
      System.out.println("");
      System.out.println("LINKS: A");
      System.out.println("RECHTS: D");
      System.out.println("SCHUSS: S");
      System.out.println("SCHUTZSCHILD: F");
      System.out.println("");
      System.out.println("PLAYER2");
      System.out.println("");
      System.out.println("LINKS:  K");
      System.out.println("RECHTS: H");
      System.out.println("SCHUSS: J");
      System.out.println("SCHUTZSCHILD: M");
      System.out.println("");
      System.out.println("");
      addKeyListener(new MeinKeyListener());
      setBackground (Color.black);
      player = new Player(40,20);
      player2 = new Player2(200,20);
      shots = new Shot[5];
      shots2 = new Shot2[5];
   
   }

   public void start ()
   {
      th = new Thread(this);
      // th.start ();
   }

   public void stop()
   {
      th.stop();
   }

   public void destroy()
   {
      th.stop();
   }
   public int zeit()
   {

   
      //Zeitschleife (10sec)      
         int zahler=0;
         for(int i=0;i<10;i++)
         {
         
         zahler++;
         System.out.println(zahler);
            try
            {
            th.sleep(1000);
            }
            catch(Exception e)
            {
            th.interrupt();
            }
         }
         return zahler;         
   }

   public void run ()
   {
      th.start();
      th.currentThread().setPriority(th.MIN_PRIORITY);
      int zeit=0;
      
      while (true)
      {      
         zeit=zeit();
         System.out.println(zeit);
      }
   }
}
```



_Edit von L-ectron-X: Code-Tags eingefügt._


----------



## Maddog (12. Nov 2004)

geht so net


----------

