学了一段golang,觉得应该实践一下,写了这个猜拳小游戏,顺带着学习下go testing。
主程序源码:
package main import ( "bufio" // 输入输出 "fmt" "math" "math/rand" "os" "strconv" "time" ) //rock, paper, scissors const ( rock int = 1 scissors int = 2 paper int = 3 rockName string = "石头" scissorsName string = "剪刀" paperName string = "布" win int = 1 lose int = -1 draw int = 0 ) // 拳的结构 type Finger struct { value int name string } func createFinger(n int) (finger Finger) { switch n { case rock: finger.value = rock finger.name = rockName case scissors: finger.value = scissors finger.name = scissorsName case paper: finger.value = paper finger.name = paperName } return } fun