Ejemplo n.º 1
0
    def move(self):
        rail = False
        #Behandlung der Weichen:
        if self.oldchars[self.y][self.x] == b"^":
            if self.screen.instr(self.y - 1, self.x, 1) == b"#":  #oben
                rail = True
                self.y -= 1
        elif self.oldchars[self.y][self.x] == b"<":
            if self.screen.instr(self.y, self.x - 1, 1) == b"#":  #links
                rail = True
                self.x -= 1
        elif self.oldchars[self.y][self.x] == b"v":
            if self.screen.instr(self.y + 1, self.x, 1) == b"#":  #unten
                rail = True
                self.y += 1
        elif self.oldchars[self.y][self.x] == b">":
            if self.screen.instr(self.y, self.x + 1, 1) == b"#":  #rechts
                rail = True
                self.x += 1
        elif (None, None) != self.char_which_direction(self.y, self.x, b"_"):
            self.game.lokopizza.nextLevel()
        #normale Schienen - oder der Start
        else:
            for char in [b"#", b"^", b">", b"v", b"<"]:
                newy, newx = self.char_which_direction(self.y, self.x, char)
                if newy and newx:  #Schienen in der Naehe
                    rail = True
                    self.y = newy
                    self.x = newx
                    break

        if not rail:  #Explosion, wenn es keine Schienen gibt
            self.game.animations.append(
                specialfx.explosion(self.y, self.x, self.game))
            gameover(self.game)
Ejemplo n.º 2
0
def pizzanone(game):
    screen = game.lokopizza.screen

    # Mache den Cursor unsichtbar, weil sichtbar haesslich
    curses.curs_set(0)
    # Setze while schleife auf True
    keeprunning = True

    # Hier faengt die while an, in der die pizza nach unten geflogen kommt
    while (keeprunning):
        randy = random.randint(0, 22)
        randx = random.randint(0, 78)

        # Suche nach Koordinaten, wo randy und randx eine # sind
        if screen.instr(randy, randx, 1) == "#":
            # Wenn eins gefunden wurde, hoert die schleife auf und keeprunning wird false
            keeprunning = False
            # Damit die Pizza runterfallen kann wird fally = 0 gesetzt
            fally = 0
            oldchar = None

            # Waehrend fally nicht randy ist, soll die Pizza in Richtung der Schiene fallen
            while (fally != randy):
                if oldchar:
                    screen.addstr(fally, randx, oldchar)
                oldchar = screen.instr(fally + 1, randx)
                screen.addstr(fally + 1, randx, "Q")
                screen.refresh()
                yield None
                fally += 1

            # Und bei fally <= randy wird die Schiene plus Pizza entfernt und special effects sollen danach in x form um die einschlagsstelle auftauchen und wieder verschwinden
            if (fally <= randy):
                game.animations.append(specialfx.explosion(fally, randx, game))
                game.schienen.append(schienen.Schiene(fally, randx, game, "#"))
Ejemplo n.º 3
0
	def move(self):
		rail = False
		#Behandlung der Weichen:
		if self.oldchars[self.y][self.x] == "^":
			if self.screen.instr(self.y-1, self.x, 1) == "#": #oben
				rail = True
				self.y -= 1
		elif self.oldchars[self.y][self.x] == "<":
			if self.screen.instr(self.y, self.x-1, 1) == "#": #links
				rail = True
				self.x -= 1
		elif self.oldchars[self.y][self.x] == "v":
			if self.screen.instr(self.y+1, self.x, 1) == "#": #unten
				rail = True
				self.y += 1
		elif self.oldchars[self.y][self.x] == ">":
			if self.screen.instr(self.y, self.x+1, 1) == "#": #rechts
				rail = True
				self.x += 1
		elif (None, None) != self.char_which_direction(self.y, self.x, "_"):
			self.game.lokopizza.nextLevel()
		#normale Schienen - oder der Start
		else:
			for char in ["#", "^", ">", "v", "<"]:
				newy, newx = self.char_which_direction(self.y, self.x, char)
				if newy and newx: #Schienen in der Naehe
					rail = True
					self.y = newy
					self.x = newx
					break

		if not rail: #Explosion, wenn es keine Schienen gibt
			self.game.animations.append(specialfx.explosion(self.y, self.x, self.game))
