Exemple #1
0
def main():  # Secondary main function to help in calling and returning
    global returnval
    returnval = func(1, -1)
    if returnval == 1:
        os.system("clear")

        global name
        oldname = raw_input(colors.YELLOW + colors.BOLD + "Enter Player name : " + colors.BLUE)
        name = oldname.replace("n", "")

        call(["stty", "-echo"])  # To prevent lag

        global savemem, scores
        savemem = 1
        scores = 0

        while savemem != -1:
            savemem, scores = mainfunc(savemem, name, scores)

        if savemem == -1:
            tempcheck = 0
            while returnval == 1:
                if tempcheck == 0:
                    returnval = func(2, scores)
                    savemem = 1
                    scores = 0
                savemem, scores = mainfunc(savemem, name, scores)
                if savemem != -1:
                    tempcheck = 1
                else:
                    tempcheck = 0

            if returnval == 2:
                call(["stty", "echo"])
                sys.exit()
        else:
            call(["stty", "echo"])
            sys.exit()

    else:
        sys.exit()

    call(["stty", "echo"])
    sys.exit()
Exemple #2
0
def main():	#Secondary main function to help in calling and returning
	global returnval
	returnval = func(1,-1)
	if returnval == 1:
		os.system("clear")
		
		global name
		oldname = raw_input(colors.YELLOW+colors.BOLD+"Enter Player name : "+colors.BLUE)	
		name = oldname.replace("n", "")	
		
		call(["stty","-echo"])	#To prevent lag	

		global savemem,scores		
		savemem = 1
		scores = 0

		while savemem != -1:
			savemem,scores = mainfunc(savemem,name,scores)

		if savemem == -1:
			tempcheck = 0
			while returnval == 1:
				if tempcheck == 0:				
					returnval = func(2,scores)
					savemem = 1
					scores = 0
				savemem,scores = mainfunc(savemem,name,scores)
				if savemem != -1:
					tempcheck = 1
				else:
					tempcheck = 0
					
			if returnval == 2:
				call(["stty","echo"])
				sys.exit()
		else:
			call(["stty","echo"])
			sys.exit()

	else:
		sys.exit()
	
	call(["stty","echo"])
	sys.exit()
Exemple #3
0
def mainfunc(level, pname, score):  # Tertiary main function. Contains the main while loop

    # Create hookmanager
    hookman = pyxhook.HookManager()
    # Define our callback to fire when a key is pressed down
    hookman.KeyDown = kbevent
    # Hook the keyboard
    hookman.HookKeyboard()
    # Start our listener
    hookman.start()

    global ball1time, ball2time
    ball1time = time.time()  # These ensure that the balls are produced after a time gap and not all together

    global P
    P = Player(pname, ROWS - 2, 1, COLUMNS, level, score)  # Instantiating Player

    # Create new layout
    global newboard, mainarr
    while True:
        mainarr = []
        newboard = Board()
        if (
            newboard.init(COLUMNS, ROWS, mainarr, P) == True
        ):  # Creating board and ensuring that there exists a path from player spawn position to the princess
            break

    global numofdonkeys, numofball, upint
    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, newboard, mainarr, COLUMNS
    )  # Create donkeys

    oldtime = time.time()  # To judge jump direction

    global keyarr
    global running

    running = True
    while running:  # Main while loop
        os.system("clear")

        newtime = time.time()  # To judge jump direction when the spacebar is pressed
        if (newtime - oldtime) > 1:
            keyarr.pop(0)
            keyarr.append(115)
            oldtime = newtime

            # Choose what to do depending on current variable values

        if P.life == 0:
            os.system("clear")
            hookman.cancel()
            return (-1), P.score

        if P.getX() == 1 and P.getY() == newboard.princess:
            P.score += 50
            if P.level == 3:
                os.system("clear")
                func(3, P.score)
                hookman.cancel()
                return (-1), P.score
            hookman.cancel()
            return P.level + 1, P.score

        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
            P.score -= 25
            continue

        tempr, tempcol = P.getPosition()
        if mainarr[tempr + 1][tempcol] != -1 and mainarr[tempr + 1][tempcol] != 2 and P.updown != 1:
            mainarr[tempr][tempcol] = 0
            mainarr[tempr + 1][tempcol] = 4
            P.changeposn(tempr + 1, tempcol)

        global note
        note = -1
        tempindex = 0
        for i in dobjectarr:
            if i != 0:
                if i.checkCollision(mainarr) == True:
                    i.killDonkey(mainarr, P)
                    note = 1
                    break
                else:
                    i.donkeyWalk(mainarr)
            tempindex += 1

        if note != -1:
            dobjectarr[tempindex] = 0
            P.score += 25
            note = -1

            # ball section

        ball2time = time.time()
        dobjectarr, ball1time, currball, fbarr = createBalls(
            ball1time, ball2time, currball, numofball, dobjectarr, COLUMNS, fbarr
        )

        mainarr, fbarr = updateBalls(mainarr, fbarr, ROWS, COLUMNS, dobjectarr)

        printboard(COLUMNS, ROWS, mainarr, P)  # Print the board

        time.sleep(0.12)

        # Close the listener when we are done
    hookman.cancel()
    sys.exit()
