[ADD] added joining lobbies

This commit is contained in:
Sem van der Hoeven
2020-10-20 22:49:25 +02:00
parent 7b30911cd7
commit 76cd392525
7 changed files with 72 additions and 32 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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)
{
}
}
}

View File

@@ -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();
}
}
}
}