-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndicator.swift
63 lines (52 loc) · 1.47 KB
/
Indicator.swift
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
//
// Indicator.swift
// DropTetris
//
// Created by Kevin Yue on 1/6/15.
// Copyright (c) 2015 Kevin Yue. All rights reserved.
//
import Foundation
class Indicator{
private var center:Coordinate = Coordinate.zero
private var contents:Array<Coordinate>
convenience init(occupied:Array<GridSq>){
self.init(occupied: occupied.map({$0.coord}))
}
init(occupied:Array<Coordinate>){
contents = occupied
}
func newContents(c:Array<GridSq>){
newContents(c.map({$0.coord}))
}
func newContents(c:Array<Coordinate>){
contents = c
}
func moveTo(coord:Coordinate){
center = coord
}
func moveTo(d: Direction){
center = center.adjacent(d)
}
func getContents() -> Array<Coordinate>{
var shifted = Array<Coordinate>()
for c:Coordinate in contents{
shifted.append(c+center)
}
return shifted
}
func indicatorInBounds(xMin:Int, xMax:Int, yMin:Int, yMax:Int)->Bool{
for coord:Coordinate in getContents(){
if(coord.x < xMin){return false}
if(coord.x > xMax){return false}
if(coord.y < yMin){return false}
if(coord.y > yMax){return false}
}
return true
}
private func debugContents(){
println("\nSTART INDICATOR DEBUG:")
for c:Coordinate in contents{
println("Indicator contains (\(c.x),\(c.y))")
}
}
}