1- const ColorMode =
2- {
1+ /*
2+ class server {
3+ constructor(name, power, SecurityLevel, HackedLevel) {
4+ this.name = name;
5+ this.power = power;
6+ this.SecurityLevel = SecurityLevel;
7+ this.HackedLevel = HackedLevel;
8+ this.working = false;
9+ }
10+ }
11+
12+ const ColorMode = {
313 DARK: 0,
414 LIGHT: 1
515};
616
717const userInputField = document.getElementById('userInputField');
818const runButton = document.getElementById('runButton');
919const themeToggleButton = document.getElementById('themeToggleButton');
20+ const containerForWallet = document.getElementById('containerForWallet');
1021
22+ const validCommands = ["pass", "clear", "clean", "cls", "hack", "mine", "listServers", "phish", "bruteForce", "exploit"];
23+
24+ var containerForOutput = document.getElementById("containerForOutput");
1125var themeToggleImg = document.getElementById("themeToggleImg");
1226
13- var themeAdjustDark = "themeAdjustDark.png"
14- var themeAdjustLight = "themeAdjustLight.png"
27+ var themeAdjustDark = "themeAdjustDark.png";
28+ var themeAdjustLight = "themeAdjustLight.png";
1529
1630var CurrentTheme = ColorMode.LIGHT;
1731
18- themeToggleImg . src = themeAdjustDark
32+ themeToggleImg.src = themeAdjustDark;
33+
34+ var profitPerSecond = 0;
35+ var totalMoney = 0;
36+
37+ let servers = [
38+ new server("analServer", 10, 1, 0),
39+ new server("oralServer", 15, 2, 0),
40+ new server("dataVault", 30, 5, 0),
41+ new server("cryptoFarm", 50, 8, 0),
42+ new server("mainframe", 100, 10, 0)
43+ ];
1944
20- //Deal with the input.
21- function printToConsole ( )
22- {
45+ var CurrentServer = servers[0];
46+
47+ // Deal with the input.
48+ function runUserCode() {
2349 const inputValue = userInputField.value.trim();
24- if ( inputValue )
25- {
26- console . log ( inputValue ) ;
50+ if (inputValue) {
51+ addUserInputToOutput(inputValue); // Print the input
2752 userInputField.value = ''; // Clear the input field
53+
54+ EditedInput = inputValue.toLowerCase();
55+ EditedInput = EditedInput.replaceAll("();", "");
56+ commands = EditedInput.split(' ');
57+
58+ // Find strings in commands that are not in validCommands
59+ const faultyCommands = commands.filter(command_ => !validCommands.includes(command_));
60+
61+ if (faultyCommands.length > 1) {
62+ addErrorToOutput("Some commands were not recognized as a valid internal or external command: \"" +
63+ (faultyCommands.join("\", \"")) + "\"");
64+ } else if (faultyCommands.length == 1) {
65+ addErrorToOutput("A command was not recognized as a valid internal or external command: " + faultyCommands[0]);
66+ } else {
67+ processCommands(commands);
68+ }
2869 }
2970}
3071
31- // Function to toggle dark theme
32- function toggleTheme ( )
33- {
34- document . body . classList . toggle ( 'dark-theme' ) ;
35- if ( CurrentTheme == ColorMode . DARK )
36- {
37- CurrentTheme = ColorMode . LIGHT ;
38- themeToggleImg . src = themeAdjustDark
72+ function processCommands(commands) {
73+ if (commands.includes("pass")) {
74+ commands.splice(commands.indexOf("pass"), 1);
75+ processCommands(commands);
76+ } else if (commands.includes("clear") || commands.includes("clean") || commands.includes("cls")) {
77+ if (commands.length > 1) {
78+ addErrorToOutput("The clear/clean/cls command cannot be combined with other commands or values.");
79+ } else {
80+ setOutput("");
81+ }
82+ } else if (commands.includes("mine")) {
83+ if (commands.length > 1) {
84+ addErrorToOutput("The command mine cannot be combined with other commands or values.");
85+ } else {
86+ startMining();
87+ }
88+ } else if (commands.includes("hack")) {
89+ if (commands.length > 1) {
90+ addErrorToOutput("The command hack cannot be combined with other commands or values.");
91+ } else {
92+ hackServer();
93+ }
94+ } else if (commands.includes("listServers")) {
95+ listServers();
96+ } else if (commands.includes("phish")) {
97+ phishingAttack();
98+ } else if (commands.includes("bruteForce")) {
99+ bruteForceAttack();
100+ } else if (commands.includes("exploit")) {
101+ exploitServer();
39102 }
40- else
41- {
42- CurrentTheme = ColorMode . DARK ;
43- themeToggleImg . src = themeAdjustLight
103+ }
104+
105+ function startMining() {
106+ if (!CurrentServer.working) {
107+ if (CurrentServer.HackedLevel >= CurrentServer.SecurityLevel) {
108+ CurrentServer.working = true;
109+ profitPerSecond += CurrentServer.power;
110+ addSysMessageToOutput(`Mining started on the {${CurrentServer.name}} server.`);
111+ } else {
112+ addErrorToOutput("Access denied.");
113+ }
114+ } else {
115+ addErrorToOutput("The server is already assigned a task.");
44116 }
45117}
46118
47- //Event listeners for buttons
48- themeToggleButton . addEventListener ( 'click' , toggleTheme ) ;
49- runButton . addEventListener ( 'click' , printToConsole ) ;
119+ function hackServer() {
120+ if (CurrentServer.HackedLevel >= CurrentServer.SecurityLevel) {
121+ addErrorToOutput("You already have full access to this server.");
122+ } else {
123+ CurrentServer.HackedLevel++;
124+ addSysMessageToOutput(`Successfully hacked the {${CurrentServer.name}} server.`);
125+ }
126+ }
127+
128+ function listServers() {
129+ const serverList = servers.map((server, index) => `${index + 1}. ${server.name} (Security Level: ${server.SecurityLevel}, Power: ${server.power})`).join("<br>");
130+ addSysMessageToOutput("Available Servers:<br>" + serverList);
131+ }
50132
51- //Event listeners for key presses
52- userInputField . addEventListener ( 'keydown' , function ( event )
53- {
54- if ( event . key === 'Enter' )
55- {
56- printToConsole ( ) ;
133+ function phishingAttack() {
134+ if (Math.random() > 0.5) {
135+ CurrentServer.HackedLevel++;
136+ addSysMessageToOutput("Phishing attack successful! Security level breached.");
137+ } else {
138+ addErrorToOutput("Phishing attack failed." );
57139 }
58- } ) ;
140+ }
141+
142+ function bruteForceAttack() {
143+ if (Math.random() > 0.7) {
144+ CurrentServer.HackedLevel++;
145+ addSysMessageToOutput("Brute force attack successful! Security level breached.");
146+ } else {
147+ addErrorToOutput("Brute force attack failed.");
148+ }
149+ }
150+
151+ function exploitServer() {
152+ if (Math.random() > 0.3) {
153+ CurrentServer.HackedLevel += 2;
154+ addSysMessageToOutput("Exploit successful! Multiple security levels breached.");
155+ } else {
156+ addErrorToOutput("Exploit failed.");
157+ }
158+ }
59159
60- toggleTheme ( ) ; //makes the default theme dark.
160+ toggleTheme(); // Make the default theme dark.
161+ */
0 commit comments