Skip to content

Commit

Permalink
Day14 - 跑马机
Browse files Browse the repository at this point in the history
1.升级到swift4
2.增加了模式选择,可开启开挂模式,不然太难bingo了
  • Loading branch information
qianyb committed Dec 25, 2018
1 parent fcc4b11 commit f15389f
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
TargetAttributes = {
9F77B6F71C4E79BF0042507F = {
CreatedOnToolsVersion = 7.2;
DevelopmentTeam = F3YT8BWBYJ;
LastSwiftMigration = 0830;
};
9F77B70B1C4E79C00042507F = {
Expand Down Expand Up @@ -400,23 +401,27 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = F3YT8BWBYJ;
INFOPLIST_FILE = EmojiMachine/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = me.appkitchen.EmojiMachine;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
};
9F77B7221C4E79C00042507F /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = F3YT8BWBYJ;
INFOPLIST_FILE = EmojiMachine/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = me.appkitchen.EmojiMachine;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15D13b" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -22,8 +25,8 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
</imageView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="wkW-sx-lOy">
<rect key="frame" x="27" y="458" width="320" height="45"/>
<color key="backgroundColor" red="0.71489375829696655" green="1" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<rect key="frame" x="27" y="524.5" width="321" height="45"/>
<color key="backgroundColor" red="0.66897320747375488" green="1" blue="0.034617960453033447" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="45" id="RSV-Ut-8Oj"/>
</constraints>
Expand All @@ -34,16 +37,16 @@
</connections>
</button>
<pickerView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Lo2-8k-W21">
<rect key="frame" x="-3" y="201" width="383" height="216"/>
<rect key="frame" x="-3" y="225.5" width="383" height="216"/>
</pickerView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Bingo" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="syA-dH-uTw">
<rect key="frame" x="0.0" y="586" width="375" height="28"/>
<rect key="frame" x="0.0" y="589.5" width="375" height="27.5"/>
<constraints>
<constraint firstAttribute="width" constant="375" id="DCr-IU-aZ2"/>
<constraint firstAttribute="height" constant="28" id="Pjt-eM-HYf"/>
</constraints>
<fontDescription key="fontDescription" name="AvenirNext-Heavy" family="Avenir Next" pointSize="20"/>
<color key="textColor" red="0.99990576505661011" green="1" blue="0.99987310171127319" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="textColor" red="0.99988853931427002" green="0.99998223781585693" blue="0.99983125925064087" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
Expand All @@ -52,13 +55,26 @@
</mask>
</variation>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="MHO-lC-83w">
<rect key="frame" x="0.0" y="583.5" width="100" height="40"/>
<constraints>
<constraint firstAttribute="width" constant="100" id="ZXS-4v-gY7"/>
<constraint firstAttribute="height" constant="40" id="mHz-Lm-3Zt"/>
</constraints>
<state key="normal" title="常规模式"/>
<connections>
<action selector="amazingButtonDidTouch:" destination="BYZ-38-t0r" eventType="touchUpInside" id="ILv-sV-e6R"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="Ylo-ai-q9x" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="37g-fZ-kDr"/>
<constraint firstItem="syA-dH-uTw" firstAttribute="top" secondItem="wkW-sx-lOy" secondAttribute="bottom" constant="83" id="A6X-dN-E9U"/>
<constraint firstItem="wkW-sx-lOy" firstAttribute="top" secondItem="Ylo-ai-q9x" secondAttribute="bottom" constant="-142.5" id="9Ab-1A-VOS"/>
<constraint firstItem="syA-dH-uTw" firstAttribute="bottom" secondItem="Ylo-ai-q9x" secondAttribute="bottom" constant="-50" id="BjO-mp-WhP"/>
<constraint firstAttribute="trailing" secondItem="Ylo-ai-q9x" secondAttribute="trailing" id="Cjn-Li-Pn9"/>
<constraint firstItem="wkW-sx-lOy" firstAttribute="top" secondItem="Lo2-8k-W21" secondAttribute="bottom" constant="41" id="DNp-w4-NDV"/>
<constraint firstItem="Lo2-8k-W21" firstAttribute="centerY" secondItem="Ylo-ai-q9x" secondAttribute="centerY" id="Cud-QT-kYd"/>
<constraint firstItem="MHO-lC-83w" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="HUY-Lo-pwv"/>
<constraint firstItem="syA-dH-uTw" firstAttribute="top" secondItem="wkW-sx-lOy" secondAttribute="bottom" constant="82" id="Hsd-x8-YUW"/>
<constraint firstAttribute="bottom" secondItem="Ylo-ai-q9x" secondAttribute="bottom" id="L2e-lr-vhB"/>
<constraint firstItem="syA-dH-uTw" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="PcG-kP-xOy"/>
Expand All @@ -70,13 +86,13 @@
<constraint firstAttribute="trailing" secondItem="syA-dH-uTw" secondAttribute="trailing" id="VuY-6S-Xca"/>
<constraint firstAttribute="trailingMargin" secondItem="Lo2-8k-W21" secondAttribute="trailing" constant="-21" id="XwU-Hw-XfQ"/>
<constraint firstAttribute="bottom" secondItem="wkW-sx-lOy" secondAttribute="bottom" constant="197" id="cJc-fc-LP7"/>
<constraint firstItem="Lo2-8k-W21" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="181" id="dE2-iJ-88E"/>
<constraint firstItem="wkW-sx-lOy" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" constant="11" id="fcy-J9-IRH"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="syA-dH-uTw" secondAttribute="bottom" constant="54" id="pLL-BC-c33"/>
<constraint firstItem="Ylo-ai-q9x" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="sdq-Oz-8zI"/>
<constraint firstItem="Lo2-8k-W21" firstAttribute="centerX" secondItem="syA-dH-uTw" secondAttribute="centerX" id="tBk-sY-waH"/>
<constraint firstItem="Lo2-8k-W21" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" constant="-15" id="ufB-c0-kHg"/>
<constraint firstItem="wkW-sx-lOy" firstAttribute="centerX" secondItem="Ylo-ai-q9x" secondAttribute="centerX" id="z32-ij-1o1"/>
<constraint firstItem="MHO-lC-83w" firstAttribute="centerY" secondItem="syA-dH-uTw" secondAttribute="centerY" id="zI9-sq-knD"/>
<constraint firstItem="Ylo-ai-q9x" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="zyk-Iw-Guh"/>
</constraints>
<variation key="default">
Expand All @@ -91,7 +107,6 @@
</mask>
</variation>
</view>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina47"/>
<connections>
<outlet property="emojiPickerView" destination="Lo2-8k-W21" id="FZt-4i-2zb"/>
<outlet property="goButton" destination="wkW-sx-lOy" id="QYN-43-nL6"/>
Expand All @@ -104,6 +119,6 @@
</scene>
</scenes>
<resources>
<image name="Hyperspace" width="621" height="1104"/>
<image name="Hyperspace" width="1242" height="2208"/>
</resources>
</document>
2 changes: 0 additions & 2 deletions Project 14 - EmojiSlotMachine/EmojiMachine/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
106 changes: 62 additions & 44 deletions Project 14 - EmojiSlotMachine/EmojiMachine/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,20 @@

import UIKit

class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
class ViewController: UIViewController {

@IBOutlet weak var emojiPickerView: UIPickerView!
@IBOutlet weak var goButton: UIButton!
@IBAction func goButtoDidTouch(_ sender: AnyObject) {

emojiPickerView.selectRow(Int(arc4random()) % 90 + 3, inComponent: 0, animated: true)
emojiPickerView.selectRow(Int(arc4random()) % 90 + 3, inComponent: 1, animated: true)
emojiPickerView.selectRow(Int(arc4random()) % 90 + 3, inComponent: 2, animated: true)


if(dataArray1[emojiPickerView.selectedRow(inComponent: 0)] == dataArray2[emojiPickerView.selectedRow(inComponent: 1)] && dataArray2[emojiPickerView.selectedRow(inComponent: 1)] == dataArray3[emojiPickerView.selectedRow(inComponent: 2)]) {

resultLabel.text = "Bingo!"

} else {

resultLabel.text = "💔"

}


//animate

UIView.animate(withDuration: 0.5, delay: 0.0, usingSpringWithDamping: 0.1, initialSpringVelocity: 5, options: .curveLinear, animations: {

self.goButton.bounds = CGRect(x: self.bounds.origin.x, y: self.bounds.origin.y, width: self.bounds.size.width + 20, height: self.bounds.size.height)

}, completion: { (compelete: Bool) in

UIView.animate(withDuration: 0.1, delay: 0.0, options: UIViewAnimationOptions(), animations: {

self.goButton.bounds = CGRect(x: self.bounds.origin.x, y: self.bounds.origin.y, width: self.bounds.size.width, height: self.bounds.size.height)

}, completion: nil)

})

}

@IBOutlet weak var resultLabel: UILabel!

var imageArray = [String]()
var dataArray1 = [Int]()
var dataArray2 = [Int]()
var dataArray3 = [Int]()
var amazingFlag = false
var bounds: CGRect = CGRect.zero

// MARK:生命周期
override func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -74,7 +40,7 @@ class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSo
emojiPickerView.dataSource = self

goButton.layer.cornerRadius = 6

goButton.layer.masksToBounds = true

}

Expand All @@ -100,12 +66,67 @@ class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSo

}



