├── assets ├── explosion.png ├── enemy_ship.png ├── player_ship.png ├── allowed_ship.png └── 504230__Port Invaders_ video game cover styled after spac_xl-1024-v1-0.jpg ├── README.md └── port_invaders.py /assets/explosion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milosilo/port-invaders/HEAD/assets/explosion.png -------------------------------------------------------------------------------- /assets/enemy_ship.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milosilo/port-invaders/HEAD/assets/enemy_ship.png -------------------------------------------------------------------------------- /assets/player_ship.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milosilo/port-invaders/HEAD/assets/player_ship.png -------------------------------------------------------------------------------- /assets/allowed_ship.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milosilo/port-invaders/HEAD/assets/allowed_ship.png -------------------------------------------------------------------------------- /assets/504230__Port Invaders_ video game cover styled after spac_xl-1024-v1-0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milosilo/port-invaders/HEAD/assets/504230__Port Invaders_ video game cover styled after spac_xl-1024-v1-0.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Port Invaders: Learn Network Ports Through Gaming 🚀 2 | 3 | ![Port Invaders](https://i.redd.it/kviy1a3vh5mb1.png) 4 | 5 | ## Overview 6 | 7 | Port Invaders is an arcade-style educational game designed to help you learn and memorize common networking port numbers. Whether you're studying for Network+, Security+, OSCP, CEH, A+, MCSA, or any other IT certification, this game offers a fun and interactive way to get familiar with port numbers. 8 | 9 | ## Features 10 | 11 | - **Arcade Gameplay**: Classic 8-bit graphics and immersive gameplay. 12 | - **Learning Through Interaction**: Memorize port numbers by shooting down unauthorized ports while letting authorized ones pass through your firewall. 13 | - **Multi-Level Learning**: Each level introduces new ports, with varying difficulties. 14 | - **Dynamic Scoring**: Gain points for correct actions and lose points for mistakes, just like in a real-world scenario. 15 | 16 | ## How to Play 17 | 18 | 1. **Installation**: Clone this repository and install Pygame. 19 | 20 | ``` 21 | pip install pygame 22 | ``` 23 | 24 | 2. **Run the Game**: Navigate to the project directory and run: 25 | 26 | ``` 27 | python port_invaders_arcade_game_final_single_file.py 28 | ``` 29 | 30 | 3. **Gameplay**: Use the arrow keys to move your ship and spacebar to shoot. Your objective is to let only the allowed ports pass through. Shooting an allowed port will result in a deduction of points. 31 | 32 | ## Educational Value 33 | 34 | This game serves as a practical tool for learning and memorizing port numbers, an essential skill for various IT and cybersecurity certifications, including: 35 | 36 | - **Network+**: Understand networking fundamentals. 37 | - **Security+**: Get a grasp of firewall rules and security protocols. 38 | - **OSCP**: Know your ports to set up or exploit services. 39 | - **CEH**: Familiarize yourself with commonly used ports for ethical hacking. 40 | - **A+**: Build a foundation in IT, including networking basics. 41 | - **MCSA**: Prepare for Microsoft's certification with a focus on networking. 42 | 43 | ## Contributing 44 | 45 | Feel free to fork this repository and contribute. Pull requests are welcome! 46 | 47 | ## License 48 | 49 | This project is licensed under the MIT License. 50 | 51 | --- 52 | 53 | Feel free to use or modify this README for your GitHub repository. Would you like to download this README as a file? 54 | -------------------------------------------------------------------------------- /port_invaders.py: -------------------------------------------------------------------------------- 1 | 2 | import pygame 3 | import random 4 | import time 5 | import os 6 | 7 | # Initialize Pygame 8 | pygame.init() 9 | 10 | # Constants 11 | SCREEN_WIDTH = 800 12 | SCREEN_HEIGHT = 600 13 | PLAYER_SIZE = 50 14 | ENEMY_SIZE = 50 15 | ALLOWED_SIZE = 50 16 | FONT_SIZE = 30 17 | WHITE = (255, 255, 255) 18 | 19 | # Function to display text on screen 20 | def display_text(text, pos, screen, font, color=WHITE): 21 | text_surface = font.render(text, True, color) 22 | screen.blit(text_surface, pos) 23 | 24 | # Set up the screen 25 | screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) 26 | pygame.display.set_caption("Port Invaders") 27 | 28 | # Load font and images 29 | font = pygame.font.SysFont(None, FONT_SIZE) 30 | player_image = pygame.image.load(os.path.join("assets", "player_ship.png")) 31 | enemy_image = pygame.image.load(os.path.join("assets", "enemy_ship.png")) 32 | allowed_image = pygame.image.load(os.path.join("assets", "allowed_ship.png")) 33 | explosion_image = pygame.image.load(os.path.join("assets", "explosion.png")) 34 | 35 | # Main game loop 36 | clock = pygame.time.Clock() 37 | level = 1 38 | score = 0 39 | common_ports = [22, 80, 443, 21, 25, 110, 143, 161, 162, 389, 636, 989, 990] 40 | 41 | port_names = { 42 | 20: "FTP", 43 | 21: "FTP", 44 | 22: "SSH", 45 | 23: "Telnet", 46 | 25: "SMTP", 47 | 53: "DNS", 48 | 80: "HTTP", 49 | 110: "POP3", 50 | 143: "IMAP", 51 | 443: "HTTPS", 52 | 465: "SMTPS", 53 | 587: "SMTP", 54 | 993: "IMAPS", 55 | 995: "POP3S", 56 | 3306: "MySQL", 57 | 3389: "RDP", 58 | 5432: "PostgreSQL", 59 | 27017: "MongoDB", 60 | 22: "SFTP", 61 | 161: "SNMP", 62 | 162: "SNMP Trap", 63 | 389: "LDAP", 64 | 636: "LDAPS", 65 | 989: "FTPS Data", 66 | 990: "FTPS Control", 67 | 2049: "NFS", 68 | 3690: "SVN", 69 | 22: "SCP", 70 | 873: "RSYNC", 71 | 6660: "IRC", 72 | 6667: "IRC SSL", 73 | 6697: "IRC SSL", 74 | 9418: "Git", 75 | 1194: "OpenVPN", 76 | 1723: "PPTP", 77 | 5060: "SIP", 78 | 514: "Syslog", 79 | 1080: "SOCKS Proxy", 80 | 3128: "HTTP Proxy", 81 | 8080: "HTTP Proxy", 82 | 8081: "HTTP Proxy", 83 | 21: "FTPS", 84 | 137: "NetBIOS", 85 | 139: "NetBIOS", 86 | 445: "SMB/CIFS", 87 | 514: "Shell", 88 | 135: "MS RPC", 89 | 1433: "MSSQL", 90 | 1521: "Oracle SQL" 91 | } 92 | 93 | while True: 94 | start_time = time.time() 95 | player_pos = [SCREEN_WIDTH // 2, SCREEN_HEIGHT - 2 * PLAYER_SIZE] 96 | allowed_ports = random.sample(common_ports, 3) 97 | enemies = [] 98 | allowed = [] 99 | bullets = [] 100 | 101 | while time.time() - start_time < 15: 102 | 103 | # Event handling 104 | for event in pygame.event.get(): 105 | if event.type == pygame.QUIT: 106 | pygame.quit() 107 | exit() 108 | elif event.type == pygame.KEYDOWN: 109 | if event.key == pygame.K_SPACE: 110 | bullets.append([player_pos[0] + PLAYER_SIZE // 2, player_pos[1]]) 111 | 112 | # Move player 113 | keys = pygame.key.get_pressed() 114 | if keys[pygame.K_LEFT]: 115 | player_pos[0] -= 10 116 | if keys[pygame.K_RIGHT]: 117 | player_pos[0] += 10 118 | 119 | # Generate random enemies 120 | if random.randint(1, 20) == 20: 121 | enemies.append([random.randint(0, SCREEN_WIDTH - ENEMY_SIZE), 0]) 122 | 123 | # Generate allowed ships 124 | if random.randint(1, 20) == 20: 125 | allowed.append([random.randint(0, SCREEN_WIDTH - ALLOWED_SIZE), 0, random.choice(allowed_ports)]) 126 | 127 | # Update enemy and bullet positions 128 | for enemy in enemies: 129 | enemy[1] += 5 130 | if enemy[1] > SCREEN_HEIGHT: 131 | enemies.remove(enemy) 132 | score -= 50 133 | 134 | for bullet in bullets: 135 | bullet[1] -= 5 136 | if bullet[1] < 0: 137 | bullets.remove(bullet) 138 | 139 | # Update allowed positions 140 | for allow in allowed: 141 | allow[1] += 5 142 | if allow[1] > SCREEN_HEIGHT: 143 | allowed.remove(allow) 144 | score += 100 145 | 146 | # Collision detection 147 | for enemy in enemies: 148 | for bullet in bullets: 149 | if ( 150 | bullet[0] > enemy[0] 151 | and bullet[0] < enemy[0] + ENEMY_SIZE 152 | and bullet[1] > enemy[1] 153 | and bullet[1] < enemy[1] + ENEMY_SIZE 154 | ): 155 | bullets.remove(bullet) 156 | enemies.remove(enemy) 157 | score += 100 158 | 159 | for allow in allowed: 160 | for bullet in bullets: 161 | if ( 162 | bullet[0] > allow[0] 163 | and bullet[0] < allow[0] + ALLOWED_SIZE 164 | and bullet[1] > allow[1] 165 | and bullet[1] < allow[1] + ALLOWED_SIZE 166 | ): 167 | bullets.remove(bullet) 168 | allowed.remove(allow) 169 | score -= 150 170 | 171 | # Draw everything 172 | screen.fill((0, 0, 0)) 173 | 174 | # Draw player using image 175 | screen.blit(player_image, (player_pos[0], player_pos[1])) 176 | 177 | # Draw bullets 178 | for bullet in bullets: 179 | pygame.draw.circle(screen, WHITE, (bullet[0], bullet[1]), 5) 180 | 181 | # Draw enemies using image 182 | for enemy in enemies: 183 | screen.blit(enemy_image, (enemy[0], enemy[1])) 184 | 185 | # Draw allowed using image and display port numbers 186 | for allow in allowed: 187 | screen.blit(allowed_image, (allow[0], allow[1])) 188 | display_text(str(allow[2]), (allow[0] + 10, allow[1] + 55), screen, font, color=(255, 255, 255)) 189 | 190 | # Draw score and allowed ports 191 | display_text(f"Score: {score}", [30, 30], screen, font) 192 | display_text(f"Allowed Ports: {allowed_ports} - {[port_names[port] for port in allowed_ports]}", [30, 60], screen, font) 193 | 194 | pygame.display.flip() 195 | clock.tick(30) 196 | 197 | # Level Transition Screen 198 | screen.fill((0, 0, 0)) 199 | display_text(f"Level {level} Complete!", [250, 250], screen, font) 200 | display_text(f"Score: {score}", [300, 300], screen, font) 201 | display_text("Press any key to continue...", [200, 350], screen, font) 202 | pygame.display.update() 203 | time.sleep(3) 204 | 205 | while True: 206 | for event in pygame.event.get(): 207 | if event.type == pygame.QUIT: 208 | pygame.quit() 209 | exit() 210 | elif event.type == pygame.KEYDOWN: 211 | break 212 | 213 | if event.type == pygame.KEYDOWN: 214 | break 215 | 216 | level += 1 217 | allowed_ports = random.sample(common_ports, 3) 218 | --------------------------------------------------------------------------------