ronaldo or messi
đã đăng vào 18, Tháng 6, 2026, 6:22Chat kết quả: 1 cho ronaldo
2 cho messi
Chat kết quả: 1 cho ronaldo
2 cho messi
cmd : curl https://ascii.live/earth
import tkinter as tk, math
class UltraImpossibleGame:
def __init__(self, root):
self.root = root
self.root.title("The Impossible Game")
self.w, self.h, self.sidebar_w, self.gravity, self.jump_force, self.base_speed, self.ground_y = 700, 400, 160, 1.5, -16, 8.5, 280
self.vy, self.is_jumping, self.angle, self.active, self.loop_id, self.score, self.attempt = 0, False, 0, True, None, 0, 1
self.speed = self.base_speed
if not hasattr(self, 'top_scores'): self.top_scores = [0] * 10
self.blocks, self.spikes = [], []
self.track_layout = [(400, 's'), (650, 's'), (900, 'b'), (930, 'b'), (1150, 's'), (1350, 'b'), (1500, 's'), (2000, 's'), (2030, 's'), (2300, 'b'), (2330, 'b'), (2450, 's'), (2700, 'b'), (2730, 'u'), (3000, 's'), (3030, 's'), (3300, 'b'), (3330, 'b'), (3360, 'b'), (3550, 's'), (3800, 'b'), (3950, 's'), (3980, 's'), (4200, 'b'), (4230, 'b'), (4350, 's'), (4600, 'b'), (4630, 'b'), (4750, 'b'), (4780, 'b'), (4900, 's'), (4930, 's'), (4960, 's'), (5200, 'b'), (5230, 'u'), (5260, 'b'), (5500, 's'), (5700, 'b'), (5730, 'b'), (5760, 'u'), (6000, 's'), (6030, 's'), (6300, 'b'), (6330, 'b'), (6450, 's'), (6480, 's'), (6800, 'b'), (6830, 'b'), (6860, 'b'), (6890, 'u'), (7100, 's'), (7500, 's'), (7530, 's'), (7560, 's'), (7850, 'b'), (7880, 'u'), (7910, 'b'), (7940, 'u'), (8200, 's'), (8400, 'b'), (8430, 'b'), (8550, 's'), (8580, 's'), (8800, 'b'), (8830, 'u'), (9100, 's'), (9130, 's'), (9160, 's'), (9400, 'b'), (9430, 'b'), (9460, 'b'), (9600, 'u'), (9900, 's'), (10200, 'b'), (10230, 'u'), (10500, 's'), (10530, 's'), (11000, 'b'), (11030, 'b'), (11060, 'b'), (11090, 'b'), (11120, 'u')]
self.canvas = tk.Canvas(root, width=self.w + self.sidebar_w, height=self.h, bg="#001122", highlightthickness=0)
self.canvas.pack()
self.setup()
self.tick()
def setup(self):
self.score_txt = self.canvas.create_text(20, 30, text="PROGRESS: 0%", fill="#fff", font=("Arial", 12, "bold"), anchor="w")
self.attempt_txt = self.canvas.create_text(self.w - 20, 30, text=f"ATTEMPT {self.attempt}", fill="#fff", font=("Arial", 12, "bold"), anchor="e")
self.canvas.create_line(0, self.ground_y, self.w, self.ground_y, fill="#fff", width=3)
self.canvas.create_rectangle(self.w, 0, self.w + self.sidebar_w, self.h, fill="#000b14", outline="#00ffff", width=2)
self.canvas.create_text(self.w + 15, 30, text="TOP 10 RUNS", fill="#00ffff", font=("Arial", 11, "bold"), anchor="w")
for i, val in enumerate(self.top_scores):
color = "#ffaa00" if i==0 else "#00ffaa" if i<3 else "#8c9ea3"
self.canvas.create_text(self.w + 15, 65 + (i * 28), text=f"{i+1}. {val}%", fill=color, font=("Courier New", 11, "bold"), anchor="w")
self.p_size = 30
self.px, self.py = 120, self.ground_y - self.p_size
self.player_id = self.canvas.create_polygon(0, 0, 0, 0, 0, 0, 0, 0, fill="#ff4400", outline="#fff", width=2)
for x, t in self.track_layout:
if t == 's': self.spikes.append(self.canvas.create_polygon(x, self.ground_y, x+15, self.ground_y-30, x+30, self.ground_y, fill="#fff", outline="#001122"))
elif t == 'b': self.blocks.append(self.canvas.create_rectangle(x, self.ground_y-30, x+30, self.ground_y, fill="#002244", outline="#00ffff", width=2))
elif t == 'u':
self.blocks.append(self.canvas.create_rectangle(x, self.ground_y-30, x+30, self.ground_y, fill="#002244", outline="#00ffff", width=2))
self.spikes.append(self.canvas.create_polygon(x, self.ground_y-30, x+15, self.ground_y-60, x+30, self.ground_y-30, fill="#fff", outline="#001122"))
self.root.bind("<space>", lambda e: self.jump())
self.root.bind("<Up>", lambda e: self.jump())
def jump(self):
if not self.is_jumping and self.active: self.vy, self.is_jumping = self.jump_force, True
def tick(self):
if not self.active: return
self.vy += self.gravity
self.py += self.vy
self.score += self.speed
self.speed = self.base_speed + (self.score / 3500)
self.percentage = min(100, int((self.score / 11500) * 100))
self.canvas.itemconfig(self.score_txt, text=f"PROGRESS: {self.percentage}%")
if self.percentage >= 100:
self.active = False
self.canvas.create_text(self.w//2, 200, text="THE IMPOSSIBLE CLEARED!", fill="#00ffaa", font=("Arial", 22, "bold"))
return
self.angle = (self.angle + 9.0) % 360 if self.is_jumping else round(self.angle / 90) * 90
if self.py >= self.ground_y - self.p_size: self.py, self.vy, self.is_jumping = self.ground_y - self.p_size, 0, False
cx, cy, r = self.px + 15, self.py + 15, math.radians(self.angle)
cos_a, sin_a, h = math.cos(r), math.sin(r), 15
pts = []
for lx, ly in [(-h,-h), (h,-h), (h,h), (-h,h)]: pts.extend([cx + (lx * cos_a - ly * sin_a), cy + (lx * sin_a + ly * cos_a)])
self.canvas.coords(self.player_id, *pts)
for s in self.spikes: self.canvas.move(s, -self.speed, 0)
for b in self.blocks: self.canvas.move(b, -self.speed, 0)
px1, py1, px2, py2 = self.px, self.py, self.px + 30, self.py + 30
on_plat = False
for b in self.blocks:
bbox = self.canvas.bbox(b)
if bbox:
bx1, by1, bx2, by2 = bbox
if px2 > bx1 + 3 and px1 < bx2 - 3:
if py2 >= by1 and py2 <= by1 + 12 and self.vy >= 0: self.py, self.vy, self.is_jumping, on_plat = by1 - 30, 0, False, True
elif py2 > by1 + 8 and px2 >= bx1 and px1 < bx1: return self.die()
if not on_plat and self.py < self.ground_y - 30 and self.vy == 0: self.is_jumping = True
for s in self.spikes:
c = self.canvas.coords(s)
if c and len(c) >= 6 and px2 > c[0] + 4 and px1 < c[4] - 4:
pm = (px1 + px2) / 2
ratio = (pm - c[0]) / (c[2] - c[0]) if pm <= c[2] else (c[4] - pm) / (c[4] - c[2])
if py2 > (c[1] - (ratio * (c[1] - c[3]))) + 4: return self.die()
self.loop_id = self.root.after(16, self.tick)
def die(self):
self.active = False
if self.loop_id: self.root.after_cancel(self.loop_id)
self.top_scores.append(self.percentage)
self.top_scores = sorted(list(set(self.top_scores)), reverse=True)[:10]
while len(self.top_scores) < 10: self.top_scores.append(0)
self.canvas.create_text(self.w//2, 170, text="TRY AGAIN", fill="#ff4400", font=("Arial", 28, "bold"))
self.canvas.create_text(self.w//2, 215, text=f"Reached: {self.percentage}%", fill="#fff", font=("Arial", 14))
self.root.after(850, self.reset)
def reset(self):
self.canvas.delete("all")
self.spikes.clear()
self.blocks.clear()
self.vy, self.angle, self.score, self.speed, self.is_jumping, self.active, self.attempt = 0, 0, 0, self.base_speed, False, True, self.attempt + 1
self.setup()
self.tick()
if __name__ == "__main__":
win = tk.Tk()
UltraImpossibleGame(win)
win.mainloop()
import tkinter as tk, math class UltraImpossibleGame: def init(self, root): self.root = root self.root.title("The Impossible Game") self.w, self.h, self.sidebarw, self.gravity, self.jumpforce, self.basespeed, self.groundy = 700, 400, 160, 1.5, -16, 8.5, 280 self.vy, self.isjumping, self.angle, self.active, self.loopid, self.score, self.attempt = 0, False, 0, True, None, 0, 1 self.speed = self.basespeed if not hasattr(self, 'topscores'): self.topscores = [0] * 10 self.blocks, self.spikes = [], [] self.tracklayout = [(400, 's'), (650, 's'), (900, 'b'), (930, 'b'), (1150, 's'), (1350, 'b'), (1500, 's'), (2000, 's'), (2030, 's'), (2300, 'b'), (2330, 'b'), (2450, 's'), (2700, 'b'), (2730, 'u'), (3000, 's'), (3030, 's'), (3300, 'b'), (3330, 'b'), (3360, 'b'), (3550, 's'), (3800, 'b'), (3950, 's'), (3980, 's'), (4200, 'b'), (4230, 'b'), (4350, 's'), (4600, 'b'), (4630, 'b'), (4750, 'b'), (4780, 'b'), (4900, 's'), (4930, 's'), (4960, 's'), (5200, 'b'), (5230, 'u'), (5260, 'b'), (5500, 's'), (5700, 'b'), (5730, 'b'), (5760, 'u'), (6000, 's'), (6030, 's'), (6300, 'b'), (6330, 'b'), (6450, 's'), (6480, 's'), (6800, 'b'), (6830, 'b'), (6860, 'b'), (6890, 'u'), (7100, 's'), (7500, 's'), (7530, 's'), (7560, 's'), (7850, 'b'), (7880, 'u'), (7910, 'b'), (7940, 'u'), (8200, 's'), (8400, 'b'), (8430, 'b'), (8550, 's'), (8580, 's'), (8800, 'b'), (8830, 'u'), (9100, 's'), (9130, 's'), (9160, 's'), (9400, 'b'), (9430, 'b'), (9460, 'b'), (9600, 'u'), (9900, 's'), (10200, 'b'), (10230, 'u'), (10500, 's'), (10530, 's'), (11000, 'b'), (11030, 'b'), (11060, 'b'), (11090, 'b'), (11120, 'u')] self.canvas = tk.Canvas(root, width=self.w + self.sidebarw, height=self.h, bg="#001122", highlightthickness=0) self.canvas.pack() self.setup() self.tick() def setup(self): self.scoretxt = self.canvas.createtext(20, 30, text="PROGRESS: 0%", fill="#fff", font=("Arial", 12, "bold"), anchor="w") self.attempttxt = self.canvas.createtext(self.w - 20, 30, text=f"ATTEMPT {self.attempt}", fill="#fff", font=("Arial", 12, "bold"), anchor="e") self.canvas.createline(0, self.groundy, self.w, self.groundy, fill="#fff", width=3) self.canvas.createrectangle(self.w, 0, self.w + self.sidebarw, self.h, fill="#000b14", outline="#00ffff", width=2) self.canvas.createtext(self.w + 15, 30, text="TOP 10 RUNS", fill="#00ffff", font=("Arial", 11, "bold"), anchor="w") for i, val in enumerate(self.topscores): color = "#ffaa00" if i==0 else "#00ffaa" if i<3 else "#8c9ea3" self.canvas.createtext(self.w + 15, 65 + (i * 28), text=f"{i+1}. {val}%", fill=color, font=("Courier New", 11, "bold"), anchor="w") self.psize = 30 self.px, self.py = 120, self.groundy - self.psize self.playerid = self.canvas.createpolygon(0, 0, 0, 0, 0, 0, 0, 0, fill="#ff4400", outline="#fff", width=2) for x, t in self.tracklayout: if t == 's': self.spikes.append(self.canvas.createpolygon(x, self.groundy, x+15, self.groundy-30, x+30, self.groundy, fill="#fff", outline="#001122")) elif t == 'b': self.blocks.append(self.canvas.createrectangle(x, self.groundy-30, x+30, self.groundy, fill="#002244", outline="#00ffff", width=2)) elif t == 'u': self.blocks.append(self.canvas.createrectangle(x, self.groundy-30, x+30, self.groundy, fill="#002244", outline="#00ffff", width=2)) self.spikes.append(self.canvas.createpolygon(x, self.groundy-30, x+15, self.groundy-60, x+30, self.groundy-30, fill="#fff", outline="#001122")) self.root.bind("<space>", lambda e: self.jump()) self.root.bind("<up>", lambda e: self.jump()) def jump(self): if not self.is</up></space>jumping and self.active: self.vy, self.isjumping = self.jumpforce, True def tick(self): if not self.active: return self.vy += self.gravity self.py += self.vy self.score += self.speed self.speed = self.basespeed + (self.score / 3500) self.percentage = min(100, int((self.score / 11500) * 100)) self.canvas.itemconfig(self.scoretxt, text=f"PROGRESS: {self.percentage}%") if self.percentage >= 100: self.active = False self.canvas.createtext(self.w//2, 200, text="THE IMPOSSIBLE CLEARED!", fill="#00ffaa", font=("Arial", 22, "bold")) return self.angle = (self.angle + 9.0) % 360 if self.isjumping else round(self.angle / 90) * 90 if self.py >= self.groundy - self.psize: self.py, self.vy, self.isjumping = self.groundy - self.psize, 0, False cx, cy, r = self.px + 15, self.py + 15, math.radians(self.angle) cosa, sina, h = math.cos(r), math.sin(r), 15 pts = [] for lx, ly in [(-h,-h), (h,-h), (h,h), (-h,h)]: pts.extend([cx + (lx * cosa - ly * sina), cy + (lx * sina + ly * cosa)]) self.canvas.coords(self.playerid, *pts) for s in self.spikes: self.canvas.move(s, -self.speed, 0) for b in self.blocks: self.canvas.move(b, -self.speed, 0) px1, py1, px2, py2 = self.px, self.py, self.px + 30, self.py + 30 onplat = False for b in self.blocks: bbox = self.canvas.bbox(b) if bbox: bx1, by1, bx2, by2 = bbox if px2 > bx1 + 3 and px1 < bx2 - 3: if py2 >= by1 and py2 <= by1 + 12 and self.vy >= 0: self.py, self.vy, self.isjumping, onplat = by1 - 30, 0, False, True elif py2 > by1 + 8 and px2 >= bx1 and px1 < bx1: return self.die() if not onplat and self.py < self.groundy - 30 and self.vy == 0: self.isjumping = True for s in self.spikes: c = self.canvas.coords(s) if c and len(c) >= 6 and px2 > c[0] + 4 and px1 < c[4] - 4: pm = (px1 + px2) / 2 ratio = (pm - c[0]) / (c[2] - c[0]) if pm <= c[2] else (c[4] - pm) / (c[4] - c[2]) if py2 > (c[1] - (ratio * (c[1] - c[3]))) + 4: return self.die() self.loopid = self.root.after(16, self.tick) def die(self): self.active = False if self.loopid: self.root.aftercancel(self.loopid) self.topscores.append(self.percentage) self.topscores = sorted(list(set(self.topscores)), reverse=True)[:10] while len(self.topscores) < 10: self.topscores.append(0) self.canvas.createtext(self.w//2, 170, text="TRY AGAIN", fill="#ff4400", font=("Arial", 28, "bold")) self.canvas.createtext(self.w//2, 215, text=f"Reached: {self.percentage}%", fill="#fff", font=("Arial", 14)) self.root.after(850, self.reset) def reset(self): self.canvas.delete("all") self.spikes.clear() self.blocks.clear() self.vy, self.angle, self.score, self.speed, self.isjumping, self.active, self.attempt = 0, 0, 0, self.base_speed, False, True, self.attempt + 1 self.setup() self.tick() if name == "main": win = tk.Tk() UltraImpossibleGame(win) win.mainloop()
print("I love Thay Thinh")
these are no longer humans anymore unless you came from alaska and i believe nobody do so only some people stay in the school because uh ummm tomato is a vegetable and just forget the fact that they have seeds cause cucumbers do to and no non-idiots call them a fruit but you might think that this fact does not relate to how most people leave alaska and that is because it just does and you might wonder why this sentence is so long and now i have to say this again that it just does but now i am tired of typing when it is just 556 characters long but now it went to 579 so i might be typing for a while cause now it is just 637 and i only typed about 60 characters a minute and that is 1 per second plus this sentence is so long and your brain might think why i am typing and expressing my thoughts in the so called rules zone and that is because i like to do so and this place can hold 5 thousand characters for me to type random stuff but the thing is we have just reached 1000 characters yes of course it is exactly 1000 you can check it ending in characters but now i am getting off topic about alaska people and i dont exaclt care because i am typing way too long and i think i should stop here but just one more thing that there are exactly 116 letter e s in this text and um i um hmm er so uhh i huh um what and uhh erm i uh want to say thet um you guys are umm sigma and that is no offensive thoughts.
but attually you guys stink because umm ah erm uh 67 harhar shuriken RIP baby chicken print('doctor lol is dum') um well btw i was joking you guys dont stink lets go gambling yess a flush wait what he has a full house how unfortunately i was all in and now im broke oops
yeah so btw...
WELCOME TO TICA!!
where nerds do blogs post and tutorials and python c++ but cats are cuter ... oops i got of topic ding dong zap blut blortt
umm so where was was I?
oh yeah me making a post
so um er in a umm uhh ehh arr uar uam i think its ... no but ermm urm hurr villager logis be like no wait that not right yeah so once upom a time I have 12 dollars and Fred takes away 7 dollars. What do you have left?
...
wrong!! harahr loser LOL omg youre sooo dumb
the answer is a fight. come seriously use your brains, ok? if someone take your money, your would punchthem right. umm so once upon a time Le Duy beat the top demons called thinking space II and in conclusion, he is fat
also, you are in a race in alaska, you passed 2nd place. which place are you in?
no. you came last because you tripped over an ice cube. Lol
so i guess im out of paper, so this is THE END bye have a great time
also, I founded that there are exactly 183 'E's on this blog.
. you died . score: -1 you were being an idiot
*ps. youre supa gay.
import pygame import random import sys
pygame.init()
info = pygame.display.Info() SW, SH = info.currentw, info.currenth screen = pygame.display.setmode((SW, SH), pygame.FULLSCREEN) pygame.display.setcaption("Boss Rush Driver - Pygame Edition") clock = pygame.time.Clock()
BGCOLOR = (26, 26, 26) PLAYERCOLOR = (0, 255, 255) ENEMYCOLOR = (255, 165, 0) BOSSP1COLOR = (255, 0, 0) BOSSP2COLOR = (128, 0, 128) # Tím khi sang Phase 2 BULLETPLAYER = (255, 255, 0) BULLETBOSS = (255, 50, 50) MAGENTACAR = (255, 0, 255)
class Bullet: def init(self, x, y, speed, color, width=10, height=20): self.rect = pygame.Rect(x, y, width, height) self.speed = speed self.color = color
def update(self):
self.rect.y += self.speed
class Enemy: def init(self, x, y, speed, color): self.rect = pygame.Rect(x, y, 60, 100) self.speed = speed self.color = color
def update(self):
self.rect.y += self.speed
class Game: def init(self): self.fontmain = pygame.font.SysFont("Arial", 30) self.fontbig = pygame.font.SysFont("Arial", 70, bold=True) self.hi_score = 0 self.reset()
def reset(self):
self.score = 0
self.player_rect = pygame.Rect(SW//2 - 30, SH - 150, 60, 100)
self.player_bullets = []
self.boss_bullets = []
self.enemies = []
# Boss stats
self.is_boss_spawned = False
self.boss_rect = pygame.Rect(SW//2 - 150, -250, 300, 150)
self.boss_hp = 50
self.boss_phase = 1
self.boss_dir = 1
self.game_over = False
self.win = False
# Timers
self.last_spawn = pygame.time.get_ticks()
self.last_boss_shot = pygame.time.get_ticks()
def handle_input(self):
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and self.player_rect.left > 0:
self.player_rect.x -= 10
if keys[pygame.K_RIGHT] and self.player_rect.right < SW:
self.player_rect.x += 10
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit(); sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit(); sys.exit()
if event.key == pygame.K_SPACE and not self.game_over:
# Bắn đạn
b = Bullet(self.player_rect.centerx - 5, self.player_rect.top - 20, -15, BULLET_PLAYER)
self.player_bullets.append(b)
if event.key == pygame.K_r and self.game_over:
self.reset()
def update(self):
if self.game_over: return
now = pygame.time.get_ticks()
# Spawn quái thường nếu chưa có Boss
if self.score < 150 and not self.is_boss_spawned:
spawn_rate = max(300, 800 - (self.score * 2))
if now - self.last_spawn > spawn_rate:
x = random.randint(50, SW - 110)
self.enemies.append(Enemy(x, -100, random.randint(7, 12), ENEMY_COLOR))
self.last_spawn = now
elif self.score >= 150 and not self.is_boss_spawned:
self.is_boss_spawned = True
# Logic Boss
if self.is_boss_spawned:
# Xuất hiện Boss (di chuyển xuống màn hình)
if self.boss_rect.y < 50:
self.boss_rect.y += 2
# Kiểm tra Phase
if self.boss_hp <= 25:
self.boss_phase = 2
# Boss di chuyển qua lại
move_speed = 5 if self.boss_phase == 1 else 12
self.boss_rect.x += move_speed * self.boss_dir
if self.boss_rect.right >= SW or self.boss_rect.left <= 0:
self.boss_dir *= -1
# Boss bắn đạn và gọi xe hồng
shot_delay = 1000 if self.boss_phase == 1 else 400
if now - self.last_boss_shot > shot_delay:
# Bắn đạn đỏ
self.boss_bullets.append(Bullet(self.boss_rect.centerx - 10, self.boss_rect.bottom, 10 if self.boss_phase == 1 else 16, BULLET_BOSS, 20, 40))
# Gọi xe hồng (Magenta)
spawn_chance = 0.4 if self.boss_phase == 1 else 0.8
if random.random() < spawn_chance:
x = random.randint(self.boss_rect.left, self.boss_rect.right - 60)
speed = 15 if self.boss_phase == 1 else 22
self.enemies.append(Enemy(x, self.boss_rect.bottom, speed, MAGENTA_CAR))
self.last_boss_shot = now
# Cập nhật đạn Player
for b in self.player_bullets[:]:
b.update()
if b.rect.bottom < 0: self.player_bullets.remove(b)
else:
# Đạn trúng quái
for e in self.enemies[:]:
if b.rect.colliderect(e.rect):
if b in self.player_bullets: self.player_bullets.remove(b)
self.enemies.remove(e)
self.score += 2
# Đạn trúng Boss
if self.is_boss_spawned and b.rect.colliderect(self.boss_rect):
if b in self.player_bullets: self.player_bullets.remove(b)
self.boss_hp -= 1
if self.boss_hp <= 0:
self.win = True
self.game_over = True
# Cập nhật đạn Boss
for b in self.boss_bullets[:]:
b.update()
if b.rect.top > SH: self.boss_bullets.remove(b)
if b.rect.colliderect(self.player_rect):
self.game_over = True
# Cập nhật Enemies
for e in self.enemies[:]:
e.update()
if e.rect.top > SH:
self.enemies.remove(e)
self.score += 1
if e.rect.colliderect(self.player_rect):
self.game_over = True
# Va chạm với thân Boss
if self.is_boss_spawned and self.player_rect.colliderect(self.boss_rect):
self.game_over = True
if self.score > self.hi_score: self.hi_score = self.score
def draw(self):
screen.fill(BG_COLOR)
# Vẽ Player
pygame.draw.rect(screen, PLAYER_COLOR, self.player_rect)
pygame.draw.rect(screen, (255, 255, 255), self.player_rect, 2)
# Vẽ Enemies
for e in self.enemies:
pygame.draw.rect(screen, e.color, e.rect)
pygame.draw.rect(screen, (255, 255, 255), e.rect, 1)
# Vẽ đạn
for b in self.player_bullets:
pygame.draw.rect(screen, b.color, b.rect)
for b in self.boss_bullets:
pygame.draw.rect(screen, b.color, b.rect)
# Vẽ Boss
if self.is_boss_spawned:
color = BOSS_P1_COLOR if self.boss_phase == 1 else BOSS_P2_COLOR
pygame.draw.rect(screen, color, self.boss_rect)
pygame.draw.rect(screen, (255, 255, 255), self.boss_rect, 5)
# HP Boss
hp_text = self.font_main.render(f"BOSS HP: {self.boss_hp} (PHASE {self.boss_phase})", True, (255, 50, 50))
screen.blit(hp_text, (SW - 350, 50))
# HUD
score_txt = self.font_main.render(f"Score: {self.score}", True, (255, 255, 255))
hi_txt = self.font_main.render(f"High Score: {self.hi_score}", True, (255, 255, 0))
screen.blit(score_txt, (50, 50))
screen.blit(hi_txt, (50, 90))
if self.game_over:
msg = "CONGRATULATIONS!" if self.win else "GAME OVER"
color = (0, 255, 0) if self.win else (255, 255, 255)
over_txt = self.font_big.render(msg, True, color)
restart_txt = self.font_main.render("Press 'R' to Restart or 'ESC' to Quit", True, (200, 200, 200))
screen.blit(over_txt, (SW//2 - over_txt.get_width()//2, SH//2 - 50))
screen.blit(restart_txt, (SW//2 - restart_txt.get_width()//2, SH//2 + 50))
pygame.display.flip()
game = Game() while True: game.handle_input() game.update() game.draw() clock.tick(144) # 144 FPS

Khi lập trình bằng Python, chúng ta thường xuyên phải in ra màn hình các giá trị của biến để kiểm tra chương trình hoặc xuất kết quả theo định dạng yêu cầu.
Trước Python 3.6, lập trình viên thường sử dụng:
name = "Steve"
age = 15
print("Tên:", name, "Tuổi:", age)
hoặc:
print("Tên: {} Tuổi: {}".format(name, age))
Tuy nhiên, từ Python 3.6 trở đi, Python giới thiệu f-string (formatted string literal) giúp việc định dạng chuỗi trở nên ngắn gọn, trực quan và nhanh hơn.
print(f"Tên: {name} Tuổi: {age}")
Ngày nay, f-string được xem là cách định dạng chuỗi phổ biến nhất trong Python.
Để tạo f-string, thêm ký tự f trước dấu nháy.
name = "Steve"
print(f"Xin chào {name}")
Kết quả:
Xin chào Steve
Mọi biểu thức nằm trong dấu {} sẽ được Python tính toán rồi thay thế vào chuỗi.
name = "Steve"
age = 15
print(f"Tôi là {name}, năm nay {age} tuổi.")
Kết quả:
Tôi là Steve, năm nay 15 tuổi.
Không chỉ biến, f-string còn cho phép viết trực tiếp các biểu thức.
a = 5
b = 7
print(f"{a} + {b} = {a + b}")
Kết quả:
5 + 7 = 12
Ví dụ khác:
x = 10
print(f"Bình phương của x là {x ** 2}")
Kết quả:
Bình phương của x là 100
name = "steve"
print(f"{name.upper()}")
Kết quả:
STEVE
Hoặc:
print(f"{len(name)}")
Kết quả:
5
Đây là một trong những ứng dụng quan trọng nhất của f-string.
pi = 3.1415926535
print(f"{pi:.2f}")
Kết quả:
3.14
Ý nghĩa:
.2 : lấy 2 chữ số sau dấu phẩy.f : hiển thị dưới dạng số thực.Ví dụ:
x = 12.345678
print(f"{x:.3f}")
Kết quả:
12.346
score = 0.875
print(f"{score:.2%}")
Kết quả:
87.50%
Python tự động nhân với 100 và thêm ký hiệu %.
n = 1234567890
print(f"{n:,}")
Kết quả:
1,234,567,890
Rất hữu ích khi hiển thị số lớn.
print(f"{'ABC':>10}")
Kết quả:
ABC
print(f"{'ABC':<10}")
Kết quả:
ABC
print(f"{'ABC':^10}")
Kết quả:
ABC
print(f"{'ABC':*^10}")
Kết quả:
***ABC****
Giải thích:
* là ký tự điền.^ là căn giữa.10 là độ rộng.x = 42
print(f"{x:05}")
Kết quả:
00042
Ứng dụng:
hour = 8
minute = 5
print(f"{hour:02}:{minute:02}")
Kết quả:
08:05
n = 25
print(f"{n:b}")
Kết quả:
11001
print(f"{n:o}")
Kết quả:
31
print(f"{n:x}")
Kết quả:
19
Chữ hoa:
print(f"{n:X}")
Kết quả:
19
(với các số lớn hơn 9 sẽ hiện A, B, C...)
Từ Python 3.8:
x = 10
y = 20
print(f"{x=}, {y=}")
Kết quả:
x=10, y=20
Rất tiện khi debug.
Ví dụ:
mid = (l + r) // 2
print(f"{l=}, {r=}, {mid=}")
age = 15
print(f"{'Đủ tuổi' if age >= 18 else 'Chưa đủ tuổi'}")
Kết quả:
Chưa đủ tuổi
name = "Steve"
age = 15
print(f"Tên: {name}\nTuổi: {age}")
Kết quả:
Tên: Steve
Tuổi: 15
Nếu muốn in dấu { hoặc } thật sự:
print(f"{{Hello}}")
Kết quả:
{Hello}
Trong Competitive Programming, f-string thường được dùng để:
print(f"{i=}, {j=}, {ans=}")
print(f"{ans:.6f}")
for i in range(1, 6):
print(f"{i:<5}{i*i:<5}")
Kết quả:
1 1
2 4
3 9
4 16
5 25
name = "Steve"
print("Hello {}".format(name))
print(f"Hello {name}")
Ưu điểm của f-string:
Vì vậy, khi dùng Python 3.6+, f-string thường là lựa chọn tốt nhất.
| Cú pháp | Ý nghĩa |
|---|---|
f"{x}" |
Chèn biến |
f"{a+b}" |
Chèn biểu thức |
f"{x:.2f}" |
2 chữ số thập phân |
f"{x:,}" |
Dấu phẩy hàng nghìn |
f"{x:b}" |
Nhị phân |
f"{x:o}" |
Bát phân |
f"{x:x}" |
Hex |
f"{x:05}" |
Thêm số 0 |
f"{s:<10}" |
Căn trái |
f"{s:>10}" |
Căn phải |
f"{s:^10}" |
Căn giữa |
f"{x=}" |
Debug |
f-string là một trong những tính năng hữu ích nhất của Python hiện đại. Nó giúp mã nguồn ngắn gọn, dễ đọc và mạnh mẽ hơn rất nhiều so với cách nối chuỗi hoặc sử dụng format() truyền thống.
Nếu bạn đang học Python hoặc lập trình thi đấu, hãy tập thói quen sử dụng f-string ngay từ đầu. Chỉ cần nắm vững các định dạng cơ bản như:
=là đã đủ để giải quyết phần lớn nhu cầu trong thực tế.
Binary Search Tree (BST) hay Cây tìm kiếm nhị phân là một dạng cây nhị phân đặc biệt, trong đó:
Mọi node ở cây con bên trái đều có giá trị nhỏ hơn node hiện tại. Mọi node ở cây con bên phải đều có giá trị lớn hơn node hiện tại.
Nhờ tính chất này, việc tìm kiếm dữ liệu trở nên rất nhanh.
Với node 8:
Các số bên trái 8 đều nhỏ hơn 8
Các số bên phải 8 đều lớn hơn 8
Và quy tắc đó đúng với mọi node trong cây. 🌳
BST hỗ trợ rất hiệu quả các thao tác:
Tìm kiếm
Thêm phần tử
Xóa phần tử
Độ phức tạp trung bình:
O(log n) 📈
Nhanh hơn nhiều so với tìm kiếm tuyến tính trên mảng.
So sánh: 📊
Số phần tử: 100 Tìm kiếm tuyến tính: 50 lần lặp BST: 7 lần lặp
Số phần tử: 1000 Tìm kiếm tuyến tính: 500 lần lặp BST: 10 lần lặp
Số phần tử: 1000000 😵 Tìm kiếm tuyến tính: 500000 lần lặp BST: 20 lần lặp 🤯
BST (Binary Search Tree) là một cấu trúc tìm kiếm dạng cây cực kỳ hữu dụng (dễ cài đặt 🛠️, tìm kiếm nhanh ⚡). Hiểu rõ BST sẽ giúp cho rất nhiều bài code sau này.