This commit is contained in:
Benjamyn Love 2021-09-28 19:51:07 +10:00
commit 3da69bccc6
5 changed files with 74 additions and 0 deletions

46
deck/deck.go Normal file
View File

@ -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
}

6
deck/main.go Normal file
View File

@ -0,0 +1,6 @@
package main
func main() {
cards := newDeck()
cards.saveToFile("mydeck.txt")
}

15
hello_world/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}"
}
]
}

BIN
hello_world/main Executable file

Binary file not shown.

7
hello_world/main.go Normal file
View File

@ -0,0 +1,7 @@
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}