Sure! Let's design and implement a simple command-line game inspired by Bitburner using Python. The game will allow you to navigate a network of servers, gain control over them, and perform actions such as stealing money or growing the server's funds.
Game Design
1. Components:
-
Server:
- Attributes:
name: Unique identifier for the server.
adjacent: List of connected server names.
controlled: Boolean indicating if the player has control.
money: Current amount of money on the server.
growth_factor: Multiplier that affects money growth.
steal_multiplier: Multiplier that affects money stolen.
-
Player:
- Attributes:
current_server: The server the player is currently connected to.
controlled_servers: List of servers the player has control over.
wallet: Total money stolen.
2. Commands:
scan: Lists adjacent servers to the current server.
connect <server_name>: Connects to an adjacent server.
gain_control <server_name>: Gains control over a connected server.
steal <server_name>: Steals money from a controlled server.
grow <server_name>: Grows the money on a controlled server.
enhance <server_name>: Increases the steal multiplier for a controlled server.
status: Shows the player's status and controlled servers.
help: Displays available commands.
exit: Exits the game.
3. Game Flow:
-
Initialization:
- Create a network of servers with predefined connections.
- Initialize server attributes such as money, growth factors, etc.
- Set the player's starting server.
-
Main Loop:
- Display a prompt for the player to enter commands.
- Execute commands based on player input.
- Update server and player states accordingly.
- Continue until the player decides to exit.
Python Implementation
Below is the complete Python code for the game. You can run this code in your local environment.
import sys
class Server:
def __init__(self, name):
self.name = name
self.adjacent = []
self.controlled = False
self.money = 1000 # Starting money
self.growth_factor = 1.0
self.steal_multiplier = 1.0
def connect(self, other_server):
if other_server not in self.adjacent:
self.adjacent.append(other_server)
other_server.adjacent.append(self)
class Player:
def __init__(self, starting_server):
self.current_server = starting_server
self.controlled_servers = []
self.wallet = 0
def scan(self):
return [server.name for server in self.current_server.adjacent]
def connect(self, server_name, servers):
for server in self.current_server.adjacent:
if server.name == server_name:
self.current_server = server
print(f"Connected to {server.name}.")
return
print(f"Server {server_name} is not adjacent to {self.current_server.name}.")
def gain_control(self, server_name, servers):
for server in self.current_server.adjacent:
if server.name == server_name:
if not server.controlled:
server.controlled = True
self.controlled_servers.append(server)
print(f"Gained control over {server.name}.")
else:
print(f"Already have control over {server.name}.")
return
print(f"Server {server_name} is not adjacent to {self.current_server.name}.")
def steal(self, server_name):
server = self.get_controlled_server(server_name)
if server:
stolen = server.money * 0.1 * server.steal_multiplier
stolen = round(stolen, 2)
server.money -= stolen
self.wallet += stolen
print(f"Stole ${stolen} from {server.name}.")
else:
print(f"You don't control server {server_name}.")
def grow(self, server_name):
server = self.get_controlled_server(server_name)
if server:
growth = server.money * 0.05 * server.growth_factor
growth = round(growth, 2)
server.money += growth
print(f"Grew ${growth} on {server.name}.")
else:
print(f"You don't control server {server_name}.")
def enhance(self, server_name):
server = self.get_controlled_server(server_name)
if server:
server.steal_multiplier += 0.5
print(f"Enhanced steal multiplier on {server.name} to {server.steal_multiplier}.")
else:
print(f"You don't control server {server_name}.")
def status(self):
print(f"Current Server: {self.current_server.name}")
print(f"Wallet: ${round(self.wallet,2)}")
print("Controlled Servers:")
if self.controlled_servers:
for server in self.controlled_servers:
print(f" - {server.name}: ${round(server.money,2)} | Growth x{server.growth_factor} | Steal x{server.steal_multiplier}")
else:
print(" None")
def get_controlled_server(self, server_name):
for server in self.controlled_servers:
if server.name == server_name:
return server
return None
def initialize_servers():
# Create servers
servers = {}
for name in ['home', 'alpha', 'beta', 'gamma', 'delta', 'epsilon']:
servers[name] = Server(name)
# Define connections (undirected)
connections = [
('home', 'alpha'),
('home', 'beta'),
('alpha', 'gamma'),
('beta', 'delta'),
('gamma', 'epsilon'),
('delta', 'epsilon')
]
for a, b in connections:
servers[a].connect(servers[b])
return servers
def display_help():
help_text = """
Available commands:
- scan
Lists adjacent servers to the current server.
- connect <server_name>
Connects to an adjacent server.
- gain_control <server_name>
Gains control over a connected server.
- steal <server_name>
Steals money from a controlled server.
- grow <server_name>
Grows the money on a controlled server.
- enhance <server_name>
Enhances the steal multiplier on a controlled server.
- status
Displays your current status.
- help
Shows this help message.
- exit
Exits the game.
"""
print(help_text)
def main():
servers = initialize_servers()
player = Player(servers['home'])
print("Welcome to BitHack CLI Game!")
print("Type 'help' to see available commands.\n")
while True:
command = input(f"[{player.current_server.name}]> ").strip().split()
if not command:
continue
cmd = command[0].lower()
if cmd == 'scan':
scanned = player.scan()
print("Adjacent Servers:")
for srv in scanned:
print(f" - {srv}")
elif cmd == 'connect':
if len(command) < 2:
print("Usage: connect <server_name>")
continue
server_name = command[1]
if server_name not in [s.name for s in player.current_server.adjacent]:
print(f"Server {server_name} is not adjacent to {player.current_server.name}.")
continue
player.connect(server_name, servers)
elif cmd == 'gain_control':
if len(command) < 2:
print("Usage: gain_control <server_name>")
continue
server_name = command[1]
player.gain_control(server_name, servers)
elif cmd == 'steal':
if len(command) < 2:
print("Usage: steal <server_name>")
continue
server_name = command[1]
player.steal(server_name)
elif cmd == 'grow':
if len(command) < 2:
print("Usage: grow <server_name>")
continue
server_name = command[1]
player.grow(server_name)
elif cmd == 'enhance':
if len(command) < 2:
print("Usage: enhance <server_name>")
continue
server_name = command[1]
player.enhance(server_name)
elif cmd == 'status':
player.status()
elif cmd == 'help':
display_help()
elif cmd == 'exit':
print("Exiting game. Goodbye!")
sys.exit()
else:
print("Unknown command. Type 'help' to see available commands.")
if __name__ == "__main__":
main()
How to Run the Game
-
Prerequisites:
- Ensure you have Python 3 installed on your system.
-
Save the Code:
- Save the above code in a file named
bithack_game.py.
-
Run the Game:
- Open your terminal or command prompt.
- Navigate to the directory where
bithack_game.py is saved.
- Execute the game by running:
python bithack_game.py
-
Gameplay:
- Upon starting, you'll be at the
home server.
- Type
help to see all available commands.
- Use
scan to see adjacent servers.
- Connect to a server using
connect <server_name>.
- Gain control using
gain_control <server_name>.
- Once controlled, you can
steal, grow, or enhance servers.
Sample Gameplay
Welcome to BitHack CLI Game!
Type 'help' to see available commands.
[home]> help
Available commands:
- scan
Lists adjacent servers to the current server.
- connect <server_name>
Connects to an adjacent server.
- gain_control <server_name>
Gains control over a connected server.
- steal <server_name>
Steals money from a controlled server.
- grow <server_name>
Grows the money on a controlled server.
- enhance <server_name>
Enhances the steal multiplier on a controlled server.
- status
Displays your current status.
- help
Shows this help message.
- exit
Exits the game.
[home]> scan
Adjacent Servers:
- alpha
- beta
[home]> connect alpha
Connected to alpha.
[alpha]> gain_control gamma
Server gamma is not adjacent to alpha.
[alpha]> scan
Adjacent Servers:
- home
- gamma
[alpha]> gain_control gamma
Gained control over gamma.
[alpha]> status
Current Server: alpha
Wallet: $0
Controlled Servers:
- gamma: $1000 | Growth x1.0 | Steal x1.0
[alpha]> steal gamma
Stole $100.0 from gamma.
[alpha]> status
Current Server: alpha
Wallet: $100.0
Controlled Servers:
- gamma: $900.0 | Growth x1.0 | Steal x1.0
[alpha]> grow gamma
Grew $45.0 on gamma.
[alpha]> status
Current Server: alpha
Wallet: $100.0
Controlled Servers:
- gamma: $945.0 | Growth x1.0 | Steal x1.0
[alpha]> enhance gamma
Enhanced steal multiplier on gamma to 1.5.
[alpha]> steal gamma
Stole $141.75 from gamma.
[alpha]> status
Current Server: alpha
Wallet: $241.75
Controlled Servers:
- gamma: $803.25 | Growth x1.0 | Steal x1.5
[alpha]> exit
Exiting game. Goodbye!
Conclusion
This simple Python-based command-line game allows you to navigate between servers, gain control, and perform various actions to manage and steal money. You can expand this game by adding more features such as:
- Security Levels: Introduce security measures that prevent easy control or stealing.
- Server Levels: Different servers with varying amounts of money and growth rates.
- Upgrades: More enhancements for servers or the player's capabilities.
- Networking: Implement more complex server networks for exploration.
Feel free to modify and enhance the game to your liking!