-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc.go
56 lines (49 loc) · 1.24 KB
/
func.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"math/rand"
"time"
"github.com/yanzay/tbot/v2"
)
var picks = []string{"rock", "paper", "scissors"} // choices from where the bot picks
func init() {
rand.Seed(time.Now().Unix()) // initialize global pseudo random generator
}
func makeButtons() *tbot.InlineKeyboardMarkup {
// Create butttons with visible Text and CallbackData as a value.
btnRock := tbot.InlineKeyboardButton{
Text: "Rock",
CallbackData: "rock",
}
btnPaper := tbot.InlineKeyboardButton{
Text: "Paper",
CallbackData: "paper",
}
btnScissors := tbot.InlineKeyboardButton{
Text: "Scissors",
CallbackData: "scissors",
}
return &tbot.InlineKeyboardMarkup{
InlineKeyboard: [][]tbot.InlineKeyboardButton{
[]tbot.InlineKeyboardButton{btnRock, btnPaper, btnScissors},
},
}
}
func (a *application) draw(humanMove string) (msg string) {
var result string
botMove := picks[rand.Intn(len(picks))] // Generaate a random option for the bot
// Determine the outcome
switch humanMove {
case botMove:
result = "drew"
a.draws++
case options[botMove]:
result = "lost"
a.losses++
default:
result = "won"
a.wins++
}
msg = fmt.Sprintf("You %s! You chose %s and I chose %s.", result, humanMove, botMove)
return
}