matching_base 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a83ea3ce16b85a63924a67f8ced611d3733ef2fd
4
+ data.tar.gz: e44d50bc7363d68d064973c9c9545e1401a95e51
5
+ SHA512:
6
+ metadata.gz: 47191d7ae4dff2f98ce5159f7226a60d5a2a1fb24bdef158686e903d46463289e52c7102330240c1b375877ca8b8c54807a26694ae8c10f29124510e5e454f87
7
+ data.tar.gz: 109d4f0267ca0312bc3f8de389ff455e57b94fab6f73d1d15baa9bb6a43543ddc5f68a532e1ec7cf1952a2855c3765a96a97cd6c35765de5cf711788ab09074c
@@ -0,0 +1,9 @@
1
+ class MatchingBase
2
+ def self.matching_files
3
+ core_lib = File.join(File.dirname(__FILE__), 'matching_base')
4
+ res = Dir.glob(File.join(core_lib, '*.rb'))
5
+ res
6
+ end
7
+ end
8
+
9
+
@@ -0,0 +1,47 @@
1
+ class ApplicationStylesheet < RubyMotionQuery::Stylesheet
2
+
3
+ def application_setup
4
+
5
+ # Change the default grid if desired
6
+ # rmq.app.grid.tap do |g|
7
+ # g.num_columns = 12
8
+ # g.column_gutter = 10
9
+ # g.num_rows = 18
10
+ # g.row_gutter = 10
11
+ # g.content_left_margin = 10
12
+ # g.content_top_margin = 74
13
+ # g.content_right_margin = 10
14
+ # g.content_bottom_margin = 10
15
+ # end
16
+
17
+ # An example of setting standard fonts and colors
18
+ font_family = 'Helvetica Neue'
19
+ font.add_named :large, font_family, 36
20
+ font.add_named :medium, font_family, 24
21
+ font.add_named :small, font_family, 18
22
+
23
+ color.add_named :tint, '236EB7'
24
+ color.add_named :translucent_black, color(0, 0, 0, 0.4)
25
+ color.add_named :battleship_gray, '#7F7F7F'
26
+
27
+ StandardAppearance.apply app.window
28
+ end
29
+
30
+ def standard_button(st)
31
+ st.frame = {w: 40, h: 18}
32
+ st.background_color = color.tint
33
+ st.color = color.white
34
+ end
35
+
36
+ def standard_label(st)
37
+ st.frame = {w: 40, h: 18}
38
+ st.background_color = color.clear
39
+ st.color = color.black
40
+ end
41
+
42
+ def rounded_image(st)
43
+ st.view.layer.cornerRadius = st.frame.width/2
44
+ st.clips_to_bounds = true
45
+ end
46
+
47
+ end
@@ -0,0 +1,125 @@
1
+ module MatchingAnimation
2
+ def popup(i, matched_index, final_screen)
3
+ @home_link.hide
4
+ @reset_link.hide
5
+ @visit_link.hide
6
+ form_sheet = MZFormSheetController.new
7
+ form_sheet.initWithViewController MatchingLayoutTestController.alloc.initWithCardInfo(form_sheet, i, @data[matched_index], @home_link, @reset_link, @visit_link, final_screen, self)
8
+ form_sheet.shouldDismissOnBackgroundViewTap = true
9
+ form_sheet.formSheetWindow.transparentTouchEnabled = true
10
+ form_sheet.portraitTopInset = 10
11
+ form_sheet.presentedFormSheetSize = CGSizeMake(UIScreen.mainScreen.bounds.size.width * 0.90, UIScreen.mainScreen.bounds.size.height * 0.90);
12
+ form_sheet.presentAnimated true, completionHandler: lambda {|c| }
13
+ form_sheet
14
+ end
15
+
16
+ def final_screen
17
+ open MatchingCongratsScreen.new(nav_bar: false, :f_score=> @score.text)
18
+ end
19
+
20
+ def shuffle_images(images)
21
+ shuffled_images = images.shuffle[0..9]
22
+ uniq_shuffled_images = (shuffled_images.shuffle + shuffled_images.shuffle).shuffle
23
+ uniq_shuffled_images.unshift("")
24
+ uniq_shuffled_images
25
+ end
26
+
27
+ def rotate_image(index, image, time, re_flip)
28
+ @new_image = UIImage.imageNamed image
29
+ @old_image = UIImage.imageNamed 'Blank.jpg'
30
+ UIView.transitionWithView @img[index], duration: time, options: UIViewAnimationOptionTransitionFlipFromLeft,
31
+ animations: lambda {
32
+ @timer = false
33
+ @img[index].image = @new_image
34
+ },
35
+ completion: lambda {|finished|
36
+ @timer = true
37
+ }
38
+ end
39
+
40
+ def replace_old_image(index)
41
+ UIView.transitionWithView @img[index], duration: 0.6, options: UIViewAnimationOptionTransitionFlipFromRight,
42
+ animations: lambda {
43
+ @img[index].image = @old_image
44
+ },
45
+ completion: lambda {|finished|
46
+ @timer = true
47
+ }
48
+ end
49
+
50
+ def change_image(index_of_clicked, clicked_image)
51
+ if @pause_timer
52
+ @pause_timer.invalidate
53
+ @pause_timer = nil
54
+ nw_image = UIImage.imageNamed 'Blank.jpg'
55
+ @img[@index_of_prev_clic].image = nw_image
56
+ end
57
+ if (un_matched_image(index_of_clicked))
58
+ if (@first_clicked != "")
59
+ @second_clicked = clicked_image[0]
60
+ if ((@first_clicked == @second_clicked) && (@index_of_prev_clic != index_of_clicked))
61
+ rotate_the_image_after_map(index_of_clicked, clicked_image)
62
+ else
63
+ @first_clicked = @second_clicked
64
+ @index_of_prev_clic = index_of_clicked
65
+ @second_clicked = ""
66
+ rotate_image(index_of_clicked, @first_clicked, 0.6, true)
67
+ @pause_timer = NSTimer.scheduledTimerWithTimeInterval(2.0, target:self, selector:'timerFired', userInfo:nil, repeats:false)
68
+ @clicked_index = index_of_clicked
69
+ end
70
+ else
71
+ @first_clicked = clicked_image[0]
72
+ @second_clicked = ""
73
+ @index_of_prev_clic = index_of_clicked
74
+ rotate_image(index_of_clicked, clicked_image[0], 0.6, true)
75
+ @pause_timer = NSTimer.scheduledTimerWithTimeInterval(2.0, target:self, selector:'timerFired', userInfo:nil, repeats:false)
76
+ @clicked_index = index_of_clicked
77
+ end
78
+ end
79
+ end
80
+
81
+
82
+ def timerFired(index = nil)
83
+ index = @clicked_index || index
84
+ @pause_timer = nil
85
+ replace_old_image(index)
86
+ end
87
+
88
+ def get_match_score(index_of_clicked)
89
+ puts "kdjfvhvfnmk,llkmdjnnjm,lmkjnnm,lmjnh"
90
+ count = (@image_clicked_count["#{index_of_clicked}"] + @image_clicked_count["#{@index_of_prev_clic}"])
91
+ matched_score = case count
92
+ when 3
93
+ 50
94
+ when 2
95
+ 50
96
+ when 4
97
+ 25
98
+ when 5
99
+ 10
100
+ else
101
+ 1
102
+ end
103
+ matched_score
104
+ end
105
+
106
+ def rotate_the_image_after_map(index_of_clicked, clicked_image)
107
+ rotate_image(@index_of_prev_clic, @first_clicked, 0.2, false)
108
+ rotate_image(index_of_clicked, @second_clicked, 0.2, false)
109
+ ms = get_match_score(index_of_clicked)
110
+ @get_score += ms
111
+ @score.text = @get_score.to_s
112
+ @matched_count += 1
113
+ @clicked_images << index_of_clicked
114
+ @clicked_images << @index_of_prev_clic
115
+ @index_of_prev_clic = ""
116
+ @first_clicked = ""
117
+ @second_clicked = ""
118
+ if (@matched_count == 10)
119
+ popup(@index_of_prev_clic, clicked_image[1], true)
120
+ #open MatchingCongratsScreen.new(nav_bar: false, :f_score=> @score.text)
121
+ else
122
+ popup(@index_of_prev_clic, clicked_image[1], false)
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,40 @@
1
+ class MatchingCongratsScreen < PM::Screen
2
+ stylesheet MatchingSuccessScreenStylesheet
3
+ attr_accessor :f_score
4
+ include GoogleAnalytics
5
+
6
+ def init
7
+
8
+ end
9
+
10
+ def on_load
11
+ UIApplication.sharedApplication.statusBar.setAlpha 0
12
+ @img = UIImageView.alloc.init()
13
+ @img.apply_style(:team_dog_image)
14
+ self.view.addSubview(@img)
15
+ track_pageview("Congrats")
16
+ # @congrats = append!(UILabel, :congrats_msg)
17
+
18
+ @score = append!(UILabel, :final_score)
19
+ @score.text = "Your Score is \n #{f_score}"
20
+
21
+ @start_over = append!(UILabel, :start_again).on(:tap){|s| open MatchingWelcomeScreen.new(nav_bar: false)}
22
+ @play_over = append!(UIButton, :play_again).on(:tap){|s| open MatchingHomeScreen.new(nav_bar: false)}
23
+ # rmq.append(UIButton, :play_again).on(:touch) do
24
+ # open MatchingHomeScreen.new(nav_bar: false)
25
+ # end
26
+
27
+ # @button = UIButton.buttonWithType(UIButtonTypeSystem)
28
+
29
+ # @button.setTitle("Play Again", forState: UIControlStateNormal)
30
+ # @button.layer.cornerRadius = 10 # SET THE ROUNDING RADIUS HERE
31
+ # @button.backgroundColor = UIColor.darkGrayColor
32
+ # # @button.addTarget(self, action: :actionForTheButton, forControlEvents: UIControlEventTouchUpInside)
33
+ # @button.apply_style(:play_again)
34
+ # @button.on(:touch) do
35
+ # open MatchingHomeScreen.new(nav_bar: false)
36
+ # end
37
+ # self.view.addSubview(@button)
38
+
39
+ end
40
+ end
@@ -0,0 +1,82 @@
1
+ class MatchingHomeScreen < PM::Screen
2
+ stylesheet MatchingHomeScreenStylesheet
3
+ include MatchingTimer
4
+ include MatchingAnimation
5
+
6
+ def on_load
7
+ UIApplication.sharedApplication.statusBar.setAlpha 0
8
+ self.view.backgroundColor = UIColor.colorWithPatternImage UIImage.imageNamed('background_image')
9
+ self.navigationController.navigationBarHidden = true
10
+ score
11
+ time
12
+ generate_views
13
+ @home_link = append!(UILabel, :home_link).on(:tap){|x| open MatchingWelcomeScreen.new(nav_bar: true)}
14
+ @reset_link = append!(UILabel, :reset_link).on(:tap){|x| reset_all}
15
+ end
16
+
17
+ def score
18
+ return @score unless @score.nil?
19
+ @score ||= UILabel.new
20
+ @score.text = '0 '
21
+ @score.textColor = UIColor.whiteColor
22
+ fontD = @score.font.fontDescriptor
23
+ fontD.fontDescriptorWithSymbolicTraits UIFontDescriptorTraitBold
24
+ @score.font = UIFont.fontWithDescriptor fontD, size: 0
25
+ # @score.frame = {grid: "b0:c0", w: 100}
26
+ @score.apply_style(:main_score)
27
+ @score.sizeToFit
28
+ view.addSubview(@score)
29
+ end
30
+
31
+ def generate_views
32
+ images = []
33
+ get_csv_data
34
+ @data.each_with_index do |l, index|
35
+ images << [l[0], index]
36
+ end
37
+ set_initial_values
38
+ uniq_shuffled_images = shuffle_images(images)
39
+ @img = Array.new(21, -1)
40
+ (1..20).each do |i|
41
+ puts "iiiiiiiiiiiiiiiiiiiiii #{i}"
42
+ puts "mmmmmmmmmmmmmmmmmmmmmm #{uniq_shuffled_images[i]}"
43
+ @img[i] = UIImageView.alloc.init()
44
+ @img[i].apply_style("img#{i}".to_sym)
45
+ @img[i].on(:tap){|s| change_image(i, uniq_shuffled_images[i])}
46
+ self.view.addSubview(@img[i])
47
+ @image_clicked_count["#{i}"] = 0
48
+ end
49
+ end
50
+
51
+ def get_csv_data
52
+ @file = @file || NSURL.fileURLWithPath(File.join(NSBundle.mainBundle.resourcePath, 'characters.csv'))
53
+ @data = @data || MotionCSV.parse(NSData.dataWithContentsOfURL(@file).to_s)
54
+ end
55
+
56
+ def set_initial_values
57
+ @first_clicked = ""
58
+ @timer = true
59
+ @image_clicked_count = {}
60
+ @clicked_images = []
61
+ @get_score = 0
62
+ @matched_count = 0
63
+ end
64
+
65
+
66
+ def un_matched_image(index_of_clicked)
67
+ @image_clicked_count["#{index_of_clicked}"] += 1
68
+ (!(@clicked_images.include?(index_of_clicked)) && @timer)
69
+ end
70
+
71
+ def reset_all
72
+ @score.text = "0"
73
+ generate_views
74
+ reapply_styles
75
+ @set_timer.text = "00:00"
76
+ @startTime = Time.now
77
+ end
78
+
79
+ def will_animate_rotate(orientation, duration)
80
+ find.all.reapply_styles
81
+ end
82
+ end
@@ -0,0 +1,241 @@
1
+ class MatchingHomeScreenStylesheet < ApplicationStylesheet
2
+
3
+ def setup
4
+ if (rmq.device.height >= 1024)
5
+ self.grid = RubyMotionQuery::Grid.new({
6
+ content_left_margin: 0,
7
+ content_right_margin: 0,
8
+ content_top_margin: 10,
9
+ content_bottom_margin: 10,
10
+ num_columns: 13, #13
11
+ column_gutter: 0, #0
12
+ num_rows: 17,
13
+ row_gutter: 0
14
+ })
15
+ else
16
+ self.grid = RubyMotionQuery::Grid.new({
17
+ content_left_margin: 0,
18
+ content_right_margin: 0,
19
+ content_top_margin: 10,
20
+ content_bottom_margin: 10,
21
+ num_columns: 14, #13
22
+ column_gutter: 10, #0
23
+ num_rows: 17,
24
+ row_gutter: 0
25
+ })
26
+ end
27
+ # Add stylesheet specific setup stuff here.
28
+ # Add application specific setup stuff in application_stylesheet.rb
29
+ end
30
+
31
+ def root_view(st)
32
+ st.background_color = color.black
33
+ puts "widthhhhhhhhhhhhhhhhhhh #{rmq.frame.width}"
34
+ puts "heightttttttttttttttttt #{rmq.frame.height}"
35
+ end
36
+
37
+ def get_width
38
+ case rmq.device.height
39
+ when 1024
40
+ puts "1024"
41
+ @width = 129#152#rmq.frame.width/4.8 #160
42
+ @height = 172#204#rmq.frame.height/6.02 #170
43
+ when 736
44
+ puts "736"
45
+ @width = 88#rmq.frame.width/5.048 #82
46
+ @height = 120 #rmq.frame.height/6.4 #115 #87
47
+ when 667
48
+ puts "667"
49
+ @width = 78#rmq.frame.width/5.1 #73.5
50
+ @height = 108#rmq.frame.height/6.4 #104 79
51
+ when 568
52
+ puts"568"
53
+ @width = 68#rmq.frame.width/5.1 #62.1
54
+ @height = 90#rmq.frame.height/6.52 #87 79
55
+ else
56
+ puts "480"
57
+ @width = 59#rmq.frame.width/4.92 #67
58
+ @height = 79#rmq.frame.height/6.07 # 79 69
59
+ end
60
+ end
61
+
62
+ def img1(st)
63
+ get_width
64
+ puts "heighttttttt #{@height}"
65
+ puts "widthhhhhhhh #{@width}"
66
+ st.frame = {grid: "b1:d3", w: @width, h: @height}#{t: rmq.frame.height/18, w: rmq.frame.width/5, h: rmq.frame.height/6.5, l: rmq.frame.width/22}
67
+ st.image = image.resource('Blank.jpg')
68
+ # st.border_width = 4
69
+ #st.border_color = color.white
70
+ end
71
+
72
+ def img2(st)
73
+ st.frame = {grid: "e1:g3", w: @width, h: @height}#{t: rmq.frame.height/18, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/3.6}
74
+ st.image = image.resource('Blank.jpg')
75
+ end
76
+
77
+ def img3(st)
78
+ st.frame = {grid: "h1:j3", w: @width, h: @height}#{t: rmq.frame.height/18, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/1.96}
79
+ st.image = image.resource('Blank.jpg')
80
+ end
81
+
82
+ def img4(st)
83
+ st.frame = {grid: "k1:m3", w: @width, h: @height}#{t: rmq.frame.height/18, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/1.34}
84
+ st.image = image.resource('Blank.jpg')
85
+ end
86
+
87
+ def img5(st)
88
+ st.frame = {grid: "b4:d6", w: @width, h: @height}#{t: rmq.frame.height/4.4, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/22}
89
+ st.image = image.resource('Blank.jpg')
90
+
91
+ end
92
+
93
+ def img6(st)
94
+ st.frame = {grid: "e4:g6", w: @width, h: @height}#{t: rmq.frame.height/4.4, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/3.6}
95
+ st.image = image.resource('Blank.jpg')
96
+ end
97
+
98
+ def img7(st)
99
+ st.frame = {grid: "h4:j6", w: @width, h: @height}#{t: rmq.frame.height/4.4, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/1.96}
100
+ st.image = image.resource('Blank.jpg')
101
+ end
102
+
103
+ def img8(st)
104
+ st.frame = {grid: "k4:m6", w: @width, h: @height}#{t: rmq.frame.height/4.4, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/1.34}
105
+ st.image = image.resource('Blank.jpg')
106
+ end
107
+
108
+ def img9(st)
109
+ st.frame = {grid: "b7:d9", w: @width, h: @height}#{t: rmq.frame.height/2.50, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/22}
110
+ st.image = image.resource('Blank.jpg')
111
+ end
112
+
113
+ def img10(st)
114
+ st.frame = {grid: "e7:g9", w: @width, h: @height}#{t: rmq.frame.height/2.50, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/3.6}
115
+ st.image = image.resource('Blank.jpg')
116
+ end
117
+
118
+ def img11(st)
119
+ st.frame = {grid: "h7:j9", w: @width, h: @height}#{t: rmq.frame.height/2.50, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/1.96}
120
+ st.image = image.resource('Blank.jpg')
121
+ end
122
+
123
+ def img12(st)
124
+ st.frame = {grid: "k7:m9", w: @width, h: @height}#{t: rmq.frame.height/2.50, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/1.34}
125
+ st.image = image.resource('Blank.jpg')
126
+
127
+ end
128
+
129
+ def img13(st)
130
+ st.frame = {grid: "b10:d12", w: @width, h: @height}#{t: rmq.frame.height/1.75, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/22}
131
+ st.image = image.resource('Blank.jpg')
132
+ #st.border_width = 4
133
+ #st.border_color = color.white
134
+ end
135
+
136
+ def img14(st)
137
+ st.frame = {grid: "e10:g12", w: @width, h: @height} #{t: rmq.frame.height/1.75, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/3.6}
138
+ st.image = image.resource('Blank.jpg')
139
+ #st.border_width = 4
140
+ #st.border_color = color.white
141
+ end
142
+
143
+ def img15(st)
144
+ st.frame = {grid: "h10:j12", w: @width, h: @height} #{t: rmq.frame.height/1.75, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/1.96}
145
+ st.image = image.resource('Blank.jpg')
146
+ #st.border_width = 4
147
+ #st.border_color = color.white
148
+ end
149
+
150
+ def img16(st)
151
+ st.frame = {grid: "k10:m12", w: @width, h: @height} #{t: rmq.frame.height/1.75, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/1.34}
152
+ st.image = image.resource('Blank.jpg')
153
+ #st.border_width = 4
154
+ #st.border_color = color.white
155
+ end
156
+
157
+ def img17(st)
158
+ st.frame = {grid: "b13:d15", w: @width, h: @height}# {t: rmq.frame.height/1.34, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/22}
159
+ st.image = image.resource('Blank.jpg')
160
+ #st.border_width = 4
161
+ #st.border_color = color.white
162
+ end
163
+
164
+ def img18(st)
165
+ st.frame = {grid: "e13:g15", w: @width, h: @height}#{t: rmq.frame.height/1.34, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/3.6}
166
+ st.image = image.resource('Blank.jpg')
167
+ #st.border_width = 4
168
+ #st.border_color = color.white
169
+ end
170
+
171
+ def img19(st)
172
+ st.frame = {grid: "h13:j15", w: @width, h: @height}# {t: rmq.frame.height/1.34, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/1.96}
173
+ st.image = image.resource('Blank.jpg')
174
+ #st.border_width = 4
175
+ #st.border_color = color.white
176
+ end
177
+
178
+ def img20(st)
179
+ st.frame = {grid: "k13:m15", w: @width, h: @height} #{t: rmq.frame.height/1.34, w: rmq.frame.width/5, h: rmq.frame.height/6.5, fl: rmq.frame.width/1.34}
180
+ st.image = image.resource('Blank.jpg')
181
+ #st.border_width = 4
182
+ #st.border_color = color.white
183
+ end
184
+
185
+ def home_link(st)
186
+ st.frame = {grid: "b16:c16", w: 100}
187
+ if (rmq.device.height >= 1024)
188
+ st.font = rmq.font.system(30)
189
+ end
190
+ st.color = color.white
191
+ st.text = "Home"
192
+ end
193
+
194
+ def reset_link(st)
195
+ # st.frame = {fl: 10, top: rmq.frame.height - 40, h: 30, w: 50}
196
+ st.frame = {grid: "l16:m16", w: 150}
197
+ st.color = color.white
198
+ if (rmq.device.height >= 1024)
199
+ st.font = rmq.font.system(30)
200
+ end
201
+ st.text = "Reset"
202
+ end
203
+
204
+ def main_score(st)
205
+ st.frame = {grid: "b0:c0", w: 100}
206
+ if (rmq.device.height >= 1024)
207
+ st.font = rmq.font.system(30)
208
+ end
209
+ end
210
+
211
+ def main_time(st)
212
+ st.frame = {grid: "l0:m0", w: 150}
213
+ if (rmq.device.height >= 1024)
214
+ st.font = rmq.font.system(30)
215
+ end
216
+ end
217
+
218
+
219
+ def close_button_style(st)
220
+ if (rmq.device.height >= 1024)
221
+ st.frame = {grid:"f15", w: 70}
222
+ elsif (rmq.device.height == 667)
223
+ st.frame = {grid:"f14", w: 70}
224
+ elsif (rmq.device.height == 736)
225
+ st.frame = {grid:"f14", w: 60}
226
+ elsif (rmq.device.height == 480)
227
+ st.frame = {grid:"f14", w: 50}
228
+ else
229
+ st.frame = {grid:"f14", w: 50}
230
+ end
231
+ end
232
+ end
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
@@ -0,0 +1,73 @@
1
+ class MatchingLayoutTestController < UIViewController
2
+ stylesheet MatchingLayoutTestControllerStylesheet
3
+
4
+ def initWithCardInfo(form_sheet, i, csv_content)
5
+ # @img = a
6
+ @index = i
7
+ @form_sheet = form_sheet
8
+ @csv = csv_content
9
+ self
10
+ end
11
+
12
+ def on_load
13
+ super
14
+ self.view.backgroundColor = UIColor.whiteColor
15
+ self.view.alpha = 0.93
16
+ image = append!(UIImageView, :image_view)
17
+ image.tap do |imgv|
18
+ imgv.contentMode = UIViewContentModeScaleAspectFit
19
+ imgv.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin
20
+ imgv.backgroundColor = UIColor.clearColor
21
+ imgv.userInteractionEnabled = true
22
+ imgv.image = UIImage.imageNamed(@csv[0]) #AnimationHelper.renderImage(UIImage.imageNamed(@character.name), withMargin:10.0, color:UIColor.whiteColor)
23
+ self.view.addSubview(imgv)
24
+ end
25
+
26
+ close_button
27
+ image_title
28
+ image_sub_title
29
+ second_status
30
+ end
31
+
32
+ def image_sub_title
33
+ @image_sub_title = append!(UILabel, :img_sub_title)
34
+ @image_sub_title.text = @csv[2].upcase
35
+ self.view.addSubview(@image_sub_title)
36
+ end
37
+
38
+ def image_title
39
+ @image_title = append!(UILabel, :image_title_style)
40
+ @image_title.text = @csv[1]
41
+ self.view.addSubview(@image_title)
42
+ end
43
+
44
+ def close_button
45
+ @close_button = UIButton.buttonWithType UIButtonTypeRoundedRect
46
+ @close_button.setTitle "X", forState: UIControlStateNormal
47
+ @close_button.setTitleColor UIColor.redColor, forState: UIControlStateNormal
48
+ @close_button.sizeToFit
49
+ @close_button.addTarget(self, action: 'closePopup', forControlEvents: UIControlEventTouchUpInside)
50
+ @close_button.titleLabel.font = UIFont.fontWithName("Corbel", size: '20')
51
+ #@close_button.frame = [[rmq.frame.width/2.7, rmq.frame.height/1.2], [50,50]]
52
+ @close_button.apply_style(:close_button_style)
53
+ self.view.addSubview @close_button
54
+ end
55
+
56
+
57
+ def second_status
58
+ desc_index = [3,5,7]
59
+ index = desc_index.sample(1)
60
+ @second_status = append!(UILabel, :second_status_style)
61
+ @second_status.text = @csv[index[0]].gsub("\\n", "\n")
62
+ self.view.addSubview(@second_status)
63
+ end
64
+
65
+
66
+ def closePopup
67
+ @form_sheet.mz_dismissFormSheetControllerAnimated(true, completionHandler: nil)
68
+ end
69
+
70
+ def will_animate_rotate(orientation, duration)
71
+ reapply_styles
72
+ end
73
+ end
@@ -0,0 +1,35 @@
1
+ class MatchingLayoutTestControllerStylesheet < ApplicationStylesheet
2
+
3
+ def setup
4
+ # Add stylesheet specific setup stuff here.
5
+ # Add application specific setup stuff in application_stylesheet.rb
6
+ end
7
+
8
+ def image_title_style(st)
9
+ st.frame = {t: rmq.frame.height/2.3, fl: 38, fr: 50, h: 50}
10
+ st.color = UIColor.redColor
11
+ st.text_alignment = :center
12
+ #st.font = rmq.font.font_with_name('GoodDog', 60)
13
+ st.font = rmq.font.system(30)
14
+ end
15
+
16
+ def second_status_style(st)
17
+ st.frame = {t: rmq.frame.height/2-20, fl: 30, fr: 50, h: 200}
18
+ st.number_of_lines = 5
19
+ st.font = rmq.font.system(25)
20
+ st.text_alignment = :center
21
+ st.color = UIColor.brownColor
22
+ end
23
+
24
+ def image_view(st)
25
+ st.frame = {t: 40, w: rmq.frame.width/2.8, h: rmq.frame.height/3, fl: rmq.frame.width/3.5}
26
+ end
27
+
28
+ def img_sub_title(st)
29
+ st.frame = {t: rmq.frame.height/2 + 10, fl: 38, fr: 50, h: 50}
30
+ st.color = UIColor.redColor
31
+ st.text_alignment = :center
32
+ st.font = rmq.font.system(20)
33
+ end
34
+
35
+ end
@@ -0,0 +1,39 @@
1
+ module MatchingTimer
2
+ def time
3
+ @set_timer = UILabel.new
4
+ @set_timer.text = '00:00 '
5
+ @set_timer.textColor = UIColor.whiteColor
6
+ # @set_timer.frame = {grid: "l0:m0", w: 150} #[[rmq.device.width-50, 5], [100,50]]
7
+ view.addSubview(@set_timer)
8
+ @set_timer.apply_style(:main_time)
9
+ @set_timer.sizeToFit
10
+ @startTime = Time.now
11
+ startTimer
12
+ @set_timer
13
+ end
14
+
15
+ def startTimer
16
+ NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: 'updateTimer', userInfo: nil, repeats: true)
17
+ end
18
+
19
+
20
+ def updateTimer
21
+ status = UIApplication.sharedApplication.applicationState == UIApplicationStateBackground
22
+ if (!status)
23
+ @currentTime = @currentTime || Time.now
24
+ @currentTime += 1
25
+ @set_timer.text = time_diff(@startTime, @currentTime) #- @idle_time
26
+ end
27
+ end
28
+
29
+ def time_diff(start_time, end_time)
30
+ seconds_diff = (start_time - end_time).to_i.abs
31
+ hours = seconds_diff / 3600
32
+ seconds_diff -= hours * 3600
33
+ minutes = seconds_diff / 60
34
+ seconds_diff -= minutes * 60
35
+ seconds = seconds_diff
36
+ "#{minutes.to_s.rjust(2, '0')}:#{seconds.to_s.rjust(2, '0')}"
37
+ end
38
+
39
+ end
@@ -0,0 +1,14 @@
1
+ class MatchingWelcomeScreen < PM::Screen
2
+ stylesheet MatchingWelcomeScreenStylesheet
3
+
4
+
5
+ def on_load
6
+ UIApplication.sharedApplication.statusBar.setAlpha 0
7
+ @img = UIImageView.alloc.init()
8
+ @img.apply_style(:team_dog_image)
9
+ @img.on(:tap){|s| open MatchingHomeScreen.new(nav_bar: true)}
10
+ self.view.addSubview(@img)
11
+ #@start_over = append!(UILabel, :start_game).on(:tap){|s| open MatchingHomeScreen.new(nav_bar: true)}
12
+ end
13
+
14
+ end
@@ -0,0 +1,21 @@
1
+ class MatchingWelcomeScreenStylesheet < ApplicationStylesheet
2
+
3
+ def root_view(st)
4
+ st.background_color = color.white
5
+ end
6
+
7
+ def team_dog_image(st)
8
+ st.frame = {t: 0, w: rmq.frame.width, h: rmq.frame.height, fl: 0}
9
+ st.image = image.resource('opening_screen.png')
10
+ end
11
+
12
+ def start_game(st)
13
+ st.frame = {t: rmq.frame.height/2 + 90, w: rmq.frame.width, h: 100}
14
+ st.font = rmq.font.font_with_name('Corbel', 40)
15
+ st.color = color.white
16
+ st.text_alignment = :centered
17
+ st.text = "Can You Find \n Two of a Kind?"
18
+ st.number_of_lines = 2
19
+ end
20
+
21
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: matching_base
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Manju Sagar
8
+ - Siddalingappa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-05-25 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: This Gem is used to match the cards and display the popup when the image
15
+ matches. For each match there will be certain scores based on hoew many times you
16
+ click the same image.
17
+ email: manjusagar.sn@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/matching_base/application_stylesheet.rb
23
+ - lib/matching_base/matching_animation.rb
24
+ - lib/matching_base/matching_congrats_screen.rb
25
+ - lib/matching_base/matching_home_screen.rb
26
+ - lib/matching_base/matching_home_screen_stylesheet.rb
27
+ - lib/matching_base/matching_layout_test_controller.rb
28
+ - lib/matching_base/matching_layout_test_controller_stylesheet.rb
29
+ - lib/matching_base/matching_timer.rb
30
+ - lib/matching_base/matching_welcome_screen.rb
31
+ - lib/matching_base/matching_welcome_screen_style_sheet.rb
32
+ - lib/matching_base.rb
33
+ homepage: https://rubygems.org/gems/ms
34
+ licenses:
35
+ - MIT
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 2.0.14
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: A RubyMotion gem.
57
+ test_files: []