From 825fc555b51702d19e59d708e75d15a299dfb05d Mon Sep 17 00:00:00 2001 From: XXXXX43 Date: Wed, 27 Apr 2016 18:22:06 +0200 Subject: [PATCH 1/2] enums implement --- 04 - Poker.playground/Contents.swift | 51 ++++++++++++++++++++++- 04 - Poker.playground/timeline.xctimeline | 4 +- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/04 - Poker.playground/Contents.swift b/04 - Poker.playground/Contents.swift index 855b3ee..882e75b 100644 --- a/04 - Poker.playground/Contents.swift +++ b/04 - Poker.playground/Contents.swift @@ -7,11 +7,60 @@ */ /* EURE ANTWORT HIER + 1. only need one refernce to Card + 2. Enums eignen sich, weil es bei der Suit- und Rank-Auswahl mehrere Möglichkeiten gibt, welche sich gegenseitig ausschließen */ +enum Rank: Int { + case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace + func RankDescription() -> String { + switch self { + case .Ace: + return "Ace" + case .King: + return "Jack" + case .Queen: + return "Queen" + case .Jack: + return "King" + case .Ten: + return "Ten" + case .Nine: + return "Nine" + case .Eight: + return "Eight" + case .Seven: + return "Seven" + case .Six: + return "Six" + case .Five: + return "Five" + case .Four: + return "Four" + case .Three: + return "Three" + case .Two: + return "Two" + } + } +} - +enum Suit: Int { + case Spades, Hearts, Diamonds, Clubs + func SuitDescription() -> String { + switch self { + case .Spades: + return "U+2660" + case .Hearts: + return "U+2665" + case .Diamonds: + return "U+2666" + case .Clubs: + return "U+2663" + } + } +} //: ## Testing /* diff --git a/04 - Poker.playground/timeline.xctimeline b/04 - Poker.playground/timeline.xctimeline index 407a5d9..5ab2dd9 100644 --- a/04 - Poker.playground/timeline.xctimeline +++ b/04 - Poker.playground/timeline.xctimeline @@ -3,12 +3,12 @@ version = "3.0"> From a8619db202c25ca0c346ff8878acdc9bd8022142 Mon Sep 17 00:00:00 2001 From: XXXXX43 Date: Mon, 2 May 2016 16:15:54 +0200 Subject: [PATCH 2/2] fixed problem --- 04 - Poker.playground/Contents.swift | 27 +++++++++++++++++++---- 04 - Poker.playground/timeline.xctimeline | 4 ++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/04 - Poker.playground/Contents.swift b/04 - Poker.playground/Contents.swift index 882e75b..9ce6a06 100644 --- a/04 - Poker.playground/Contents.swift +++ b/04 - Poker.playground/Contents.swift @@ -11,10 +11,11 @@ 2. Enums eignen sich, weil es bei der Suit- und Rank-Auswahl mehrere Möglichkeiten gibt, welche sich gegenseitig ausschließen */ +import Foundation -enum Rank: Int { +enum Rank: Int, CustomStringConvertible { case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace - func RankDescription() -> String { + var description: String { switch self { case .Ace: return "Ace" @@ -46,9 +47,9 @@ enum Rank: Int { } } -enum Suit: Int { +enum Suit: Int, CustomStringConvertible { case Spades, Hearts, Diamonds, Clubs - func SuitDescription() -> String { + var description: String { switch self { case .Spades: return "U+2660" @@ -62,6 +63,24 @@ enum Suit: Int { } } +struct Card: CustomStringConvertible { + let suit: Suit + let rank: Rank + var description: String { + return "\(Rank.self) + \(Suit.self)" + } +} + +struct Pokerhand { + let cards: [Card] + var description: String { + return "\(Rank.self) + \(Suit.self)" + } +} + +let rndSuit = Suit(rawValue: Int(arc4random_uniform(4)))! +let rndRank = Rank(rawValue: Int(arc4random_uniform(13)))! +let rndCard = Card(suit: rndSuit, rank: rndRank) //: ## Testing /* var rankingCounts = [Ranking : Int]() diff --git a/04 - Poker.playground/timeline.xctimeline b/04 - Poker.playground/timeline.xctimeline index 5ab2dd9..86c30ad 100644 --- a/04 - Poker.playground/timeline.xctimeline +++ b/04 - Poker.playground/timeline.xctimeline @@ -3,12 +3,12 @@ version = "3.0">