Newer
Older
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
-*- mode: org -*-
ֻݵĵ
* notes
** game design
- buttons are named Button1 to Button15. last empty block is named Button0.
-
* current
**
** 2018-01-14 make the basic work
- make blocks move in GUI when I click it.
when click a non-movable block, do nothing.
- generate a game and reflect it in GUI using buttons.
- problems
- how to write the click event for all buttons?
decide which button is it.
decide where is the button, where should it move.
I decide to change button label and visibility.
don't change button margin.
create a model for the current board. then just relfect the board on the
GUI. when user click a block, send a event to the model, then the model
should decide which commands to send to the GUI components.
class Board {
initState: int[16];
// block1 to block15 is just 1 to 15.
// block0 is 0.
currentState: int[16];
}
Button12 click.
decide the block int id using reflection.
blockId = getClickButtonId();
String clickBlockLabel = eventTarget.Content;
if board.blockCanMove(blockId) {
String oldBlock0Name = board.getBlock0ButtonName();
board.moveBlock(blockId); // change currentState array.
getButtonByName(board.getBlock0ButtonName()).Visibility = Hidden;
getButtonByName(oldBlock0Name).Content = clickBlockLabel;
}
works on first try.
-
* done