7
\$\begingroup\$

This is the little tcg I made in Python. It's a bit basic I guess, but was still very fun to make. I know the code is a bit messy. If anyone has any ideas on how to improve it, I would love to hear them!

Basically, you can battle, visit different card shops, buy cards, pick up grab bags, open booster packs and booster boxs and more throughout the game!

import time
import sys
import random
##
class Player:

    def __init__(self, name):
        self.name = name
        self.money = 100
        self.cards = 0
        pass
class phrex:

    def __init__(self, name, value):
        self.name = name
        self.value = value
        self.phrex = 0
        pass

jug = phrex("Phrexian God", 3)
pala = phrex("Phrexian Paladin", 7)
god = phrex("Phrexian Anhillator", 13)
admin = phrex("Phrexian Godsend", 99999999999999999999999999999999999999999999)
p = Player("Player")
class emb:

    def __init__(self, name):
        self.emb = 0
        self.name = name
        pass
bbox = emb("Booster Stopper")

pjug = emb("Phrexian jug")
gjug = emb("god jug")
bjug = emb("lol")

def home():
    print("You are home. Your money:")
    print p.money
    time.sleep(1)
    print("1.) Your Local Card Shop")
    print("2.) Collection")   #TRADE????????????????????????????????? trade/get card graded?????
    print("3.) Get Cards Graded (On Condition)")
    print("4.) Sell cards") # make diff shops?
    print("5.) Go to a different card shop")
    print("6.) Battle")
    show = input("")
    if show == 1:
        cardshop()
    elif show == 2:
        collection()
    elif show == 3:
        psa()
    elif show == 4:
        sell()
    elif show == 5:
        alt()
    elif show == 6:
        battle()        
def bat():
    battle()
def battle():
    print("Here is the battle arena! Choose one:")
    print("1.) Deck Information")
    print("2.) Battle")
    print("3.) Back")
    battle1 = input("")
    if battle1 == 3:
        home()
    elif battle1 == 1:
        print("1.) Check your current decks")
        print("2.) Buy a deck")
        papi = input("")
        if papi == 1:
            print("1.) Basic Phrexian Deck")
            print("2.) Back")
            oh = input("")
            if oh == 1:
                print("It contains:")
                print("1 Coleas Admin Card ")
                time.sleep(1)
                print("1.) Back")
                leave = input("")
                if leave == 1:
                    bat()
        elif papi == 2:
            print("No decks avilable at the moment.")
            print("1.) Back")
            papo = input("")
            if papo == 1:
                bat()
    elif battle1 == 2:
        print("What deck do you want to use?")
        print("1.) Basic Phrexian Deck")
        papno = input("")
        if papno == 1:
            print("You selected the Basic Phrexian Deck!")
            time.sleep(1)
            print("You place down your 1 card, for each 50$ in that cards worth, flip a dice (3 sided), the person with the highest roll wins. ")
            print("You placed down Coleas Admin card, so you roll the dice 2 times.")
            time.sleep(1)
            print("Your opponent placed down Coleas Admin card, so they roll the dice 2 times.")
            olo = random.randint(1,3)
            if olo == 1:
                time.sleep(3)
                print("You rolled a 1")
                print("You rolled a 2")
                time.sleep(1)
                print("Your opponent rolled a 2")
                print("Your opponent rolled a 3")
                time.sleep(1)
                print("Your opponent wins.")
                bat()
            elif olo == 2:
                time.sleep(3)
                print("You rolled a 3")
                print("You rolled a 2")
                time.sleep(1)
                print("Your opponent rolled a 1")
                print("Your opponent rolled a 2")
                time.sleep(1)
                print("You win! You got 20$!")
                p.money += 20
                bat()
            elif olo == 3:
                time.sleep(3)
                print("You rolled a 3")
                print("You rolled a 3")
                time.sleep(1)
                print("Your opponent rolled a 2")
                print("Your opponent rolled a 3")
                time.sleep(1)
                print("You win! You got 20$!")
                bat()



def alt():
    print("You can go to the following shops:")
    print("1.) Back")
    print("2.) Coleas Grand Card Emporium")

    alt = input("")
    if alt == 1:
        home()
    if alt == 2:
        coae()
def coaes():
    coae()
def coae():
    print("Welcome To Coleas Grand Card Emporium.")
    print("We have a large array of cards.")
    time.sleep(1)
    print("1.) Back")
    print("2.) Buy a grab bag (1 Card) (5 Dollars)")
    co = input("")
    if co == 1:
        alt()
    elif co == 2:
        p.money -= 5
        altme = random.randint(1,3)
        if altme == 1:
            print("You got a Phrexian Anhillator! (Value: 13)")
            bjug.emb += 1
            time.sleep(1)
            coaes()
        elif altme == 2:
            print("You got a Coleas Admin Card! (Value: 100)")
            colea.emb += 1
            time.sleep(1)
            coaes()
        elif altme == 3:
            print("You got a Phrexian God! (Value: 3)")
            time.sleep(1)
            gjug.emb += 1
            coaes()





