def test_fireballexit(self): starttime = time.time() P = Player("Hello",1,ROWS - 2, COLS, 1, 0) newb = Board() mainarr = [] while True: pathexists,numofcoins,testofthree = newb.init(COLS,ROWS,mainarr,P) if pathexists == True: break numofdonkeys,numofball,upint = levelVar(P) numofball = 1 #One ball is enough for testing dindexarr = [0,0,0] dlenarr = [0,0,0] #global dobjectarr dobjectarr = [0,0,0] #global fbarr fbarr = [0,0,0,0,0,0,0,0] #global currball currball = 0 #global counter counter = 0 dindexarr,dlenarr,counter = createDonkeys(dindexarr,dlenarr,counter,numofdonkeys,newb,mainarr,COLS,dobjectarr,upint) ball1time = time.time() tempcount = 0 P.changeposn(ROWS-2,7) mainarr[ROWS-2][7] = 4 running = True while running: #Main while loop for i in dobjectarr: if i != 0: i.donkeyWalk(mainarr) ball2time = time.time() dobjectarr,ball1time,currball,fbarr = createBalls(ball1time, ball2time, currball, numofball, dobjectarr, COLS, fbarr,upint, mainarr) for i in fbarr: if i != 0: x,y = i.getPosition() if y == 1 and x == ROWS-2: updateBalls(mainarr,fbarr,ROWS,COLS,dobjectarr) assert mainarr[ROWS-2][1] != 6 running = False mainarr,fbarr = updateBalls(mainarr,fbarr,ROWS,COLS,dobjectarr)
def test_donkeyandwall(self): starttime = time.time() P = Player("Hello", 1, ROWS - 2, COLS, 1, 0) newb = Board() mainarr = [] while True: pathexists, numofcoins, testofthree = newb.init(COLS, ROWS, mainarr, P) if pathexists == True: break numofdonkeys, numofball, upint = levelVar(P) numofball = 1 # One ball is enough for testing dindexarr = [0, 0, 0] dlenarr = [0, 0, 0] # global dobjectarr dobjectarr = [0, 0, 0] # global fbarr fbarr = [0, 0, 0, 0, 0, 0, 0, 0] # global currball currball = 0 # global counter counter = 0 dindexarr, dlenarr, counter = createDonkeys( dindexarr, dlenarr, counter, numofdonkeys, newb, mainarr, COLS, dobjectarr, upint ) ball1time = time.time() tempcount = 0 running = True while running: # Main while loop for i in dobjectarr: if i != 0: i.donkeyWalk(mainarr) ball2time = time.time() dobjectarr, ball1time, currball, fbarr = createBalls( ball1time, ball2time, currball, numofball, dobjectarr, COLS, fbarr, upint, mainarr ) for i in dobjectarr: if i != 0: oldtempx, oldtempy = i.getPosition() i.donkeyWalk(mainarr) tempx, tempy = i.getPosition() assert tempx == oldtempx if (time.time() - starttime) > 10: running = False
def test_directionchange(self): starttime = time.time() P = Player("Hello",1,ROWS - 2, COLS, 1, 0) newb = Board() mainarr = [] while True: pathexists,numofcoins,testofthree = newb.init(COLS,ROWS,mainarr,P) if pathexists == True: break numofdonkeys,numofball,upint = levelVar(P) numofball = 1 dindexarr = [0,0,0] dlenarr = [0,0,0] #global dobjectarr dobjectarr = [0,0,0] #global fbarr fbarr = [0,0,0,0,0,0,0,0] #global currball currball = 0 #global counter counter = 0 dindexarr,dlenarr,counter = createDonkeys(dindexarr,dlenarr,counter,numofdonkeys,newb,mainarr,COLS,dobjectarr,upint) ball1time = time.time() P.changeposn(ROWS-2,7) mainarr[ROWS-2][7] = 4 running = True while running: #Main while loop for i in dobjectarr: if i != 0: i.donkeyWalk(mainarr) ball2time = time.time() dobjectarr,ball1time,currball,fbarr = createBalls(ball1time, ball2time, currball, numofball, dobjectarr, COLS, fbarr,upint, mainarr) tempcount = 0 for i in fbarr: if i != 0: olddirection = i.getDirection() if i.getY()+1 == COLS-1 or i.getY() - 1 == 0: mainarr,fbarr = updateBalls(mainarr,fbarr,ROWS,COLS,dobjectarr) assert i.getDirection() != olddirection running = False mainarr,fbarr = updateBalls(mainarr,fbarr,ROWS,COLS,dobjectarr)
def test_fireballfromdonkey(self): starttime = time.time() P = Player("Hello",1,ROWS - 2, COLS, 1, 0) newb = Board() mainarr = [] while True: pathexists,numofcoins,testofthree = newb.init(COLS,ROWS,mainarr,P) if pathexists == True: break numofdonkeys,numofball,upint = levelVar(P) dindexarr = [0,0,0] dlenarr = [0,0,0] #global dobjectarr dobjectarr = [0,0,0] #global fbarr fbarr = [0,0,0,0,0,0,0,0] #global currball currball = 0 #global counter counter = 0 dindexarr,dlenarr,counter = createDonkeys(dindexarr,dlenarr,counter,numofdonkeys,newb,mainarr,COLS,dobjectarr,upint) ball1time = time.time() tempcount = 0 running = True while running: #Main while loop for i in dobjectarr: if i != 0: i.donkeyWalk(mainarr) ball2time = time.time() dobjectarr,ball1time,currball,fbarr = createBalls(ball1time, ball2time, currball, numofball, dobjectarr, COLS, fbarr,upint, mainarr) for i in fbarr: if i != 0: x,y = i.getPosition() for j in dobjectarr: if j != 0: if x == j.getX() and y == j.getY()+1: assert x == j.getX() and y == j.getY()+1 # Checks if fireball originates from donkey if (time.time() - starttime) >= numofball * 4: running = False
def test_numoffireballs(self): starttime = time.time() P = Player("Hello",1,ROWS - 2, COLS, 2, 0) newb = Board() mainarr = [] while True: pathexists,numofcoins,testofthree = newb.init(COLS,ROWS,mainarr,P) if pathexists == True: break numofdonkeys,numofball,upint = levelVar(P) dindexarr = [0,0,0] dlenarr = [0,0,0] #global dobjectarr dobjectarr = [0,0,0] #global fbarr fbarr = [0,0,0,0,0,0,0,0] #global currball currball = 0 #global counter counter = 0 dindexarr,dlenarr,counter = createDonkeys(dindexarr,dlenarr,counter,numofdonkeys,newb,mainarr,COLS,dobjectarr,upint) ball1time = time.time() P.changeposn(ROWS-2,7) mainarr[ROWS-2][7] = 4 running = True while running: #Main while loop for i in dobjectarr: if i != 0: i.donkeyWalk(mainarr) ball2time = time.time() dobjectarr,ball1time,currball,fbarr = createBalls(ball1time, ball2time, currball, numofball, dobjectarr, COLS, fbarr,upint, mainarr) tempcount = 0 for i in fbarr: if i != 0: tempcount += 1 if tempcount == numofball: running = False assert tempcount == numofball
def test_donkeyandplayer(self): starttime = time.time() P = Player("Hello", 1, ROWS - 2, COLS, 1, 0) newb = Board() mainarr = [] while True: pathexists, numofcoins, testofthree = newb.init(COLS, ROWS, mainarr, P) if pathexists == True: break numofdonkeys, numofball, upint = levelVar(P) numofball = 1 # One ball is enough for testing dindexarr = [0, 0, 0] dlenarr = [0, 0, 0] # global dobjectarr dobjectarr = [0, 0, 0] # global fbarr fbarr = [0, 0, 0, 0, 0, 0, 0, 0] # global currball currball = 0 # global counter counter = 0 dindexarr, dlenarr, counter = createDonkeys( dindexarr, dlenarr, counter, numofdonkeys, newb, mainarr, COLS, dobjectarr, upint ) ball1time = time.time() tempcount = 0 running = True while running: # Main while loop for i in dobjectarr: if i != 0: i.donkeyWalk(mainarr) ball2time = time.time() dobjectarr, ball1time, currball, fbarr = createBalls( ball1time, ball2time, currball, numofball, dobjectarr, COLS, fbarr, upint, mainarr ) note = -1 tempindex = 0 for i in dobjectarr: if i != 0: if i.getdir() == 1: P.changeposn(i.getX(), i.getY() + 1) mainarr[i.getX()][i.getY() + 1] = 4 else: P.changeposn(i.getX(), i.getY() - 1) mainarr[i.getX()][i.getY() - 1] = 4 assert i.checkCollision(mainarr) == True if i.checkCollision(mainarr) == True: i.killDonkey(mainarr, P) note = 1 running = False break else: i.donkeyWalk(mainarr) tempindex += 1 if note != -1: dobjectarr[tempindex] = 0 P.score += 25 note = -1
def test_numofdonkeys(self): P = Player("Hello", 1, ROWS - 2, COLS, 2, 0) newb = Board() mainarr = [] while True: pathexists, numofcoins, testofthree = newb.init(COLS, ROWS, mainarr, P) if pathexists == True: break numofdonkeys, numofball, upint = levelVar(P) numofball = 1 # One ball is enough for testing dindexarr = [0, 0, 0] dlenarr = [0, 0, 0] # global dobjectarr dobjectarr = [0, 0, 0] # global fbarr fbarr = [0, 0, 0, 0, 0, 0, 0, 0] # global currball currball = 0 # global counter counter = 0 dindexarr, dlenarr, counter = createDonkeys( dindexarr, dlenarr, counter, numofdonkeys, newb, mainarr, COLS, dobjectarr, upint ) running = True while running: # Main while loop tempcnt = 0 for i in dobjectarr: if i != 0: i.donkeyWalk(mainarr) tempcnt += 1 assert tempcnt == numofdonkeys running = False P = Player("Hello", 1, ROWS - 2, COLS, 3, 0) newb = Board() mainarr = [] while True: pathexists, numofcoins, testofthree = newb.init(COLS, ROWS, mainarr, P) if pathexists == True: break numofdonkeys, numofball, upint = levelVar(P) numofball = 1 # One ball is enough for testing dindexarr = [0, 0, 0] dlenarr = [0, 0, 0] # global dobjectarr dobjectarr = [0, 0, 0] # global fbarr fbarr = [0, 0, 0, 0, 0, 0, 0, 0] # global currball currball = 0 # global counter counter = 0 dindexarr, dlenarr, counter = createDonkeys( dindexarr, dlenarr, counter, numofdonkeys, newb, mainarr, COLS, dobjectarr, upint ) running = True while running: # Main while loop tempcnt = 0 for i in dobjectarr: if i != 0: i.donkeyWalk(mainarr) tempcnt += 1 assert tempcnt == numofdonkeys running = False
def test_fireballandplayer(self): starttime = time.time() P = Player("Hello",1,ROWS - 2, COLS, 1, 0) newb = Board() mainarr = [] while True: pathexists,numofcoins,testofthree = newb.init(COLS,ROWS,mainarr,P) if pathexists == True: break numofdonkeys,numofball,upint = levelVar(P) numofball = 1 #One ball is enough for testing dindexarr = [0,0,0] dlenarr = [0,0,0] #global dobjectarr dobjectarr = [0,0,0] #global fbarr fbarr = [0,0,0,0,0,0,0,0] #global currball currball = 0 #global counter counter = 0 dindexarr,dlenarr,counter = createDonkeys(dindexarr,dlenarr,counter,numofdonkeys,newb,mainarr,COLS,dobjectarr,upint) ball1time = time.time() tempcount = 0 running = True while running: #Main while loop for i in dobjectarr: if i != 0: i.donkeyWalk(mainarr) ball2time = time.time() dobjectarr,ball1time,currball,fbarr = createBalls(ball1time, ball2time, currball, numofball, dobjectarr, COLS, fbarr,upint, mainarr) for i in fbarr: if i != 0: x,y = i.getPosition() if i.getDirection() == 1: P.changeposn(x,y+1) else: P.changeposn(x,y-1) break if mainarr[P.getX()][P.getY()+1] == 6 or mainarr[P.getX()][P.getY()-1] == 6: mainarr[P.getX()][P.getY()] = 0 P.life -= 1 P.changeposn(ROWS - 2, 1) mainarr[P.getX()][P.getY()] = 4 assert P.getX() == ROWS-2 and P.getY() == 1 P.score -= 25 running = False