1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00
This commit is contained in:
Steffo 2016-04-05 17:12:17 +02:00
parent 8faec4496f
commit 12b1227d6e

View file

@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
import telegram
import pickle
class Player:
telegramid = int()
username = str()
role = 0 # 0 = normale, 1 = mifia
role = 0 # 0 normale | 1 rryg | 2 resistenza
alive = True
votedfor = str()
special = False
@ -35,7 +35,7 @@ class Game:
telegram.sendmessage(text, self.adminid)
def evilmessage(self, text):
"""Manda un messaggio alla chat generale del gioco
"""Manda un messaggio al team dei nemici del gioco
:param text: Testo del messaggio
"""
for player in self.players:
@ -60,7 +60,7 @@ class Game:
if not player.alive:
tosend += "\U0001F480 "
elif player.role == 1:
tosend += "_Mifia_ "
tosend += "RRYG "
else:
tosend += "\U0001F636 "
tosend += player.username + "\n"
@ -94,4 +94,52 @@ class Game:
def mostvoted(self):
"""Trova il giocatore più votato"""
votelist = dict()
for player in self.players:
if player.votedfor != str():
if player.votedfor not in votelist:
votelist[player.votedfor] = 1
else:
votelist[player.votedfor] += 1
mostvoted = str()
mostvotes = int()
for player in votelist:
if mostvoted == str():
mostvoted = player
mostvotes = votelist[player]
else:
if votelist[player] > mostvotes:
mostvoted = player
mostvotes = votelist[player]
return self.findusername(mostvoted)
def save(self):
"""Salva in un file di testo con il numero del gruppo lo stato attuale del gioco"""
try:
file = open(str(self.groupid) + ".txt", "w")
except OSError:
file = open(str(self.groupid) + ".txt", "x")
pickle.dump(self, file)
def endday(self):
for player in self.players:
player.votedfor = str()
if player.role != 0:
player.special = True
killed = self.mostvoted()
killed.alive = False
self.message(killed.username + " è stato il più votato del giorno.")
def load(filename):
"""Restituisci da un file di testo con il numero del gruppo lo stato del gioco (Funzione non sicura, non importare
file a caso pls)
:param filename: Nome del file da cui caricare lo stato"""
try:
file = open(str(filename) + ".txt", "r")
except OSError:
return None
else:
return pickle.load(file)
partiteincorso = list()