-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.go
91 lines (85 loc) · 1.73 KB
/
commands.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"fmt"
)
func homeCommands(resp []string) bool{
switch(resp[0]){
case "/create":
if(len(resp) > 1){
switch(resp[1]){
case "new":
if(len(resp) > 2 && resp[2] == "game"){
if(len(resp) == 5 && resp[3] == "as"){
createGame(resp[4]);
}else{
var username string
fmt.Println("Type your username: ");
fmt.Scanf("%s", &username)
createGame(username);
}
fmt.Println("create");
}
case "-h":
fmt.Println("/create: ");
fmt.Println("new game: creates new game and wait for players");
default:
commandNotFound("create");
}
}else{
commandNotFound("create");
}
case "/join":
if(len(resp) > 1){
if(len(resp) > 3 && resp[2] == "as"){
joinGame(resp[1], resp[3]);
}
if(resp[1] == "-h"){
fmt.Println("/join [addr]")
}
}else{
commandNotFound("join");
}
case "/exit":
return false;
default:
if(len(resp) > 0){
fmt.Println("/!\\ '" + resp[0] + "' is not a command");
}
}
return true;
}
func lobbyCommands(resp []string) int{
switch(resp[0]){
case "/players":
for key, value := range(players){
fmt.Println("[" + key + "] => " + value.String());
}
case "/start":
return 1;
case "/exit":
return -1;
}
return 0;
}
func gameCommands(resp []string, boats [] boat){
if(len(resp) > 0){
switch(resp[0]){
case "/gameSet":
if(len(resp) == 1){
fmt.Println(getGameSet(true, boats));
}
if(len(resp) == 2 ){
askForGameSet(resp[1]);
}
case "/players":
if(len(resp) == 1){
for username, _ := range(players) {
fmt.Println(username);
}
}
}
}
}
func commandNotFound(command string){
fmt.Println("/!\\ Command not found type '/"+ command +" -h' for help");
}