-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetRun.java
More file actions
170 lines (148 loc) · 5.82 KB
/
Copy pathNetRun.java
File metadata and controls
170 lines (148 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
public class NetRun {
// ANSI Terminal Colors
private static final String RESET = "\u001B[0m";
private static final String GREEN = "\u001B[32m";
private static final String RED = "\u001B[31m";
private static final String CYAN = "\u001B[36m";
private static final String YELLOW = "\u001B[33m";
private static final String CLEAR_SCREEN = "\033[2J\033[H";
private static final int WIDTH = 20;
private static final int HEIGHT = 10;
private static int playerX = 2;
private static int playerY = 2;
private static int score = 0;
private static int securityTrace = 0;
private static boolean running = true;
static class DataNode {
int x, y;
boolean isThreat;
DataNode(int x, int y, boolean isThreat) {
this.x = x;
this.y = y;
this.isThreat = isThreat;
}
}
private static List<DataNode> nodes = new ArrayList<>();
private static Random rand = new Random();
public static void main(String[] args) {
spawnNodes();
Scanner scanner = new Scanner(System.in);
System.out.println(CLEAR_SCREEN);
System.out.println(CYAN + "=== WELCOME TO NETRUN ===" + RESET);
System.out.println("Use " + GREEN + "W/A/S/D" + RESET + " + Enter to navigate the grid.");
System.out.println("Collect Green Nodes (" + GREEN + "$" + RESET + "), Avoid Red Firewalls (" + RED + "X" + RESET + ").");
System.out.println("Press Enter to begin hacking...");
scanner.nextLine();
while (running) {
renderGrid();
System.out.print(CYAN + "Move (W/A/S/D) [or Q to quit]: " + RESET);
String input = scanner.nextLine().trim().toLowerCase();
if (input.equals("q")) {
running = false;
break;
}
processInput(input);
updateGameState();
}
System.out.println(CLEAR_SCREEN);
System.out.println(RED + "=== CONNECTION TERMINATED ===" + RESET);
System.out.println("Final Score (Data Harvested): " + GREEN + score + " TB" + RESET);
System.out.println("Security Trace Level: " + RED + securityTrace + "%" + RESET);
if (securityTrace >= 100) {
System.out.println(RED + "Result: SYSTEM LOCKDOWN. You were caught." + RESET);
} else {
System.out.println(CYAN + "Result: Disconnected safely." + RESET);
}
}
private static void spawnNodes() {
nodes.clear();
for (int i = 0; i < 4; i++) {
nodes.add(new DataNode(rand.nextInt(WIDTH - 2) + 1, rand.nextInt(HEIGHT - 2) + 1, false));
}
for (int i = 0; i < 3; i++) {
nodes.add(new DataNode(rand.nextInt(WIDTH - 2) + 1, rand.nextInt(HEIGHT - 2) + 1, true));
}
}
private static void renderGrid() {
StringBuilder sb = new StringBuilder();
sb.append(CLEAR_SCREEN);
sb.append(CYAN + "SCORE: " + score + " TB | SECURITY TRACE: " + securityTrace + "%\n" + RESET);
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
if (y == 0 || y == HEIGHT - 1 || x == 0 || x == WIDTH - 1) {
sb.append(CYAN + "#" + RESET);
} else if (x == playerX && y == playerY) {
sb.append(GREEN + "▲" + RESET);
} else {
boolean printed = false;
for (DataNode node : nodes) {
if (node.x == x && node.y == y) {
if (node.isThreat) {
sb.append(RED + "X" + RESET);
} else {
sb.append(GREEN + "$" + RESET);
}
printed = true;
break;
}
}
if (!printed) {
sb.append(" ");
}
}
}
sb.append("\n");
}
System.out.print(sb.toString());
}
private static void processInput(String input) {
if (input.isEmpty()) return;
char move = input.charAt(0);
int nextX = playerX;
int nextY = playerY;
switch (move) {
case 'w' -> nextY--;
case 's' -> nextY++;
case 'a' -> nextX--;
case 'd' -> nextX++;
}
// Collision with boundary walls
if (nextX > 0 && nextX < WIDTH - 1 && nextY > 0 && nextY < HEIGHT - 1) {
playerX = nextX;
playerY = nextY;
}
}
private static void updateGameState() {
DataNode collectedNode = null;
for (DataNode node : nodes) {
if (node.x == playerX && node.y == playerY) {
collectedNode = node;
break;
}
}
if (collectedNode != null) {
if (collectedNode.isThreat) {
securityTrace += 35;
System.out.println(RED + "\n[!] ALERT: FIREWALL BREACHED! +35% Security Trace!" + RESET);
} else {
score += 10;
System.out.println(GREEN + "\n[+] DATA NODE SECURED! +10 TB" + RESET);
}
nodes.remove(collectedNode);
// Spawn replacements
nodes.add(new DataNode(rand.nextInt(WIDTH - 2) + 1, rand.nextInt(HEIGHT - 2) + 1, rand.nextBoolean()));
}
// Slowly increase trace over time to add pressure
if (rand.nextInt(10) > 7) {
securityTrace += 5;
}
if (securityTrace >= 100) {
running = false;
}
}
}