Skip to content

Instantly share code, notes, and snippets.

@gautamrege
Last active April 4, 2020 05:55
Show Gist options
  • Save gautamrege/1583f228e81f1fe0a9132864e578b18c to your computer and use it in GitHub Desktop.
Save gautamrege/1583f228e81f1fe0a9132864e578b18c to your computer and use it in GitHub Desktop.
Hangman - Part 1 (working basic)
package main
import (
"fmt"
"strings"
)
func main() {
word := "elephant"
// lookup for entries made by the user.
entries :=
// list of "_" corrosponding to the number of letters in the word. [ _ _ _ _ _ ]
placeholder :=
for {
// evaluate a loss! If user guesses a wrong letter or the wrong word, they lose a chance.
// evaluate a win!
// Console display
fmt.Println("\n")
fmt.Println() // render the placeholder
fmt.Printf() // render the chances left
fmt.Printf() // show the letters or words guessed till now.
fmt.Printf("Guess a letter or the word: ")
// take the input
str := ""
fmt.Scanln(&str)
// compare and update entries, placeholder and chances.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment