import time import random # List of 60 commonly used Linux commands linux_commands = [ "ls", "cd", "pwd", "mkdir", "rmdir", "rm", "cp", "mv", "touch", "cat", "echo", "grep", "find", "locate", "man", "chmod", "chown", "chgrp", "df", "du", "ps", "top", "kill", "wget", "curl", "tar", "zip", "unzip", "bzip2", "gzip", "nano", "vim", "vi", "apt", "yum", "dnf", "git", "svn", "docker", "docker-compose", "ssh", "scp", "rsync", "chmod", "chown", "ifconfig", "ip", "alias", "export", "history", "uptime", "shutdown", "reboot", "systemctl", "service", "journalctl", "mount", "umount", "echo", "sudo", "passwd", "useradd", "groupadd", "usermod", "groupmod", "ps aux", "htop", "free" ] # Developer and Disclaimer Information __author__ = "Jan Gebser" __version__ = "1.0" __license__ = "MIT" __email__ = "github@brainhub24.com" __date__ = "2024-11-13" # DISCLAIMER: # This code is for educational and recreational purposes only. # It is provided "as is", without warranty of any kind, express or implied, # including but not limited to the warranties of merchantability, fitness for a particular purpose, # and non-infringement. The author is not responsible for any direct, indirect, incidental, or consequential # damages arising from the use or misuse of this software. def typing_game(): """ Starts the typing game where the user has to type Linux commands within a given time. @param target_words: The number of commands the user must type to meet the goal. @param target_time: The time limit in seconds for the user to complete typing the target commands. @return: None (the function displays results and handles the game flow) """ # Set the target words and time target_words = 60 target_time = 60 # seconds print("Welcome to the Linux Commands Typing Game!") print(f"Your goal is to type {target_words} Linux commands in {target_time} seconds!") print("Type the following commands as quickly as you can when prompted.") input("Press Enter to start...") # Timer starts now start_time = time.time() words_typed = 0 word_accuracy = 0 # Loop until time runs out while True: # Select a random command from the list command = random.choice(linux_commands) print(f"Type this command: {command}") # Get user input typed_command = input("Your input: ").strip() # Check if user typed the command correctly if typed_command == command: words_typed += 1 # Calculate elapsed time elapsed_time = time.time() - start_time # End the game if time is up or the user reached the word target if elapsed_time >= target_time or words_typed >= target_words: break # Calculate total time taken and score end_time = time.time() total_time = end_time - start_time score = (words_typed / target_time) * 100 # Score based on words typed per second print("\nGame Over!") print(f"Total time: {total_time:.2f} seconds") print(f"Words typed: {words_typed}/{target_words}") print(f"Your score: {score:.2f} points") # Determine if user met the target if words_typed >= target_words: print(f"Congratulations! You met the target of {target_words} words in {target_time} seconds!") else: print(f"Sorry, you didn't reach the target. Try again to improve your speed!") # Run the game if __name__ == "__main__": typing_game()