blob: 90bba32932236466e669de8a00b8cca0f1b14f59 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
package adapter;
import model.Board;
import observer.*;
import java.util.*;
/**
* Created by loic on 21/09/16.
*/
public class ModelAdapter implements IObservable{
private Board model;
private Collection<IObserver> observers;
public ModelAdapter(Board model){
this.model=model;
observers = new ArrayList<IObserver>();
}
/**
* Add a random number on the board
*/
public void addRandomNumber() {
this.model.addRandomNumber();
this.notifyObservers();
}
/**
* Go up
*/
public void goUp() {
model.goUp();
this.notifyObservers();
}
/**
* Go down
*/
public void goDown() {
model.goDown();
this.notifyObservers();
}
/**
* Go left
*/
public void goLeft() {
model.goLeft();
this.notifyObservers();
}
/**
* Go right
*/
public void goRight() {
model.goRight();
this.notifyObservers();
}
/**
* Return true if the game is loose, false else
* @return
*/
public boolean isLoosed() {
return this.model.isLoosed();
}
@Override
public void addObserver(IObserver observer) {
this.observers.add(observer);
}
@Override
public void removeObserver(IObserver observer) {
this.observers.remove(observer);
}
@Override
public void notifyObservers() {
Iterator<IObserver> i=this.observers.iterator();
while(i.hasNext()){
i.next().update();
}
}
}
|