jeudi 5 novembre 2020

Die Roller to import in other Python Projects

I need to come up with a short function in Python to simply roll dice.

  1. It needs to be able to imported into other projects.
  2. Be able to receive any ammount of rolls and sides.
  3. And needs to be able to randomly select things in other files.

What I really need this for, is a text style game. The die roller would be used to select a name, history, stats etcfor a player.

I have tried many different things and cant seem to find it.

Here is an example of what I will need to use it for:

def nameGen():
    Syl1 = ["Mar", "Kar", "Mon", "Don", "Ben", "Sim", "Car", "Ar", "Par", "Kal"]
    Syl2 = "cus lon tin bin bon son zon eon".split()
    Syl3 = "ly thy on ight".split()
    First = Syl1[randint(0, len(Syl1) - 1)]
    Second = Syl2[randint(0, len(Syl2) - 1)]
    Last = Syl3[randint(0, len(Syl3) - 1)]
    return "Your name" + " " + First + Second + Last + ", "
print(nameGen())

def historyGen():
    Hisyl = ["You have been worthless your entire life living with your parents and have no job. While you may not be much you are well liked. You have a natural ability to commit crimes, while being bad at hiding them which is why you are in prison for 5 years",
        "You live in the mountains far far far away from any human contact, so much so you've never encountered interaction with another human in your life. While you may not know what a human is you do know what animals are. You are able to fight, kill or call for any animal without any tools.",
        "You are in college. You are what some think as the funnest person ever. You love to party, tailgate, and all that stuff, but you absolutely do nothing when it comes to school, but yet somehow you still seem to be smarter than others",
        "You are rich, none knows how nor why we just know that you are. You live a life of luxury, with your mansions, cars, boats etc. You aren't great at much though as you just pay your way through life.",
        "Congrats! Your truly the Jack of all trades. It doesn't get much better than you. You can do it all. Your a fighter, runner, swimmer, climber, jumper and nothing can get in your way."]
    Species = "Human Alien AI Ghost Zombie Mummy ".split()
    Weakness = "Fatigue Speed Strength Agility Accuracy Heights Water Climbing".split()
    Place = Hisyl[randint(0, len(Hisyl) - 1)]
    Spec = Species[randint(0, len(Species) - 1)]
    Weak = Weakness[randint(0, len(Weakness) - 1)]
    return "About you," + Place + "," + " You are a " + Spec + "," + " And your Weakness is " + Weak
print(historyGen())

def GenAttack():
    attack = "punch kick stab shoot slam choke".split()
    return attack[randint(0,len(attack)-1)]

def GenDefense():
     affect = randint(5,100)
     return affect



def GenHealth():
    heal = randint(0,100)
    return heal






def GenPlayer(level):
    Player = {}
    Player ["name"] = nameGen()
    Player ["history"] = historyGen()
    Player ["attack"] = GenAttack()
    Player["defense"] = GenDefense()
    Player["health"] = GenHealth()
    Player["row"] = 0
    Player["col"] = 0
    return Player

And here is what I have for the roller but it doesn't work:

def DieRoller(times,sides):
    # Rolls any amount of dice and any amount of sides and returns the sum
    total = 0 #accumulator
    for i in range(times):
        roll = randint(1,sides)
        total += roll #total = total + roll
    return total



Aucun commentaire:

Enregistrer un commentaire