Ejemplo n.º 4
0
def pizzanone(game):
    screen = game.lokopizza.screen
    
    # Mache den Cursor unsichtbar, weil sichtbar haesslich
    curses.curs_set(0)
    # Setze while schleife auf True
    keeprunning = True

    # Hier faengt die while an, in der die pizza nach unten geflogen kommt
    while(keeprunning):
        randy = random.randint(0, 22)
        randx = random.randint(0, 78)

        # Suche nach Koordinaten, wo randy und randx eine # sind
        if screen.instr(randy, randx, 1) == "#":
            # Wenn eins gefunden wurde, hoert die schleife auf und keeprunning wird false
            keeprunning = False
            # Damit die Pizza runterfallen kann wird fally = 0 gesetzt
            fally = 0
            oldchar = None

            # Waehrend fally nicht randy ist, soll die Pizza in Richtung der Schiene fallen
            while(fally != randy):
                if oldchar:
                    screen.addstr(fally, randx, oldchar)
                oldchar = screen.instr(fally+1, randx)
                screen.addstr(fally+1, randx, "Q")
                screen.refresh()
                yield None
                fally += 1

            # Und bei fally <= randy wird die Schiene plus Pizza entfernt und special effects sollen danach in x form um die einschlagsstelle auftauchen und wieder verschwinden
            if(fally <= randy):
                game.animations.append(specialfx.explosion(fally, randx, game))
                game.schienen.append(schienen.Schiene(fally, randx, game, "#"))
Ejemplo n.º 5
0
def gameover(lokopizza):
    mapread(lokopizza, "gameover.txt")
    lokopizza.screen.refresh()

    while(True):
        randy = random.randint(2, 22)
        randx = random.randint(2, 78)
        for _ in specialfx.explosion(randy, randx, lokopizza):
            sleep(0.1)
        char = lokopizza.screen.instr(randy, randx, 1)
        lokopizza.schienen.append(Schiene(randy, randx, lokopizza, char))
Ejemplo n.º 6
0
def gameover(lokopizza):
    mapread(lokopizza, "gameover.txt")
    lokopizza.screen.refresh()

    while (True):
        randy = random.randint(2, 22)
        randx = random.randint(2, 78)
        for _ in specialfx.explosion(randy, randx, lokopizza):
            sleep(0.1)
        char = lokopizza.screen.instr(randy, randx, 1)
        lokopizza.schienen.append(Schiene(randy, randx, lokopizza, char))
Ejemplo n.º 7
0
def gameover(game):
	game.lokopizza.screen.clear()
	mapread(game, "gameover.txt")
	game.lokopizza.screen.refresh()	
	while(True):
		game.lesen()
		randy = random.randint(2, 22)
		randx = random.randint(2, 78)
		for _ in specialfx.explosion(randy, randx, game):
			sleep(0.1)
		char = game.lokopizza.screen.instr(randy, randx, 1)
		game.schienen.append(Schiene(randy, randx, game, char))
Ejemplo n.º 8
0
def gameover(game):
    game.lokopizza.screen.clear()
    mapread(game, "gameover.txt")
    game.lokopizza.screen.refresh()
    while (True):
        game.lesen()
        randy = random.randint(2, 22)
        randx = random.randint(2, 78)
        for _ in specialfx.explosion(randy, randx, game):
            sleep(0.1)
        char = game.lokopizza.screen.instr(randy, randx, 1)
        game.schienen.append(Schiene(randy, randx, game, char))
