Jan-15-2019, 05:34 PM
Hi to everyone,
I have a question. I have a game map and 5 monsters. I want all my monsters born on the "dirt" not on the rock or water and I have this code;
How can I shorten this code by using a function? I know that there is a short way by using a function but I can't do it :) Thanks in advance.
I have a question. I have a game map and 5 monsters. I want all my monsters born on the "dirt" not on the rock or water and I have this code;
while True: mnstrh=random.randint(0,mapheight-1) mnstrw=random.randint(0,mapwidth-1) if floormap[mnstrh][mnstrw]=="dirt": monsterpos[0]=mnstrw monsterpos[1]=mnstrh break else: True while True: mnstrh1=random.randint(0,mapheight-1) mnstrw1=random.randint(0,mapwidth-1) if floormap[mnstrh1][mnstrw1]=="dirt": monster1pos[0]=mnstrw1 monster1pos[1]=mnstrh1 break else: TrueMonster variable names are monster,monster1... and their position names are monsterpos, monster1pos, monster2pos..
How can I shorten this code by using a function? I know that there is a short way by using a function but I can't do it :) Thanks in advance.