diff --git a/tour-of-go/methods/go.mod b/tour-of-go/methods/go.mod new file mode 100644 index 0000000..56e1c06 --- /dev/null +++ b/tour-of-go/methods/go.mod @@ -0,0 +1,11 @@ +module methods + +go 1.22.1 + +require github.com/fatih/color v1.16.0 + +require ( + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + golang.org/x/sys v0.14.0 // indirect +) diff --git a/tour-of-go/methods/go.sum b/tour-of-go/methods/go.sum new file mode 100644 index 0000000..7f13de9 --- /dev/null +++ b/tour-of-go/methods/go.sum @@ -0,0 +1,11 @@ +github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= +github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/tour-of-go/methods/main.go b/tour-of-go/methods/main.go new file mode 100644 index 0000000..d1a135f --- /dev/null +++ b/tour-of-go/methods/main.go @@ -0,0 +1,54 @@ +package main + +import ( + "fmt" + "github.com/fatih/color" +) + +var x int +var y int + +type Coordinates struct { + X, Y int +} + +func getMatrix(mat [][]string, c Coordinates) { + col := color.New(color.FgBlack).Add(color.Underline).Add(color.BgHiRed) + for i := range mat { + for i1 := range mat[i] { + if i == c.X && i1 == c.Y { + col.Printf("%v", mat[i][i1]) + fmt.Printf(" ") + } else { + fmt.Printf("%v ", mat[i][i1]) + } + } + fmt.Println() + } +} + +func main() { + matrix := make([][]string, 5) + for i := range matrix { + matrix[i] = make([]string, 5) + } + + for i := range matrix { + for i1 := range matrix[i] { + matrix[i][i1] = "A" + } + } + fmt.Printf("X coordinate: ") + fmt.Scanln(&x) + + fmt.Printf("Y coordinate: ") + fmt.Scanln(&y) + + x-- + y-- + + coords := Coordinates{x, y} + + getMatrix(matrix, coords) + +}