Code Monkey home page Code Monkey logo

swift-flatironcasino-lab's Introduction

Flatiron Casino

A lot of this project has already been built for you. The point of this lab is not to have you create everything from scratch. Instead, you will be working with a code base that has most of what you need already implemented. Before beginning the lab, take a look around the various files to see how things were implemented. This lab is to get you to use higher-order functions like map, flatMap, filter, reduce and forEach.

Note: In your implementation of the following tasks, you are not allowed to use a for-in loop. This is to force you to become familiar with higher-order functions. Stay out of your comfort zone, challenge yourself and learn!

You should find that printAllPiles() is getting called in the CardDetailViewController which should help you debug any problems while you're implementing the tasks below.

The main tasks that you will be implementing are the following (all of these tasks are marked as TODO in the code base):

  • Create a deck (which won't be a separate class, it will be an array of Cards) in the CasinoViewController class.
  • Implement the playCard(_:) method available to the CasinoViewController class. This method fires off as soon as a tap occurs within the green felt (greenFeltImageView).
  • Implement the prepare(for:sender:) method passing forward any dealt cards to the cards stored property on CardDetailViewController.
  • Navigate to the CardDetailViewController.swift file.
  • CardDetailViewController type should flip all of the cards handed to it. You should find that the TODO asks that you only use the forEach method instead of a for-in loop.
  • CardDetailViewController should be able to separate all of the cards into different piles. You should find four stored properties available to you which should wind up holding on to the necessary cards associated with the name of that variable. For example, all diamond cards should wind up in the diamonds stored property.
  • The CardDetailViewController should be able to sort all of the cards in each of its piles. They should be sorted as [Ace, 2, 3, 4 ... Q, K, A] for all four of the piles.
  • The CardDetailViewController has a scores stored property on it of type [Suit : Int] which should represent the total scores of all the cards within that particular pile. Implement the calculateScores() adhering to the TODO comment. You should look to go through all of the piles, tallying up the total score for each pile while updating the scores dictionary to reflect this total value (pertaining to the particular suit).

Advanced:

Navigate to the Main.storyboard. You should find that the CardDetailViewController is kind of bland. At this point, you should have a lot of data that we can display within this view. It's up to you how to go about doing this, but you should display all of the values you calculated above.

  • The total scores pertaining to their suits should be displayed.
  • Each pile should display all of its cards. A stack view might be your friend here. Or not. Implement this how you like.
  • Have fun with it!

swift-flatironcasino-lab's People

Contributors

ianrahman avatar jimcampagno avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.