// Ashok Sivakumar			 		6.030  Final Project
// 12/04/99

package breakout;

import java.io.*;
import java.awt.*;				// Necessary  import statements



/*  This class spawns a thread for the sole purpose of making sure that the
	screen canvas class is always updating the position of the ghost ball.
	We needed a separate thread so that there is no delay in reading the updating
	coordinates of the ghost ball and painting it as fast as we can.      */

public class Updater implements Runnable
{

	private Thread walker;
	private ScreenCanvas sc;
	
	//constructor: takes a Screen Canvas and sets fields
	public Updater (ScreenCanvas screenCan)
	{	
		this.sc = screenCan;
		this.walker = new Thread (this);
		this.walker.start();
		
	}

	/* This is the run method that is continously being called on the thread.
	   Its purpose is to continously call the screenCanvas' updatePlayers() routine. */	
	
	public void run()
	{ 
	
		try
		{
			this.walker.sleep(10000); // initial delay so that users have time to begin game
		}
		catch(InterruptedException ie)
		{
		}
		
		
		while (true)
		{
			
			
			this.sc.updatePlayers(); // calls screenCanvas method to continuously read 
									 // new coordinates of ghost ball and paint its new location
			
			
			try
			{
				
				this.walker.sleep(25);  // programmed delay so each user has advantage over opponent
			}							// in long run.
			catch (InterruptedException ie)
			{
			}
		
		} // end of while(true) loop
	}// end of run method
}