Exemple #4
0
def mainfunc(level,pname,score):	#Tertiary main function. Contains the main while loop
	
	#Create hookmanager
	hookman = pyxhook.HookManager()
	#Define our callback to fire when a key is pressed down
	hookman.KeyDown = kbevent
	#Hook the keyboard
	hookman.HookKeyboard()
	#Start our listener
	hookman.start()	

	global ball1time,ball2time
	ball1time = time.time()		#These ensure that the balls are produced after a time gap and not all together
	
	global P	
	P = Player(pname, ROWS-2, 1,COLUMNS, level,score)	#Instantiating Player
	
	#Create new layout
	global newboard,mainarr
	while True:
		mainarr = []
		newboard = Board()
		if newboard.init(COLUMNS,ROWS,mainarr,P) == True:	#Creating board and ensuring that there exists a path from player spawn position to the princess
			break
	
	global numofdonkeys,numofball,upint
	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,newboard,mainarr,COLUMNS)	#Create donkeys

	oldtime=time.time()	#To judge jump direction
	
	global keyarr
	global running

	running = True
	while running:		#Main while loop
		os.system("clear")
	
		newtime=time.time()	#To judge jump direction when the spacebar is pressed
		if (newtime-oldtime) > 1:
			keyarr.pop(0)
			keyarr.append(115)
			oldtime=newtime
		
		#Choose what to do depending on current variable values		

		if P.life == 0:
			os.system("clear")			
			hookman.cancel()
			return (-1),P.score
	
		if P.getX() == 1 and P.getY() == newboard.princess:
			P.score += 50
			if P.level == 3:
				os.system("clear")
				func(3, P.score)
				hookman.cancel()				
				return (-1),P.score
			hookman.cancel()
			return P.level+1,P.score

		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
			P.score -= 25
			continue

		tempr,tempcol = P.getPosition()
		if mainarr[tempr+1][tempcol] != -1 and mainarr[tempr+1][tempcol] != 2 and P.updown != 1:
			mainarr[tempr][tempcol] = 0
			mainarr[tempr+1][tempcol] = 4
			P.changeposn(tempr+1,tempcol)
		
		global note
		note = -1
		tempindex = 0
		for i in dobjectarr:
			if i != 0:			
				if i.checkCollision(mainarr) == True:
					i.killDonkey(mainarr,P)					
					note = 1
					break
				else:
					i.donkeyWalk(mainarr)
			tempindex += 1		
		
		if note != -1:
			dobjectarr[tempindex] = 0
			P.score += 25
			note = -1
	
		#ball section
		
		
		ball2time = time.time()
		dobjectarr,ball1time,currball,fbarr = createBalls(ball1time, ball2time, currball, numofball, dobjectarr, COLUMNS, fbarr)
			
		mainarr,fbarr = updateBalls(mainarr,fbarr,ROWS,COLUMNS,dobjectarr)
		
		printboard(COLUMNS, ROWS, mainarr, P)	#Print the board

		time.sleep(0.12)

	
		
	#Close the listener when we are done
	hookman.cancel()
	sys.exit()