private void request_player_info() { //message 생성 StringBuilder sb = new StringBuilder(); sb.Append("GOMIN"); sb.Append(Global.Major_User); sb.Append(Global.User_Record); sb.Append(Global.padding); sb.Append(Socket_script.user_idx); //send if (Socket_script.send_message(sb)) { Debug.Log("Send Success"); } else { Debug.Log("Send Fail"); } //receive string return_message = Socket_script.receive_message(); string[] param = return_message.Split(' '); try { Player_Info.text = Socket_script.user_id + "\n" + param[0] + "승 | " + param[1] + "패 (" + (Int32.Parse(param[0]) / (Int32.Parse(param[0]) + Int32.Parse(param[1]))) + "%)"; }catch { Player_Info.text = Socket_script.user_id + "\n0승 | 0패 (0) "; } }
public void reload_list() { //message 생성 StringBuilder sb = new StringBuilder(); sb.Append("GOMIN"); sb.Append(Global.Major_Room); sb.Append(Global.Room_List); sb.Append(Global.padding); //send if (Socket_script.send_message(sb)) { Debug.Log("Send Success"); } else { Debug.Log("Send Fail"); } //receive string return_message = Socket_script.receive_message(); Room_List.Clear(); //list count int list_count = Int32.Parse(return_message); Debug.Log("list_count : " + list_count); //add room to list for (int i = 0; i < list_count; i++) { Room_Info room_info = new Room_Info(); return_message = Socket_script.receive_message(); string[] param = return_message.Split(' '); room_info.Room_ID = Int32.Parse(param[0]); room_info.status = Int32.Parse(param[1]); room_info.Player_Num = "( " + param[2] + " / " + "4)"; room_info.Name = param[3]; room_info.OnButtonClick = new Button.ButtonClickedEvent(); room_info.OnButtonClick.AddListener(() => enter_room(room_info.Room_ID)); Room_List.Add(room_info); } Socket_script.receive_message(); this.Binding(); Debug.Log("click"); }
public void create_id() { get_id_password(); Debug.Log("id = " + id); Debug.Log("password = "******"GOMIN"); sb.Append(Global.Major_User); sb.Append(Global.User_Signup); sb.Append(Global.padding); sb.Append(id); sb.Append(Global.delim); sb.Append(password); //send if (Socket_script.send_message(sb)) { Debug.Log("Send Success"); } else { Debug.Log("Send Fail"); } //receive string return_message = Socket_script.receive_message(); Debug.Log(return_message); if (return_message == Global.Fail)//중복 ID 존재 { popup_name = "Error"; popup_text = "중복된 아이디가 있습니다."; } else//ID 생성 성공 { popup_name = "Success"; popup_text = "아이디가 생성되었습니다."; } showPopUp = true; }
public void Login() { get_id_password(); Debug.Log("id = " + id); Debug.Log("password = "******"GOMIN"); sb.Append(Global.Major_User); sb.Append(Global.User_Login); sb.Append(Global.padding); sb.Append(id); sb.Append(Global.delim); sb.Append(password); //send if (Socket_script.send_message(sb)) { Debug.Log("Send Success"); } else { Debug.Log("Send Fail"); } //receive string return_message = Socket_script.receive_message(); if (return_message == Global.Fail) { popup_name = "Error"; popup_text = "아이디와 비밀번호를 확인해주세요."; showPopUp = true; } else { user_idx = Int32.Parse(return_message); Socket_script.user_idx = user_idx; Socket_script.user_id = id; SceneManager.LoadScene("list_scene"); } }
private void enter_room(int room_id) { //message 생성 StringBuilder sb = new StringBuilder(); sb.Append("GOMIN"); sb.Append(Global.Major_Room); sb.Append(Global.Room_Enter); sb.Append(Global.padding); sb.Append(room_id); sb.Append(Global.delim); sb.Append(Socket_script.user_idx); //send if (Socket_script.send_message(sb)) { Debug.Log("Send Success"); } else { Debug.Log("Send Fail"); } //receive string return_message = Socket_script.receive_message(); if (return_message != Global.Fail) { Global.room_maker = false; Global.room_number = room_id; SceneManager.LoadScene("room_scene"); } else { Debug.Log(return_message); Debug.Log("게임 입장이 실패했습니다."); } }
private void create_game_process() { //message 생성 StringBuilder sb = new StringBuilder(); sb.Append("GOMIN"); sb.Append(Global.Major_Room); sb.Append(Global.Room_Create); sb.Append(Global.padding); sb.Append(Socket_script.user_idx); sb.Append(Global.delim); sb.Append(game_name); //send if (Socket_script.send_message(sb)) { Debug.Log("Send Success"); } else { Debug.Log("Send Fail"); } //receive string return_message = Socket_script.receive_message(); if (return_message != Global.Fail) { Global.room_maker = true; Global.room_number = Int32.Parse(return_message); SceneManager.LoadScene("room_scene"); } else { Debug.Log("게임 생성이 실패했습니다."); } }
private void play_game() { while (end_init == false) { } while (true) { Debug.Log("while--"); string return_message = Socket_script.receive_message(); if (Socket_script.message_type == Global.Room_Alert_Enter) { Debug.Log("Room_Alert_Enter"); string[] parse = return_message.Split(Global.delim); int player_num = Int32.Parse(parse[0]); Debug.Log("Player Num : " + player_num); for (int i = 0; i < player_num; i++) { player_info[i].id = parse[i + 1]; player_info[i].money = Global.Start_Money; player_info[i].is_empty = false; player_info[i].room_player_id = i + 1; player_info[i].position = 0; if (Int32.Parse(parse[i + 1]) == Socket_script.user_idx) { this.room_player_id = i + 1; } } set_log_ready("새로운 플레이어가 접속했습니다."); } else if (Socket_script.message_type == Global.Room_Start) { set_log_ready("게임이 시작됩니다."); while (true) { while (main_thread_log_finish == false) { } return_message = Socket_script.receive_message(); if (Socket_script.message_type == Global.Game_Turn) { Debug.Log("Game Turn"); lock (lock_obj) { if (this.room_player_id == Int32.Parse(return_message)) { my_turn = true; showMyTurn = true; } else { my_turn = false; } } lock (lock_string) { //set_log_ready(("플레이어" + return_message.ToString() + "이(가)순서입니다.")); string tmp = Int32.Parse(return_message).ToString(); //set_log_ready("플레이어" + return_message.ToString() + "이(가)순서입니다."); set_log_ready("플레이어 " + tmp + "의 순서입니다."); } } else if (Socket_script.message_type == Global.Game_DiceRoll) { string[] token = return_message.Split(Global.delim); int turn = Int32.Parse(token[0]); int dice = Int32.Parse(token[1]); if (turn != 0) { } else { //showIsolation = true; } } else if (Socket_script.message_type == Global.Game_Move) { Debug.Log("Game Move"); string[] token = return_message.Split(Global.delim); int turn = Int32.Parse(token[0]); int dice = Int32.Parse(token[1]); main_thread_turn = turn; main_thread_dice = dice; set_log_ready("플레이어 " + main_thread_turn.ToString() + "이(가) 이동했습니다."); main_thread_check = true; } else if (Socket_script.message_type == Global.Game_Buy) { Debug.Log("buy restaurant"); string turn = main_thread_turn.ToString(); string restaurant = board_arr[player_info[main_thread_turn - 1].position].name; set_log_ready("플레이어 " + turn + " 이(가) " + restaurant + "를 구매했습니다."); main_thread_buy = true; } else if (Socket_script.message_type == Global.Game_Pay) { Debug.Log("Game_Pay"); string[] token = return_message.Split(Global.delim); Debug.Log(return_message); int chk = Int32.Parse(token[0]); int pay = Int32.Parse(token[1]); int recv = Int32.Parse(token[2]); int money = Int32.Parse(token[3]); if (chk == 1) { if (pay == 0 && recv != 0) { player_info[recv - 1].money += money; } else if (pay != 0 && recv == 0) { player_info[pay - 1].money -= money; } else { player_info[recv - 1].money += money; player_info[pay - 1].money -= money; } main_thread_change_player_info = true; main_thread_pay_user = pay; main_thread_recv_user = recv; main_thread_money = money; showPay = true; } } else if (Socket_script.message_type == Global.Game_GoldKey) { Debug.Log("Golden Key"); GoldKey_message = Global.Golden_Key[Int32.Parse(return_message)]; Debug.Log("GoldKey message : " + GoldKey_message); showGoldKey = true; } else if (Socket_script.message_type == Global.Game_BuyCheck) { Debug.Log("Buy Check"); target_board = board_arr[player_info[main_thread_turn - 1].position]; showBuyCheck = true; } else if (Socket_script.message_type == Global.Game_Isolation) { Debug.Log("Isolation"); showIsolation = true; } else if (Socket_script.message_type == Global.Game_Salay) { Debug.Log("Salay"); int turn = Int32.Parse(return_message); player_info[turn - 1].money += Global.Game_Salay; main_thread_change_player_info = true; } } } } }