-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.py
More file actions
57 lines (37 loc) · 1.35 KB
/
Client.py
File metadata and controls
57 lines (37 loc) · 1.35 KB
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
import socket
import time as sleep
import pygame
import sys
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((300,200))
print("Kører klienten\n")
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
host = "172.20.10.10"
port = 5454
def send(msg):
dataKodet = msg.encode("UTF-8")
s.sendto(dataKodet, (host, port))
print(msg)
while True:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN and event.key == pygame.K_UP:
send("frem")
elif event.type == pygame.KEYUP and event.key == pygame.K_UP:
send("stop")
elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN:
send("tilbage")
elif event.type == pygame.KEYUP and event.key == pygame.K_DOWN:
send("stop")
elif event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT:
send("venstre")
elif event.type == pygame.KEYUP and event.key == pygame.K_LEFT:
send("stop")
elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT:
send("højre")
elif event.type == pygame.KEYUP and event.key == pygame.K_RIGHT:
send("stop")