summaryrefslogtreecommitdiffstats
path: root/alcogotchi-server/alcogotchi.py
diff options
context:
space:
mode:
Diffstat (limited to 'alcogotchi-server/alcogotchi.py')
-rw-r--r--alcogotchi-server/alcogotchi.py56
1 files changed, 41 insertions, 15 deletions
diff --git a/alcogotchi-server/alcogotchi.py b/alcogotchi-server/alcogotchi.py
index 2385561..7402ff3 100644
--- a/alcogotchi-server/alcogotchi.py
+++ b/alcogotchi-server/alcogotchi.py
@@ -7,7 +7,11 @@ from random import randint
BEVERAGES = {"beer": 2.5, "wine": 3, "whisky": 2, "lemonade": 0}
driving = False
+terminated = False
+def play_music_once(melody_name):
+ buzzer.melody(melody_name)
def drive(base_speed):
+ global driving
screen.rect(0,0,160,128,(0, 0, 0),1)
driving = True
happiness = 9
@@ -19,6 +23,8 @@ def drive(base_speed):
opposing_vehicle_ys = [0,0,0]
number_of_vehicles = 10
+ base_speed *= 2.5
+ base_speed = int(base_speed)
opposing_vehicle_speeds = [randint(base_speed,base_speed+range_speed) for i in range(number_of_vehicles)]
opposing_vehicle_lanes = [randint(0,3) for i in range(number_of_vehicles)]
playing = True
@@ -26,14 +32,14 @@ def drive(base_speed):
for i in range(len(opposing_vehicle_ys)):
screen.rect(13+opposing_vehicle_lanes[i]*40, opposing_vehicle_ys[i],20,40,(500, 500, 555),1)
def play_music(CHASE):
- while True:
+ global driving
+ while driving:
buzzer.melody(CHASE)
CHASE = "a4:1 b c5 b4 a:2 r a:1 b c5 b4 a:2 r a:2 e5 d# e f e d# e b4:1 c5 d c b4:2 r b:1 c5 d c b4:2 r b:2 e5 d# e f e d# e "
- # new_thread = _thread.start_new_thread(play_music, [CHASE])
-
+ new_thread = _thread.start_new_thread(play_music, [CHASE])
while playing and driving:
driving_time += 1
if driving_time > 100:
@@ -42,7 +48,7 @@ def drive(base_speed):
# WAWA = "e3:3 r:1 d#:3 r:1 d:4 r:1 c#:8 "
startup_time += 1
- if startup_time >= 3:
+ if startup_time >= 10:
for i in range(len(opposing_vehicle_ys)):
opposing_vehicle_ys[i]+=opposing_vehicle_speeds[i]
if 80 <= (opposing_vehicle_ys[i]+40) <= 120 and opposing_vehicle_lanes[i] == lane:
@@ -90,10 +96,10 @@ def drive(base_speed):
screen.rect(13,80,20,40,(0, 0, 0),1)
screen.rect(53,80,20,40,(0, 0, 0),1)
screen.rect(93,80,20,40,(0, 0, 0),1)
-
screen.refresh()
else:
screen.rect(0,0,160,128,(0, 0, 0),1)
+ driving = False
return True
screen.text("GAME OVER", x=10, y=90, ext=1, color=255)
driving = False
@@ -107,7 +113,8 @@ def s():
happiness = alcogotchi.happiness
health = alcogotchi.health
screen.loadPng('alcogotchi.png')
-
+
+ screen.text("Coin: {0}".format(alcogotchi.alco_coin), x=10, y=50, ext=1, color=255)
screen.text("Health", x=10, y=60, ext=1, color=255)
#screen.rect(10,100,150,10,(0, 0, 0),1)
screen.rect(10,70,int(health*1.2),10,(255-int(2.55*health), int(2.55*health), 0),1)
@@ -133,14 +140,22 @@ class Alcogotchi:
return self.__dict__
def double_or_nothing(self, data):
+ BA_DING = "b5:1 e6:3 "
+ ERROR = "a3:2 r a3:2 "
+
+
bet = dict(data)["bet"]
if self.alco_coin >= bet:
if random.randint(0,1) == 0:
self.alco_coin += bet
self.happiness += 2
+ new_thread = _thread.start_new_thread(play_music_once, [BA_DING])
else:
self.alco_coin -= bet
self.happiness -= 2
+ new_thread = _thread.start_new_thread(play_music_once, [ERROR])
+
+ s()
return self.get_alcogotchi()
s()
raise Exception("You got no coin")
@@ -150,10 +165,12 @@ class Alcogotchi:
if item in self.items and self.alco_coin > 3:
self.alco_coin -= 3
self.items[item] += 1
+ s()
return self.get_alcogotchi()
raise Exception("Item doesn't exist")
def drink(self, data):
+ global terminated
drink_choice = data["drink"]
if self.last_drunkentime + 8 < time.time() and self.items[drink_choice] > 0:
self.drunk += BEVERAGES[drink_choice]
@@ -161,21 +178,25 @@ class Alcogotchi:
self.last_drunkentime = time.time()
self.items[drink_choice] -= 1
self.health -= 1
- if self.health == 0:
- del self
+ if self.health <1:
+ terminated = True
self.drunk = min(100, self.drunk)
self.happiness = min(100, self.happiness)
s()
return self.get_alcogotchi()
def drive(self):
+ global terminated
crash = drive(int(self.drunk))
if crash:
- self.health -= 10
+ self.health -= 20
+ self.happiness -= 10
if self.health == 0:
- del self
- self.happiness += 10
- self.happiness = min(100, self.happiness)
+ terminated = True
+ self.happiness = max(self.happiness, 0)
+ else:
+ self.happiness += 10
+ self.happiness = min(100, self.happiness)
s()
return self.get_alcogotchi()
@@ -183,10 +204,11 @@ class Alcogotchi:
if self.happiness > 0:
self.happiness -= 1
self.alco_coin += 2
+ s()
return self.get_alcogotchi()
self.items["beer"] += 1
s()
- raise Exception("You're too sad to mine coin. Here have a beer :)")
+ raise Exception("You're too sad to mine coal. Here have a beer :)")
alcogotchi = Alcogotchi("Brian")
@@ -220,8 +242,9 @@ class Server:
)
def start(self):
+ global terminated
print("Server running on port {0}...".format(self.port))
- while True:
+ while not terminated:
self.connection, client_address = self._sock.accept()
try:
request = self.connection.recv(1024).decode().split("\r\n")
@@ -247,7 +270,7 @@ class Server:
ap = network.WLAN(network.AP_IF)
ap.active(True)
-ap.config(essid="Cool Server", password="password123")
+ap.config(essid="Cool Server1", password="password123")
print("Connection avalible on {0}".format(ap.ifconfig()))
server = Server()
@@ -261,3 +284,6 @@ server.add_route("/mine", alcogotchi.mine)
# _thread.start_new_thread(s, ())
s()
server.start()
+FUNERAL = "c3:4 c:3 c:1 c:4 d#:3 d:1 d:3 c:1 c:3 b2:1 c3:4 "
+time.sleep(5)
+buzzer.melody(FUNERAL)