|
| 1 | +package gamelogic |
| 2 | + |
| 3 | +import ( |
| 4 | + "bufio" |
| 5 | + "errors" |
| 6 | + "fmt" |
| 7 | + "math/rand" |
| 8 | + "os" |
| 9 | + "strings" |
| 10 | +) |
| 11 | + |
| 12 | +func PrintClientHelp() { |
| 13 | + fmt.Println("Possible commands:") |
| 14 | + fmt.Println("* move <location> <unitID> <unitID> <unitID>...") |
| 15 | + fmt.Println(" example:") |
| 16 | + fmt.Println(" move asia 1") |
| 17 | + fmt.Println("* spawn <location> <rank>") |
| 18 | + fmt.Println(" example:") |
| 19 | + fmt.Println(" spawn europe infantry") |
| 20 | + fmt.Println("* status") |
| 21 | + fmt.Println("* spam <n>") |
| 22 | + fmt.Println(" example:") |
| 23 | + fmt.Println(" spam 5") |
| 24 | + fmt.Println("* quit") |
| 25 | + fmt.Println("* help") |
| 26 | +} |
| 27 | + |
| 28 | +func ClientWelcome() (string, error) { |
| 29 | + fmt.Println("Welcome to the Peril client!") |
| 30 | + fmt.Println("Please enter your username:") |
| 31 | + words := GetInput() |
| 32 | + if len(words) == 0 { |
| 33 | + return "", errors.New("you must enter a username. goodbye") |
| 34 | + } |
| 35 | + username := words[0] |
| 36 | + fmt.Printf("Welcome, %s!\n", username) |
| 37 | + PrintClientHelp() |
| 38 | + return username, nil |
| 39 | +} |
| 40 | + |
| 41 | +func PrintServerHelp() { |
| 42 | + fmt.Println("Possible commands:") |
| 43 | + fmt.Println("* pause") |
| 44 | + fmt.Println("* resume") |
| 45 | + fmt.Println("* quit") |
| 46 | + fmt.Println("* help") |
| 47 | +} |
| 48 | + |
| 49 | +func GetInput() []string { |
| 50 | + fmt.Print("> ") |
| 51 | + scanner := bufio.NewScanner(os.Stdin) |
| 52 | + scanned := scanner.Scan() |
| 53 | + if !scanned { |
| 54 | + return nil |
| 55 | + } |
| 56 | + line := scanner.Text() |
| 57 | + line = strings.TrimSpace(line) |
| 58 | + return strings.Fields(line) |
| 59 | +} |
| 60 | + |
| 61 | +func GetMaliciousLog() string { |
| 62 | + possibleLogs := []string{ |
| 63 | + "Never interrupt your enemy when he is making a mistake.", |
| 64 | + "The hardest thing of all for a soldier is to retreat.", |
| 65 | + "A soldier will fight long and hard for a bit of colored ribbon.", |
| 66 | + "It is well that war is so terrible, otherwise we should grow too fond of it.", |
| 67 | + "The art of war is simple enough. Find out where your enemy is. Get at him as soon as you can. Strike him as hard as you can, and keep moving on.", |
| 68 | + "All warfare is based on deception.", |
| 69 | + } |
| 70 | + randomIndex := rand.Intn(len(possibleLogs)) |
| 71 | + msg := possibleLogs[randomIndex] |
| 72 | + return msg |
| 73 | +} |
| 74 | + |
| 75 | +func PrintQuit() { |
| 76 | + fmt.Println("I hate this game! (╯°□°)╯︵ ┻━┻") |
| 77 | +} |
| 78 | + |
| 79 | +func (gs *GameState) CommandStatus() { |
| 80 | + if gs.isPaused() { |
| 81 | + fmt.Println("The game is paused.") |
| 82 | + return |
| 83 | + } else { |
| 84 | + fmt.Println("The game is not paused.") |
| 85 | + } |
| 86 | + |
| 87 | + p := gs.GetPlayerSnap() |
| 88 | + fmt.Printf("You are %s, and you have %d units.\n", p.Username, len(p.Units)) |
| 89 | + for _, unit := range p.Units { |
| 90 | + fmt.Printf("* %v: %v, %v\n", unit.ID, unit.Location, unit.Rank) |
| 91 | + } |
| 92 | +} |
0 commit comments