From 9000450834d6d4b7355e399eb162c2dea04f73fb Mon Sep 17 00:00:00 2001 From: brausjonas Date: Fri, 14 Apr 2023 17:49:48 +0200 Subject: [PATCH] Full Rotator Sync --- .../.idea.FlufflParty/.idea/workspace.xml | 2 +- FlufflParty/Assets/Scenes/WesternMap.unity | 60 ++--- FlufflParty/Assets/Scripts/Client.cs | 68 +++++ .../Assets/Scripts/Players/PlayablePlayer.cs | 4 +- FlufflParty/Assets/Scripts/RandomRotator.cs | 18 +- Server/.idea/workspace.xml | 2 +- Server/out/artifacts/Server_jar/Server.jar | Bin 10133 -> 10174 bytes Server/out/production/Server/Room$1.class | Bin 3206 -> 3309 bytes Server/out/production/Server/Room.class | Bin 4748 -> 4748 bytes Server/src/Room.java | 235 +++++++----------- 10 files changed, 206 insertions(+), 183 deletions(-) diff --git a/FlufflParty/.idea/.idea.FlufflParty/.idea/workspace.xml b/FlufflParty/.idea/.idea.FlufflParty/.idea/workspace.xml index 97173aa..c4276e8 100644 --- a/FlufflParty/.idea/.idea.FlufflParty/.idea/workspace.xml +++ b/FlufflParty/.idea/.idea.FlufflParty/.idea/workspace.xml @@ -165,7 +165,7 @@ - + diff --git a/FlufflParty/Assets/Scenes/WesternMap.unity b/FlufflParty/Assets/Scenes/WesternMap.unity index 206bb1a..7a39053 100644 --- a/FlufflParty/Assets/Scenes/WesternMap.unity +++ b/FlufflParty/Assets/Scenes/WesternMap.unity @@ -1298,8 +1298,8 @@ ParticleSystem: serializedVersion: 2 m_Curve: - serializedVersion: 3 - time: 0.008106232 - value: 0.689188 + time: 0 + value: 0.14864922 inSlope: 0 outSlope: 0 tangentMode: 0 @@ -1307,8 +1307,8 @@ ParticleSystem: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.57541054 - value: 0.4783156 + time: 0.57811135 + value: 0.3161528 inSlope: -0.19598381 outSlope: -0.19598381 tangentMode: 0 @@ -1317,7 +1317,7 @@ ParticleSystem: outWeight: 0.33333334 - serializedVersion: 3 time: 1 - value: 0.43243706 + value: 0.25676262 inSlope: -0.11902377 outSlope: -0.11902377 tangentMode: 0 @@ -7855,8 +7855,8 @@ ParticleSystem: serializedVersion: 2 m_Curve: - serializedVersion: 3 - time: 0.008106232 - value: 0.689188 + time: 0 + value: 0.14864922 inSlope: 0 outSlope: 0 tangentMode: 0 @@ -7864,8 +7864,8 @@ ParticleSystem: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.57541054 - value: 0.4783156 + time: 0.57811135 + value: 0.3161528 inSlope: -0.19598381 outSlope: -0.19598381 tangentMode: 0 @@ -7874,7 +7874,7 @@ ParticleSystem: outWeight: 0.33333334 - serializedVersion: 3 time: 1 - value: 0.43243706 + value: 0.25676262 inSlope: -0.11902377 outSlope: -0.11902377 tangentMode: 0 @@ -15703,8 +15703,8 @@ ParticleSystem: serializedVersion: 2 m_Curve: - serializedVersion: 3 - time: 0.008106232 - value: 0.689188 + time: 0 + value: 0.14864922 inSlope: 0 outSlope: 0 tangentMode: 0 @@ -15712,8 +15712,8 @@ ParticleSystem: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.57541054 - value: 0.4783156 + time: 0.57811135 + value: 0.3161528 inSlope: -0.19598381 outSlope: -0.19598381 tangentMode: 0 @@ -15722,7 +15722,7 @@ ParticleSystem: outWeight: 0.33333334 - serializedVersion: 3 time: 1 - value: 0.43243706 + value: 0.25676262 inSlope: -0.11902377 outSlope: -0.11902377 tangentMode: 0 @@ -29023,8 +29023,8 @@ ParticleSystem: serializedVersion: 2 m_Curve: - serializedVersion: 3 - time: 0.008106232 - value: 0.689188 + time: 0 + value: 0.14864922 inSlope: 0 outSlope: 0 tangentMode: 0 @@ -29032,8 +29032,8 @@ ParticleSystem: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.57541054 - value: 0.4783156 + time: 0.57811135 + value: 0.3161528 inSlope: -0.19598381 outSlope: -0.19598381 tangentMode: 0 @@ -29042,7 +29042,7 @@ ParticleSystem: outWeight: 0.33333334 - serializedVersion: 3 time: 1 - value: 0.43243706 + value: 0.25676262 inSlope: -0.11902377 outSlope: -0.11902377 tangentMode: 0 @@ -38995,8 +38995,8 @@ ParticleSystem: serializedVersion: 2 m_Curve: - serializedVersion: 3 - time: 0.008106232 - value: 0.689188 + time: 0 + value: 0.14864922 inSlope: 0 outSlope: 0 tangentMode: 0 @@ -39004,8 +39004,8 @@ ParticleSystem: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.57541054 - value: 0.4783156 + time: 0.57811135 + value: 0.3161528 inSlope: -0.19598381 outSlope: -0.19598381 tangentMode: 0 @@ -39014,7 +39014,7 @@ ParticleSystem: outWeight: 0.33333334 - serializedVersion: 3 time: 1 - value: 0.43243706 + value: 0.25676262 inSlope: -0.11902377 outSlope: -0.11902377 tangentMode: 0 @@ -46502,8 +46502,8 @@ ParticleSystem: serializedVersion: 2 m_Curve: - serializedVersion: 3 - time: 0.008106232 - value: 0.689188 + time: 0 + value: 0.14864922 inSlope: 0 outSlope: 0 tangentMode: 0 @@ -46511,8 +46511,8 @@ ParticleSystem: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.57541054 - value: 0.4783156 + time: 0.57811135 + value: 0.3161528 inSlope: -0.19598381 outSlope: -0.19598381 tangentMode: 0 @@ -46521,7 +46521,7 @@ ParticleSystem: outWeight: 0.33333334 - serializedVersion: 3 time: 1 - value: 0.43243706 + value: 0.25676262 inSlope: -0.11902377 outSlope: -0.11902377 tangentMode: 0 diff --git a/FlufflParty/Assets/Scripts/Client.cs b/FlufflParty/Assets/Scripts/Client.cs index 33f39e4..7236f29 100644 --- a/FlufflParty/Assets/Scripts/Client.cs +++ b/FlufflParty/Assets/Scripts/Client.cs @@ -9,6 +9,7 @@ using TMPro; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; +using Random = UnityEngine.Random; public class Client : MonoBehaviour { @@ -290,6 +291,44 @@ public class Client : MonoBehaviour } players[job.data[3]].AddCoins(amount); break; + case 14: + int type = job.data[9]; + RandomRotator rotator = uiHandler.rotator.GetComponent(); + switch (type) + { + case 0: + + for (int i = 0; i < 4; i++) + { + int option = job.data[i + 1]; + int value = job.data[i + 5]; + + switch (option) + { + case 0: + rotator.SetOptionsText(i, value + " Coins"); + break; + case 1: + rotator.SetOptionsText(i, "-" + value + " Coins"); + break; + case 2: + rotator.SetOptionsText(i, "Random Item"); + break; + } + } + + break; + } + + uiHandler.ActivateRotator(); + rotator.StartRandom(); + break; + case 15: + RandomRotator rotator2 = uiHandler.rotator.GetComponent(); + rotator2.Stop(job.data[1]); + Invoke("ActivateLayout1", 3.5f); + break; + case 126: stream.Write(new byte[]{126, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 10); break; @@ -301,6 +340,11 @@ public class Client : MonoBehaviour } } + private void ActivateLayout1() + { + uiHandler.ActivateLayout1(); + } + private void Activate(int player) { for (int i = 0; i < players.Length; i++) @@ -402,9 +446,33 @@ public class Client : MonoBehaviour if (amount < 0) { isPositive = 0; + amount *= -1; } stream.Write(new byte[]{13, isPositive, (byte)amount, 0, 0, 0, 0, 0, 0, 0}); } + + /* + * OPT: + * 0 = Get Coins + * 1 = Loose Coins + * 2 = Get Item (Random) + * 3 = Loose Item (Random) + * + * VAL: + * value of each option (not needed = 0) + * + * TYPE: + * 0 = Pink Field + */ + public void SendStartRotator(int opt1, int opt2, int opt3, int opt4, int val1, int val2, int val3, int val4, int type) + { + stream.Write(new byte[]{14, (byte)opt1, (byte)opt2, (byte)opt3, (byte)opt4, (byte)val1, (byte)val2, (byte)val3, (byte)val4, (byte)type}); + } + + public void SendStopRotator(int stopIndex) + { + stream.Write(new byte[]{15, (byte)stopIndex, 0, 0, 0, 0, 0, 0, 0, 0}); + } } \ No newline at end of file diff --git a/FlufflParty/Assets/Scripts/Players/PlayablePlayer.cs b/FlufflParty/Assets/Scripts/Players/PlayablePlayer.cs index 7ef216d..eb94923 100644 --- a/FlufflParty/Assets/Scripts/Players/PlayablePlayer.cs +++ b/FlufflParty/Assets/Scripts/Players/PlayablePlayer.cs @@ -270,7 +270,8 @@ public class PlayablePlayer : Player rotator.SetOptionsText(3, "Random Item"); rotator.StartRandom(); - + client.SendStartRotator(0, 0, 1, 2, randCoins1, randCoins2, -randCoins3, 0, 0); + int randomOption = Random.Range(0, 4); switch (randomOption) { @@ -489,6 +490,7 @@ public class PlayablePlayer : Player private void StopRotator() { + client.SendStopRotator(rotatorStopIndex); rotator.Stop(rotatorStopIndex); } } \ No newline at end of file diff --git a/FlufflParty/Assets/Scripts/RandomRotator.cs b/FlufflParty/Assets/Scripts/RandomRotator.cs index 3b0371e..30eb596 100644 --- a/FlufflParty/Assets/Scripts/RandomRotator.cs +++ b/FlufflParty/Assets/Scripts/RandomRotator.cs @@ -14,6 +14,7 @@ public class RandomRotator : MonoBehaviour private float lastTimeSwitched = 0; private int stopIndex = 0; public UIHandler uiHandler; + private bool ended = false; public void SetOptionsText(int index, string text) { @@ -45,31 +46,35 @@ public class RandomRotator : MonoBehaviour lastTimeSwitched = Time.time; ColorOption(currentIndex); currentIndex++; - if (currentIndex > options.Length) + if (currentIndex >= options.Length) { currentIndex = 0; } } } - else + else if(!ended) { if (currentIndex != stopIndex) { if (Time.time - lastTimeSwitched > slowDown) { - slowDown += 0.2f; + slowDown += 0.05f; lastTimeSwitched = Time.time; ColorOption(currentIndex); currentIndex++; - if (currentIndex > options.Length) + if (currentIndex >= options.Length) { currentIndex = 0; } } } - else + if(currentIndex == stopIndex) { - ColorOption(stopIndex); + if (Time.time - lastTimeSwitched > slowDown) + { + ColorOption(stopIndex); + ended = true; + } } } } @@ -78,6 +83,7 @@ public class RandomRotator : MonoBehaviour { lastTimeSwitched = Time.time; started = true; + ended = false; } public void Stop(int index) diff --git a/Server/.idea/workspace.xml b/Server/.idea/workspace.xml index 032a810..beb32c6 100644 --- a/Server/.idea/workspace.xml +++ b/Server/.idea/workspace.xml @@ -101,7 +101,7 @@ - + diff --git a/Server/out/artifacts/Server_jar/Server.jar b/Server/out/artifacts/Server_jar/Server.jar index ba6c662dd4666fb52228709b1dbd86c385c242b7..931320b4f4a517e4d6fcfac7cfd9ce6b71f6c27f 100644 GIT binary patch delta 4269 zcmV;e5K`}zPrgqKP)h>@6aWYa2mo%3u?#o_0&a|xMg%1SZj6&{1S)^s?S*a&g+fJn z6xbF@ON+=$(3Tcfwhy{XVW9}OyO(y`rMYz`q8H-gcagzEzF?YWc<){z_OP#1hl`vQ)W|xc3Bf1Av ztWe=qQO%GRZwa^Omk{vQN28k;5?B;A!|}xo4!5l;Xkd^lq9KDJ(;GI8nvTs)M$E4_ zMM#tFjRy5dgB}ZuaZ)J@rwp3MG>uqAL~n05Xqaxf%b!ggJl20%2W@9Dk5RSB)bf^*M`UC z+2uElc(Kn?kyYjZ6~oA8BYsnbsCMpxzK!pCBeUsdc5!sMlx2 zwi>a8;;fLuKCao`z8a7R+Ds9>ZAp$oM#P94c13dBx7rG}v}i}%I$`7cov>O<+ZXQb z=IDfOi-mvV6pP|sS8n~1#8FNTJ$>2CE}3`JFRtH2$<2dO8YHbe1s+VK`(ZRFd@z?w z98J15Bx<=BN80g(7SmX0oP{&q11mfV>9A#!M|~REfUb)>s2^inVFK;~EF`?q&yP4J z*}l?CXoUhO4;6NUb%V>HMXdTb~J$ z9VCChv1$UokfcU(zwJvF6&y)&6Uoe^e2nBCK3C3>`?9Uik@F6qDyhhk`w~r~Jo7|` zMRM6ta@-|TdWi%-J7flRm<(}y16`|anU&%?2u(nK4B4v(1W`8#y^`EW@-XC$v_j}g zNS6lq_gP6U8-&F*tUA7tkX{%-v0^aiH%fmv^ym*Iq_P37S6b0m4n~mv{|VkqurG&R z9>?&?!=gi{a1N6~8#;wHJPLFTpjc&5cm|^wK@^sErAQGRf^G;Toe3-*Kr+!H8QqVh zC}n>xVbAotAQM+s+5J;;Eu5YB_&d zt{~eQvi4#+sxc3BG_z7XNN8;Xt@dL-={o7P(M2zfcjzgR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hh+(G%qs{~BQH(ib zm~dWTQZ2=V%EfaPz$;aPDYXV~5~_s{$1tsqV@9392X!7F)fDwKKB@OeswBRsZ}_gu zk<=UTLvO-Qy#v2=jX+6{9peqNnisH&L-r8h6C zewv-0z<@r&UlM{c`Ttf3r*5bzLq1k=H@^uX%+Cp2Q-l&k;2?DiyRp_r+yZH~+ucL< Hv0M5V@qm|Y diff --git a/Server/out/production/Server/Room.class b/Server/out/production/Server/Room.class index 1dc3fa8850ca93b125d3af0c2c187478673a38cb..d38ec0c45b7db70ef56bf8989b33491370256811 100644 GIT binary patch delta 395 zcmWNL!Ap|?9ERWLH^aWN+%S^SU}>8ztd)!oA+Vbt@8NlQcn@zQ+K7I8<|I1RB)?h|RJ%f6!s<{&U5YBM zn6B%Lit1KbJ(|)vy;9u$z~g^la?y^`Yi<2p zvLIJ1LekEAyiCfnWNd)6<+x^}1gwPL?lNdE$l12X?+n`yhU_PK`$NH9I@0c|kIA8= z8;q;K9TmB)TinwG_q9q{8&tH(Lv2yjHZ}d_vHtN?dpyy9CNZAV#}tF!;~}QW^M-L| js4~k6Z&_oGbP>~v~ z5tUC&dtBB&P1JIg>s+IaBpt4GlVXS#9ymVc1~0kAE86kgJLUQ`Jsgs;<7DkLy>_OB zJ}al+!VFs6@d`O>BX8~8vkvZCFEJY;YI#QN1*5j^xWyCOVa$FqZU;Q`r%#myJWoMh zE6p2qGpP*kl%=2??={Z{Eit1NK5CUYt+Sv%Eb1>`^pDRvVi{wVX1;Qh?{xBwE;hK! jCL?Sy#}12ZQ*_%Bznt~kS-bpTPj@7h%DC-c2tDFIVn$I1 diff --git a/Server/src/Room.java b/Server/src/Room.java index 24c6870..6caea90 100644 --- a/Server/src/Room.java +++ b/Server/src/Room.java @@ -11,8 +11,7 @@ import java.util.TimerTask; /** * this class handels all operations / syncs performed in a single room */ -public class Room -{ +public class Room { //tells how many clients can connect to a room public Client[] players = new Client[2]; //the array of players start positions @@ -32,8 +31,7 @@ public class Room private int currentPlayer = 0; - public Room(String roomCode, Server server) - { + public Room(String roomCode, Server server) { this.roomCode = roomCode; startPositions = new Vector3[4]; @@ -49,17 +47,15 @@ public class Room /** * Adds a Client to the game (on new player joined the room) + * * @param client */ - public void addClient(Client client) - { + public void addClient(Client client) { //loops through all players existing and sends the needed information - for (int i = 0; i < players.length; i++) - { + for (int i = 0; i < players.length; i++) { //places the new joined player in the next free slot - if (players[i] == null) - { + if (players[i] == null) { players[i] = client; playerCount++; @@ -67,42 +63,32 @@ public class Room System.out.println(client.name.replace(" ", "") + " joined room " + roomCode + " successfully as player " + i); //creates a thread for the connection with the joined player - Thread t = new Thread(new Runnable() - { + Thread t = new Thread(new Runnable() { @Override - public void run() - { + public void run() { //assignes a player id int player = playerCount - 1; DataInputStream input = null; - try - { + try { //tries to get the input stream (TCP) input = new DataInputStream(players[player].socket.getInputStream()); - } catch (IOException e) - { + } catch (IOException e) { server.deleteRoom(roomCode); } - for(int i = 0; i < players.length; i++) - { - if(players[i] != null) - { - try - { - players[i].output.write(new byte[]{11, (byte)playerCount, 0, 0, 0, 0, 0, 0, 0, 0}); - } catch (IOException e) - { + for (int i = 0; i < players.length; i++) { + if (players[i] != null) { + try { + players[i].output.write(new byte[]{11, (byte) playerCount, 0, 0, 0, 0, 0, 0, 0, 0}); + } catch (IOException e) { } } } - while (true) - { - try - { + while (true) { + try { //this is a buffer for all data being received by the player byte[] readData = new byte[10]; @@ -120,18 +106,15 @@ public class Room ---------------------------------------- */ //Checks which action (array[0]) is received - switch (readData[0]) - { + switch (readData[0]) { /** * //spieler hat gewürfelt */ case 3: - for (int i = 0; i < players.length; i++) - { + for (int i = 0; i < players.length; i++) { //sync to all OTHER players - if (i != player) - { + if (i != player) { //!!data processing!! //----------------------------action---player-------rolled number----free space-------- players[i].output.write(new byte[]{3, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0}); @@ -142,12 +125,10 @@ public class Room * //pfeil wurde ausgewählt */ case 4: - for (int i = 0; i < players.length; i++) - { + for (int i = 0; i < players.length; i++) { //!!data processing!! //sync to all OTHER players - if (i != player) - { + if (i != player) { //-------------------------------action----player-----arrow index--------free space----- players[i].output.write(new byte[]{4, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0}); } @@ -160,13 +141,11 @@ public class Room case 5: //calculate the next player currentPlayer++; - if (currentPlayer >= players.length) - { + if (currentPlayer >= players.length) { currentPlayer = 0; } //sync the activation of the current player to ALL clients - for (int i = 0; i < players.length; i++) - { + for (int i = 0; i < players.length; i++) { //!!data processing!! //----------------------------action--------the next player-----------free space------ players[i].output.write(new byte[]{2, (byte) currentPlayer, 0, 0, 0, 0, 0, 0, 0, 0}); @@ -177,14 +156,12 @@ public class Room * //Es wurde auf ein CoinField getreten (Rot oder Blau) */ case 6: - for (int i = 0; i < players.length; i++) - { + for (int i = 0; i < players.length; i++) { //sync to OTHER players - if (i != player) - { + if (i != player) { //!!data processing!! //-----------------------------action--player-------losse or get------------free space-- - players[i].output.write(new byte[]{6, (byte)player, readData[1], 0, 0, 0, 0, 0, 0, 0}); + players[i].output.write(new byte[]{6, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0}); } } break; @@ -194,25 +171,22 @@ public class Room */ case 7: //sync to ALL players - for (int i = 0; i < players.length; i++) - { + for (int i = 0; i < players.length; i++) { //!!simple sync!! //------------------------------action---player---------free space-------- - players[i].output.write(new byte[]{7, (byte)player, 0, 0, 0, 0, 0, 0, 0, 0}); + players[i].output.write(new byte[]{7, (byte) player, 0, 0, 0, 0, 0, 0, 0, 0}); } break; /** * //Spieler hat einen Stern gekauft */ case 8: - for (int i = 0; i < players.length; i++) - { + for (int i = 0; i < players.length; i++) { //!!simple sync!! //sync to OTHER players - if (i != player) - { + if (i != player) { //-----------------------------action----player----------free space------ - players[i].output.write(new byte[]{8, (byte)player, 0, 0, 0, 0, 0, 0, 0, 0}); + players[i].output.write(new byte[]{8, (byte) player, 0, 0, 0, 0, 0, 0, 0, 0}); } } break; @@ -221,49 +195,53 @@ public class Room * //Spieler hat ein Item Gekauft */ case 9: - for (int i = 0; i < players.length; i++) - { + for (int i = 0; i < players.length; i++) { //Sync to OTHER players - if (i != player) - { + if (i != player) { //!!data processing!! //------------------------------action---player-------item ID--------free space-------- - players[i].output.write(new byte[]{9, (byte)player, readData[1], 0, 0, 0, 0, 0, 0, 0}); + players[i].output.write(new byte[]{9, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0}); } } break; case 10: - for (int i = 0; i < players.length; i++) - { + for (int i = 0; i < players.length; i++) { //Sync to OTHER players - if (i != player) - { + if (i != player) { //!!data processing!! //------------------------------action---player-------item index--------free space-------- - players[i].output.write(new byte[]{10, (byte)player, readData[1], 0, 0, 0, 0, 0, 0, 0}); + players[i].output.write(new byte[]{10, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0}); } } break; case 12: - for (int i = 0; i < players.length; i++) - { + for (int i = 0; i < players.length; i++) { //Sync to OTHER players - if (i != player) - { + if (i != player) { //!!data processing!! //------------------------------action---player-------item index--------free space-------- - players[i].output.write(new byte[]{12, (byte)player, readData[1], 0, 0, 0, 0, 0, 0, 0}); + players[i].output.write(new byte[]{12, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0}); } } break; + //Coins Sync case 13: - for (int i = 0; i < players.length; i++) - { + for (int i = 0; i < players.length; i++) { //Sync to OTHER players - if (i != player) - { - players[i].output.write(new byte[]{13, readData[1], readData[2], (byte)player, 0, 0, 0, 0, 0, 0}); + if (i != player) { + players[i].output.write(new byte[]{13, readData[1], readData[2], (byte) player, 0, 0, 0, 0, 0, 0}); + } + } + break; + + //Start Rotator AND stop Rotator + case 14: case 15: + + for (int i = 0; i < players.length; i++) { + //Sync to OTHER players + if (i != player) { + players[i].output.write(readData); } } break; @@ -272,8 +250,7 @@ public class Room break; } - } catch (IOException e) - { + } catch (IOException e) { //if something is crashing, the room is being deleted server.deleteRoom(roomCode); } @@ -291,12 +268,9 @@ public class Room } //Make clients add all players to the world - if (playerCount == players.length) - { - for (int j = 0; j < players.length; j++) - { - for (int k = 0; k < players.length; k++) - { + if (playerCount == players.length) { + for (int j = 0; j < players.length; j++) { + for (int k = 0; k < players.length; k++) { //0 1 create new player //1 0 no playable player //1 1 playable character @@ -304,12 +278,10 @@ public class Room //5 player index //if the player should be playable - if (j == k) - { - try - { + if (j == k) { + try { //sends the inital message to the player - players[j].output.write(new byte[]{1, 1, (byte) startPositions[k].x, (byte) startPositions[k].y, (byte) startPositions[k].z, (byte) k, 0, 0, 0, (byte)players[k].characterID}); + players[j].output.write(new byte[]{1, 1, (byte) startPositions[k].x, (byte) startPositions[k].y, (byte) startPositions[k].z, (byte) k, 0, 0, 0, (byte) players[k].characterID}); //sends the name of the player (ASCII encoding)............................................................................ byte[] name = players[k].name.substring(0, 8).getBytes(StandardCharsets.US_ASCII); @@ -317,37 +289,31 @@ public class Room send[0] = 5; send[1] = (byte) k; - for (int i = 2; i < send.length; i++) - { + for (int i = 2; i < send.length; i++) { send[i] = name[i - 2]; } players[j].output.write(send); //stop sending the name................................................................................ - } catch (IOException e) - { + } catch (IOException e) { server.deleteRoom(roomCode); } - } + } //if the player should be a bot - else - { - try - { - players[j].output.write(new byte[]{1, 0, (byte) startPositions[k].x, (byte) startPositions[k].y, (byte) startPositions[k].z, (byte) k, 0, 0, 0, (byte)players[k].characterID}); + else { + try { + players[j].output.write(new byte[]{1, 0, (byte) startPositions[k].x, (byte) startPositions[k].y, (byte) startPositions[k].z, (byte) k, 0, 0, 0, (byte) players[k].characterID}); byte[] name = players[k].name.substring(0, 8).getBytes(StandardCharsets.US_ASCII); byte[] send = new byte[10]; send[0] = 5; send[1] = (byte) k; - for (int i = 2; i < send.length; i++) - { + for (int i = 2; i < send.length; i++) { send[i] = name[i - 2]; } players[j].output.write(send); - } catch (IOException e) - { + } catch (IOException e) { server.deleteRoom(roomCode); } } @@ -358,14 +324,11 @@ public class Room //1 x, x = idx //send the inital activation message - try - { - for (Client c : players) - { + try { + for (Client c : players) { c.output.write(new byte[]{2, 0, 0, 0, 0, 0, 0, 0, 0, 0}); } - } catch (IOException e) - { + } catch (IOException e) { server.deleteRoom(roomCode); } } @@ -374,69 +337,53 @@ public class Room /** * Closes the room */ - public void closeRoom() - { + public void closeRoom() { //try to cick all the players (still connected) of the room - try - { - - if (players[0] != null) - { + try { + + if (players[0] != null) { //127 is the action for room cick players[0].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); players[0].close(); } - } catch (Exception ex) - { + } catch (Exception ex) { } - try - { - if (players[1] != null) - { + try { + if (players[1] != null) { players[1].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); players[1].close(); } - } catch (Exception ex) - { + } catch (Exception ex) { } - try - { - if (players[2] != null) - { + try { + if (players[2] != null) { players[2].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); players[2].close(); } - } catch (Exception ex) - { + } catch (Exception ex) { } - try - { - if (players[3] != null) - { + try { + if (players[3] != null) { players[3].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); players[3].close(); } - } catch (Exception ex) - { + } catch (Exception ex) { } //try to close all open threads (not crashed yet) - for (int i = 0; i < threads.size(); i++) - { - try - { + for (int i = 0; i < threads.size(); i++) { + try { threads.get(i).interrupt(); System.out.println("thread " + threads.get(i).getName() + " stopped!"); - } catch (Exception e) - { + } catch (Exception e) { } }