Skip to content
This repository was archived by the owner on May 18, 2021. It is now read-only.

Commit 7813622

Browse files
authored
Merge pull request #60 from imsuperman/master
Project 14 - EmojiSlotMachine
2 parents 04facf8 + ac22a23 commit 7813622

File tree

6 files changed

+180
-12
lines changed

6 files changed

+180
-12
lines changed

Project 14 - EmojiSlotMachine/EmojiMachine/Assets.xcassets/AppIcon.appiconset/Contents.json

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "20x20",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "20x20",
11+
"scale" : "3x"
12+
},
313
{
414
"idiom" : "iphone",
515
"size" : "29x29",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "Hyperspace - iPhone.jpg",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,82 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
59
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
610
</dependencies>
711
<scenes>
812
<!--View Controller-->
913
<scene sceneID="tne-QT-ifu">
1014
<objects>
11-
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
15+
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="EmojiMachine" customModuleProvider="target" sceneMemberID="viewController">
1216
<layoutGuides>
1317
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
1418
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
1519
</layoutGuides>
1620
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
1721
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1822
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
23+
<subviews>
24+
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Hyperspace" translatesAutoresizingMaskIntoConstraints="NO" id="1zo-Iw-uaF">
25+
<rect key="frame" x="0.0" y="20" width="375" height="647"/>
26+
</imageView>
27+
<pickerView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="6ND-LC-trp">
28+
<rect key="frame" x="12.5" y="233.5" width="350" height="200"/>
29+
<constraints>
30+
<constraint firstAttribute="width" constant="350" id="2cX-aG-dgq"/>
31+
<constraint firstAttribute="height" constant="200" id="5RX-7d-XSh"/>
32+
</constraints>
33+
</pickerView>
34+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="P3c-gH-eq6">
35+
<rect key="frame" x="12" y="474.5" width="350" height="45"/>
36+
<color key="backgroundColor" red="0.6705882353" green="1" blue="0.035294117649999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
37+
<constraints>
38+
<constraint firstAttribute="height" constant="45" id="Tii-XF-Zht"/>
39+
</constraints>
40+
<fontDescription key="fontDescription" type="system" weight="heavy" pointSize="16"/>
41+
<state key="normal" title="GO"/>
42+
<connections>
43+
<action selector="goButtonPressed:" destination="BYZ-38-t0r" eventType="touchUpInside" id="edA-dl-nxm"/>
44+
</connections>
45+
</button>
46+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rsu-xO-K17">
47+
<rect key="frame" x="12" y="577" width="350" height="21"/>
48+
<fontDescription key="fontDescription" type="system" weight="heavy" pointSize="17"/>
49+
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
50+
<nil key="highlightedColor"/>
51+
</label>
52+
</subviews>
1953
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
54+
<constraints>
55+
<constraint firstItem="P3c-gH-eq6" firstAttribute="top" secondItem="6ND-LC-trp" secondAttribute="bottom" constant="41" id="3DQ-gF-wF4"/>
56+
<constraint firstAttribute="trailing" secondItem="1zo-Iw-uaF" secondAttribute="trailing" id="3jh-Ke-52e"/>
57+
<constraint firstItem="rsu-xO-K17" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="BV2-x1-5cn"/>
58+
<constraint firstItem="6ND-LC-trp" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="RGV-Ae-ubo"/>
59+
<constraint firstItem="6ND-LC-trp" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="c7k-Gg-2Ui"/>
60+
<constraint firstItem="1zo-Iw-uaF" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="e87-Fi-Kvu"/>
61+
<constraint firstItem="P3c-gH-eq6" firstAttribute="width" secondItem="6ND-LC-trp" secondAttribute="width" id="fhi-yh-Hh3"/>
62+
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="1zo-Iw-uaF" secondAttribute="bottom" id="ghe-Xg-p4Q"/>
63+
<constraint firstItem="P3c-gH-eq6" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="jAO-ao-DeM"/>
64+
<constraint firstItem="rsu-xO-K17" firstAttribute="top" secondItem="P3c-gH-eq6" secondAttribute="bottom" constant="57.5" id="vzi-Kp-a9L"/>
65+
<constraint firstItem="1zo-Iw-uaF" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="wbe-g8-buj"/>
66+
<constraint firstItem="rsu-xO-K17" firstAttribute="width" secondItem="P3c-gH-eq6" secondAttribute="width" id="zQ4-Gj-Ek6"/>
67+
</constraints>
2068
</view>
69+
<connections>
70+
<outlet property="emojiPickerView" destination="6ND-LC-trp" id="YPW-hu-jIb"/>
71+
<outlet property="goButton" destination="P3c-gH-eq6" id="XhK-hY-Frk"/>
72+
<outlet property="tipsLabel" destination="rsu-xO-K17" id="fSu-zI-0bQ"/>
73+
</connections>
2174
</viewController>
2275
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
2376
</objects>
2477
</scene>
2578
</scenes>
79+
<resources>
80+
<image name="Hyperspace" width="1242" height="2208"/>
81+
</resources>
2682
</document>

Project 14 - EmojiSlotMachine/EmojiMachine/ViewController.swift

+83-8
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,93 @@
88

99
import UIKit
1010

11-
class ViewController: UIViewController {
11+
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
12+
13+
fileprivate let emojis = ["👻","👸","💩","😘","🍔","🤖","🍟","🐼","🚖","🐷"]
14+
15+
fileprivate var dataArray1 = [Int]()
16+
fileprivate var dataArray2 = [Int]()
17+
fileprivate var dataArray3 = [Int]()
1218

19+
@IBOutlet weak var emojiPickerView: UIPickerView! {
20+
didSet {
21+
emojiPickerView.isUserInteractionEnabled = false
22+
}
23+
}
24+
@IBOutlet weak var goButton: UIButton! {
25+
didSet {
26+
goButton.layer.cornerRadius = 6
27+
}
28+
}
29+
@IBOutlet weak var tipsLabel: UILabel! {
30+
didSet {
31+
tipsLabel.text = ""
32+
}
33+
}
34+
35+
@IBAction func goButtonPressed(_ sender: UIButton) {
36+
let randomInt1 = Int(arc4random()) % 90 + 3
37+
let randomInt2 = Int(arc4random()) % 90 + 3
38+
let randomInt3 = Int(arc4random()) % 90 + 3
39+
40+
emojiPickerView.selectRow(randomInt1, inComponent: 0, animated: true)
41+
emojiPickerView.selectRow(randomInt2, inComponent: 1, animated: true)
42+
emojiPickerView.selectRow(randomInt3, inComponent: 2, animated: true)
43+
44+
if (dataArray1[randomInt1] == dataArray2[randomInt2] &&
45+
dataArray2[randomInt2] == dataArray3[randomInt3]) {
46+
tipsLabel.text = "Bingo!"
47+
} else {
48+
tipsLabel.text = "💔"
49+
}
50+
}
51+
1352
override func viewDidLoad() {
1453
super.viewDidLoad()
15-
// Do any additional setup after loading the view, typically from a nib.
54+
55+
for _ in 1..<100 {
56+
dataArray1.append(Int(arc4random()%10))
57+
dataArray2.append(Int(arc4random()%10))
58+
dataArray3.append(Int(arc4random()%10))
59+
}
60+
61+
emojiPickerView.delegate = self
62+
emojiPickerView.dataSource = self
1663
}
17-
18-
override func didReceiveMemoryWarning() {
19-
super.didReceiveMemoryWarning()
20-
// Dispose of any resources that can be recreated.
64+
65+
// MARK: UIPickerViewDelegate && UIPickerViewDataSource
66+
67+
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
68+
return 100
69+
}
70+
71+
func numberOfComponents(in pickerView: UIPickerView) -> Int {
72+
return 3
73+
}
74+
75+
func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
76+
return 100.0
77+
}
78+
79+
func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
80+
return 100.0
81+
}
82+
83+
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
84+
85+
let pickerLabel = UILabel()
86+
pickerLabel.font = UIFont(name: "Apple Color Emoji", size: 80)
87+
pickerLabel.textAlignment = .center
88+
89+
if component == 0 {
90+
pickerLabel.text = emojis[(Int)(dataArray1[row])]
91+
} else if component == 1 {
92+
pickerLabel.text = emojis[(Int)(dataArray2[row])]
93+
} else {
94+
pickerLabel.text = emojis[(Int)(dataArray3[row])]
95+
}
96+
97+
return pickerLabel
2198
}
22-
23-
2499
}
25100

0 commit comments

Comments
 (0)