Skip to content

Commit 2c25bf6

Browse files
committed
added some other functions and some content
1 parent 04d8394 commit 2c25bf6

File tree

5 files changed

+183
-166
lines changed

5 files changed

+183
-166
lines changed

Hack(2);/script.js

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ const runButton = document.getElementById('runButton');
2121
const themeToggleButton = document.getElementById('themeToggleButton');
2222
const containerForWallet = document.getElementById('containerForWallet');
2323

24-
const validCommands = ["pass", "clear", "clean", "cls", "hack", "mine"];
24+
const validCommands =
25+
[
26+
"pass", "clear", "clean", "cls", "hack", "mine",
27+
"list"
28+
];
2529

2630
var containerForOutput = document.getElementById("containerForOutput");
2731
var themeToggleImg = document.getElementById("themeToggleImg");
@@ -38,8 +42,11 @@ var totalMoney = 0;
3842

3943
let servers =
4044
[
41-
new server("analServer", 10, 1, 0),
42-
new server("oralServer", 10, 1, 0)
45+
new server("localServer", 10, 1, 1),
46+
new server("MinebuildGameServer", 15, 2, 0),
47+
new server("dataVault", 30, 5, 0),
48+
new server("cryptoFarm", 50, 8, 0),
49+
new server("mainframe", 100, 10, 0)
4350
]
4451
var CurrentServer = servers[0];
4552

@@ -61,11 +68,13 @@ function runUserCode()
6168
// Find strings in commands that are not in validCommands
6269
const faultyCommands = commands.filter(command_ => !validCommands.includes(command_));
6370

71+
//more than one commands are valid
6472
if (faultyCommands.length > 1)
6573
{
6674
addErrorToOutput("Some commands were not recognized as a valid internal or external command: \"" +
6775
(faultyCommands.join("\", \"")) + "\"");
6876
}
77+
//a command is not valid
6978
else if (faultyCommands.length == 1)
7079
{
7180
addErrorToOutput("A command was not recognized as a valid internal or external command: " + faultyCommands[0]);
@@ -118,10 +127,7 @@ function processCommands(commands)
118127
{
119128
if(CurrentServer.HackedLevel >= CurrentServer.SecurityLevel)
120129
{
121-
CurrentServer.working = true;
122-
profitPerSecond = profitPerSecond + CurrentServer.power;
123-
124-
addSysMessageToOutput("Mining started on the {" + CurrentServer.name + "} server.");
130+
startMining();
125131
}
126132
else
127133
{
@@ -149,12 +155,41 @@ function processCommands(commands)
149155
}
150156
else
151157
{
152-
CurrentServer.HackedLevel = CurrentServer.HackedLevel + 1;
153-
154-
addSysMessageToOutput("Succesfully hacked the {" + CurrentServer.name + "} server.");
158+
hackServer();
155159
}
156160
}
157161
}
162+
//list servers
163+
else if(commands.includes("list"))
164+
{
165+
if(commands.length > 1)
166+
{
167+
addErrorToOutput("The command list cannot be combined with other commands or values.");
168+
}
169+
else
170+
{
171+
listServers();
172+
}
173+
}
174+
}
175+
176+
function listServers()
177+
{
178+
const serverList = servers.map((server, index) => `${index + 1}. ${server.name} (Security Level: ${server.SecurityLevel}, Power: ${server.power})`).join("<br>");
179+
addSysMessageToOutput("Available Servers:<br>" + serverList);
180+
}
181+
182+
function hackServer()
183+
{
184+
CurrentServer.HackedLevel = CurrentServer.HackedLevel + 1;
185+
addSysMessageToOutput("Succesfully hacked the {" + CurrentServer.name + "} server.");
186+
}
187+
188+
function startMining()
189+
{
190+
CurrentServer.working = true;
191+
profitPerSecond = profitPerSecond + CurrentServer.power;
192+
addSysMessageToOutput("Mining started on the {" + CurrentServer.name + "} server.");
158193
}
159194

160195
function getTextBetween(text, startMarker, endMarker)

Hack(2);/styles.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ button:hover
141141
}
142142
.dark-theme .error
143143
{
144-
color: rgb(255, 30, 30);
144+
color: rgb(255, 90, 90);
145145
}
146146

147147
.warning
@@ -150,7 +150,7 @@ button:hover
150150
}
151151
.dark-theme .warning
152152
{
153-
color: rgb(255, 255, 30);
153+
color: rgb(255, 255, 90);
154154
}
155155

156156
.sysmsg
@@ -159,7 +159,7 @@ button:hover
159159
}
160160
.dark-theme .sysmsg
161161
{
162-
color: rgb(30, 30, 255);
162+
color: rgb(90, 90, 255);
163163
}
164164

165165

Hack(2);/test/index.html

Lines changed: 0 additions & 20 deletions
This file was deleted.

Hack(2);/test/script.js

Lines changed: 135 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,161 @@
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
717
const userInputField = document.getElementById('userInputField');
818
const runButton = document.getElementById('runButton');
919
const 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");
1125
var 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
1630
var 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

Comments
 (0)