diff --git a/.idea/.idea.FNAF_Clone/.idea/codeStyles/codeStyleConfig.xml b/.idea/.idea.FNAF_Clone/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..a55e7a1
--- /dev/null
+++ b/.idea/.idea.FNAF_Clone/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/FNAF_Clone.sln.DotSettings.user b/FNAF_Clone.sln.DotSettings.user
index e95bd55..0f56013 100644
--- a/FNAF_Clone.sln.DotSettings.user
+++ b/FNAF_Clone.sln.DotSettings.user
@@ -12,10 +12,17 @@
ForceIncluded
ForceIncluded
ForceIncluded
+ ForceIncluded
ForceIncluded
+ ForceIncluded
ForceIncluded
ForceIncluded
+ ForceIncluded
ForceIncluded
ForceIncluded
+ ForceIncluded
ForceIncluded
- ForceIncluded
\ No newline at end of file
+ ForceIncluded
+ <AssemblyExplorer>
+ <Assembly Path="/home/perry/RiderProjects/FNAF_Clone/FNAF_Clone/link/MonoGameLibrary.dll" />
+</AssemblyExplorer>
\ No newline at end of file
diff --git a/FNAF_Clone/Client.cs b/FNAF_Clone/Client.cs
index b44d782..85efab3 100644
--- a/FNAF_Clone/Client.cs
+++ b/FNAF_Clone/Client.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
@@ -37,9 +38,8 @@ public class Client {
public static ClientPlayer Opponent { get; } = new();
public static ClientPlayer GetPlayer(int pid) => Player.state.pid == pid ? Player : Opponent;
-
- public static void Connect(string endPoint, int port) {
- State = ConnectionState.CONNECTING;
+
+ public static void Init() {
writer = new NetDataWriter();
processor = new NetPacketProcessor();
@@ -57,9 +57,6 @@ public class Client {
client = new NetManager(listener){
AutoRecycle = true
};
-
- client.Start();
- Console.WriteLine($"Connecting to server @ {endPoint}:{port}");
listener.NetworkReceiveEvent += (peer, reader, channel, method) => {
OnNetworkReceive(peer, reader, method);
@@ -71,6 +68,13 @@ public class Client {
State = ConnectionState.CONNECTED;
SendPacket(new JoinPacket {username = Player.username == "" ? "Anonymous" : Player.username}, DeliveryMethod.ReliableOrdered);
};
+ }
+
+ public static void Connect(string endPoint, int port) {
+ State = ConnectionState.CONNECTING;
+
+ client.Start();
+ Console.WriteLine($"Connecting to server @ {endPoint}:{port}");
new Thread(() => client.Connect(endPoint, port, "")).Start(); // TODO: figure out how keys work
}
@@ -108,9 +112,18 @@ public class Client {
public static void OnPlayerUpdate(UpdatePlayerPacket packet) { // TODO: move this to a separate class
EventProcessor.Evaluate(packet.events);
//Player.state = Player.state.pid == 0 ? packet.stateP1 : packet.stateP2;
-
-
}
+ public static void Disconnect() {
+ if (client == null || client.ConnectedPeersCount == 0) return;
+ client.DisconnectAll();
+ client.Stop();
+ State = ConnectionState.IDLE;
+ }
+ public static void StartServer() {
+ Process.Start("FNAF_Server");
+ // new Thread(() => Server.Start(9012)).Start();
+ }
+
}
\ No newline at end of file
diff --git a/FNAF_Clone/ClientEnemyManager.cs b/FNAF_Clone/ClientEnemyManager.cs
index 1026ba0..74551b4 100644
--- a/FNAF_Clone/ClientEnemyManager.cs
+++ b/FNAF_Clone/ClientEnemyManager.cs
@@ -99,4 +99,8 @@ public static class ClientEnemyManager {
return output.ToArray();
}
+
+ public static void ClearEnemies() {
+ enemies.Clear();
+ }
}
\ No newline at end of file
diff --git a/FNAF_Clone/EventProcessor.cs b/FNAF_Clone/EventProcessor.cs
index c2ee66f..a3f0114 100644
--- a/FNAF_Clone/EventProcessor.cs
+++ b/FNAF_Clone/EventProcessor.cs
@@ -105,6 +105,8 @@ public class EventProcessor {
case 11:
Console.WriteLine($"E: Player {e.Args[0]} won");
if(Client.Player.state.pid == e.Args[0]) UIManager.ShowVictoryScreen();
+ Client.Disconnect();
+ ClientEnemyManager.ClearEnemies();
break;
case 12: // game start
diff --git a/FNAF_Clone/FNAF_Clone.csproj b/FNAF_Clone/FNAF_Clone.csproj
index 361522c..d1ad6ea 100644
--- a/FNAF_Clone/FNAF_Clone.csproj
+++ b/FNAF_Clone/FNAF_Clone.csproj
@@ -1,52 +1,63 @@
-
- WinExe
- net9.0
- Major
- false
- false
- 14
-
-
- app.manifest
- Icon.ico
-
-
-
-
-
-
-
-
- Icon.ico
-
-
- Icon.bmp
-
-
-
-
-
-
-
-
-
-
-
-
-
- lib\MonoGameLibrary.dll
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+ WinExe
+ net9.0
+ Major
+ false
+ false
+ 14
+
+
+ app.manifest
+ Icon.ico
+
+
+ ../bin/Client/
+
+
+ ../bin/Debug/Client/
+
+
+
+
+
+
+
+
+ Icon.ico
+
+
+ Icon.bmp
+
+
+
+
+
+
+
+
+
+
+
+
+
+ link\MonoGameLibrary.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/FNAF_Clone/GUI/Screen.cs b/FNAF_Clone/GUI/Screen.cs
index 1b22436..f24e523 100644
--- a/FNAF_Clone/GUI/Screen.cs
+++ b/FNAF_Clone/GUI/Screen.cs
@@ -73,6 +73,8 @@ public class Screen {
public bool Active { get; private set; } = false;
private InputListenerHook mouseInputHook = new(true);
private bool temporary = false;
+
+ private List temporaryElements = new();
public Screen(string label) {
Label = label;
@@ -87,7 +89,7 @@ public class Screen {
public UIElement this[string id] => elements[id];
public UIElement TryGetElement(string id) => elements.TryGetValue(id, out var val) ? val : null;
- public UIElement AddElement(string id, UIElement element) {
+ public UIElement AddElement(string id, UIElement element, bool temporary = false) {
elements.Add(id, element);
int insertIndex = elementsInDrawOrder.FindLastIndex(e => e.DrawPriority == element.DrawPriority);
@@ -97,10 +99,25 @@ public class Screen {
else{
elementsInDrawOrder.Insert(insertIndex + 1, element);
}
+
+ if (temporary){
+ temporaryElements.Add(id);
+ }
return element;
}
+ public void RemoveElement(string id) {
+ if (!elements.ContainsKey(id)) return;
+ elements.Remove(id, out var element);
+ elementsInDrawOrder.RemoveAll(e => e == element);
+ }
+
+ public void RemoveTemporary() {
+ temporaryElements.ForEach(RemoveElement);
+ temporaryElements.Clear();
+ }
+
public void SetActive(bool active) {
Active = active;
if (Active == active) return;
diff --git a/FNAF_Clone/GUI/TimerUIElement.cs b/FNAF_Clone/GUI/TimerUIElement.cs
index 4df57b5..8116f81 100644
--- a/FNAF_Clone/GUI/TimerUIElement.cs
+++ b/FNAF_Clone/GUI/TimerUIElement.cs
@@ -22,7 +22,7 @@ public class TimerUIElement : TextUIElement{
}
public void Start() {
- stopwatch.Start();
+ stopwatch.Restart();
}
public void Stop() {
diff --git a/FNAF_Clone/GUI/UIManager.cs b/FNAF_Clone/GUI/UIManager.cs
index 99864f9..297c1a4 100644
--- a/FNAF_Clone/GUI/UIManager.cs
+++ b/FNAF_Clone/GUI/UIManager.cs
@@ -88,6 +88,14 @@ public class UIManager {
cameraView = new UIElement(rooms.ToArray(), new(64, 64));
monitorScreen.AddElement("camera-view", cameraView);
+ monitorScreen.AddElement("p1-office-door-left", new UIElement([MonitorAtlas["door-office-p1-left-open"], MonitorAtlas["door-office-p1-left-closed"]], new Point(400, 272)));
+ monitorScreen.AddElement("p1-office-door-centre", new UIElement([MonitorAtlas["door-office-p1-centre-open"], MonitorAtlas["door-office-p1-centre-closed"]], new Point(400, 272)));
+ monitorScreen.AddElement("p1-office-door-right", new UIElement([MonitorAtlas["door-office-p1-right-open"], MonitorAtlas["door-office-p1-right-closed"]], new Point(400, 272)));
+ monitorScreen.AddElement("p2-office-door-right", new UIElement([MonitorAtlas["door-office-p2-right-open"], MonitorAtlas["door-office-p2-right-closed"]], new Point(400, 144)));
+ monitorScreen.AddElement("p2-office-door-centre", new UIElement([MonitorAtlas["door-office-p2-centre-open"], MonitorAtlas["door-office-p2-centre-closed"]], new Point(400, 144)));
+ monitorScreen.AddElement("p2-office-door-left", new UIElement([MonitorAtlas["door-office-p2-left-open"], MonitorAtlas["door-office-p2-left-closed"]], new Point(400, 144)));
+
+
// main menu
timerElement = new(new(0, 0), PixelMonoFont);
overlayScreen.AddElement("timer", timerElement);
@@ -119,20 +127,70 @@ public class UIManager {
}
});
menuScreen.AddElement("host-button",
- new TextUIElement(new(connectButton.Bounds.Item1.X, connectButton.Bounds.Item2.Y + 30), PixelMonoFont) {Text = "HOST"});
+ new TextUIElement(new(connectButton.Bounds.Item1.X, connectButton.Bounds.Item2.Y + 30), PixelMonoFont) {Text = "HOST", Pressable = true,
+ OnMousePress = () => {
+ Client.StartServer();
+ Client.Player.username = usernameField.Text;
+ Client.Connect("127.0.0.1", 9012);
+ Screen.SetScreen(ScreenTypes.LOADING);
+
+ }});
loadingScreen.AddElement("loading-text", new LoadingUIElement(new(320, 180), PixelMonoFont, field.Text));
}
public static void DisplayMainMenu() {
+ ResetUI();
Screen.SetScreen(ScreenTypes.MENU);
CommandManager.AllowGameControls(false);
// if(Client.Player.username != null)
// ((MenuInputField)menuScreen["username-field"]).Text = Client.Player.username;
}
+
+ public static void SpawnMapElements(TileConnectorProjection[] doors) {
+
+
+ for (int i = 0; i < 5; i++){ // NOTE: this loop does y in reverse, y labels are inverted to match server
+ for (int j = 0; j < 5; j++){
+ int id = ClientMapManager.CoordsToId(i, 4 - j);
+ if (Client.Player.state.officeTileId == id || Client.Opponent.state.officeTileId == id) continue; // TODO: remove the other check for office
+ Point point1 = new Point(336 + (32 * i), 144 + (32 * j));
+ Point point2 = new Point(367 + (32 * i), 175 + (32 * j));
+ monitorScreen.AddElement(
+ $"room{id}", new UIElement(point1, point2)
+ {Pressable = true, OnMousePress = (() => CommandManager.SendChangeCamera(id))},
+ true);
+ lightIndicators.Add(id,
+ monitorScreen.AddElement(
+ $"light{id}", new UIElement(MonitorAtlas["map-light-indicator"], point1)
+ {Visible = false},
+ true));
+
+ //
+ // if (doorPositions.ContainsKey((i, j))){
+ // monitorScreen.AddElement("door"+doorPositions[(i, j)], new UIElement([monitorAtlas[5], monitorAtlas[6]], point1));
+ // }
+ }
+ }
+
+ monitorScreen.AddElement("eye-player", new UIElement(MonitorAtlas["eye-small-player"], monitorScreen["room"+Client.Player.state.camera].Bounds.Item1), true);
+ monitorScreen.AddElement("eye-opponent", new UIElement([MonitorAtlas["eye-small-opponent-closed"], MonitorAtlas["eye-small-opponent-open"]], monitorScreen["room"+Client.Opponent.state.camera].Bounds.Item1), true);
-
+ foreach (var door in doors){
+ if(door.Type != ConnectorType.DOOR_REMOTE) continue;
+
+ (int x, int y) dpos = (Math.Abs(door.Tiles.tile1.GridPosition.x - door.Tiles.tile2.GridPosition.x), Math.Abs(door.Tiles.tile1.GridPosition.y - door.Tiles.tile2.GridPosition.y));
+
+ if (dpos.y == 1){
+ int targetId = door.Tiles.tile1.GridPosition.y > door.Tiles.tile2.GridPosition.y ? door.Tiles.tile1.Id : door.Tiles.tile2.Id;
+ UIElement tile = monitorScreen["room"+targetId];
+
+ monitorScreen.AddElement("door"+Math.Max(door.Tiles.tile1.Id, door.Tiles.tile2.Id)+"-"+Math.Min(door.Tiles.tile1.Id, door.Tiles.tile2.Id), new UIElement([MonitorAtlas["door-remote-open"], MonitorAtlas["door-remote-closed"]], tile.Bounds.Item1), true);
+ }
+ }
+ }
+
public static void DisplayGameUI() {
Screen.SetScreen(ScreenTypes.OFFICE);
Screen.SetOverlayScreen(ScreenTypes.OVERLAY);
@@ -145,53 +203,10 @@ public class UIManager {
timerElement.Start();
}
- public static void SpawnMapElements(TileConnectorProjection[] doors) {
- for (int i = 0; i < 5; i++){ // NOTE: this loop does y in reverse, y labels are inverted to match server
- for (int j = 0; j < 5; j++){
- int id = ClientMapManager.CoordsToId(i, 4 - j);
- if (Client.Player.state.officeTileId == id || Client.Opponent.state.officeTileId == id) continue; // TODO: remove the other check for office
- Point point1 = new Point(336 + (32 * i), 144 + (32 * j));
- Point point2 = new Point(367 + (32 * i), 175 + (32 * j));
- monitorScreen.AddElement($"room{id}", new UIElement(point1, point2)
- {Pressable = true, OnMousePress = (() => CommandManager.SendChangeCamera(id))});
- lightIndicators.Add(id, monitorScreen.AddElement($"light{id}", new UIElement(MonitorAtlas["map-light-indicator"], point1){Visible = false}));
-
- //
- // if (doorPositions.ContainsKey((i, j))){
- // monitorScreen.AddElement("door"+doorPositions[(i, j)], new UIElement([monitorAtlas[5], monitorAtlas[6]], point1));
- // }
- }
- }
-
- monitorScreen.AddElement("eye-player", new UIElement(MonitorAtlas["eye-small-player"], monitorScreen["room"+Client.Player.state.camera].Bounds.Item1));
- monitorScreen.AddElement("eye-opponent", new UIElement([MonitorAtlas["eye-small-opponent-closed"], MonitorAtlas["eye-small-opponent-open"]], monitorScreen["room"+Client.Opponent.state.camera].Bounds.Item1));
-
- foreach (var door in doors){
- if(door.Type != ConnectorType.DOOR_REMOTE) continue;
-
- (int x, int y) dpos = (Math.Abs(door.Tiles.tile1.GridPosition.x - door.Tiles.tile2.GridPosition.x), Math.Abs(door.Tiles.tile1.GridPosition.y - door.Tiles.tile2.GridPosition.y));
-
- if (dpos.y == 1){
- int targetId = door.Tiles.tile1.GridPosition.y > door.Tiles.tile2.GridPosition.y ? door.Tiles.tile1.Id : door.Tiles.tile2.Id;
- UIElement tile = monitorScreen["room"+targetId];
-
- monitorScreen.AddElement("door"+Math.Max(door.Tiles.tile1.Id, door.Tiles.tile2.Id)+"-"+Math.Min(door.Tiles.tile1.Id, door.Tiles.tile2.Id), new UIElement([MonitorAtlas["door-remote-open"], MonitorAtlas["door-remote-closed"]], tile.Bounds.Item1));
- }
- }
-
- monitorScreen.AddElement("p1-office-door-left", new UIElement([MonitorAtlas["door-office-p1-left-open"], MonitorAtlas["door-office-p1-left-closed"]], new Point(400, 272)));
- monitorScreen.AddElement("p1-office-door-centre", new UIElement([MonitorAtlas["door-office-p1-centre-open"], MonitorAtlas["door-office-p1-centre-closed"]], new Point(400, 272)));
- monitorScreen.AddElement("p1-office-door-right", new UIElement([MonitorAtlas["door-office-p1-right-open"], MonitorAtlas["door-office-p1-right-closed"]], new Point(400, 272)));
- monitorScreen.AddElement("p2-office-door-right", new UIElement([MonitorAtlas["door-office-p2-right-open"], MonitorAtlas["door-office-p2-right-closed"]], new Point(400, 144)));
- monitorScreen.AddElement("p2-office-door-centre", new UIElement([MonitorAtlas["door-office-p2-centre-open"], MonitorAtlas["door-office-p2-centre-closed"]], new Point(400, 144)));
- monitorScreen.AddElement("p2-office-door-left", new UIElement([MonitorAtlas["door-office-p2-left-open"], MonitorAtlas["door-office-p2-left-closed"]], new Point(400, 144)));
-
- }
-
public static void AddEnemySprite(int id, UIElement sprite, UIElement jumpscareSprite = null) {
- monitorScreen.AddElement($"enemy{id}", sprite);
+ monitorScreen.AddElement($"enemy{id}", sprite, true);
if (jumpscareSprite != null){
- officeScreen.AddElement($"enemy{id}-jumpscare", jumpscareSprite);
+ officeScreen.AddElement($"enemy{id}-jumpscare", jumpscareSprite, true);
jumpscareSprite.Active = false;
jumpscareSprite.Visible = false;
}
@@ -314,6 +329,16 @@ public class UIManager {
SoundManager.StopAmbience();
InputManager.AddListener(Keys.Space, DisplayMainMenu, InputTiming.PRESS, new InputListenerHook(true, true));
}
+
+ public static void ResetUI() {
+ foreach (Screen screen in Screen.Screens.Values){
+ screen.RemoveTemporary();
+ }
+ lightIndicators.Clear();
+ enemyElements.Clear();
+
+ timerElement.Stop();
+ }
// private static Point GetRoomUIPos((int x, int y) pos) {
// return new Point(336 + (32 * pos.x), 144 + (32 * pos.y));
diff --git a/FNAF_Clone/GameMain.cs b/FNAF_Clone/GameMain.cs
index 0b5cac1..fea64ab 100644
--- a/FNAF_Clone/GameMain.cs
+++ b/FNAF_Clone/GameMain.cs
@@ -16,6 +16,10 @@ public class GameMain() : Core("fnafkooo", 1280, 720, false) {
protected override void Initialize() {
+ Exiting += (_, _) => {
+ Client.Disconnect();
+ };
+
// Client.Connect("127.0.0.1", 9012);
CommandManager.InitInputListeners();
@@ -23,6 +27,7 @@ public class GameMain() : Core("fnafkooo", 1280, 720, false) {
base.Initialize();
+ Client.Init();
UIManager.InitUI();
UIManager.DisplayMainMenu();
}
@@ -35,9 +40,9 @@ public class GameMain() : Core("fnafkooo", 1280, 720, false) {
}
protected override void Update(GameTime gameTime) {
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
- Keyboard.GetState().IsKeyDown(Keys.Escape))
+ if (Keyboard.GetState().IsKeyDown(Keys.Escape)){
Exit();
+ }
InputManager.NextInputCycle();
Screen.UpdateAll();
@@ -59,4 +64,6 @@ public class GameMain() : Core("fnafkooo", 1280, 720, false) {
spriteBatch.End();
base.Draw(gameTime);
}
+
+
}
\ No newline at end of file
diff --git a/FNAF_Clone/Program.cs b/FNAF_Clone/Program.cs
index 99c5548..5b0bb57 100644
--- a/FNAF_Clone/Program.cs
+++ b/FNAF_Clone/Program.cs
@@ -1,2 +1,5 @@
-using var game = new FNAF_Clone.GameMain();
+using System;
+
+using var game = new FNAF_Clone.GameMain();
+Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
game.Run();
\ No newline at end of file
diff --git a/FNAF_Clone/lib/MonoGameLibrary.dll b/FNAF_Clone/lib/MonoGameLibrary.dll
deleted file mode 120000
index 1929591..0000000
--- a/FNAF_Clone/lib/MonoGameLibrary.dll
+++ /dev/null
@@ -1 +0,0 @@
-../../MonoGameLibrary/MonoGameLibrary/bin/Debug/net8.0/MonoGameLibrary.dll
\ No newline at end of file
diff --git a/FNAF_Clone/link/MonoGameLibrary.dll b/FNAF_Clone/link/MonoGameLibrary.dll
new file mode 120000
index 0000000..3b2d4ec
--- /dev/null
+++ b/FNAF_Clone/link/MonoGameLibrary.dll
@@ -0,0 +1 @@
+../../MonoGameLibrary/MonoGameLibrary/bin/Release/net9.0/publish/MonoGameLibrary.dll
\ No newline at end of file
diff --git a/FNAF_Server/Enemies/NekoEnemy.cs b/FNAF_Server/Enemies/NekoEnemy.cs
index 72f8722..c8e80f5 100644
--- a/FNAF_Server/Enemies/NekoEnemy.cs
+++ b/FNAF_Server/Enemies/NekoEnemy.cs
@@ -55,25 +55,22 @@ public class NekoEnemy : Enemy {
Server.SendUpdateToAll([GameEvent.NEKO_ANGERED(Location.Owner.state.pid, Id)]);
}
- if (movementOpportunity.CheckAndRoll() || (Aggressive && GameLogic.NSecondUpdate)){
- if (Target == null){
- if (Server.P1.state.power > Server.P2.state.power){
- Target = Server.P2;
- }
- else if (Server.P1.state.power < Server.P2.state.power){
- Target = Server.P1;
- }
- else{
- if (GameLogic.PhaseCounter > 1){
- Target = Server.Players[new Random().Next(2)];
- SetDifficulty(8);
- }
- else{
- return;
- }
+ if (Target == null){
+ if (Server.P1.state.power > Server.P2.state.power){
+ Target = Server.P2;
+ }
+ else if (Server.P1.state.power < Server.P2.state.power){
+ Target = Server.P1;
+ }
+ else{
+ if (GameLogic.PhaseCounter > 1){
+ Target = Server.Players[new Random().Next(2)];
+ SetDifficulty(8);
}
}
-
+ }
+
+ if (Target != null && (movementOpportunity.CheckAndRoll() || (Aggressive && GameLogic.NSecondUpdate))){
Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(Target.state.officeTileId));
switch (decision.type){
case Pathfinder.Decision.MoveType:
diff --git a/FNAF_Server/FNAF_Server.csproj b/FNAF_Server/FNAF_Server.csproj
index 72aa55a..81a1f22 100644
--- a/FNAF_Server/FNAF_Server.csproj
+++ b/FNAF_Server/FNAF_Server.csproj
@@ -8,6 +8,14 @@
14
+
+ ../bin/Debug/Server
+
+
+
+ ../bin/Server
+
+
diff --git a/FNAF_Server/GameLogic.cs b/FNAF_Server/GameLogic.cs
index 175ac4a..d6ee6ff 100644
--- a/FNAF_Server/GameLogic.cs
+++ b/FNAF_Server/GameLogic.cs
@@ -11,7 +11,7 @@ public class GameLogic {
public const int START_CAMERA = 12;
private static MovementOpportunity secondCycleTimer = new(1000);
- private static MovementOpportunity gamePhaseTimer = new(30_000);
+ private static MovementOpportunity gamePhaseTimer = new(60_000);
public static bool NSecondUpdate{ get; private set; } = false;
public static MapTile P1Office;
@@ -84,7 +84,7 @@ public class GameLogic {
// EnemyManager.AddEnemy(new MareEnemy(10)).Spawn(MapManager.Get(22));
EnemyManager.AddEnemy(new LurkEnemy(4)).Spawn(MapManager.Get(2));
- EnemyManager.AddEnemy(new NekoEnemy(4)).Spawn(MapManager.Get(22));
+ EnemyManager.AddEnemy(new NekoEnemy(4)).Spawn(MapManager.Get(0));
}
public static void Update() {
@@ -122,9 +122,16 @@ public class GameLogic {
}
public static void DeclareWinner(ServerPlayer player) {
- Server.SendUpdateToAll([GameEvent.PLAYER_WIN(player.state.pid)]);
+ if (Server.Players.Count == 2){
+ Server.SendUpdateToAll([GameEvent.PLAYER_WIN(player.state.pid)]);
+ Console.WriteLine("Player " + player.state.pid + " won!");
+ }
+ Thread.Sleep(1000);
Server.Stop();
- Console.WriteLine("Player " + player.state.pid + " won!");
+
+ if (!Server.AutoStop){
+ Program.Restart();
+ }
}
private static (int p1Usage, int p2Usage) CalculatePowerUsage() {
@@ -158,7 +165,7 @@ public class GameLogic {
PhaseCounter++;
Server.SendUpdateToAll([GameEvent.NEXT_PHASE()]);
- int roll = random.Next(3);
+ int roll = spawnOrder.Count > 0 ? random.Next(3) : random.Next(1,3);
switch (roll){
case 0:
int spawnRoll = random.Next(spawnOrder[0].Count);
diff --git a/FNAF_Server/Program.cs b/FNAF_Server/Program.cs
index 1a0d1d6..e1c6274 100644
--- a/FNAF_Server/Program.cs
+++ b/FNAF_Server/Program.cs
@@ -1,9 +1,18 @@
-using System.Security.Cryptography.X509Certificates;
+using System.Diagnostics;
namespace FNAF_Server;
public class Program {
public static void Main(string[] args) {
+ if (args.Contains("--persistent")){
+ Server.AutoStop = false;
+ }
Server.Start(9012);
}
+
+ public static void Restart() {
+ Console.WriteLine("Game concluded -> restarting server");
+ Process.Start(new ProcessStartInfo{ FileName = Environment.ProcessPath, UseShellExecute = false });
+ Environment.Exit(0);
+ }
}
\ No newline at end of file
diff --git a/FNAF_Server/Server.cs b/FNAF_Server/Server.cs
index dc8ef7b..56a9f6e 100644
--- a/FNAF_Server/Server.cs
+++ b/FNAF_Server/Server.cs
@@ -15,6 +15,8 @@ public class Server {
public static ServerPlayer P2;
public static readonly Dictionary Players = new();
public static ServerPlayer OtherPlayer(ServerPlayer player) => player.state.pid == P1.state.pid ? P2 : P1;
+
+ public static bool AutoStop{ get; set; } = true;
private static EventBasedNetListener listener;
private static NetManager server;
@@ -138,6 +140,8 @@ public class Server {
}
public static void OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo) {
+ GameLogic.DeclareWinner(OtherPlayer(Players.Values.First(p => Equals(p.peer, peer))));
+
if (peer.Tag != null) {
Players.Remove(peer.Id);
}
@@ -193,6 +197,7 @@ public class Server {
public static void Stop()
{
isRunning = false;
+ server.Stop();
}
}
diff --git a/GlobalClassLib/Power.cs b/GlobalClassLib/Power.cs
index 5c81423..ad91f01 100644
--- a/GlobalClassLib/Power.cs
+++ b/GlobalClassLib/Power.cs
@@ -1,5 +1,5 @@
namespace GlobalClassLib;
public static class Power {
- public const int MAX_POWER_VALUE = 1000;
+ public const int MAX_POWER_VALUE = 4000;
}
\ No newline at end of file
diff --git a/build-linux.sh b/build-linux.sh
new file mode 100755
index 0000000..367310e
--- /dev/null
+++ b/build-linux.sh
@@ -0,0 +1,7 @@
+dotnet publish MonoGameLibrary
+ln -sfrv MonoGameLibrary/MonoGameLibrary/bin/Release/net9.0/publish/MonoGameLibrary.dll FNAF_Clone/link/MonoGameLibrary.dll
+
+dotnet publish
+
+ln -sfrv bin/Server/net9.0/publish/FNAF_Server bin/Client/net9.0/publish/FNAF_Server
+ln -sfrv bin/Client/net9.0/publish/FNAF_Clone outexe
diff --git a/launch-server.sh b/launch-server.sh
new file mode 100755
index 0000000..57437a8
--- /dev/null
+++ b/launch-server.sh
@@ -0,0 +1,5 @@
+while :
+do
+ bin/Server/net9.0/publish/FNAF_Server
+ echo "Restarting server..."
+done
\ No newline at end of file
diff --git a/outexe b/outexe
new file mode 120000
index 0000000..33e90b5
--- /dev/null
+++ b/outexe
@@ -0,0 +1 @@
+bin/Client/net9.0/publish/FNAF_Clone
\ No newline at end of file