Ejemplo n.º 9
0
    def lesen(self):
        self.lokopizza.screen.nodelay(1)
        if self.level:
            try:
                res = self.lokopizza.screen.getkey()
                weiche = int(res)
                for y in range(25):
                    for x in range(80):
                        if self.lokopizza.by(
                                str(weiche)) == self.lokopizza.screen.instr(
                                    y, x, 1):
                            self.lokopizza.screen.addstr(
                                y, x, str(weiche), curses.A_REVERSE)
                            self.lokopizza.screen.addstr(
                                y + 1, x + 1,
                                self.lokopizza.screen.instr(y + 1, x + 1, 1),
                                curses.A_REVERSE)
                            while (True):
                                richtung = self.lokopizza.screen.getch()
                                if richtung not in [-1, 27,
                                                    91]:  #kein Zeichen, ESC, [
                                    break
                            if richtung == 65:  #curses.KEY_UP
                                pfeil = b"^"
                            elif richtung == 67:  #curses.KEY_RIGHT
                                pfeil = b">"
                            elif richtung == 66:  #curses.KEY_DOWN
                                pfeil = b"v"
                            elif richtung == 68:  #curses.KEY_LEFT
                                pfeil = b"<"
                            else:
                                self.lokopizza.screen.addstr(
                                    y, x, str(weiche), curses.A_NORMAL)
                                self.lokopizza.screen.addstr(
                                    y + 1, x + 1,
                                    self.lokopizza.screen.instr(
                                        y + 1, x + 1, 1), curses.A_NORMAL)
                                return

                            if self.lokopizza.screen.instr(
                                    y + 1, x + 1,
                                    1) in [b"X", b"^", b">", b"v", b"<"]:
                                self.lokopizza.screen.addstr(
                                    y + 1, x + 1, pfeil, curses.A_NORMAL)
                            else:
                                self.animations.append(
                                    specialfx.explosion(y + 1, x + 1, self))
                            self.lokopizza.screen.addstr(
                                y, x, str(weiche), curses.A_NORMAL)
            except curses.error:  #nichts gelesen
                return
            except ValueError:
                if res == "r":  #restart
                    self.lokopizza.loadLevel(self.level)
                elif res == "q":  #quit
                    self.lokopizza.loadLevel(0)
        else:
            try:
                wahl = self.lokopizza.screen.getkey()
            except curses.error:  #nichts gelesen
                return
            if wahl == " ":
                self.lokopizza.mapstr = "map{}.txt"
                self.lokopizza.loadLevel(1)
            elif wahl == "o":
                self.lokopizza.mapstr = "tut{}.txt"
                self.lokopizza.loadLevel(1)
            elif wahl == "l":
                self.lokopizza.screen.addstr(
                    24, 1, "Please type your level number. (0 to abort.)")
                self.lokopizza.screen.clrtoeol()
                self.lokopizza.screen.refresh()
                while True:
                    try:
                        level = int(self.lokopizza.screen.getkey())
                        break
                    except curses.error:
                        continue
                    except ValueError:
                        self.lokopizza.screen.addstr(
                            24, 1,
                            "That was no number. Please try again. (0 to abort.)"
                        )
                        self.lokopizza.screen.refresh()
                        continue
                self.lokopizza.loadLevel(level)
            elif wahl == "q":
                self.lokopizza.quit()
            else:
                self.lokopizza.screen.addstr(24, 1, "Please try again.")
                self.lokopizza.screen.clrtoeol()
        self.lokopizza.screen.refresh()
Ejemplo n.º 10
0
	def lesen(self):
		self.lokopizza.screen.nodelay(1)
		if self.level:
			try:
				weiche = int(self.lokopizza.screen.getkey())
			except curses.error: #nichts gelesen
				return
			except ValueError:
				return
			while (True):
				richtung = self.lokopizza.screen.getch()
				if richtung != -1: #kein Zeichen
					if richtung != 27: #ESC
						if richtung != 91: #[
							break
			if richtung == 65: #curses.KEY_UP
				pfeil = "^"
			elif richtung == 67: #curses.KEY_RIGHT
				pfeil = ">"
			elif richtung == 66: #curses.KEY_DOWN
				pfeil = "v"
			elif richtung == 68: #curses.KEY_LEFT
				pfeil = "<"
			else:
				return
			for y in range(25):
				for x in range(80):
					if str(weiche) == self.lokopizza.screen.instr(y,x,1):
						if self.lokopizza.screen.instr(y+1, x+1, 1) in ["X", "^", ">", "v", "<"]:
							self.lokopizza.screen.addstr(y+1, x+1, pfeil)
						else:
							self.animations.append(specialfx.explosion(y+1, x+1, self))
		else:
			try:
				wahl = self.lokopizza.screen.getkey()
			except curses.error: #nichts gelesen
				return
			if wahl == "s":
				self.lokopizza.loadLevel(1)
			elif wahl == "o":
				self.lokopizza.screen.addstr(24, 1, "This is currently not possible yet. Sorry.")
				#TODO: Tutorial
			elif wahl == "l":
				self.lokopizza.screen.addstr(24, 1, "Please type your level number. (0 to abort.)")
				self.lokopizza.screen.clrtoeol()
				self.lokopizza.screen.refresh()
				while(True):
					try:
						level = int(self.lokopizza.screen.getkey())
						break
					except curses.error:
						continue
					except ValueError:
						self.lokopizza.screen.addstr(24, 1, "That was no number. Please try again.")
						self.lokopizza.screen.refresh()
						continue
				self.lokopizza.loadLevel(level)
			elif wahl == "e" or wahl == "q":
				self.lokopizza.quit()
			else:
				self.lokopizza.screen.addstr(24, 1, "Please try again.")
				self.lokopizza.screen.clrtoeol()
		self.lokopizza.screen.refresh()
