private void receiveFromServerThread() { while (true) { string data = tcpModel.receiveData(); string[] value = data.Split(' '); switch(value[0]) { case "room": int rommId = int.Parse(value[1]); int userOffsetInRoom = int.Parse(value[2]); using (GameForm gameForm = new GameForm(tcpModel, rommId, userOffsetInRoom)) { this.Hide(); gameForm.ShowDialog(); //gameForm.Close(); //this.Show(); this.Close(); } break; case "user": tcpModel.setID(int.Parse(value[1])); tcpModel.sendData("join "); break; default: break; } } }
//----------------------------------------------------------------- private void receiveDataThread() { try { while (true) { string data = tcpModel.receiveData(); if (data == "Error") { this.Close(); } string[] value = data.Split(' '); int cid; switch (value[0]) { case "start": soundReceiveCard.Play(); btnPlay.Hide(); lblWiner.Location = new Point(-40, -40); isPlaying = true; initPictureBox(data); rule = new Rules(); int id = int.Parse(value[value.Length - 1]); if (id == userOffsetInRoom) { StartOrStopSunAnimation(true, sunPosition[0]); btnFight.Enabled = true; } startTimerCountDown(id); break; case "next": soundFighting.Play(); enemyCards = data; miss = int.Parse(value[1]); cid = int.Parse(value[2]); resetTimerOrWin(cid); showRecentFightCard(data); btnIgnore.Enabled = true; rule.setmyCard(getStringCards()); rule.setEnemyCard(data); if (rule.check() || miss == 3) { btnFight.Enabled = true; if (miss == 3) { btnIgnore.Enabled = false; } StartOrStopSunAnimation(true, sunPosition[0]); } else { StartOrStopSunAnimation(true, sunPosition[1]); } break; case "wait": soundFighting.Play(); cid = int.Parse(value[2]); resetTimerOrWin(cid); showRecentFightCard(data); btnFight.Enabled = false; btnIgnore.Enabled = false; break; case "end": btnPlay.Show(); isPlaying = false; cleanCardsImage(); break; case "chat": string msg = data.Substring(7); cid = int.Parse($"{UserAvatarNameById[userOffsetInRoom][int.Parse(value[1])]}"); Controls.Find($"lblChat{cid}", false).First().Text = $"{msg}\n"; //txtChatBox.Text += $"{msg}\n"; break; case "roomate": setNewRoomate(data.Substring(8)); break; case "roomates": setNewRoomates(data.Substring(9)); break; case "quitroom": cid = int.Parse($"{UserAvatarNameById[userOffsetInRoom][int.Parse($"{data[9]}")]}"); deleteRoomate(cid); break; default: break; } } }catch { this.Close(); } }