Skip to content

Instantly share code, notes, and snippets.

@ryanmr
Created January 21, 2015 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanmr/793480ffbb9771fc3db5 to your computer and use it in GitHub Desktop.
Save ryanmr/793480ffbb9771fc3db5 to your computer and use it in GitHub Desktop.
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