From 5e2dbfc2ce3cc2167f60a49eda8e75da79f4d786 Mon Sep 17 00:00:00 2001 From: kyechan99 Date: Mon, 24 Jul 2017 18:03:52 +0900 Subject: [PATCH] :bookmark: 1.2.1 --- Script/Server.cs | 2 +- Script/User/User.cs | 108 +++++++++++++++++++++++++++----------------- 2 files changed, 67 insertions(+), 43 deletions(-) diff --git a/Script/Server.cs b/Script/Server.cs index aaab92a..64d84ab 100644 --- a/Script/Server.cs +++ b/Script/Server.cs @@ -15,7 +15,7 @@ class Server public static List v_user = new List(); public static int userIdx = 0; public static ManualResetEvent allDone = new ManualResetEvent(false); - public static string version = "1.2.0"; + public static string version = "1.2.1"; /** * @brief 초기화 diff --git a/Script/User/User.cs b/Script/User/User.cs index 4d4dc9d..ee2becd 100644 --- a/Script/User/User.cs +++ b/Script/User/User.cs @@ -416,57 +416,81 @@ static void StartGame() if (Server.v_user[i] != null) memCount++; - int police = memCount / 3; - int thief = memCount - police; + PROPER[] proArr = new PROPER[memCount]; + for (int i = 0; i < memCount / 3; i++) + proArr[i] = PROPER.POLICE; + for (int i = 0; i < memCount - (memCount / 3); i++) + proArr[(memCount / 3) + i] = PROPER.THIEF; + + int mIdx = 0; for (int i = 0; i < Server.v_user.Count; i++) { - int colorT = Server.rand.Next(0, 9); - if (Server.v_user[i] != null) { - if (thief.Equals(0)) - { - police--; - Server.v_user[i].proper = PROPER.POLICE; - - for (int j = 0; j < Server.v_user.Count; j++) - if (Server.v_user[j] != null) - Server.v_user[j].SendMsg(string.Format("PROPER:{0}:{1}:{2}", Server.v_user[i].myIdx, (int)PROPER.POLICE, (int)colorT)); - } - else if (police > 0) - { - if (Server.rand.Next(0, 2) == 0) - { - police--; - Server.v_user[i].proper = PROPER.POLICE; - - for (int j = 0; j < Server.v_user.Count; j++) - if (Server.v_user[j] != null) - Server.v_user[j].SendMsg(string.Format("PROPER:{0}:{1}:{2}", Server.v_user[i].myIdx, (int)PROPER.POLICE, (int)colorT)); - } - else - { - thief--; - Server.v_user[i].proper = PROPER.THIEF; - - for (int j = 0; j < Server.v_user.Count; j++) - if (Server.v_user[j] != null) - Server.v_user[j].SendMsg(string.Format("PROPER:{0}:{1}:{2}", Server.v_user[i].myIdx, (int)PROPER.THIEF, (int)colorT)); - } - } - else - { - thief--; - Server.v_user[i].proper = PROPER.THIEF; + int colorT = Server.rand.Next(0, 9); + int pIdx = Server.rand.Next(0, memCount - (mIdx++)); + for (int j = 0; j < Server.v_user.Count; j++) + if (Server.v_user[j] != null) + Server.v_user[j].SendMsg(string.Format("PROPER:{0}:{1}:{2}", Server.v_user[i].myIdx, (int)proArr[pIdx], (int)colorT)); - for (int j = 0; j < Server.v_user.Count; j++) - if (Server.v_user[j] != null) - Server.v_user[j].SendMsg(string.Format("PROPER:{0}:{1}:{2}", Server.v_user[i].myIdx, (int)PROPER.THIEF, (int)colorT)); - } + PROPER tp = proArr[memCount - mIdx]; + proArr[memCount - mIdx] = proArr[pIdx]; + proArr[pIdx] = tp; } } + //int police = memCount / 3; + //int thief = memCount - police; + + //for (int i = 0; i < Server.v_user.Count; i++) + //{ + // int colorT = Server.rand.Next(0, 9); + + // if (Server.v_user[i] != null) + // { + // if (thief.Equals(0)) + // { + // police--; + // Server.v_user[i].proper = PROPER.POLICE; + + // for (int j = 0; j < Server.v_user.Count; j++) + // if (Server.v_user[j] != null) + // Server.v_user[j].SendMsg(string.Format("PROPER:{0}:{1}:{2}", Server.v_user[i].myIdx, (int)PROPER.POLICE, (int)colorT)); + // } + // else if (police > 0) + // { + // if (Server.rand.Next(0, 2) == 0) + // { + // police--; + // Server.v_user[i].proper = PROPER.POLICE; + + // for (int j = 0; j < Server.v_user.Count; j++) + // if (Server.v_user[j] != null) + // Server.v_user[j].SendMsg(string.Format("PROPER:{0}:{1}:{2}", Server.v_user[i].myIdx, (int)PROPER.POLICE, (int)colorT)); + // } + // else + // { + // thief--; + // Server.v_user[i].proper = PROPER.THIEF; + + // for (int j = 0; j < Server.v_user.Count; j++) + // if (Server.v_user[j] != null) + // Server.v_user[j].SendMsg(string.Format("PROPER:{0}:{1}:{2}", Server.v_user[i].myIdx, (int)PROPER.THIEF, (int)colorT)); + // } + // } + // else + // { + // thief--; + // Server.v_user[i].proper = PROPER.THIEF; + + // for (int j = 0; j < Server.v_user.Count; j++) + // if (Server.v_user[j] != null) + // Server.v_user[j].SendMsg(string.Format("PROPER:{0}:{1}:{2}", Server.v_user[i].myIdx, (int)PROPER.THIEF, (int)colorT)); + // } + // } + //} + tmr.Start(); }