def cardshop():
    print("Welcome to the card shop.")
    print("1.) Buy pack of the set Phrexisland / 10 Dollars (1 Card) ")
    print("2.) Exit")
    print("3.) Buy Booster Box of the set Phrexisland / 15 Dollars (36 Packs)")
    print("4.) Buy Singles")
    cardshops = input("")
    if cardshops == 1:
        p.money -= 10 #bbox.emb
        cardslife = random.randint(1,3)



        if cardslife == 1:
            jug.phrex += 1
            print("You got a Phrexian God! Value: 3")
            gjug.emb += 1
            home()
        elif cardslife == 2:
            pala.phrex += 1
            print("You got a Phrexian Paladin! Value: 7")
            pjug.emb += 1
            home()
        elif cardslife == 3:
            bjug.emb += 1
            god.phrex += 1
            print("You got a Phrexian Anhillator! Value: 13")
            home()

    elif cardshops == 3:
        p.money -= 15
        boostersale()

    elif cardshops == 2:
        home()
    elif cardshops == 4:
        single()
colea = emb("Coleas Admin Card")
def singles():
    single()
def single():
    print("You can buy single cards:") # make cards
    print("1.) Back")
    print("2.) Coleas Admin Card (Value: 100)")
    csl = input("")
    if csl == 1:
        cardshop()
    elif csl == 2:
        print("You got 1 Coleas Admin Card!")
        colea.emb += 1
        p.money -= 100
        singles()


#pjug = emb("Phrexian jug") # paladin
#gjug = emb("god jug")   #g god
#bjug = emb("lol") # anhil
def collection():
    print("Phrexian Paladin: (Value: 7)")
    print pjug.emb
    time.sleep(2)
    print("Phrexian God: (Value: 3)")
    print gjug.emb
    time.sleep(2)
    print("Phrexian Anhillator: (Value: 13)")
    print bjug.emb
    time.sleep(2)
    print("Phrexian Godsend: (Value: 10000)")
    print a.emb
    time.sleep(2)
    print("Graded 10 Phrexian Anhillator: (Value: 2500)")
    print psa10.emb
    time.sleep(2)
    print("Coleas Admin Card:")
    print colea.emb
    time.sleep(2)
    finalcol()



####
def finalcol():
    print("1.) Home")
    papa = input("")
    if papa == 1:
        home()
###
def bboxs():
    time.sleep(1)
    boostersale()

a = emb("aemb")
def boostersale():
    bbox.emb += 1
    if bbox.emb == 36:
        bbox.emb -= 36
        home()
    else:
        cardslifes = random.randint(1,1000)
        if cardslifes == 1000:
            admin.phrex += 1
            print("JACKPOT!!! YOU GOT A PHREXIAN GODSEND VALUE: 10000 JACKPOT!!!")
            a.emb += 1
            bboxs()
        else:
            damn = random.randint(1,3)
            if damn == 1:
                jug.phrex += 1
                print("You got a Phrexian God! Value: 3")
                gjug.emb += 1
                bboxs()
            elif damn == 2:
                pala.phrex += 1
                print("You got a Phrexian Paladin! Value: 7")
                pjug.emb += 1
                bboxs()
            elif damn == 3:
                god.phrex += 1
                print("You got a Phrexian Anhillator! Value: 13")
                bjug.emb += 1
                bboxs()











def psa():
    print("Welcome To The PSA Grading Company! We grade cards from 1 to 10, 1 being the worst possible, 10 being pristine and unblemished condition.")
    time.sleep(1)
    print("We only grade Phrexian Anhillators at the moment.")
    print("1.) Grade a Phrexian Anhillator (150 Dollars)")
    print("2.) Leave")
    psa = input("")
    if psa == 2:
        home()
    if psa == 1:
        grade()

psa10 = emb("psa 10")
def grade():
    p.money -= 150
    bjug.emb -= 1
    bug = random.randint(1,5)
    if bug == 1:
        print("Your grade is 2")
        print("We cant case it unless its a 10. Sorry.")
        psa()
    elif bug == 2:
        print("Your grade is 4")
        print("We cant case it unless its a 10. Sorry.")
        psa()
    elif bug == 3:
        print("Your grade is 6")
        print("We cant case it unless its a 10. Sorry.")
        psa()
    elif bug == 4:
        print("Your grade is 8")
        print("We cant case it unless its a 10. Sorry.")
        psa()
    elif bug == 5:
        print("Your grade is 10")
        print("You now have a Graded 10 Phrexian Anhillator! ")
        psa10.emb += 1
        psa()

