Learning structs and cleaning up old code

This commit is contained in:
raul 2024-02-10 13:44:41 +01:00
parent ab76136b4b
commit 4ea49a46b0
7 changed files with 46 additions and 7 deletions

View File

@ -7,7 +7,6 @@ import (
)
var numFinal int = 1
var multiplicado int = 1
func main() {
if len(os.Args) < 2 || len(os.Args) > 2 {
@ -22,8 +21,6 @@ func main() {
fmt.Println(err)
}
// TODO: Fix this garbage
for i := 1; i <= numFactorial; i++ {
numFinal = numFinal * i
}

View File

@ -5,6 +5,8 @@ import (
"fmt"
"math/rand"
"os"
"strconv"
"strings"
//"strconv"
)
@ -21,8 +23,9 @@ var guessLetter rune
func scanLine() (line string) {
in := bufio.NewReader(os.Stdin)
line, err := in.ReadString('\n')
lineNew, err := in.ReadString('\n')
catchErr(err)
line = strings.Trim(lineNew, "\n")
return line
}
@ -37,7 +40,25 @@ func main() {
// catchErr(err)
player.name = scanLine()
fmt.Println(player.name)
for {
fmt.Printf("How many lives would you like to have?\nLives: ")
stringLives := scanLine()
//TODO: fix this garbage
intLives, err := strconv.Atoi(stringLives)
catchErr(err)
player.lives = uint8(intLives)
fmt.Printf("Name: %v\n", player.name)
fmt.Printf("Lives: %v\n", player.lives)
fmt.Printf("Proceed? [y/n] ")
var choice string
_, err = fmt.Scanln(&choice)
catchErr(err)
if choice == "y" {
break
}
}
filePath := os.Args[1]
randWord := getWord(filePath)

View File

@ -2,4 +2,4 @@ module range
go 1.21.6
require git.bulgariu.xyz/raul/min-max-array v0.0.0-20240130184833-a25a49c11fc5
require git.bulgariu.xyz/raul/min-max-array v0.0.0-20240131105739-41c2fcc5af70

View File

@ -1,2 +1,4 @@
git.bulgariu.xyz/raul/min-max-array v0.0.0-20240130184833-a25a49c11fc5 h1:+4SdxwW8y687yR/ctDOdmcuJGxcI0oLPiNOrg28zSIo=
git.bulgariu.xyz/raul/min-max-array v0.0.0-20240130184833-a25a49c11fc5/go.mod h1:PdMyknNgNZYKg03bYhSc4aaSA/P3yScGPfxC4z+ju0c=
git.bulgariu.xyz/raul/min-max-array v0.0.0-20240131105739-41c2fcc5af70 h1:q/uQwkakAZnaus16KHG6UkBFZzNaMbjY3SCZjh0Pytk=
git.bulgariu.xyz/raul/min-max-array v0.0.0-20240131105739-41c2fcc5af70/go.mod h1:PdMyknNgNZYKg03bYhSc4aaSA/P3yScGPfxC4z+ju0c=

View File

@ -8,7 +8,6 @@ import (
)
// https://golangr.com/range
// TODO: Create something similar to the array exercise but cleaner and better
var notas []float64
var choice int8
@ -93,6 +92,8 @@ func getMinMax() {
// Me finally getting to make use of my first library :)
minNota := minmax.Min(notas)
maxNota := minmax.Max(notas)
// minNota := Min(notas)
// maxNota := Max(notas)
fmt.Printf("\n-----------------------------------------------")
fmt.Printf("\nLargest grade: %v\n", maxNota)
fmt.Printf("Smallest grade: %v\n", minNota)

10
yes-clone/go.mod Normal file
View File

@ -0,0 +1,10 @@
module yesClone
go 1.21.6
require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/urfave/cli/v2 v2.27.1 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
)

8
yes-clone/go.sum Normal file
View File

@ -0,0 +1,8 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=