Python Forum
[PyGame] Can my crafting system improve?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Can my crafting system improve?
#1
Hello all! It works! lol

I've been working on making a efficient, logical crafting system. It seems pretty lean to me, but I would like to get some feedback before I start going crazy adding content to it.

Here is the dictionary. There is one for builds and one for available_builds:
 self.builds = {"Blaster 1" : { "cost" : [("Copper", 4), ("Iron", 4)],
                                       "function" : self.blaster_upgrades},
                            
                       "Copper Bars" : { "cost" : [("Copper", 4)],
                                       "function" : self.smelt_copper}}


Here is where I check for the cost of the build, and examples of what the functions could be.
 def build(self, upgrade):
        has_cost = True
        for item in upgrade["cost"]:
            if item[0] in self.bunker.storage.keys():
                if self.bunker.storage[item[0]] >= item[1]:
                    pass
                  
                   
                else:
                    has_cost = False
                    print("not enough stuff")  
            else:
                    has_cost = False
                    print("not enough stuff")    

        if has_cost:
            for item in upgrade["cost"]:
         
           
                self.bunker.storage[item[0]] -= item[1]
            upgrade["function"]()

    def blaster_upgrades(self):
        
        self.game.player.firing_rate -= 5
        

    def smelt_copper(self):
        if "Copper Bars" in self.storage:
            self.storage["Copper Bars"] += 1
        else:
            self.storage.update({"Copper Bars" : 1})



Is it traditional to keep these crafting functions as class methods for the crafting menu, or should they go in a file and use import *?

Also, I don't feel how I am checking the cost is very elegant.

If anyone has tips on things that are best added now for increased functionality or how to make the code more "pythonic", I'd love to see your ideas.

Thank-you
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020