public void StartGame() { Connect con = new Connect(); MenuAfterLogin cojg = new MenuAfterLogin(); Game game = new Game(); CreateRoom createRoom = new CreateRoom(); JoinRoom joinRoom = new JoinRoom(); Ranking ranking = new Ranking(); ConnectController controller = new ConnectController(con, cojg, createRoom, joinRoom, ranking, game); controller.LoadViewConnect(con); con.ShowDialog(); _view.Hide(); }
private void ReceiveMessages() { strReader = new StreamReader(tcpClient.GetStream()); string numCardsInSet = "0"; // While we are successfully connected, read incoming lines from the server while (isConnectedToServer) { string serverResponse = strReader.ReadLine(); string[] data = serverResponse.Split(';'); if (data[0].Equals("AVALIABLE_NICK")) { // Console.WriteLine("Test = nick was avaliable. OK"); } if (data[0].Equals("LOGIN_FAILED")) { string message = data[1]; //ZMIENIC NA CONNECT _viewConnect.ShowInformation(message, "Login failed"); _viewConnect.Hide(); Connect con = new Connect(); con.Visible = false; MenuAfterLogin cojg = new MenuAfterLogin(); cojg.Visible = false; Game game = new Game(); game.Visible = false; CreateRoom createRoom = new CreateRoom(); createRoom.Visible = false; JoinRoom joinRoom = new JoinRoom(); joinRoom.Visible = false; Ranking ranking = new Ranking(); ranking.Visible = false; ConnectController controller = new ConnectController(con, cojg, createRoom, joinRoom, ranking, game); controller.LoadViewConnect(con); con.ShowDialog(); } if (data[0].Equals("WRONG_NICK")) { string message = data[1]; _viewGame.ShowInformation(message, "Wrong nick"); Connect con = new Connect(); MenuAfterLogin cojg = new MenuAfterLogin(); Game game = new Game(); CreateRoom createRoom = new CreateRoom(); JoinRoom joinRoom = new JoinRoom(); Ranking ranking = new Ranking(); ConnectController controller = new ConnectController(con, cojg, createRoom, joinRoom, ranking, game); controller.LoadViewConnect(con); con.ShowDialog(); _viewConnect.Hide(); Console.WriteLine("od nowa"); _viewGame.ShowInformation(message, "Wrong nick"); _viewConnect.SetClientMessage("[Log]:" + message); } if (data[0].Equals("INCOMING_MSG")) { string source = data[1]; string message = data[2]; _viewGame.SetClientMessage(source + ": " + message); } if (data[0].Equals("INCOMING_NUM_OF_PLAYERS")) { string message = data[1]; } if (data[0].Equals("INCOMING_SYMBOLS_NAMES")) { string message = data[1]; cards.PathToImages = message; } if (data[0].Equals("ROOM_FOUND")) { string message = data[1]; _viewGame.ShowInformation(message, "Room found"); _viewGame.SetClientMessage("[Log]:" + message); } if (data[0].Equals("ROOM_NOT_FOUND")) { string message = data[1]; _viewGame.ShowInformation(message, "Room not found"); } if (data[0].Equals("ROOM_FULL")) { string message = data[1]; _viewGame.ShowInformation(message, "Room full"); } if (data[0].Equals("START_GAME")) { string message = data[1]; _viewGame.ShowInformation(message, "Start game!"); _viewGame.SetClientMessage("[Log]:" + message); } if (data[0].Equals("WAITING")) { string message = data[1]; _viewGame.ShowInformation(message, "Waiting..."); _viewGame.SetClientMessage("[Log]:" + message); } if (data[0].Equals("MAIN_CARD")) { if (data.Length == 9) { mainCard8(data); } if (data.Length == 7) { mainCard6(data); } } if (data[0].Equals("PLAYER_CARD")) { if (data.Length == 9) { symbols8(data); } if (data.Length == 7) { symbols6(data); } } if (data[0].Equals("NUM_CARDS_IN_SET")) { string message = data[1]; numCardsInSet = message; } if (data[0].Equals("NUM_CURRENT_CARD")) { string message = data[1]; string text = message + "/" + numCardsInSet; _viewGame.NumCurrentCard(text); } if (data[0].Equals("LAST_NICK")) { string message = data[1]; _viewGame.LastNick(message); } if (data[0].Equals("BAN")) { string message = data[1]; _viewGame.ShowInformation(message, "Ban!"); _viewGame.SetClientMessage(message); _viewGame.Ban(); } if (data[0].Equals("UNBAN")) { string message = data[1]; _viewGame.ShowInformation(message, "Unban"); _viewGame.SetClientMessage(message); _viewGame.Unban(); } if (data[0].Equals("WIN")) { string message = data[1]; _viewGame.ShowInformation(message, "Win!"); _viewGame.SetClientMessage(message); _viewGame.Win(); } if (data[0].Equals("ROOM_LIST")) { string message = data[1] + data[2]; _viewJoinRoom.RoomList(message); } if (data[0].Equals("STATUS_CLEAR")) { string nick = "Nick"; string status = "Status"; int a = 150; int b = 56; _viewGame.StatusClear(nick, status, a, b); } if (data[0].Equals("ROOM_CLEAR")) { _viewJoinRoom.Clear(); } if (data[0].Equals("STATUS_PLAYERS")) { string col1 = data[1]; string col2 = data[2] + "/" + data[3]; _viewGame.StatusPlayers(col1, col2); } if (data[0].Equals("RANKING_ROW")) { string col1 = data[1]; string col2 = data[2]; string col3 = data[3]; _viewRanking.AddRowRanking(col1, col2, col3); } if (data[0].Equals("RANKING_ROW_LOWER")) { string col1 = data[1]; string col2 = data[2]; string col3 = data[3]; _viewRanking.AddRowRankingLower(col1, col2, col3); } _viewGame.AutoscrollingList(); } }
public void AddNewAccount(string serveripTextbox, string portTextbox, string userNameTextbox, string passwordTextbox, string emailTextbox, string yearComboBox, string genderComboBox, string captchaTextbox) { string connectionEstablish; connectionEstablish = "CREATE_ACCOUNT;" + userNameTextbox + ";" + passwordTextbox + ";" + emailTextbox + ";" + yearComboBox + ";" + genderComboBox; tcpClient = new TcpClient(); tcpClient.Connect(serveripTextbox, int.Parse(portTextbox)); isConnectedToServer = true; strWritter = new StreamWriter(tcpClient.GetStream()); strWritter.WriteLine(connectionEstablish); strWritter.Flush(); Console.WriteLine("nowy Connection"); incomingMessageHandler = new Thread(() => ReceiveMessages()); incomingMessageHandler.IsBackground = true; incomingMessageHandler.Start(); int interval = 3000; while (!ACCOUNT_CREATED_SUCCESFULLY) { Console.WriteLine("spie 3 sek: "); Thread.Sleep(interval); if (ACCOUNT_CREATED_SUCCESFULLY == true) { Console.WriteLine("JEST JUZ OK, ZAMYKAMY!"); SaveSettings(); ConnectController c = new ConnectController(); Connect con = new Connect(); MenuAfterLogin cojg = new MenuAfterLogin(); Game game = new Game(); CreateRoom createRoom = new CreateRoom(); JoinRoom joinRoom = new JoinRoom(); Ranking ranking = new Ranking(); ConnectController controller = new ConnectController(con, cojg, createRoom, joinRoom, ranking, game); controller.LoadViewConnect(con); con.ShowDialog(); _view.Hide(); _view.Close(); _view.DisposeForm(); Console.WriteLine(ACCOUNT_CREATED_SUCCESFULLY + "jest just tru!!"); } Console.WriteLine("ja zyje"); } }