Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "math/rand"
- "time"
- )
- func main() {
- // Set a random object
- r := rand.New(rand.NewSource(time.Now().UnixNano()))
- // The initial state of our runner.
- miles := 0
- GAME_OVER:
- for {
- // Get a new game state for each round.
- state := r.Intn(10)
- // Update the state of our runner.
- switch state {
- case 7:
- fmt.Println("Jump!")
- miles += 3
- case 0:
- fmt.Println("You FAIL")
- break GAME_OVER
- case 6:
- fmt.Println("Missed!")
- miles -= 2
- default:
- fmt.Println("Walk")
- miles += 1
- }
- // End the game if you win.
- if miles >= 10 {
- fmt.Println("You WIN")
- break GAME_OVER
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement