[ADD] added joining lobbies
This commit is contained in:
@@ -21,6 +21,7 @@ namespace Client
|
||||
private string username;
|
||||
public Callback OnSuccessfullConnect;
|
||||
public Callback OnLobbiesListReceived;
|
||||
public Callback OnLobbyJoinSuccess;
|
||||
public OnLobbyCreated OnLobbyCreated;
|
||||
public Lobby[] Lobbies { get; set; }
|
||||
|
||||
@@ -107,7 +108,9 @@ namespace Client
|
||||
Debug.WriteLine("[CLIENT] got lobby object");
|
||||
Lobby lobby = JSONConvert.GetLobby(payload);
|
||||
OnLobbyCreated?.Invoke(lobby.ID,lobby.PlayersIn,lobby.MaxPlayers);
|
||||
|
||||
break;
|
||||
case LobbyIdentifier.JOIN_SUCCESS:
|
||||
OnLobbyJoinSuccess?.Invoke();
|
||||
break;
|
||||
}
|
||||
//TODO fill lobby with the data received
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Client
|
||||
|
||||
OnHostButtonClick = new RelayCommand(hostGame);
|
||||
|
||||
JoinSelectedLobby = new RelayCommand(startGameInLobby, true);
|
||||
JoinSelectedLobby = new RelayCommand(joinLobby, true);
|
||||
}
|
||||
|
||||
private void hostGame()
|
||||
@@ -57,6 +57,17 @@ namespace Client
|
||||
});
|
||||
}
|
||||
|
||||
private void joinLobby()
|
||||
{
|
||||
client.OnLobbyJoinSuccess = OnLobbyJoinSuccess;
|
||||
client.SendMessage(JSONConvert.ConstructLobbyJoinMessage(SelectedLobby.ID));
|
||||
}
|
||||
|
||||
private void OnLobbyJoinSuccess()
|
||||
{
|
||||
startGameInLobby();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void updateLobbies()
|
||||
@@ -85,8 +96,11 @@ namespace Client
|
||||
private void startGameWindow()
|
||||
{
|
||||
_model.CanStartGame = false;
|
||||
GameWindow window = new GameWindow();
|
||||
window.Show();
|
||||
Application.Current.Dispatcher.Invoke(delegate
|
||||
{
|
||||
GameWindow window = new GameWindow();
|
||||
window.Show();
|
||||
});
|
||||
}
|
||||
|
||||
private void ClickCheck()
|
||||
|
||||
@@ -113,5 +113,10 @@ namespace Client.Views
|
||||
string user = data.User.Username;
|
||||
SentMessage.AppendText($"{user}: {message}\n");
|
||||
}
|
||||
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,18 +33,7 @@ namespace Client
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
Lobby lobbySelected = LobbyList.SelectedItem as Lobby;
|
||||
if(lobbySelected != null)
|
||||
{
|
||||
testLabel.Content = lobbySelected.ID;
|
||||
colorSelection.IsEnabled = false;
|
||||
joinButton.IsEnabled = false;
|
||||
hostButton.IsEnabled = false;
|
||||
|
||||
GameWindow window = new GameWindow();
|
||||
window.Show();
|
||||
Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user