Skip to content
Extraits de code Groupes Projets
Valider c19a8936 rédigé par Enzo De Carvalho Bittencourt's avatar Enzo De Carvalho Bittencourt
Parcourir les fichiers

first commit DARE v0.1

parent
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
#!/usr/bin/env python
"""
File that implements DARE dice-system for my tabletop game
"""
import dice
import codecs
class SpecialDice(dice.Dice):
def __init__(self, n, name):
"""init a special dice"""
super().__init__(n)
self.name=str(name)
return None
def __str__(self):
if self.value != None:
return self.name+str(self.n)+"["+str(self.value)+"]"
else:
return self.name+str(self.n)
def __repr__(self):
return "SDice object : "+str(self)
def __lt__(self, otherdice):
return self.n <= otherdice.n
class LatencyQueue():
def __init__(self):
"""init the Latency Queue"""
self.oneQueue = []
self.twoQueue = []
def add(elt, index):
"""put elt in the indexQueue"""
if index == 1:
self.oneQueue.append(elt)
return None
elif index == 2:
self.oneQueue.append(elt)
return None
else:
return None
def move(self):
ret = self.oneQueue
self.oneQueue = self.twoQueue
self.twoQueue = []
return ret
def __str__(self):
return "2:"+str(self.twoQueue)+"1:"+str(self.oneQueue)
def __repr__(self):
return "Latency Queue Object :"+str(self)
def logo():
print(
"""
\033[38;5;195m
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣶⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⢴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠢⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⣼⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⡀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣿⣿⠽⠿⢛⢻⢟⡽⣛⣿⢿⣿⣿⣿⠿⣿⣿⣿⣿⣿⣟⣻⠿⣿⣻⣙⠛⠾⣄⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢀⣽⡈⡋⠠⠀⡀⣈⢚⣥⢽⢫⢦⣷⣾⢋⣺⣷⣻⣿⠫⢿⣿⣿⣿⣖⡸⣿⣝⠿⣧⣘⡷⡀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢿⣶⣾⣿⣿⣁⣣⣾⡞⠚⢂⡤⠂⠃⡗⢾⢿⣯⡾⢿⣿⣿⣿⣶⣿⡿⣿⡟⣓⢧⣛⡗⢹⣿⣿⣷⡀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠙⣿⠋⡿⠉⢩⣿⢟⣀⡍⠀⠀⠘⣿⣬⣶⣷⣿⣿⣿⣿⣝⣿⠇⠣⠿⣿⣶⠋⡽⢽⠽⢣⣿⣧⠑⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢻⡀⠅⠀⢹⠟⠿⠊⢉⢀⢘⣮⣿⣿⣿⣿⣿⣏⡈⢙⣽⣛⡄⡇⠂⠘⢾⢟⡓⠒⠿⡁⢉⣿⡦⣇\033[38;5;193m
██████ █████ ██████ ███████
██ ██ ██ ██ ██ ██ ██
██ ██ ███████ ██████ █████
██ ██ ██ ██ ██ ██ ██
██████ ██ ██ ██ ██ ███████⠀⠀⠀\033[38;5;214m ⠀⠀⠀⠀
⠀ Dice As REssources (v0.1)⠀⠀⠀⠀⠀⠀\033[38;5;195m ⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠐⠐⠲⣦⣀⣄⡀⠀⡀⢀⢀⣠⣀⢆⡒⡀⢢⣶⣶⣶⠖⣴⠤⣆⣲⢖⣆⣶⣦⣤⣐⠒⠀⠀⠠⠠⣤⢶⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠂⠡⣿⣿⠦⣄⣒⣿⡁⢠⣍⡳⠈⢸⣼⣿⣽⣹⣿⡽⠉⢾⣷⣸⠙⢞⣝⡿⠲⣒⣀⠔⠋⢀⠃⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢋⣦⡀⠀⠋⠁⠀⠀⠥⠀⠀⠁⢀⡀⡸⣿⣼⣳⢴⡻⡣⣄⡌⣿⣏⣶⠾⢓⠾⠶⠁⣁⣤⡤⠁⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠨⠿⣷⠀⠀⢀⠀⠀⠀⠄⠀⣴⡟⠻⣿⡊⡦⢮⢁⡅⠀⠁⠈⠁⠀⠀⣀⣤⣤⣶⣿⣿⠟⠁⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠁⠀⠀⢀⣀⣉⣉⡭⡻⢇⠀⢀⢠⣀⣤⣤⣶⣾⣾⣷⣿⣿⣿⣿⠟⠋⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠁⠀⠐⣦⣶⣚⠻⢿⣿⣿⣷⣗⣤⠊⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠟⣺⡟⡾⣯⣛⣿⣿⣿⣚⣛⣛⣿⡿⣛⠿⠛⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠛⠛⠓⠒⠋⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
\033[0m
"""
)
def art():
f = codecs.open("art", "r", encoding="utf-8")
art = f.read()
f.close()
print("\033[2J\033[0;0H",end="")
print(art)
print(
"""
\033[38;5;148m\033[11;10H ██████ █████ ██████ ███████
\033[38;5;149m\033[12;10H ██ ██ ██ ██ ██ ██ ██
\033[38;5;150m\033[13;10H ██ ██ ███████ ██████ █████
\033[38;5;151m\033[14;10H ██ ██ ██ ██ ██ ██ ██
\033[38;5;152m\033[15;10H ██████ ██ ██ ██ ██ ███████
\033[38;5;223m\033[16;16H Dice As REssources \033[0m\033[25;0H"""
)
return None
def line():
print("\033[38;5;240m------------------------------------------------\033[0m",end="")
return None
def ask(symbol):
out = input("\033[38;5;217m"+symbol+">\033[0m")
return out
if __name__=="__main__":
from types import SimpleNamespace
##INITVAR
S = SimpleNamespace()
S.PHIdicepool = []
S.PSIdicepool = []
S.PDiceTray = dice.DiceTray() #PHI DiceTray
S.pDiceTray = dice.DiceTray() #pSI DiceTray
S.Latency = LatencyQueue()
S.PHIqueue = [SpecialDice(2,"Ψ"),SpecialDice(6,"Ψ")]
S.PSIqueue = [SpecialDice(2,"Ψ"),SpecialDice(6,"Ψ")]
S.thro = ["dx"]
S.name = ""
S.PDiceTray.add(SpecialDice(2,"Ψ"))
art()
## get init param :
print(
"""
Please give your (sur)name"""
)
S.name=ask("name?")
if S.name == "": S.name = "Ninten"
print(
"""
Please give your PHI dice pool
formatting is expected to be such as :
d4,d4,d6,d4,d8 (no spaces at the start !)"""
)
uinput = ask("Φ?")
if uinput=="":uinput="d4,d4,d4,d6,d6,d6"
argsdice = uinput.split(",")
S.PHIdicepool = []
for e in argsdice:
dval = int(e[1:])
S.PHIdicepool.append(SpecialDice(dval,"Φ"))
S.PHIdicepool.sort()
print(
"""
Please give your PSI dice pool
(same format)"""
)
uinput=ask("Ψ?")
if uinput=="":uinput="d4,d4,d4,d6,d8"
argsdice = uinput.split(",")
S.PSIdicepool = []
for e in argsdice:
dval = int(e[1:])
S.PSIdicepool.append(SpecialDice(dval,"Ψ"))
S.PSIdicepool.sort()
def stupidPrint(mlist):
out = ""
for e in mlist:
out += str(e)+" "
return out
def printDiceTray():
print(" ROL [ \033[38;5;214m"+stupidPrint(S.PDiceTray)+"\033[38;5;159m"+stupidPrint(S.pDiceTray)+"\033[0m] ")
def printallstat(ShowDiceTray=False):
print("\033[38;5;214m PHI \033[38;5;10m [ "+stupidPrint(S.PHIdicepool)+"]\033[0m "
,end="")
if not S.PHIqueue: print("") #list is empty
else:
print("\033[38;5;64m < "+str(S.PHIqueue[0])+"\033[38;5;242m "+stupidPrint(S.PHIqueue[1:])+"< \033[0m " )
print("\033[38;5;214m PSI \033[38;5;159m [ "+stupidPrint(S.PSIdicepool)+"]\033[0m "
,end="")
if not S.PSIqueue: print("")
else:
print("\033[38;5;67m < "+str(S.PSIqueue[0])+"\033[38;5;242m "+stupidPrint(S.PSIqueue[1:])+"< \033[0m " )
if S.Latency.oneQueue or S.Latency.twoQueue: # not empty
print("\033[38;5;202 LAT \033[38;5;242m 1[ "+stupidPrint(S.Latency.oneQueue)+"] 2[ "+stupidPrint(S.Latency.twoQueue)+"]")
if ShowDiceTray:
printDiceTray()
if S.thro:
print("\033[38;5;242m DEL [ "+stupidPrint(S.thro)+"]\033[0m")
line()
print("\nWelcome "+S.name+" !")
while True:
printallstat(True)
print(
"""
Please type your command. Type \033[1m help \033[0m
To see available command or \033[1m help <command> \033[0m
To get an explanation of a command"""
)
ask("command?")
Fichier ajouté
                                                  
                  .----=====-::.                  
             .-+**###*+++*******++-:              
           -=*###*+++++===**++=======-:           
         -****++++++=+==+++==--------=+=:         
       -**+++===--==-+++++++=---------+*+=.       
      =*+=++++++*+==#*+*+*=--=-=++++#*=====:      
     =+==++*#*+**#+=%%*##+-=#++*+=--*#=+==-=:     
    =*+=-==+**#++*****##*#++++=::::-----*+=-=:    
   -*+++--=+--**+++%%##++=-+=*==--::---=-=*+=-    
   +=++*+==+--+++++###+=--:-=--==:-:::----=+==:   
  .+==*#++=-=**+++++=-==--:--:::::--::-::----=-   
  .+--==-+-:-===**+**=--=-:::::::::-+-=-::=----   
  .+--====+*==--=*#%%*===--:-:::::::-===::-:-=-   
   ++**=-=*##*=--=+*#@@@@@@#*=:--===-:-+-:---=:   
   :*#@==+++++:.-+=*+=+@@@@@#+--=++*+:--#-:-=-    
    =*@*=+++*#*=-=*%@%%@@%#**=-=+=#%***+*+=--.    
     -%@**+*+=#@**%#@@%##*+++===-=+*==*#*==-.     
      -#*#+#%+*@%##+*###*+*++++++=----==---.      
       .=+++##=+*#%#%@#*#%%###+++++++++==-.       
         :=+*%%%@@@%@@@@@@@@@@##***++++=:         
           .=*#%%@@#@@@@@@@@@%%#***+=-.           
              .:=+#*#%%%%%#***+++=:.              
                   .:::----:::..                  
                                                  
