[ADDED] lobby now secured when the game starts. start button is still for everyone available, not working yet

This commit is contained in:
Lars
2020-10-22 15:40:09 +02:00
parent 8190724f77
commit cac0fdc0a4
10 changed files with 467 additions and 363 deletions

View File

@@ -11,7 +11,10 @@ using System.Collections.ObjectModel;
using Client.Views;
using System.Linq;
using System.Windows.Data;
using System.Data;
using System.Windows.Controls.Primitives;
using System.Windows.Controls;
namespace Client
{
class ViewModel : INotifyPropertyChanged
@@ -79,8 +82,16 @@ namespace Client
{
// lobby die je wilt joinen verwijderen
// nieuwe binnengekregen lobby toevoegen
client.OnLobbyJoinSuccess = OnLobbyJoinSuccess;
client.SendMessage(JSONConvert.ConstructLobbyJoinMessage(SelectedLobby.ID));
if (SelectedLobby != null)
{
if (SelectedLobby.PlayersIn == SelectedLobby.MaxPlayers || !SelectedLobby.LobbyJoineble)
{
return;
}
client.OnLobbyJoinSuccess = OnLobbyJoinSuccess;
client.SendMessage(JSONConvert.ConstructLobbyJoinMessage(SelectedLobby.ID));
}
}
private void OnLobbyJoinSuccess()
@@ -168,5 +179,7 @@ namespace Client
get { return _lobbies; }
set { _lobbies = value; }
}
}
}

View File

@@ -13,21 +13,15 @@ namespace Client.ViewModels
{
class ViewModelGame : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private ClientData data = ClientData.Instance;
private GameWindow window;
public event PropertyChangedEventHandler PropertyChanged;
private Point currentPoint = new Point();
private Color color;
public ObservableCollection<string> Messages { get; } = new ObservableCollection<string>();
private dynamic _payload;
private string _username;
private string _message;
public string Message
{
get
@@ -39,7 +33,43 @@ namespace Client.ViewModels
_message = value;
}
}
public User User
{
get { return data.User; }
set
{
data.User = value;
}
}
public ViewModelGame(GameWindow window)
{
this.window = window;
if (_payload == null)
{
_message = "";
}
else
{
//_message = data.Message;
//_username = data.User.Username;
//Messages.Add($"{data.User.Username}: {Message}");
}
OnKeyDown = new RelayCommand(ChatBox_KeyDown);
ButtonStartGame = new RelayCommand(BeginGame);
data.Client.CanvasDataReceived = UpdateCanvasWithNewData;
}
public ObservableCollection<string> Messages { get; } = new ObservableCollection<string>();
public ICommand OnKeyDown { get; set; }
public ICommand ButtonStartGame { get; set; }
public void BeginGame()
{
data.Client.SendMessage(JSONConvert.ConstructGameStartData(data.Lobby.ID));
}
public void Canvas_MouseDown(MouseButtonEventArgs e, GameWindow window)
{
@@ -82,26 +112,6 @@ namespace Client.ViewModels
colorSelected.B = window.ClrPcker_Background.SelectedColor.Value.B;
color = colorSelected;
}
public ViewModelGame(GameWindow window)
{
this.window = window;
if (_payload == null)
{
_message = "";
}
else
{
//_message = data.Message;
//_username = data.User.Username;
//Messages.Add($"{data.User.Username}: {Message}");
}
OnKeyDown = new RelayCommand(ChatBox_KeyDown);
data.Client.CanvasDataReceived = UpdateCanvasWithNewData;
}
private void UpdateCanvasWithNewData(double[] coordinates)
{