override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

// MARK:按钮事件
@IBAction func amazingButtonDidTouch(_ sender: UIButton) {
amazingFlag = !amazingFlag;
sender.setTitle(amazingFlag ? "开挂模式":"常规模式", for: .normal)
}
@IBAction func goButtoDidTouch(_ sender: AnyObject) {
let index1: Int
let index2: Int
let index3: Int
if amazingFlag {
index1 = Int(arc4random()) % 90 + 3
index2 = dataArray2.firstIndex(of: dataArray1[index1])!
index3 = dataArray3.lastIndex(of: dataArray1[index1])!

} else {
index1 = Int(arc4random()) % 90 + 3
index2 = Int(arc4random()) % 90 + 3
index3 = Int(arc4random()) % 90 + 3
}

emojiPickerView.selectRow(index1, inComponent: 0, animated: true)
emojiPickerView.selectRow(index2, inComponent: 1, animated: true)
emojiPickerView.selectRow(index3, inComponent: 2, animated: true)


if(dataArray1[emojiPickerView.selectedRow(inComponent: 0)] == dataArray2[emojiPickerView.selectedRow(inComponent: 1)] && dataArray2[emojiPickerView.selectedRow(inComponent: 1)] == dataArray3[emojiPickerView.selectedRow(inComponent: 2)]) {

resultLabel.text = "Bingo!"

} else {

resultLabel.text = "💔"

}


//animate

UIView.animate(withDuration: 0.5, delay: 0.0, usingSpringWithDamping: 0.1, initialSpringVelocity: 5, options: .curveLinear, animations: {

self.goButton.bounds = CGRect(x: self.bounds.origin.x, y: self.bounds.origin.y, width: self.bounds.size.width - 20, height: self.bounds.size.height)

}, completion: { (compelete: Bool) in

UIView.animate(withDuration: 0.1, delay: 0.0, options: UIViewAnimationOptions(), animations: {

self.goButton.bounds = CGRect(x: self.bounds.origin.x, y: self.bounds.origin.y, width: self.bounds.size.width, height: self.bounds.size.height)

}, completion: nil)

})

}
}

extension ViewController : UIPickerViewDelegate, UIPickerViewDataSource {
// MARK:UIPickerViewDataSource
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return 100
}
Expand All @@ -114,6 +135,7 @@ class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSo
return 3
}

// MARK:UIPickerViewDelegate
func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
return 100.0
}
Expand All @@ -138,10 +160,6 @@ class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSo
pickerLabel.textAlignment = NSTextAlignment.center

return pickerLabel

}



}

0 comments on commit f15389f

Please sign in to comment.