编辑文本时光标变成一闪一闪的方块该怎么办

今天笔者在码代码时发现自己的光标变成了一闪一闪的阴影方块。

这时我们按下    insert(ins)    键即可

这种是覆盖模式,光标位置新输入字会替代原来的字;

根据百度百科上的说法是这样的:

插入键(Insert key,缩写INS)是电脑键盘的一个键,主要用于在文字处理器切换文本输入的模式。一种为覆盖模式,光标位置新输入字会替代原来的字;另一种为插入模式,新输入的字插入到光标位置,原来的字相应后移。在早期的计算机终端里,如果在覆盖模式,光标会变成一个方块而不是通常的竖线。

  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
可以使用 Pygame 库来编写俄罗斯方块游戏的 Python 版本。以下是一个基本的俄罗斯方块游戏代码的示例: ```python import pygame import random pygame.init() # 游戏区宽度和高度 SCREEN_WIDTH = 400 SCREEN_HEIGHT = 600 # 方块的大小 BLOCK_SIZE = 20 # 游戏区列数和行数 NUM_COLUMNS = SCREEN_WIDTH // BLOCK_SIZE NUM_ROWS = SCREEN_HEIGHT // BLOCK_SIZE # 方块类型和颜色 BLOCK_TYPES = ['I', 'J', 'L', 'O', 'S', 'T', 'Z'] BLOCK_COLORS = { 'I': (0, 255, 255), # 青色 'J': (0, 0, 255), # 蓝色 'L': (255, 165, 0), # 橙色 'O': (255, 255, 0), # 黄色 'S': (0, 255, 0), # 绿色 'T': (128, 0, 128), # 紫色 'Z': (255, 0, 0) # 红色 } # 定义方块类 class Block(): def __init__(self, type, x, y): self.type = type self.color = BLOCK_COLORS[type] self.x = x self.y = y def draw(self, screen): pygame.draw.rect(screen, self.color, [self.x * BLOCK_SIZE, self.y * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE]) # 定义游戏区类 class Board(): def __init__(self): self.grid = [[None for x in range(NUM_COLUMNS)] for y in range(NUM_ROWS)] def is_valid_position(self, block): for x in range(4): for y in range(4): if x + block.x < 0 or x + block.x >= NUM_COLUMNS or y + block.y >= NUM_ROWS: if block.type[x][y] != '0': return False elif y + block.y >= 0: if self.grid[y + block.y][x + block.x] is not None and block.type[x][y] != '0': return False return True def add_block(self, block): for x in range(4): for y in range(4): if block.type[x][y] != '0': self.grid[y + block.y][x + block.x] = block def remove_block(self, block): for x in range(4): for y in range(4): if block.type[x][y] != '0': self.grid[y + block.y][x + block.x] = None def is_full_row(self, row): for column in range(NUM_COLUMNS): if self.grid[row][column] is None: return False return True def remove_full_rows(self): rows_removed = 0 row = NUM_ROWS - 1 while row >= 0: if self.is_full_row(row): for r in range(row, 0, -1): for column in range(NUM_COLUMNS): self.grid[r][column] = self.grid[r - 1][column] rows_removed += 1 else: row -= 1 return rows_removed def draw(self, screen): for row in range(NUM_ROWS): for column in range(NUM_COLUMNS): block = self.grid[row][column] if block is not None: block.draw(screen) # 主程序 def main(): # 创建游戏区和方块 board = Board() current_block = Block(random.choice(BLOCK_TYPES), 5, -3) next_block = Block(random.choice(BLOCK_TYPES), 0, 0) # 初始化 pygame 窗口 screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) pygame.display.set_caption('俄罗斯方块') # 游戏循环 clock = pygame.time.Clock() game_over = False while not game_over: # 获取事件并对事件进行响应 for event in pygame.event.get(): if event.type == pygame.QUIT: game_over = True elif event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: new_block = Block(current_block.type, current_block.x - 1, current_block.y) if board.is_valid_position(new_block): current_block = new_block elif event.key == pygame.K_RIGHT: new_block = Block(current_block.type, current_block.x + 1, current_block.y) if board.is_valid_position(new_block): current_block = new_block elif event.key == pygame.K_DOWN: new_block = Block(current_block.type, current_block.x, current_block.y + 1) if board.is_valid_position(new_block): current_block = new_block elif event.key == pygame.K_UP: new_block = Block(current_block.type.rotate(), current_block.x, current_block.y) if board.is_valid_position(new_block): current_block = new_block # 生成新方块 if current_block.y < 0: current_block.y += 1 else: new_block = Block(next_block.type, 5, -3) if not board.is_valid_position(new_block): game_over = True else: current_block = next_block next_block = Block(random.choice(BLOCK_TYPES), 0, 0) # 更新游戏区和屏幕 board.remove_block(current_block) current_block.y += 1 if not board.is_valid_position(current_block): current_block.y -= 1 board.add_block(current_block) rows_removed = board.remove_full_rows() if rows_removed > 0: score += 100 * 2 ** (rows_removed - 1) current_block = next_block next_block = Block(random.choice(BLOCK_TYPES), 0, 0) if not board.is_valid_position(current_block): game_over = True board.add_block(current_block) screen.fill((0, 0, 0)) board.draw(screen) pygame.display.flip() # 让游戏循环运行在一定的帧率下 clock.tick(10) # 显示游戏结束的信息 font = pygame.font.SysFont('Arial', 36) text = font.render('游戏结束', True, (255, 255, 255)) screen.blit(text, (SCREEN_WIDTH // 2 - text.get_width() // 2, SCREEN_HEIGHT // 2 - text.get_height() // 2)) pygame.display.flip() # 等待3秒后退出游戏 pygame.time.wait(3000) pygame.quit() quit() if __name__ == '__main__': main() ``` 你可以将此代码保存为 `tetris.py` 文件,使用 Python 运行此文件即可运行俄罗斯方块游戏。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

用编程写诗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值