//ROOMINTERFACE public async void listenToReplies() { bool exists = true; string responseCode; do /*while (exists)*/ { responseCode = await Task.Factory.StartNew(() => _client.myReceive(3)); switch (responseCode) { case "108": lblStatus.Content = "recieved user list."; readUserList(); break; case "116": lblStatus.Content = "Room Closed By Admin"; Close(); exists = false; break; case "117": //game begun string code = await Task.Factory.StartNew(() => _client.myReceive(1)); if (code == "0") //success { Hide(); Game s = new Game(_client, _timePerQuestion, _numberOfQuestions); s.listenToReplies(); s.ShowDialog(); //after game ends, returns to main menu instead of roomInterface exists = false; Close(); } else if (code == "1") { lblStatus.Content = "game creation failed because you are not admin"; } else if (code == "2") { lblStatus.Content = "game creation failed because server doesn't have enough questions"; } break; case "112": exists = false; Close(); break; default: lblStatus.Content = "Error - wrong code detected"; break; } } while (exists); }
//this is after recieved the 126 code private void requestGetStatus() { gameNo = Int32.Parse(_client.myReceive(4)); if (gameNo != 0) { correctAnsNo = Int32.Parse(_client.myReceive(6)); wrongAnsNo = Int32.Parse(_client.myReceive(6)); avgTime = Int32.Parse(_client.myReceive(2)); avgTime += Double.Parse(_client.myReceive(2)) / 100; } }
private void requestGetBestScores() { int nameSize = 0; string username = ""; for (int i = 0; i < 3; i++) { nameSize = Int32.Parse(_client.myReceive(2)); username = _client.myReceive(nameSize); _users.Add(username); _scores.Add(Int32.Parse(_client.myReceive(6))); } }
//MAINMENU public void listenToReplies() { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(async() => { string responseCode; do /*while (exists)*/ { responseCode = await Task.Factory.StartNew(() => _client.myReceive(3)); //responseCode = _client.myReceive(3); switch (responseCode) { case "106": handleRoomList(); break; case "114": //list handleCreateRoomReply(); break; case "110": handleJoinRoomReply(); break; case "124": Hide(); bestScores bestScoresWindow = new bestScores(_client); bestScoresWindow.ShowDialog(); lblStatus.Content = "success"; Show(); break; case "126": Hide(); status statusWindow = new status(_client); statusWindow.ShowDialog(); lblStatus.Content = "success"; Show(); break; case "103": Close(); _exists = false; break; default: lblStatus.Content = "Error - wrong code detected"; break; } } while (_exists); })); //end of beginInvoke. }
private string requestSignIn() { _client.mySend("200" + this.txtUsername.Text.Length.ToString().PadLeft(2, '0') + this.txtUsername.Text + this.passBox.Password.Length.ToString().PadLeft(2, '0') + this.passBox.Password); return(_client.myReceive(4)); }
//We might want to use a Password Box //203##username##password##email private string requestSignUp() { _client.mySend("203" + _username.Length.ToString().PadLeft(2, '0') + _username + _password.Length.ToString().PadLeft(2, '0') + _password + _email.Length.ToString().PadLeft(2, '0') + _email); return(_client.myReceive(4)); }
public async void listenToReplies() { //Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(async () => //{ string responseCode; while (_exists) { responseCode = await Task.Factory.StartNew(() => _client.myReceive(3)); //responseCode = _client.myReceive(3); switch (responseCode) { case "120": _currentQuestionIndex++; bool correctAnswer = (await Task.Factory.StartNew(() => _client.myReceive(1))) == "1"; if (correctAnswer) { _correctAnswerIndex++; } lblScore.Content = _correctAnswerIndex.ToString() + "/" + _currentQuestionIndex.ToString(); //updates GUI to show status.w break; case "118": //TODO use a loop for this mess handleAnswers(); break; case "121": _userNo = Int32.Parse(_client.myReceive(1)); string nameSize = ""; string userName = ""; for (int i = 0; i < _userNo; i++) { nameSize = _client.myReceive(2); userName = _client.myReceive(Int32.Parse(nameSize)); _userList.Add(userName); _scores.Add(Int32.Parse(_client.myReceive(2))); } lblStatus.Content = "Game Ended"; //display scores string msg = ""; for (int i = 0; i < _userNo; i++) { msg += _userList[i]; msg += " : "; msg += _scores[i].ToString(); msg += "\n"; } MessageBox.Show(msg, "Scores"); Close(); _exists = false; break; case "122": //leave game response _exists = false; Close(); break; default: lblStatus.Content = "Error - wrong code detected"; break; } } //})); //end of beginInvoke. }