initial
This commit is contained in:
commit
3da69bccc6
5 files changed
+74
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Create a new type of 'deck
|
||||
// which is a slice of string
|
||||
|
||||
type deck []string
|
||||
|
||||
func newDeck() deck {
|
||||
cards := deck{}
|
||||
cardSuits := []string{"Spades", "Hearts", "Diamonds", "Clubs"}
|
||||
cardValues := []string{"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"}
|
||||
|
||||
for _, suit := range cardSuits {
|
||||
for _, value := range cardValues {
|
||||
cards = append(cards, value+" of "+suit)
|
||||
}
|
||||
}
|
||||
return cards
|
||||
}
|
||||
|
||||
func (d deck) print() {
|
||||
for _, card := range d {
|
||||
fmt.Println(card)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func deal(d deck, handsize int) (deck, deck) {
|
||||
return d[:handsize], d[handsize:]
|
||||
|
||||
}
|
||||
|
||||
func (d deck) toString() string {
|
||||
return strings.Join([]string(d), ",")
|
||||
}
|
||||
|
||||
func (d deck) saveToFile(fileName string) error {
|
||||
error := ioutil.WriteFile(fileName, []byte(d.toString()), 0644)
|
||||
return error
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
cards := newDeck()
|
||||
cards.saveToFile("mydeck.txt")
|
||||
}
|
||||
Reference in new issue
Block a user