summaryrefslogtreecommitdiffstats
path: root/alcogotchi-server/alcogotchi.py
diff options
context:
space:
mode:
authorLeightonGinty <57670831+LeightonGinty@users.noreply.github.com>2024-11-17 00:52:43 +0000
committerGitHub <noreply@github.com>2024-11-17 00:52:43 +0000
commit8ddf8f862bb2cc97d1253c917bdda8dad0f080a9 (patch)
treec3877eacc3e4bf8d8a79f68aff7e132ff89e3b91 /alcogotchi-server/alcogotchi.py
parent8fa27057759b9b233588584a7aa6be0e72122785 (diff)
Fix the booze
Diffstat (limited to 'alcogotchi-server/alcogotchi.py')
-rw-r--r--alcogotchi-server/alcogotchi.py34
1 files changed, 15 insertions, 19 deletions
diff --git a/alcogotchi-server/alcogotchi.py b/alcogotchi-server/alcogotchi.py
index 415ee83..7052be3 100644
--- a/alcogotchi-server/alcogotchi.py
+++ b/alcogotchi-server/alcogotchi.py
@@ -3,7 +3,6 @@ import socket
import _thread
import time
import random
-
BEVERAGES = {"beer": 2.5, "wine": 3, "whisky": 2, "lemonade": 0}
class Alcogotchi:
@@ -13,35 +12,31 @@ class Alcogotchi:
self.drunk = 0
self.health = 100
self.alco_coin = 100
- self.items = {"food": 0, "beer": 0}
+ self.items = {}
def get_alcogotchi(self):
- self.last_drunkentime = time.time()
return self.__dict__
def double_or_nothing(self, data):
- self.last_drunkentime = time.time()
- bet = dict(data)["bet"]
- if self.alco_coin > bet:
+ if self.alco_coin > 0:
+ bet = dict(data)["bet"]
self.alco_coin += random.choice([-bet, bet])
return self.get_alcogotchi()
- raise Exception("You got no coin")
-
+ else:
+ raise Exception("You got no coin")
def buy_item(self, data):
- self.last_drunkentime = time.time()
- item = dict(data)["item"]
- if item in self.items:
- self.alco_coin -= 3
- self.items[item] += 1
- raise Exception("Item doesn't exist")
-
+ item = dict(data)["item"]
+ self.alco_coin -= 3
+ if item in self.items:
+ self.items[item] += 1
+ else:
+ self.items[item] = 1
def drink(self, data):
drink_choice = data["drink"]
- self.drunk += BEVERAGES[drink_choice]
+ self.drunk += BEVERAGES[str(drink_choice)]
if self.last_drunkentime + 60 < time.time():
self.last_drunkentime = time.time()
- self.drunk += 10
- self.drunk = max(100, self.drunk)
+ self.drunk = min(100, self.drunk)
return self.get_alcogotchi()
alcogotchi = Alcogotchi("Brian")
@@ -103,11 +98,12 @@ 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()
+server.add_route("/text", lambda: "Hello World!")
server.add_route("/", alcogotchi.get_alcogotchi)
server.add_route("/drink", alcogotchi.drink)