View Javadoc

1   /*
2    * Created on 2004-12-23
3    *
4    * TODO To change the template for this generated file go to
5    * Window - Preferences - Java - Code Style - Code Templates
6    */
7   package org.sourceforge.jvb3d.Control;
8   
9   import org.sourceforge.jvb3d.Model.*;
10  import org.sourceforge.jvb3d.Network.*;
11  import java.util.Timer;
12  import java.util.TimerTask;
13  /***
14   * @author spootnick
15   *
16   * Klasa odpowiedzialna za sterowanie całym programem.
17   * Jeje główne zadania to: obsługa wejścia, zlecanie części sieciowej wysyłania wiadomości
18   */
19  public class Control {
20  	
21  	protected INetworkModel network;
22  	protected IModelInput model;
23  	protected Timer timer;
24  	protected InputAdapter input;
25  	protected String localPlayerID;
26  	protected String localPlayerName;
27  	
28  	/***
29  	 * Konstruktor pobierający referencję do części sieciowej i logiki 
30  	 * @param network referencja do części sieciowej
31  	 * @param model referencja do części logiki
32  	 */
33  	public Control(INetworkModel network,IModelInput model){
34  		this.network=network;
35  		this.model=model;
36  		input = new InputAdapter(model,network);
37  	}
38  	/***
39  	 * Funkcja włączająca konkretną cykliczną funkcjonalność w modelu
40  	 * @param task zadanie do wykonywania
41  	 * @param period co jaki czas [ms] zadanie ma być wykonywane
42  	 * @return obiekt Timer który realizuje cykliczną funkcjonalność
43  	 */
44  	public Timer setTask(ControlTask task,long period){
45  		task.localPlayerID=this.localPlayerID;
46  		task.network=this.network;
47  		timer=new Timer(true);
48  		timer.schedule(task,0,period);
49  		return timer;
50  	}
51  	/***
52  	 * Zwraca InputAdapter skojażony z tym obiektem
53  	 * @return obiekt InputAdapter obsługujący wejście
54  	 */
55  	public InputAdapter getInputAdapter(){
56  		return input;
57  	}
58  	/***
59  	 * Ustawia identyfikator lokalnej postaci 
60  	 * @param id identyfikator jaki lokalny gracz ma w modelu
61  	 */
62  	public void setLocalPlayerID(String id){
63  		localPlayerID=id;
64  		input.localPlayerID=id;
65  	}
66  	/***
67  	 * Zwraca aktualnie ustawiony identyfikator
68  	 * @return identyfikator lokalnej postaci
69  	 */
70  	public String getLocalPlayerID(){
71  		return localPlayerID;
72  	}
73  	/***
74  	 * Ustawia imię lokalnej postaci, które jest wykorzystywane jako nazwa źródła
75  	 * przy wysyałniu wiadomości na chat
76  	 * @param name nazwa loklanej postaci
77  	 */
78  	public void setLocalPlayerName(String name){
79  		localPlayerName=name;
80  		input.localPlayerName=name;
81  	}
82  	/***
83  	 * Zwraca aktualnie ustawioną nazwę postaci
84  	 * @return nazwa postaci
85  	 */
86  	public String getLocalPlayerName(){
87  		return localPlayerName;
88  	}
89  }