Sorry I just realise that made not sense. I have created a program in python similar to battleships. I have created the class section which were working when I include the direction section in the main and not as a seperate method, However when I move the method into a seperate section and ask the function to be called, I cannot get my method to call into my main function now for the 2 ships to battle Can someone please tell me what I am doing wrong as I cannot get it working and am getting very frustrated....Thank-you
import random
class Tank1 (object):
def __init__(self):
self.xcord = 0
self.ycord = 0
self.arm = 10
self.fire = 1
def GetX (self):
return self.xcord
def GetY (self):
return self.ycord
def GetArm (self):
return self.arm
def GetFire (self):
return self.fire
def SetX (self , move):
self.xcord = self.xcord + move
def SetY (self , move):
self.ycord = self.ycord + move
def SetArm (self , n):
self.arm = self.arm + n
def SetFire (self, n):
self.fire = self.fire + n
class Tank2 (object):
def __init__(self):
self.xcord = 0
self.ycord = 0
self.arm = 10
self.fire = 1
def GetX (self):
return self.xcord
def GetY (self):
return self.ycord
def GetArm (self):
return self.arm
def GetFire (self):
return self.fire
def SetX (self , move):
self.xcord = self.xcord + move
def SetY (self , move):
self.ycord = self.ycord + move
def SetArm (self , n):
self.arm = self.arm + n
def SetFire (self, n):
self.fire = self.fire + n
class Die (object):
def __init__(self):
self.value = 1
def roll(self):
self.value = random.randrange(1,7)
return self.value
class Direction (object):
def __init__(self):
self.value = " "
def direct(self):
dir_num =random.randrange(1,5)
dic={"1":"up","2":"down","3":"right","4":"left"}
return dic[str(dir_num)]
def determine(directionx,y):
t1 = Tank1()
t2 = Tank2()
g = 10
if (direction =="up"):
t.SetY(move)
if t.ycord>10:
t.ycord = (2*g - t.ycord)
elif (direction == "down"):
t.SetY(-move)
if t.ycord<-10:
t.ycord = (-2*g) - t.ycord
elif (direction == "right"):
t.SetX(move)
if t.xcord>10:
t.xcord= (2*g - t.xcord)
else:
t.SetX(-move)
if t.xcord<-10:
t.xcord= (-2*g) - t.xcord
t.xcord,t.ycord()
print move,"\t", direction,"\t ", t.xcord,"\t ", t.ycord,"\t", t.arm,"\t", t.fire
i = i + 1
def main():
t = Tank()
i = 1
g = 10
print "number", "direction", "xValue", "yvalue", "Amour", "firepower"
while i <= 50:
d = Die()
dire = Direction()
move = d.roll()
direction = dire.direct()
determine(t.xcord,t.ycord)
t.xcord,t.ycord = determine(directionx,y)
if __name__ == "__main__":
main()