Ejemplo n.º 11
0
	def lesen(self):
		self.lokopizza.screen.nodelay(1)
		if self.level:
			try:
				res = self.lokopizza.screen.getkey()
				weiche = int(res)
				for y in range(25):
					for x in range(80):
						if self.lokopizza.by(str(weiche)) == self.lokopizza.screen.instr(y,x,1):
							self.lokopizza.screen.addstr(y, x, str(weiche),  curses.A_REVERSE)
							self.lokopizza.screen.addstr(y+1, x+1, self.lokopizza.screen.instr(y+1, x+1, 1),  curses.A_REVERSE)
							while (True):
								richtung = self.lokopizza.screen.getch()
								if richtung not in [-1, 27, 91]: #kein Zeichen, ESC, [
									break
							if richtung == 65: #curses.KEY_UP
								pfeil = b"^"
							elif richtung == 67: #curses.KEY_RIGHT
								pfeil = b">"
							elif richtung == 66: #curses.KEY_DOWN
								pfeil = b"v"
							elif richtung == 68: #curses.KEY_LEFT
								pfeil = b"<"
							else:
								self.lokopizza.screen.addstr(y, x, str(weiche),  curses.A_NORMAL)
								self.lokopizza.screen.addstr(y+1, x+1, self.lokopizza.screen.instr(y+1, x+1, 1),  curses.A_NORMAL)
								return

							if self.lokopizza.screen.instr(y+1, x+1, 1) in [b"X", b"^", b">", b"v", b"<"]:
								self.lokopizza.screen.addstr(y+1, x+1, pfeil, curses.A_NORMAL)
							else:
								self.animations.append(specialfx.explosion(y+1, x+1, self))
							self.lokopizza.screen.addstr(y, x, str(weiche),  curses.A_NORMAL)
			except curses.error: #nichts gelesen
				return
			except ValueError:
				if res == "r": #restart
					self.lokopizza.loadLevel(self.level)
				elif res == "q": #quit
					self.lokopizza.loadLevel(0)
		else:
			try:
				wahl = self.lokopizza.screen.getkey()
			except curses.error: #nichts gelesen
				return
			if wahl == " ":
				self.lokopizza.mapstr = "map{}.txt"
				self.lokopizza.loadLevel(1)
			elif wahl == "o":
				self.lokopizza.mapstr = "tut{}.txt"
				self.lokopizza.loadLevel(1)
			elif wahl == "l":
				self.lokopizza.screen.addstr(24, 1, "Please type your level number. (0 to abort.)")
				self.lokopizza.screen.clrtoeol()
				self.lokopizza.screen.refresh()
				while True:
					try:
						level = int(self.lokopizza.screen.getkey())
						break
					except curses.error:
						continue
					except ValueError:
						self.lokopizza.screen.addstr(24, 1, "That was no number. Please try again. (0 to abort.)")
						self.lokopizza.screen.refresh()
						continue
				self.lokopizza.loadLevel(level)
			elif wahl == "q":
				self.lokopizza.quit()
			else:
				self.lokopizza.screen.addstr(24, 1, "Please try again.")
				self.lokopizza.screen.clrtoeol()
		self.lokopizza.screen.refresh()