Ce diff est replié.
"""
File that describe a simple dice class.
"""
import random
import copy
class Dice:
"""Class that represent a dice"""
def __init__(self, n):
"""init a dn dice, with no init value (not rolled)"""
#error checking
if not(isinstance(n,int)): raise TypeError("not an int to init dice")
if n < 1: raise ValueError("dice value should be > 0")
self.n = n
self.value = None
return None
def roll(self):
"""roll the dice"""
self.value = random.randrange(self.n)+1
return self.value
def reset(self):
"""put dice in a "nonrolled" state"""
self.value = None
return self
def __repr__(self):
return "Dice object : "+str(self)
def __str__(self):
if self.value != None:
return "d"+str(self.n)+"["+str(self.value)+"]"
else:
return "d"+str(self.n)
class DiceTray:
"""Class that represent a dice tray"""
def __init__(self, *args):
self.tray = []
for e in args:
#error checking
if not(isinstance(e, Dice)):
self.tray.append(Dice(e))
else:
self.tray.append(copy.deepcopy(e.reset()))
return None
def roll(self, *args):
"""roll some dice"""
for index in args : self.tray[index].roll()
return self
def rollall(self):
"""roll all dice"""
for e in self.tray : e.roll()
return self
def reset(self):
"""reset all dice"""
for e in self.tray : e.reset()
return self
def remove(self, index):
return self.tray.pop(index)
def add(self, dice):
self.tray.append(copy.deepcopy(dice.reset()))
return self
def __iter__(self):
return iter(self.tray)
def __str__(self):
stroutput = "{ "
for k,v in enumerate(self.tray):
stroutput += str(k)+":"+str(v)+" "
return stroutput+"}"
def __repr__(self):
return "Dice Tray : "+str(self)
earth.jpg

672 ko

0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter