Giter VIP home page Giter VIP logo

swift-classesbj2-lab's Introduction

Blackjack Lab: Part 2

NameOfPerson

Your assumptions are your windows on the world. Scrub them off every once in a while, or the light won't come in. -Isaac Asimov

Overview

In this lab, you will finish the UI for the simple Blackjack simulation you wrote in the previous lab.

Introduction

The UI will have a button the user can press to run a simulation. Once the game simulation has been completed, the UI should be updated to show the winner of the blackjack game.

The UI will look like this:

Blackjack UI

Open BlackJack2.xcworkspace to get started.

Directions

The completed source code from the previous lab has been copied to this project, so you won't need to re-implement that. A playGame() method has been added to the ViewController class, too. Other than that, the implementation of this app is up to you.

User Interface

The first thing to implement is the user interface. Open up Main.storyboard in Interface Builder to get started. A view controller has already been added to the storyboard.

  1. Drag a new text label onto the storyboard. Change the font to Avenir Next Bold, size 42.
  2. Drag another text label onto the view controller. Put this label below the label you just created. Change the font to Avenir Next Heavy, size 48. Change the text so simply be a question mark (?).
  3. Add a button to the view controller. Place it a bit below the second label. Change the text in the button to say Play Game.
  4. You need to create an IB outlet for the second text label, which will let the user know whether the house or player won the simulated game of Blackjack. Open up ViewController.swift in an assistant editor. Control-drag an IB outlet from the second text label to the ViewController class. Call it winnerLabel.
  5. You also need to create an IB action for the button. Control-drag an IB action from the Play Game button to the ViewController class. Name the IB action playGamePressed.

ViewController

Now it's time to implement the code to run the simulation in the ViewController class. Open ViewController.swift in Xcode's code editor. Some of ViewController has been implemented; in particular, a method called playGame() that will run one game simulation and return the winner of the game.

Here are the parts of ViewController that you need to finish to run the game:

  1. Add a property of type Dealer called dealer. It should be assigned a Dealer instance.
  2. Implement playGamePressed(_:). In this method, you should do the following:
    1. Create a new Dealer and assign it to the dealer property.
    2. Call playGame() and get the winner of the simulated game.
    3. Change winnerLabel's text to be the name of the winner.

Finishing Up

Your app should now work! Build and run the project. In the simulator, press Play Game to run a game simulation and see the winner!

View this lesson on Learn.co

swift-classesbj2-lab's People

Contributors

annjohn avatar jimcampagno avatar johannkerr avatar mdippery avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift-classesbj2-lab's Issues

Please update this code!

extension MutableCollection where Index == Int {
    /// Shuffle the elements of `self` in-place.
    ////https://stackoverflow.com/questions/37843647/shuffle-array-swift-3
        mutating func shuffleInPlace() {
        // empty and single-element collections don't shuffle
        if count < 2 { return }
        
        for i in startIndex ..< endIndex - 1 {
            let j = Int(arc4random_uniform(UInt32(endIndex - i))) + i
            if i != j {
                swap(&self[i], &self[j])
            }
        }
    }
    
//    mutating func shuffleInPlace() {
//        // Borrowed from: <https://codedump.io/share/OCJt0TU9IfzE/1/how-do-i-shuffle-an-array-in-swift>
//        guard count > 1 else { return }
//
//        for i in 0..<count - 1 {
//            let j = Int(arc4random_uniform(UInt32(count - i))) + i
//            guard i != j else { continue }
//            swap(&self[i], &self[j])
//        }
//    }
//}

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.