def sells():
    sell()

def sell():
    print("You can sell cards here! You can only sell Phrexian Anhillators at the moment.")
    print("1.) Sell")
    print("2.) Back")
    sellbob = input("")
    if sellbob == 1:
        print("You have sold 1 Phrexian Anhillator!")
        p.money += 13
        bjug.emb -= 1
        sells()
    elif sellbob == 2:
        home()



home()
\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to Code Review! The post looks pretty good. Are there any specific things you hope reviewers will focus on? If so, you might want to edit your post to include those, as well as any more details that might describe how the trading game works. \$\endgroup\$ – Sᴀᴍ Onᴇᴌᴀ Mar 30 '18 at 17:36
  • 2
    \$\begingroup\$ @StephenRauch and close voters - this looks like Python 2, where input is basically eval(raw_input("")), so it should convert to a number (although there could certainly be better error handling there). Not off-topic imo \$\endgroup\$ – Dannnno Mar 30 '18 at 20:29
1
\$\begingroup\$

I'd highly recommend taking a look at pep8. For instance, there should be two spaces between the end of a function and the start of the next one.

You have a function called bat that just calls battle, why not just call battle everywhere instead of calling bat?

At the end of each init method for your classes you use pass, there's no need for that, pass is only needed when you have a function or class that has no statements, ex:

class Person:
    pass

All over your code you have what are called "magic numbers." They're magic because to anyone else looking at the code they don't know where they came from or how their meaning is derived. Here are a few examples: 3, 7, 13, 36, etc. You'll want to create another .py file for these types of constants or create a class that has no methods but has all instance variables representing these values and then pass an instance of the class around. This is good not only for explaining where these numbers came from, but if you happened to use the same magic number in multiple places, you can very easily change that value by editing one line of code in the class or in the other .py module.

Lastly, when a .py file is imported the code is executed, so if you or someone else wanted to use some functions or classes you created in this .py file they would not be able to do so as your code is currently written.

At the very bottom of this .py file remove your direct call to home and create this line:

if __name__ == '__main__':
    home()

What this will do is only call the home() function if the .py file is ran directly. If someone else decides to import your .py file then they can do so without accidentally executing home.

Current grade function is:

def grade():
    p.money -= 150
    bjug.emb -= 1
    bug = random.randint(1,5)
    if bug == 1:
        print("Your grade is 2")
        print("We cant case it unless its a 10. Sorry.")
        psa()
    elif bug == 2:
        print("Your grade is 4")
        print("We cant case it unless its a 10. Sorry.")
        psa()
    elif bug == 3:
        print("Your grade is 6")
        print("We cant case it unless its a 10. Sorry.")
        psa()
    elif bug == 4:
        print("Your grade is 8")
        print("We cant case it unless its a 10. Sorry.")
        psa()
    elif bug == 5:
        print("Your grade is 10")
        print("You now have a Graded 10 Phrexian Anhillator! ")
        psa10.emb += 1
        psa()

You could considerably shorten/improve your grade function as so:

def grade():
    p.money -= 150
    bjug.emb -= 1
    bug = random.randint(1, 5)
    bugs_messages = {1: 'Your grade is 2\nWe cant case it unless its a 10. sorry', 
                 2: 'Your grade is 4\nWe cant cant case it unless its a 10. Sorry',
                 3: 'Your grade is 6\nWe cant case it unless its a 10. Sorry',
                 4: 'Your grade is 8\nWe cant case it unless its a 10. Sorry',
                 5: 'Your grade is 10.\nWe now have a graded 10 Phrexian Anhillator!'}
    print(bugs_messages[bug])
    if bug == 5:
        psa10.emb += 1
    psa()

And here's one more alternative:

def grade():
    p.money -= 150
    bjug.emb -= 1
    bug = random.randint(1, 5)
    message = "Your grade is {number}\nWe {case}".\
        format(
            number=bug*2, 
            case="cant case it unless its a 10. Sorry" if bug in (1, 2, 3, 
    4) else "now have a graded 10 Phrexian Anhillator!")
    print(message)
    if bug == 5:
        psa10.emb += 1
    psa()
\$\endgroup\$
  • \$\begingroup\$ "All over your code you have what are called "magic numbers." They're magic because to anyone else looking at the code they don't know where they came from or how their meaning is derived. Here are a few examples: 3, 7, 13, 36, etc In the space where I define the class, I show, that that is the value. \$\endgroup\$ – Colea Apr 1 '18 at 14:36
  • \$\begingroup\$ Aswell, thank you so much for your feedback and taking the time to write it! :) I will make some changes to the code. \$\endgroup\$ – Colea Apr 1 '18 at 14:37
  • \$\begingroup\$ I added an update on the end with an additional tip for your grade function. \$\endgroup\$ – Kevin S Apr 1 '18 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.