-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathTicTacToeViewModel.java
More file actions
52 lines (35 loc) · 1.12 KB
/
Copy pathTicTacToeViewModel.java
File metadata and controls
52 lines (35 loc) · 1.12 KB
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
package com.acme.tictactoe.viewmodel;
import android.databinding.ObservableArrayMap;
import android.databinding.ObservableField;
import com.acme.tictactoe.model.Board;
import com.acme.tictactoe.model.Player;
public class TicTacToeViewModel implements ViewModel {
private Board model;
public final ObservableArrayMap<String, String> cells = new ObservableArrayMap<>();
public final ObservableField<String> winner = new ObservableField<>();
public TicTacToeViewModel() {
model = new Board();
}
@Override
public void onCreate() {
}
@Override
public void onPause() {
}
@Override
public void onResume() {
}
@Override
public void onDestroy() {
}
public void onResetSelected() {
model.restart();
winner.set(null);
cells.clear();
}
public void onClickedCellAt(int row, int col) {
Player playerThatMoved = model.mark(row, col);
cells.put("" + row + col, playerThatMoved == null ? null : playerThatMoved.toString());
winner.set(model.getWinner() == null ? null : model.getWinner().toString());
}
}