Seperate Ways CLI
Time to update the beautiful text on the terminal#
In my previous post, I changed the core API to handle Ada’s Seperate Ways playthrough. Here we’ll be updating the CLI to handle the new API functionality. I want to add an option where the user can hit l
or a
to start either playthrough. Let’s make some changes
While I write this code…wait, where’s my while?!#
Currently, I’m using a for loop to scan user input and use the API. The only way of getting out is by hitting q
or ctrl+c
. Now I’ll add another loop scanning for input on the start game conditions, wether it will be Ada or Leon. The funny thing I encountered here is that the switch automatically breaks but only out of the switch, it won’t get out of the for loop. I’m using a ready
boolean to say when it’s ready to break free of the for loop. Why did Google not add while
to Golang? Cause for
is there!
Google, I love golang a lot. I like the simple keywords and easy readability, but come on!
Rant over. We’ll add ready
in our main function:
var sd core.SaveData
var option string
var ready = false
And now we’ll add the for loop of the first scan of inputs.
1 for {
2 fmt.Scan(&option)
3 fmt.Println("Choose your option, Stranger: ")
4 switch option {
5 case string('l'):
6 fmt.Println("Starting leon's playthrough...")
7 err := sd.StartGame("L", core.Handguns, core.Shotguns, core.Rifles, core.Subs, core.Magnums)
8 if err != nil {
9 print(err.Error() + "\n")
10 os.Exit(1)
11 }
12 ready = true
13 case string('a'):
14 fmt.Println("Starting Ada's playthrough...")
15 err := sd.StartGame("A", core.AdaHandguns, core.AdaShotguns, core.AdaRifles, core.AdaSubs, core.AdaSpecials)
16 if err != nil {
17 print(err.Error() + "\n")
18 os.Exit(1)
19 }
20 ready = true
21 case string('q'):
22 fmt.Println("Quit command sent.")
23 os.Exit(0)
24 case string('h'):
25 fmt.Println("Printing Help.")
26 fmt.Println("a to roll for Seperate Ways")
27 fmt.Println("l to roll Main playthrough")
28 fmt.Println("q to quit app")
29 }
30 if ready {
31 break
32 }
33 }
With this added, the user now will now choose Leon or Ada and then you can roll for weapons like normal. The CLI is now ready to handle the new API changes. Now we can start working on the UI. I’ll download some of the new JPEGS for Ada’s weapons and we’ll learn a little bit of Fyne.