-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (71 loc) · 1.84 KB
/
main.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
package main
import (
"flag"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
"golang.org/x/image/font/opentype"
"log"
"net"
)
// Setting up the fonts used for display.
func init() {
tt, err := opentype.Parse(fonts.MPlus1pRegular_ttf)
if err != nil {
log.Fatal(err)
}
smallFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: 30,
DPI: 72,
})
if err != nil {
log.Fatal(err)
}
largeFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: 50,
DPI: 72,
})
if err != nil {
log.Fatal(err)
}
}
// Creating an auxiliary image for displaying results.
func init() {
offScreenImage = ebiten.NewImage(globalWidth, globalHeight)
}
// Creation, configuration, and launch of the game.
func main() {
ip := flag.String("ip", "", "Adresse IP du serveur")
port := flag.String("port", "", "Port du serveur")
flag.Parse()
if *ip == "" || *port == "" {
log.Fatal("L'adresse IP/Port est obligatoire. Exemple : -ip 127.0.0.1 -port 8080")
}
conn, err := connectToServer(*ip, *port)
if err != nil {
log.Println("Erreur de connexion:", err)
return
}
defer conn.Close()
g := game{}
g.debug = false // Enables or disables debug mode.
g.serverConn = conn
g.startChan = make(chan bool, 1)
g.chosenColor = make(chan bool, 1)
g.p2Position = make(chan int, 1)
g.p2ColorChan = make(chan int, 1)
go g.handleServer()
ebiten.SetWindowTitle("Programmation système : projet puissance 4")
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
if err := ebiten.RunGame(&g); err != nil {
log.Fatal(err)
}
}
// Function to establish a connection with the server.
func connectToServer(ip, port string) (net.Conn, error) {
conn, err := net.Dial("tcp", ip+":"+port)
if err != nil {
return nil, err
}
log.Println("Client connecté avec succès à", ip+":"+port)
return conn, nil
}