Closed richardspirit closed 2 years ago
Created temporary fix using map but it will be high maintenance if options change.
m := make(map[string]string)
// Set key/value pairs using typical `name[key] = val`
m["k1"] = "Enter New Deck"
m["k2"] = "Add New Game"
m["k3"] = "View Deck Records"
m["k4"] = "View Game Count"
m["k5"] = "Quit"
// print menu options
fmt.Println("1:", m["k1"]+" "+"2:", m["k2"])
fmt.Println("3:", m["k3"]+" "+"4:", m["k4"])
fmt.Println(" 10:", m["k5"])
Modified above to use verb for spacing to improve formatting and ease of reading code.
m["k1"] = fmt.Sprintf("%-20s", "Enter New Deck")
m["k2"] = fmt.Sprintf("%-20s", "Add New Game")
m["k3"] = fmt.Sprintf("%-20s", "View Deck Records")
m["k4"] = fmt.Sprintf("%-20s", "View Game Count")
m["k5"] = fmt.Sprintf("%-20s", "View All Decks")
m["k10"] = fmt.Sprintf("%20s", "10: Quit")
// print menu options
fmt.Println("1:", m["k1"]+"2:", m["k2"])
fmt.Println("3:", m["k3"]+"4:", m["k4"])
fmt.Println("5:", m["k5"])
fmt.Println(m["k10"])
Need a fix for this section - List Favorites Deck: Armed and Dangerous Date Entered: 2021-08-24 Wins: 11 Loses: 5 Deck: Avalanche! Date Entered: 2021-08-25 Wins: 15 Loses: 6 Deck: Back for More Date Entered: 2021-08-22 Wins: 9 Loses: 4 Deck: Forest's Might Date Entered: 2021-08-17 Wins: 17 Loses: 8 Deck: Large and in Charge Date Entered: 2021-08-22 Wins: 8 Loses: 7 Deck: Life Skills Date Entered: 2021-08-17 Wins: 9 Loses: 8 Deck: Savage Lands Date Entered: 2021-08-24 Wins: 8 Loses: 5 Deck: Sky Patrol Date Entered: 2021-08-24 Wins: 4 Loses: 7 Deck: Stomp Stomp Date Entered: 2021-08-17 Wins: 7 Loses: 9 Deck: Treasure Hunt Date Entered: 2021-08-24 Wins: 10 Loses: 4 Deck: White Flame Date Entered: 2021-08-17 Wins: 8 Loses: 6
Add dynamic grid to display query results. Use below as a guide.
package main
import ( "errors" "fmt" "time" )
type Grid struct { height, width int grid []byte }
func (g Grid) String() string { return string(g.grid) }
func NewGrid(x, y int) Grid { wth := 2x + 2 // +2 for right column + '\n' hgt := 2y + 1 // +1 for bottom row
}
func (g Grid) Set(c byte, x, y int) error { idx, err := g.cellAt(x, y) if err != nil { return err } g.grid[idx] = c return nil }
func (g Grid) cellAt(x, y int) (int, error) { woff := g.width2 + 2 // width offset foff := (y2+1)woff + x2 + 1
}
func (g Grid) Draw() { fmt.Print("\033[H\033[2J") // Clear screen fmt.Print("\x0c", g, "\n") // Print frame time.Sleep(250 * time.Millisecond) // Delay between frames }
func main() { const ( w = 11 h = 11 )
}
func max(is ...int) int { if len(is) == 0 { return 0 }
}