golang-exercises/star-shapes-mk2/main.go

74 lines
1.1 KiB
Go

package main
import (
"fmt"
"log"
"os"
"strconv"
)
type Shaper interface {
GenerateCube(num int)
GenerateLine(num int)
GenerateFlag(num int)
}
type Shape struct {
shape string
numOfChars int
}
func (s Shape) GenerateCube(num int) {
for i := 0; i < num; i++ {
for i := 0; i < num; i++ {
fmt.Printf("* ")
}
fmt.Printf("\n")
}
}
func (s Shape) GenerateLine(num int) {
for i := 0; i < num; i++ {
fmt.Printf("* ")
}
fmt.Printf("\n")
}
func (s Shape) GenerateFlag(num int) {
for a := 0; a < num; a++ {
for i := -1; i < a; i++ {
fmt.Printf("* ")
}
fmt.Printf("\n")
}
for i := 0; i < num/2; i++ {
fmt.Println("*")
}
}
func passToShaper(s Shaper, num int, choice int) {
switch choice {
case 1:
s.GenerateLine(num)
case 2:
s.GenerateCube(num)
case 3:
s.GenerateFlag(num)
}
}
func main() {
if len(os.Args) != 3 {
fmt.Println("Use an argument like 5 and then 1")
os.Exit(0)
}
numToGen, err := strconv.Atoi(os.Args[1])
if err != nil {
log.Fatalf("Error: %v\n", err)
}
numToChoose, err := strconv.Atoi(os.Args[2])
s := Shape{}
passToShaper(s, numToGen, numToChoose)
}