Git Product home page Git Product logo

swift-pickinfruit-lab-web-103017's Introduction

Pickin Fruit

๐ŸŽ ๐ŸŠ ๐ŸŒ ๐Ÿ ๐Ÿ‡ ๐Ÿ‰ ๐Ÿ“ ๐Ÿ’ ๐Ÿ

Objectives

  • Create a fruity slot game using UIPickerView, UIPickerViewDelegate, and UIPickerViewDataSource

Introduction

In this lab you will use UIPickerView to make a slot game called, 'Pickin Fruit'. Each component in the picker view will represent a reel of fruit within the slot machine. UIPickerView is similar to a UITableView because it requires adopting protocols (a delegate and a data source). These adoptions are necessary to provide the picker view with the data it needs to construct itself. Check out Apple's documentation about UIPickerView, UIPickerViewDelegate, and UIPickerViewDataSource. The storyboard is already set up with a picker view, a result label, and a spin button. The outlets for the label and the button are already included in the ViewController class, along with an IBAction for the button. The ViewController class has an instance property array that contains the data (fruit).

1. Implement the delegate protocols on the picker view


  • Create an outlet property for the picker view called fruitPicker.
  • Implement the 2 required data source delegate methods to provide data to the picker view. The picker view should have 3 components.
  • Implement the pickerView(_:titleForRow:forComponent:) method to set the title from the strings within the array.

2. Handle winning and losing scenarios


  • Inside the spinButton IBAction method, use the selectRow(_:inComponent:animated:) and selectedRow(inComponent:) methods to spin the picker and process the outcome.
  • Update the text value on resultLabel with "TRY AGAIN" or "WINNER!" depending on the outcome of the spin.
  • Run the test.

Advanced

  • Apple keeps the functionality of the picker view animation private but the duration is approximately 0.3 seconds. Animate the appearance of the label and make it blink a couple of times before disappearing.
  • Change the count for the UIPickerViewDataSource to be greater than the array in order to make the spin appear more like a slot machine. You can also start the picker view at different positions so the fruit will cover the view top to bottom.

Animated Slot Machine

swift-pickinfruit-lab-web-103017's People

Contributors

joelconnects avatar jimcampagno avatar johannkerr avatar susanlovaglio avatar

Watchers

 avatar Rishikesh Tirumala avatar  avatar Victoria Thevenot avatar  avatar Joe Cardarelli avatar Sara Tibbetts avatar The Learn Team avatar Sophie DeBenedetto avatar  avatar Antoin avatar  avatar  avatar Nicole Kroese  avatar Lisa Jiang avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.