Feb-02-2019, 08:50 AM
I imported gaming into char.py to access the variables of gaming.py.
char.py
These are some important points of gaming.py. Maybe i am making a mistake at these points;
gaming.py
char.py
import random,pygame,Game class Char(): def __init__(self): pass def get_position(self,mapheight,mapwidth,floormap): while True: column = random.randint(2, mapheight - 3) row = random.randint(2, mapwidth - 3) if floormap[column][row] == "dirt": return [row, column] def bloock(self,ydir, xdir, pos, direct, nocrashdir,getblock,playerpos,floormapid,floormap): if getblock == Game.coal or getblock == Game.coal1 or getblock == Game.coal2: pygame.mixer.music.load("coal.wav") pygame.mixer.music.play() if getblock == Game.coal or Game.coal1: Game.click = floormapid[playerpos[1]+ydir][playerpos[0]+xdir] Game.click += 1 floormapid[playerpos[1]+ydir][playerpos[0]+xdir] = Game.click if getblock == Game.coal and floormapid[playerpos[1]+ydir][playerpos[0]+xdir] == 4: floormap[playerpos[1]+ydir][playerpos[0]+xdir] = Game.coal1 if getblock == Game.coal1 and floormapid[playerpos[1]+ydir][playerpos[0]+xdir] == Game.coaldur: floormap[playerpos[1]+ydir][playerpos[0]+xdir] = Game.coal2 if getblock == Game.coal2: Game.click = 0 floormap[playerpos[1]+ydir][playerpos[0]+xdir] = Game.dirtWhen i run char.py, it is working perfectly, but char.py is not my main working module.It is gaming.py. However, when i run gaming.py it still says " module "char" has no attribute "Char" ".So, i am suppose to initialize gaming.py to play the game, not char.py. Isn't is true?
These are some important points of gaming.py. Maybe i am making a mistake at these points;
gaming.py
import pygame,sys,random,time import char pygame.init() pygame.mixer.init() tilesize = 50 ... charclass=char.Char() playerpos = charclass.get_position(mapheight,mapwidth,floormap) monsterpos = charclass.get_position(mapheight,mapwidth,floormap) monster1pos = charclass.get_position(mapheight,mapwidth,floormap) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT and playerpos[0] <= mapwidth - 1: if playerpos[0]==mapwidth-1: playerdir = playerright else: playerdir = playerright getblock = floormap[playerpos[1]][playerpos[0]+1] ydir = 0 xdir = 1 pos = 0 direct = playerright nocrashdir = 1 charclass.bloock(ydir, xdir, pos, direct, nocrashdir,getblock,playerpos,floormapid,floormap)