Ejemplo n.º 12
0
def pizzanone(game):
	screen = game.lokopizza.screen
	
	# Mache den Cursor unsichtbar, weil sichtbar haesslich
	curses.curs_set(0)
	# Setze while schleife auf True
	keeprunning = True
	
	# Hier faengt die while an,
	# in der die pizza nach unten geflogen kommt
	while(keeprunning):
		randy = random.randint(0, 22)
		randx = random.randint(0, 78)

		# Suche nach Koordinaten, wo randy und randx eine # sind
		if screen.instr(randy, randx, 1) == b"#":
			screen.move(24, 30)
			def suche(newy, newx):
				ergebnisgefunden = []
				searchx = newx
				searchy = newy
				koordlist = []

				while len(ergebnisgefunden) <= 2:
					#newy2 = None
					#newx2 = None
					#newx1 = None
					#newy1 = None
					
					if (searchy, searchx) not in koordlist:
						koordlist.append((searchy, searchx))
					
					for char in [b"X", b"^", b">", b"v", b"<", b"|", b"_"]: #Ende der Suche: Weichen, Start, Ziel
						newy1, newx1 = game.lokomotive.char_which_direction(searchy, searchx, game.lokopizza.by(char))
						if newy1 and newx1:
							ergebnisgefunden.append(True)
							#newy2 = newy1
							#newx2 = newx2
					#if newy2 and newx2:
					#	print str(searchx)+str(searchy)
					#	return True
					
					newy1, newx1 = game.lokomotive.char_which_direction(searchy, searchx, b"#")
					if newy1 and newx1:
						if (newy1, newx1) not in koordlist:
							#print str(searchx)+str(searchy)
							searchx = newx1
							searchy = newy1
							
							continue
						else:
							pass #print ("Schon gewesen: {} {}".format(newy1, newx1))
					
					for char in game.lokomotive.chars:
						newy1, newx1 = game.lokomotive.char_which_direction(searchy, searchx, game.lokopizza.by(char))
						if newy1 and newx1:
							ergebnisgefunden.append(False)
							#newy2 = newy1
							#newx2 = newx2
							#break
					#if newy2 and newx2:
					#	return False
				return not(False in ergebnisgefunden)
			
			if suche(randy, randx):
				# Wenn eins gefunden wurde,
				# hoert die schleife auf und keeprunning wird false
				keeprunning = False
				# Damit die Pizza runterfallen kann wird fally = 0 gesetzt
				fally = 0
				oldchar = None

				# Waehrend fally nicht randy ist,
				# soll die Pizza in Richtung der Schiene fallen
				while(fally != randy):
					if oldchar:
						screen.addstr(fally, randx, oldchar)
					oldchar = screen.instr(fally+1, randx)
					screen.addstr(fally+1, randx, "Q")
					screen.refresh()
					yield None
					fally += 1

				# Und bei fally <= randy wird die Schiene plus Pizza entfernt
				# und special effects sollen danach in x form um die einschlagsstelle
				# auftauchen und wieder verschwinden
				if(fally <= randy):
					game.animations.append(specialfx.explosion(fally, randx, game))
					game.schienen.append(schienen.Schiene(fally, randx, game, "#"))
Ejemplo n.º 13
0
def pizzanone(game):
    screen = game.lokopizza.screen

    # Mache den Cursor unsichtbar, weil sichtbar haesslich
    curses.curs_set(0)
    # Setze while schleife auf True
    keeprunning = True

    # Hier faengt die while an,
    # in der die pizza nach unten geflogen kommt
    while (keeprunning):
        randy = random.randint(0, 22)
        randx = random.randint(0, 78)

        # Suche nach Koordinaten, wo randy und randx eine # sind
        if screen.instr(randy, randx, 1) == b"#":
            screen.move(24, 30)

            def suche(newy, newx):
                ergebnisgefunden = []
                searchx = newx
                searchy = newy
                koordlist = []

                while len(ergebnisgefunden) <= 2:
                    #newy2 = None
                    #newx2 = None
                    #newx1 = None
                    #newy1 = None

                    if (searchy, searchx) not in koordlist:
                        koordlist.append((searchy, searchx))

                    for char in [b"X", b"^", b">", b"v", b"<", b"|",
                                 b"_"]:  #Ende der Suche: Weichen, Start, Ziel
                        newy1, newx1 = game.lokomotive.char_which_direction(
                            searchy, searchx, game.lokopizza.by(char))
                        if newy1 and newx1:
                            ergebnisgefunden.append(True)
                            #newy2 = newy1
                            #newx2 = newx2
                    #if newy2 and newx2:
                    #	print str(searchx)+str(searchy)
                    #	return True

                    newy1, newx1 = game.lokomotive.char_which_direction(
                        searchy, searchx, b"#")
                    if newy1 and newx1:
                        if (newy1, newx1) not in koordlist:
                            #print str(searchx)+str(searchy)
                            searchx = newx1
                            searchy = newy1

                            continue
                        else:
                            pass  #print ("Schon gewesen: {} {}".format(newy1, newx1))

                    for char in game.lokomotive.chars:
                        newy1, newx1 = game.lokomotive.char_which_direction(
                            searchy, searchx, game.lokopizza.by(char))
                        if newy1 and newx1:
                            ergebnisgefunden.append(False)
                            #newy2 = newy1
                            #newx2 = newx2
                            #break
                    #if newy2 and newx2:
                    #	return False
                return not (False in ergebnisgefunden)

            if suche(randy, randx):
                # Wenn eins gefunden wurde,
                # hoert die schleife auf und keeprunning wird false
                keeprunning = False
                # Damit die Pizza runterfallen kann wird fally = 0 gesetzt
                fally = 0
                oldchar = None

                # Waehrend fally nicht randy ist,
                # soll die Pizza in Richtung der Schiene fallen
                while (fally != randy):
                    if oldchar:
                        screen.addstr(fally, randx, oldchar)
                    oldchar = screen.instr(fally + 1, randx)
                    screen.addstr(fally + 1, randx, "Q")
                    screen.refresh()
                    yield None
                    fally += 1

                # Und bei fally <= randy wird die Schiene plus Pizza entfernt
                # und special effects sollen danach in x form um die einschlagsstelle
                # auftauchen und wieder verschwinden
                if (fally <= randy):
                    game.animations.append(
                        specialfx.explosion(fally, randx, game))
                    game.schienen.append(
                        schienen.Schiene(fally, randx, game, "#"))
Ejemplo n.º 14
0
 def lesen(self):
     self.lokopizza.screen.nodelay(1)
     if self.level:
         try:
             weiche = int(self.lokopizza.screen.getkey())
         except curses.error:  #nichts gelesen
             return
         except ValueError:
             return
         while (True):
             richtung = self.lokopizza.screen.getch()
             if richtung != -1:  #kein Zeichen
                 if richtung != 27:  #ESC
                     if richtung != 91:  #[
                         break
         if richtung == 65:  #curses.KEY_UP
             pfeil = "^"
         elif richtung == 67:  #curses.KEY_RIGHT
             pfeil = ">"
         elif richtung == 66:  #curses.KEY_DOWN
             pfeil = "v"
         elif richtung == 68:  #curses.KEY_LEFT
             pfeil = "<"
         else:
             return
         for y in range(25):
             for x in range(80):
                 if str(weiche) == self.lokopizza.screen.instr(y, x, 1):
                     if self.lokopizza.screen.instr(
                             y + 1, x + 1, 1) in ["X", "^", ">", "v", "<"]:
                         self.lokopizza.screen.addstr(y + 1, x + 1, pfeil)
                     else:
                         self.animations.append(
                             specialfx.explosion(y + 1, x + 1, self))
     else:
         try:
             wahl = self.lokopizza.screen.getkey()
         except curses.error:  #nichts gelesen
             return
         if wahl == "s":
             self.lokopizza.loadLevel(1)
         elif wahl == "o":
             self.lokopizza.screen.addstr(
                 24, 1, "This is currently not possible yet. Sorry.")
             #TODO: Tutorial
         elif wahl == "l":
             self.lokopizza.screen.addstr(
                 24, 1, "Please type your level number. (0 to abort.)")
             self.lokopizza.screen.clrtoeol()
             self.lokopizza.screen.refresh()
             while (True):
                 try:
                     level = int(self.lokopizza.screen.getkey())
                     break
                 except curses.error:
                     continue
                 except ValueError:
                     self.lokopizza.screen.addstr(
                         24, 1, "That was no number. Please try again.")
                     self.lokopizza.screen.refresh()
                     continue
             self.lokopizza.loadLevel(level)
         elif wahl == "e" or wahl == "q":
             self.lokopizza.quit()
         else:
             self.lokopizza.screen.addstr(24, 1, "Please try again.")
             self.lokopizza.screen.clrtoeol()
     self.lokopizza.screen.refresh()