def add_score(score): """ Prompts the user to input their name, and appends the created Score object to its proper position in the scorelist. Returns None if the user decided not to save their score, or otherwise the scorelist. """ pyconio.clrscr() if save_topscore() == "continue": draw.logo() pyconio.gotoxy(13, 22) pyconio.normalmode() pyconio.write("Add meg a neved (ne használj ':'-ot):", end="\n") draw.cursor(True) pyconio.flush() name = input(" ") while ":" in name: pyconio.write("Hibás név, kérlek add meg ':' nélkül.", end="\n") name = input(" ") draw.cursor(False) pyconio.rawmode() scorelist = get_scores() if scorelist is not None: scorelist.append(Score(name, score)) scorelist.sort(key=int, reverse=True) if len(scorelist) > 5: scorelist.pop(-1) elif scorelist == -1: pyconio.gotoxy(15, 26) pyconio.write("Hibás file, ellenőrizd a pontszámokat!") else: scorelist = [Score(name, score)] return scorelist else: return None
def image_draw(self): for y in range(20): for x in range(40): gotoxy(x, y) print(self.image[y][x], end='') gotoxy(0, 0) print(self.name.upper())
def __init__(self): self.fut = True self.gameState = 0 self.p = Palya() gotoxy(0, 9) print('{:^40}'.format('Loading map...')) self.p.beolvas(os.path.join(os.path.dirname(__file__), 'sziget.png')) self.k = Kamera(self.p) self.k.kirajzol() self.j = Jatekos(self.p, self.k, 476, 178) self.enemies = [] self.enemies.append( Ellenfel(self.p, self.j, self.j.x + 10, self.j.y - 10)) for _ in range(1000): while True: r_x = random.randint(0, 1023) r_y = random.randint(0, 1023) if str(self.p.adat[r_y] [r_x]) not in szilard_ellenfelnek and tavolsag( (self.j.x, self.j.y), (r_x, r_y)) >= 15: self.enemies.append(Ellenfel(self.p, self.j, r_x, r_y)) break self.dolgok = DolgokPalyan(self.p) fegyo = Fegyver('sling-shot', 0.35, round(self.j.x + 3), round(self.j.y)) self.dolgok.hozza_ad(fegyo, (fegyo.x, fegyo.y)) self.timers = [] self.timers.append(Timer(20)) tutorial(self.j.fegyver)
def game_init(mode, fieldsize, level): """ Initialize the game depending on the given mode, either from scratch, or by loading an existing saved state. This handles non-existing save files too. """ if mode == "new": field = control.make_field(fieldsize) next = control.make_random([fieldsize * 2, 0]) mainloop(control.make_random([fieldsize // 4, 0]), field, next, 0, level) elif mode == "load": loaded = control.load_game("save.txt") if loaded is not None: (field, shape, pos, next, points, level) = loaded else: pyconio.gotoxy(5, 20) pyconio.write("Nem található mentés, biztosan mentettél már?") pyconio.gotoxy(20, 29) pyconio.write("Vissza: ESC") key = pyconio.getch() while key != pyconio.ESCAPE: key = pyconio.getch() return main() fieldsize = len(field) tetro = draw.Tetromino(shape, pos[0], pos[1]) next = draw.Tetromino(next, fieldsize * 2, 0) mainloop(tetro, field, next, points, level)
def kerdes(szoveg): uzenet(szoveg, True) pont = ((40 - 30) // 2, (20 - 12) // 2) gotoxy(pont[0] + 2, pont[1] + 8) print('{:^26}'.format('[SPACE] [BACKSPACE]')) while True: if keyboard.is_pressed('backspace'): return False if keyboard.is_pressed('space'): return True
def save_menu(): """ Menu after save, asking the user to either continue or quit the game. """ pyconio.clrscr() pyconio.gotoxy(10, 18) pyconio.write("Sikeres mentés, folytatod a játékot?", flush=True) buttons = [ Button("Játék folytatása", "continue"), Button("Kilépés a főmenübe", "quit") ] return menu(buttons)
def save_topscore(): """ Menu after having earned a top score, save it, or not. """ pyconio.gotoxy(13, 17) pyconio.write("Szép volt, dicsőséglistára kerültél!", flush=True) pyconio.gotoxy(15, 18) pyconio.write("Szeretnéd menteni a pontszámod?", flush=True) buttons = [ Button("Pontszám mentése", "continue"), Button("Kilépés a főmenübe", "quit") ] return menu(buttons)
def render(self): if self.shift_x > self.palya.szel-self.SZEL: self.shift_x = self.palya.szel-self.SZEL if self.shift_x < 0: self.shift_x = 0 if self.shift_y > self.palya.mag-self.MAG: self.shift_y = self.palya.mag-self.MAG if self.shift_y < 0: self.shift_y = 0 for y in range(0, self.MAG): for x in range(0, self.SZEL): if self.adat[y][x] != self.palya.adat[y+self.shift_y][x+self.shift_x]: self.adat[y][x] = self.palya.adat[y+self.shift_y][x+self.shift_x] gotoxy(x, y) print(self.adat[y][x])
def menu(buttons, data=None): """ Common menu mechanism, including the indication of the selected button and navigation. Returns None if the user selected quit (either by pressing ESC or selecting the option), or executes the selected function otherwise, with optional data. """ pyconio.textcolor(pyconio.WHITE) buttons[0].active = True draw.logo() while True: for btn in buttons: if btn.active: pyconio.textbackground(pyconio.WHITE) pyconio.textcolor(pyconio.BLACK) else: pyconio.textbackground(pyconio.RESET) pyconio.textcolor(pyconio.RESET) pyconio.gotoxy(20, 20 + buttons.index(btn)) pyconio.write(btn) pyconio.gotoxy(15, 29) pyconio.textcolor(pyconio.RESET) pyconio.textbackground(pyconio.RESET) pyconio.write("Irányítás: ↑ ↓ ENTER ESC") pyconio.flush() pyconio.rawmode() key = pyconio.getch() active = buttons.index([x for x in buttons if x.active][0]) if key == pyconio.ENTER: return select(buttons[active].function, data) elif key == pyconio.DOWN: buttons[active].active = False if active == len(buttons) - 1: buttons[0].active = True else: buttons[active + 1].active = True elif key == pyconio.UP: buttons[active].active = False if active == 0: buttons[-1].active = True else: buttons[active - 1].active = True elif key == pyconio.ESCAPE: return select("quit")
def kep_kirajzol(): for y in range(20): for x in range(40): gotoxy(x, y) print(kep[y][x], end='') gotoxy(7, 14) print(j.skin) gotoxy(7 + e_tav, 14) print(e.skin) gotoxy(5, 16) print('◄A▒D►')
def setting_adjust(setting, label, min_val, max_val, delta=1): """ Used in the options menu, lets the user change the default options with the UP and DOWN keys. The actual setting, its label, value interval (and granularity) should be given as parameters. """ draw.logo() pyconio.textbackground(pyconio.RESET) pyconio.textcolor(pyconio.RESET) pyconio.gotoxy(20, 20) pyconio.write("{}: {:3}".format(label, setting), flush=True) pyconio.gotoxy(15, 29) pyconio.write("Irányítás: ↑ ↓ ENTER ESC") initial = setting pyconio.rawmode() key = pyconio.getch() while key != pyconio.ENTER: if key == pyconio.UP: if setting < max_val: setting += delta elif key == pyconio.DOWN: if setting > min_val: setting -= delta elif key == pyconio.ESCAPE: setting = initial break pyconio.gotoxy(20, 20) pyconio.write("{}: {:3}".format(label, setting), flush=True) key = pyconio.getch() return setting
def print(self): """ Prints the teromino to the screen. This method is required because of the newline character in the string. Using this print, the tetrominoes' new lines will be written to their proper position, not to the beginning of the new line. """ newline = 0 newrow = 0 start_x = self.pos[0] * 2 start_y = self.pos[1] pyconio.gotoxy(start_x, start_y) for c in str(self): if c == "\n": newline += 1 newrow = 0 pyconio.gotoxy(start_x, start_y + newline) elif c == " ": newrow += 1 pyconio.gotoxy(start_x + newrow, start_y + newline) else: pyconio.textcolor(self.color) pyconio.write(c)
def list_scores(scorelist, pos, data=None): """ Lists the scores from the given scorelist to the given position. Adds numbering and colors (for the top 3) to the list elements, and prints out the proper errors when needed. Returns to the main menu, with optional data if passed. """ pyconio.clrscr() draw.logo() pyconio.gotoxy(pos[0], pos[1]) pyconio.textcolor(pyconio.RESET) if scorelist is None: pyconio.gotoxy(pos[0] - 15, pos[1]) pyconio.write("A file nem található, biztosan játszottál már?") elif scorelist == -1: pyconio.gotoxy(pos[0] - 10, pos[1]) pyconio.write("Hibás file, ellenőrizd a pontszámokat!") else: for i in range(len(scorelist)): if i + 1 == 1: pyconio.textcolor(pyconio.YELLOW) elif i + 1 == 2: pyconio.textcolor(pyconio.LIGHTGRAY) elif i + 1 == 3: pyconio.textcolor(pyconio.BROWN) else: pyconio.textcolor(pyconio.RESET) pyconio.gotoxy(pos[0], pos[1] + i) pyconio.write("{}. {}".format(i + 1, scorelist[i])) pyconio.gotoxy(pos[0] + 2, pos[1] + pos[1] // 2) pyconio.textcolor(pyconio.RESET) pyconio.write("Vissza: ESC") pyconio.flush() pyconio.rawmode() key = pyconio.getch() while key != pyconio.ESCAPE: key = pyconio.getch() pyconio.clrscr() return main_menu(data)
def options(pos, settings=None): """ Options menu with the listed buttons, creating an Options object that stores the current settings. If settings are changed, those are then passed to the other menus, to make use of them when needed. """ pyconio.clrscr() pyconio.gotoxy(pos[0], pos[1]) buttons = [Button("Pálya mérete", "size"), Button("Kezdő szint", "level")] if settings is None: settings = Options() choice = menu(buttons, settings) if choice is not None: (selected, set_value) = choice else: return main_menu(settings) if selected == "size": settings.size = set_value elif selected == "level": settings.level = set_value pyconio.rawmode() return options((20, 20), settings)
def logo(file="logo.txt"): """ Prints the content of the given file under logos/ (or logo.txt as default), used for printing the title Tetris (in Russian), with the original colors. To use different colors for printing, a pipe character must be used as separator between different sections. """ pyconio.gotoxy(0, 5) colors = [ pyconio.RED, pyconio.BROWN, pyconio.YELLOW, pyconio.GREEN, pyconio.CYAN, pyconio.MAGENTA ] with open("logos/{}".format(file), "rt", encoding="utf-8") as logo: for line in logo: letters = line.rstrip("\n").split("|") for letter in range(len(letters)): pyconio.textcolor(colors[letter]) pyconio.write(letters[letter]) pyconio.write("\n") pyconio.flush() pyconio.textbackground(pyconio.RESET) pyconio.textcolor(pyconio.RESET)
def valsection(field, val, posy, label): """ Prints a section that is used for displaying the points and levels, as both the label and value should be given as parameters, in addition to the y position of the box. The box scales with the value's length, and has a height of 1 unit. """ pyconio.textcolor(pyconio.WHITE) pyconio.gotoxy(len(field) + len(field[0]) - len(label), posy + 1) pyconio.write(label) pyconio.gotoxy(len(field) + len(field[0]), posy) pyconio.write("╔" + "═" * len(str(val)) + "╗") pyconio.gotoxy(len(field) + len(field[0]), posy + 1) pyconio.write("║{}║".format(val)) pyconio.gotoxy(len(field) + len(field[0]), posy + 2) pyconio.write("╚" + "═" * len(str(val)) + "╝")
def tutorial(fegyver): gotoxy(42, 2) print(' ' * 20) if kerdes('Do you need a short tutorial?'): uzenet('Alright! Let me tell you...') uzenet('☺ <-this is you.') uzenet('☻ <-and this is an enemy.') if not kerdes('So far it\'s simple. Right?'): uzenet('Come on, it\'s not that hard...') uzenet('You can move with the <WASD> keys.') uzenet( 'You are on a big island, if you want to see how big it is just press <M>.' ) uzenet('Not now... When you will be on the field!') gotoxy(42, 0) print('STA' + '▓' * 10) uzenet( 'If you want to go faster, just hold <SHIFT>. Although, you have a stamina (shown top right) which you need for running faster.' ) gotoxy(42, 2) print('WEAPON: {}'.format(fegyver)) uzenet('Another thing you can find in your way are weapons.') uzenet('☼ <-this is a weapon!') uzenet('If you find one, step on it and press <F>.') uzenet('Not for respect this time...') uzenet('You can inspect anything by stepping on it and pressing <F>.') uzenet('I think I told you everything you need for now.') uzenet('Oh, yes, one more thing!') uzenet('░ <- this is water, you can\'t swim.') uzenet('▒ <- and this is solid rock, also you can\'t swim in it.') uzenet('Now let\'s go and explore!') uzenet('and don\'t forget to press <M> sometimes!') else: gotoxy(42, 0) print('STA' + '▓' * 10) gotoxy(42, 2) print('WEAPON: {}'.format(fegyver))
def nextsection(field, next): """ Prints a section containing the tetromino to come, after the current one is placed. The box's position depends on the matrix's size. """ size = 10 start_x = len(field) + size // 2 start_y = len(field) // 2 - 3 pyconio.gotoxy(start_x + 2, start_y - 1) pyconio.write("N E X T") pyconio.gotoxy(start_x, start_y) pyconio.write("╔" + "═" * (size - 1) + "╗") for y in range((size // 2) - 1): pyconio.gotoxy(start_x, start_y + 1 + y) pyconio.write("║") for x in range(size - 1): pyconio.write(" ") pyconio.write("║") pyconio.gotoxy(start_x, start_y + size // 2) pyconio.write("╚" + "═" * (size - 1) + "╝") next.pos = [(start_x + 2) // 2, start_y + 2] next.print()
def ground(field): """ Prints the playing field (matrix) in its current state. Boundaries are indicated with box-drawing characters, and tetrominos with block elements. """ pyconio.textcolor(pyconio.WHITE) pyconio.gotoxy(1, 0) pyconio.write("╔" + "═" * len(field) + "╗") for line in range(len(field)): pyconio.gotoxy(1, line + 1) pyconio.textcolor(pyconio.WHITE) pyconio.write("║") for row in range(len(field[line])): if field[line][row] != 0: pyconio.textcolor(get_color(field[line][row])) pyconio.write("█" * 2) else: pyconio.write(" " * 2) pyconio.textcolor(pyconio.WHITE) pyconio.write("║") pyconio.gotoxy(1, len(field) + 1) pyconio.write("╚" + "═" * len(field) + "╝")
def kirajzol(self): gotoxy(0, 0) for _ in range(20): print(' ' * 80) yy = (20 - len(self.menupontok)) // 2 n = 0 for sor in self.menupontok: n = len(sor) if len(sor) > n else n xx = (40 - n) // 2 for y in range(len(self.menupontok)): gotoxy(xx, yy + y) print(self.menupontok[y]) while True: for i in range(len(self.menupontok)): gotoxy(xx - 2, yy + i) if i == self.menu_index: print('☺', end='') else: print(' ', end='') if keyboard.is_pressed('w') or keyboard.is_pressed('up'): self.menu_index -= 1 if self.menu_index < 0: self.menu_index = len(self.menupontok) - 1 if keyboard.is_pressed('s') or keyboard.is_pressed('down'): self.menu_index += 1 if self.menu_index > len(self.menupontok) - 1: self.menu_index = 0 if keyboard.is_pressed('enter'): break time.sleep(0.05)
def csata(j, e): kep_file = os.path.join(os.path.dirname(__file__), 'csata.png') try: im = Image.open(kep_file) pixels = im.load() except: raise FileNotFoundError('PNG nem található: {}'.format(kep_file)) kep = [[' ' for _ in range(40)] for _ in range(20)] for y in range(20): for x in range(40): gotoxy(x, y) c = pixels[x, y] if c == (170, 170, 170): #szürke kep[y][x] = '░' elif c == (255, 255, 255): #fehér kep[y][x] = ' ' elif c == (0, 0, 0): #fekete kep[y][x] = '▒' lovedek = '•' e_tav = 25 celzas = j.fegyver.acc * 100 jatekos_halott = False vege = False elfutas = False def kep_kirajzol(): for y in range(20): for x in range(40): gotoxy(x, y) print(kep[y][x], end='') gotoxy(7, 14) print(j.skin) gotoxy(7 + e_tav, 14) print(e.skin) gotoxy(5, 16) print('◄A▒D►') kep_kirajzol() time.sleep(0.5) while not vege: kep_kirajzol() while not (keyboard.is_pressed('d') or keyboard.is_pressed('a')): pass if keyboard.is_pressed( 'a') and not keyboard.is_pressed('d'): #menekules uzenet('You are trying to run away...') if random.randint(1, 6) > 4: elfutas = True vege = True uzenet('...and you managed to run away!') else: uzenet('...but you can\'t, keep fighting!') e_tav -= 24 // 6 celzas *= 1.1 if keyboard.is_pressed('d') and not keyboard.is_pressed('a'): #loves gotoxy(8, 14) print(lovedek, end='') for i in range(1, 40 - 8): gotoxy(7 + i, 14) if i != e_tav: print(' ', end='') if i + 1 != e_tav: gotoxy(7 + i + 1, 14) print(lovedek, end='') time.sleep(0.014) elif random.randint(0, 100) <= celzas: vege = True print('X', end='') time.sleep(0.7) break else: e_tav -= 24 // 6 celzas *= 1.1 gotoxy(39, 14) print(' ', end='') if e_tav <= 1: e_tav = 1 jatekos_halott = True vege = True uzenet('Too late, the enemy catched you...') if elfutas: e.state = 1 else: if jatekos_halott: uzenet('You died...') return False else: e.state = -1 return True
def uzenet(szoveg, lesz_e_kerdes=False): pont = ((40 - 30) // 2, (20 - 12) // 2) gotoxy(pont[0], pont[1]) print('▓' * 30, end='') for y in range(10): gotoxy(pont[0], pont[1] + 1 + y) print('▓' + ' ' * 28 + '▓', end='') gotoxy(pont[0], pont[1] + 11) print('▓' * 30, end='') szoveg = szoveg.split(' ') sor = 0 sor_hoszz = 0 for szo in szoveg: if len(szo) + sor_hoszz > 26: sor += 1 if sor > 5: sor = 0 gotoxy(pont[0] + 2, pont[1] + 2 + 7) print('{:^26}'.format('<ENTER>')) while not keyboard.is_pressed('enter'): pass for y in range(8): gotoxy(pont[0] + 2, pont[1] + 2 + y) print(' ' * 26, end='') sor_hoszz = 0 gotoxy(pont[0] + 2 + sor_hoszz, pont[1] + 2 + sor) print(szo, end=' ') sor_hoszz += len(szo) + 1 time.sleep(0.05) time.sleep(0.5) if not lesz_e_kerdes: gotoxy(pont[0] + 2, pont[1] + 8) print('{:^26}'.format('[ENTER]')) while not keyboard.is_pressed('enter'): pass
import pyconio import time # Init pyconio.settitle("pyconio test") # Positioning pyconio.clrscr() pyconio.gotoxy(0, 0) pyconio.textcolor(pyconio.LIGHTGREEN) pyconio.write("Hello") pyconio.gotoxy(10, 0) pyconio.textbackground(pyconio.LIGHTBLUE) pyconio.write("world!") print() # Printing color codes print(pyconio.backgroundcolors[pyconio.RESET], end="") print("{}Hello {}world!".format(pyconio.textcolors[pyconio.RED], pyconio.textcolors[pyconio.GREEN])) # Color combinations for b in range(0, 16): pyconio.gotoxy(5, 5+b) for t in range(0, 16): pyconio.textcolor(t) pyconio.textbackground(b) pyconio.write(" X ") pyconio.write("\n") print() # Raw input
def statok(self): gotoxy(42, 2) print('WEAPON: {} '.format(self.fegyver))
def mozgat(self): ##SZABAD ÁLLAPOT if self.state == 0: elozo_x = self.x elozo_y = self.y ##SEBESSEG KEZELES if keyboard.is_pressed('left shift') and self.stamina > 5 and self.mozog: speed_x = self.alap_seb * 1.25 self.stamina -= 5 else: speed_x = self.alap_seb if self.stamina < 1000: self.stamina += 1 if self.stamina > 1000: self.stamina = 1000 speed_y = speed_x * 0.75 # BILLENTYŰK if keyboard.is_pressed('d'): self.x += speed_x if keyboard.is_pressed('a'): self.x -= speed_x if keyboard.is_pressed('s'): self.y += speed_y if keyboard.is_pressed('w'): self.y -= speed_y ##MAS DOLGOKKAL VALO INTERAKCIO if round(elozo_x) != round(self.x): if self.palya.adat[round(self.y)][round(self.x)] in szilard_jatekosnak: self.x = elozo_x self.speed_x = self.speed_y = 0 if round(elozo_y) != round(self.y): if self.palya.adat[round(self.y)][round(self.x)] in szilard_jatekosnak: self.y = elozo_y self.speed_x = self.speed_y = 0 ##PALYAN MOZGATAS self.palya.adat[round(elozo_y)][round(elozo_x)] = self.amin_all self.amin_all = self.palya.adat[round(self.y)][round(self.x)] self.palya.adat[round(self.y)][round(self.x)] = self.skin ##KAMERA MOZGATAS if round(self.x) > round(self.kam.SZEL/2-1) and round(self.x) < round(self.palya.szel - self.kam.SZEL/2 + 1): self.kam.shift_x = round(self.x - self.kam.SZEL/2) if round(self.y) > round(self.kam.MAG/2-1) and round(self.y) < round(self.palya.mag - self.kam.MAG/2 + 1): self.kam.shift_y = round(self.y - self.kam.MAG/2) else: gotoxy(0, 0) print('HIBA: NINCS ILYEN ÁLLAPOT') input() ##ALLAPOTTOL FUGGETLEN DOLGOK #STAMINA RAJZOLAS gotoxy(self.kam.SZEL + 2, 0) print('STA' + '▓'*(self.stamina//100) + '░'*(10-self.stamina//100), end='') #MOZGAS KEZELES if elozo_x == self.x and elozo_y == self.y: self.mozog = False else: self.mozog = True
def mainloop(tetro, field, next, points=0, level=1): """ Prints the field and the currently active tetromino to its given position. While ingame, you can control it with UP-DOWN-LEFT-RIGHT as in Tetris. Pause the loop with the ESC key, if you choose continue, the current loop ends, and is called again with the current parameters. """ game_sec = time.time() draw.screen(tetro, field, next, points, level) ingame = (True, 0) with pyconio.rawkeys(): while ingame[0]: current_sec = time.time() # Control mechanism if pyconio.kbhit(): ingame = control.ingame(tetro, field) points += ingame[1] * level draw.screen(tetro, field, next, points, level) # Fall mechanism if round(current_sec, min(level, 2)) >= round( game_sec, min(level, 2)): if control.move_valid(control.post_move(tetro, "down"), field): if control.hit(control.post_move(tetro, "down"), field): if tetro.pos[1] >= 1: last = tetro next.pos = [5, 0] tetro = next next = control.store_regen(last, field, next) # Game over if tetro hits another one, while Y pos is <1 else: ingame = (False, points) pyconio.clrscr() draw.logo("game_over.txt") time.sleep(1) # Add to top scores if needed scores = menu.get_scores() # If highscores.txt exists, is valid and not empty if scores not in (None, -1, []): if points > scores[-1].points: scorechoice = menu.add_score(points) if scorechoice is not None: menu.write_score(scorechoice) # If invalid elif scores == -1: pyconio.gotoxy(12, 25) pyconio.write("Hibás dicsőséglista!", end="\n") pyconio.gotoxy(8, 26) pyconio.write("Ellenőrizd a highscores.txt-t!") pyconio.flush() time.sleep(2.5) # If doesn't exist yet or empty else: scorechoice = menu.add_score(points) if scorechoice is not None: menu.write_score(scorechoice) return main() else: tetro.pos[1] += 1 # When hit, save tetro and generate new one. else: last = tetro next.pos = [len(field) // 4, 0] tetro = next next = control.store_regen(last, field, next) # Game ticks game_sec += control.speed_sec(level) draw.screen(tetro, field, next, points, level) # Line clear if control.line_full(field): points += control.delete_full(field) * level draw.screen(tetro, field, next, points, level) # Level up if points >= level**2 * 1000: level += 1 draw.screen(tetro, field, next, points, level) # Pause pausechoice = menu.pause() if pausechoice == "save": control.save_game(tetro, field, next, points, level) pausechoice = menu.save_menu() if pausechoice == "continue": return mainloop(tetro, field, next, points, level) elif pausechoice is None: return main()
def kirajzol(self, x=0, y=0): for yy in range(0, self.MAG): for xx in range(0, self.SZEL): gotoxy(xx+x, yy+y) print(self.adat[yy][xx], end='')
def terkep_kirajzol(self, x, y, j, bool): gotoxy(x, y) print('{:▓>17}▓'.format('BACKSPACE'), end='') for yy in range(16): gotoxy(x, y+yy+1) print('▓', end='') gotoxy(x+17, y+yy+1) print('▓', end='') gotoxy(x, y+17) print('▓'*18, end='') for yy in range(16): for xx in range(16): gotoxy(xx+x+1, yy+y+1) print(self.palya.terkep[yy][xx], end='') if bool: gotoxy(x+1+(int(j.x)//64), y+1+(int(j.y)//64)) print(j.skin, end='')
def kirajzol(self, x=0, y=0): for yy in range(0, self.mag): for xx in range(0, self.szel): gotoxy(x+xx, y+yy) print(self.adat[yy][xx], end='')
import pyconio pyconio.clrscr() print("Use cursor keys to control the asterisk") x = 40 y = 12 pyconio.rawmode() while True: pyconio.gotoxy(x, y) pyconio.textcolor(pyconio.LIGHTGREEN) pyconio.write("*") pyconio.gotoxy(80, 24) key = pyconio.getch() pyconio.gotoxy(x, y) pyconio.textcolor(pyconio.BLUE) pyconio.write(".") if key == pyconio.UP: y = max(y - 1, 1) elif key == pyconio.DOWN: y = min(y + 1, 23) elif key == pyconio.LEFT: x = max(x - 1, 0) elif key == pyconio.RIGHT: x = min(x + 1, 79) elif key == pyconio.ESCAPE: break pyconio.normalmode()