-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
151 lines (120 loc) · 2.99 KB
/
main.lua
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
--------------------------------------------------------------------
-- Main
--------------------------------------------------------------------
local GameController = require "GameController"
local Board = require "Board"
local BoardView = require "BoardView"
local Token = require "Token"
local TokenView = require "TokenView"
ENV = {
dev = false
}
boardSize = 6
cellWidth = display.contentWidth/boardSize
cellHeight = display.contentWidth/boardSize
local function setup6x6x2()
local boardSize = 6
cellWidth = display.contentWidth/boardSize
cellHeight = display.contentWidth/boardSize
local board = Board:new(6)
-- TOP
token = Token:new()
token.owner = "red"
token.isHorizontal = false
board:addToken(2, 1, token)
token = Token:new()
token.owner = "blue"
token.isHorizontal = false
board:addToken(3, 1, token)
token = Token:new()
token.owner = "red"
token.isHorizontal = false
board:addToken(4, 1, token)
token = Token:new()
token.owner = "blue"
token.isHorizontal = false
board:addToken(5, 1, token)
-- RIGHT
token = Token:new()
token.owner = "blue"
board:addToken(6, 2, token)
token = Token:new()
token.owner = "red"
board:addToken(6, 3, token)
token = Token:new()
token.owner = "blue"
board:addToken(6, 4, token)
token = Token:new()
token.owner = "red"
board:addToken(6, 5, token)
-- BOTTOM
token = Token:new()
token.owner = "red"
token.isHorizontal = false
board:addToken(2, 6, token)
token = Token:new()
token.owner = "blue"
token.isHorizontal = false
board:addToken(3, 6, token)
token = Token:new()
token.owner = "red"
token.isHorizontal = false
board:addToken(4, 6, token)
token = Token:new()
token.owner = "blue"
token.isHorizontal = false
board:addToken(5, 6, token)
-- LEFT
token = Token:new()
token.owner = "blue"
board:addToken(1, 2, token)
token = Token:new()
token.owner = "red"
board:addToken(1, 3, token)
token = Token:new()
token.owner = "blue"
board:addToken(1, 4, token)
token = Token:new()
token.owner = "red"
board:addToken(1, 5, token)
return board
end
local board = nil
if ENV.dev then
board = Board:new(boardSize)
local token = Token:new()
token.isMaster = true
board:addToken(1, 1, token)
token = Token:new()
token.isMaster = true
token.owner = "red"
board:addToken(2, 1, token)
token = Token:new()
token.owner = "blue"
token.isMaster = true
token.isHorizontal = false
board:addToken(3, 3, token)
token = Token:new {
owner = "red",
isMaster = false,
isHorizontal = false
}
board:addToken(6, 1, token)
else
board = setup6x6x2()
end
local boardView = BoardView:new(board)
local boardGroup = boardView.group
local tokensGroup = display.newGroup( )
for _, token in ipairs(board:getAllTokens()) do
TokenView:new(token, tokensGroup)
end
GameController:new(boardView)
local mainGroup = display.newGroup( )
mainGroup.anchorChildren = true
mainGroup.anchorX = 0.5
mainGroup.anchorY = 0.5
mainGroup.x = display.contentWidth/2
mainGroup.y = display.contentHeight/2
mainGroup:insert( boardGroup )
mainGroup:insert( tokensGroup )