Created
January 21, 2015 16:51
-
-
Save ryanmr/793480ffbb9771fc3db5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Value int | |
const ( | |
Two Value = 2 + iota | |
Three | |
Four | |
Five | |
Six | |
Seven | |
Eight | |
Nine | |
Ten | |
Jack | |
Queen | |
King | |
Ace | |
) | |
func (t Value) String() string { | |
var s string | |
switch t { | |
case Two: s = "Two" | |
case Three: s = "Three" | |
case Four: s = "Four" | |
case Five: s = "Five" | |
case Six: s = "Six" | |
case Seven: s = "Seven" | |
case Eight: s = "Eight" | |
case Nine: s = "Nine" | |
case Ten: s = "Ten" | |
case Jack: s = "Jack" | |
case Queen: s = "Queen" | |
case King: s = "King" | |
case Ace: s = "Ace" | |
default: s = "iUnknown or composed Value!" | |
} | |
return s | |
} | |
type Suit int | |
const ( | |
Hearts Suit = iota | |
Spades | |
Clubs | |
Diamonds | |
) | |
func (t Suit) String() string { | |
var s string | |
switch t { | |
case Hearts: s = "Hearts" | |
case Spades: s = "Spades" | |
case Clubs: s = "Clubs" | |
case Diamonds: s = "Diamonds" | |
default: s = "iUnknown or composed Suit" | |
} | |
return s | |
} | |
type Card struct { | |
value Value | |
suit Suit | |
} | |
func (this Card) String() string { | |
return this.value.String() + " of " + this.suit.String() | |
} | |
func main() { | |
var c = Card{Two, Hearts} | |
fmt.Println(c) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment