Merge branch 'master' into setupBranch
This commit is contained in:
@@ -20,6 +20,7 @@ namespace Client
|
||||
public delegate void CanvasDataReceived(double[][] coordinates, Color color);
|
||||
public delegate void CanvasReset();
|
||||
public delegate void LobbyCallback(int id);
|
||||
|
||||
|
||||
class Client : ObservableObject
|
||||
{
|
||||
@@ -48,6 +49,7 @@ namespace Client
|
||||
private ClientData data = ClientData.Instance;
|
||||
public CanvasDataReceived CanvasDataReceived;
|
||||
public CanvasReset CReset;
|
||||
public HandleIncomingPlayer UpdateUserScores;
|
||||
public Lobby[] Lobbies { get; set; }
|
||||
|
||||
public Client(string username)
|
||||
@@ -92,7 +94,6 @@ namespace Client
|
||||
throw new OutOfMemoryException("buffer too small");
|
||||
}
|
||||
|
||||
|
||||
Array.Copy(buffer, 0, totalBuffer, totalBufferReceived, amountReceived);
|
||||
totalBufferReceived += amountReceived;
|
||||
|
||||
@@ -190,7 +191,6 @@ namespace Client
|
||||
|
||||
case JSONConvert.CANVAS_WRITING:
|
||||
CanvasDataReceived?.Invoke(JSONConvert.getCoordinates(payload), JSONConvert.getCanvasDrawingColor(payload));
|
||||
// we hebben gedrawed, dus stuur dat we weer kunnen drawen
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -216,11 +216,16 @@ namespace Client
|
||||
|
||||
private void updateGameLobby()
|
||||
{
|
||||
Debug.WriteLine("[CLIENT] updating game lobby");
|
||||
foreach (var item in Lobbies)
|
||||
{
|
||||
Debug.WriteLine("[CLIENT] lobby data: {0}", item.Users.Count);
|
||||
if (item.ID == data.Lobby?.ID)
|
||||
IncomingPlayer?.Invoke(item);
|
||||
{
|
||||
//IncomingPlayer?.Invoke(item);
|
||||
UpdateUserScores?.Invoke(item as Lobby);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace Client
|
||||
|
||||
private void updateLobbies()
|
||||
{
|
||||
Debug.WriteLine("updating lobbies...");
|
||||
Debug.WriteLine("[VIEWMODEL] updating lobbies...");
|
||||
Lobby[] lobbiesArr = client.Lobbies;
|
||||
Application.Current.Dispatcher.Invoke(delegate
|
||||
{
|
||||
@@ -124,6 +124,11 @@ namespace Client
|
||||
foreach (Lobby l in lobbiesArr)
|
||||
{
|
||||
_lobbies.Add(l);
|
||||
Lobby clientLobby = ClientData.Instance.Lobby;
|
||||
if (l.ID == clientLobby?.ID)
|
||||
{
|
||||
clientLobby = l;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -48,19 +48,12 @@ namespace Client.ViewModels
|
||||
}
|
||||
|
||||
private string _randomWord;
|
||||
|
||||
public string RandomWord
|
||||
{
|
||||
get { return _randomWord; }
|
||||
set { _randomWord = value; }
|
||||
}
|
||||
|
||||
public static string Word
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public bool IsHost
|
||||
{
|
||||
get { return data.User.Host; }
|
||||
@@ -69,17 +62,6 @@ namespace Client.ViewModels
|
||||
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}");
|
||||
}
|
||||
|
||||
buffer = new double[maxLines][];
|
||||
linesQueue = new Queue<double[][]>();
|
||||
@@ -91,6 +73,7 @@ namespace Client.ViewModels
|
||||
data.Client.RandomWord = HandleRandomWord;
|
||||
data.Client.IncomingMsg = HandleIncomingMsg;
|
||||
data.Client.IncomingPlayer = HandleIncomingPlayer;
|
||||
data.Client.UpdateUserScores = UpdateUserScores;
|
||||
}
|
||||
|
||||
public ICommand OnKeyDown { get; set; }
|
||||
@@ -227,7 +210,7 @@ namespace Client.ViewModels
|
||||
data.Client.SendMessage(JSONConvert.GetMessageToSend(JSONConvert.MESSAGE, _payload));
|
||||
}
|
||||
|
||||
public static void HandleIncomingMsg(string username, string message)
|
||||
public void HandleIncomingMsg(string username, string message)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(delegate
|
||||
{
|
||||
@@ -240,12 +223,12 @@ namespace Client.ViewModels
|
||||
data.Client.SendMessage(JSONConvert.ConstructLobbyLeaveMessage(data.Lobby.ID));
|
||||
}
|
||||
|
||||
public static void HandleRandomWord(string randomWord)
|
||||
public void HandleRandomWord(string randomWord)
|
||||
{
|
||||
Debug.WriteLine("[CLIENT] Reached the handle random word method!");
|
||||
Application.Current.Dispatcher.Invoke(delegate
|
||||
{
|
||||
Word = randomWord;
|
||||
RandomWord = randomWord;
|
||||
});
|
||||
}
|
||||
public void HandleIncomingPlayer(Lobby lobby)
|
||||
@@ -255,9 +238,34 @@ namespace Client.ViewModels
|
||||
Players.Clear();
|
||||
foreach (var item in lobby.Users)
|
||||
{
|
||||
Players.Add(item.Username);
|
||||
Players.Add(item.Username + "\n" + item.Score);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void UpdateUserScores(Lobby newLobby) {
|
||||
Debug.WriteLine("[GAME] updating user scores");
|
||||
List<User> newUsers = newLobby.Users;
|
||||
// go over all users in current lobby
|
||||
foreach (User user in data.Lobby?.Users)
|
||||
{
|
||||
// check with all users in new lobby
|
||||
foreach (User newUser in newUsers)
|
||||
{
|
||||
// and update the score
|
||||
if (newUser.Username == user.Username)
|
||||
{
|
||||
Debug.WriteLine($"[GAME] setting score of {user.Username} to {newUser.Score}. it was {user.Score}");
|
||||
user.Score = newUser.Score;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update all the scores in the player list
|
||||
HandleIncomingPlayer(newLobby);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,10 +38,8 @@
|
||||
<xctk:ColorPicker Name="ClrPcker_Background" SelectedColorChanged="ClrPcker_Background_SelectedColorChanged_1" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Height="22" Width="100"/>
|
||||
|
||||
|
||||
<Label Name="GuessWord" Grid.Row="0" Grid.Column="1" Content="{Binding Path=RandomWord, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
||||
<Label Name="GuessWord" Grid.Row="0" Grid.Column="2" Content="{Binding Path=RandomWord, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20"/>
|
||||
|
||||
<Label Grid.Row="0" Grid.Column="2" FontSize="20" Content="" VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
||||
|
||||
<Button Name="CanvasReset" Click="CanvasReset_Click" Grid.Row="0" Grid.Column="3" Content="RESET"/>
|
||||
</Grid>
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<Label Grid.Row="2" FontSize="15" Content="(max amount of characters for the username is 10)"/>
|
||||
|
||||
<TextBox Name="usernameTextbox" Grid.Row="1" Grid.Column="1" MaxLength="69" FontSize="30" VerticalAlignment="Center" HorizontalAlignment="Left" Width="250"/>
|
||||
<Button Content="ENTER" Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Right" Width="100" Height="40" Click="Button_EnterUsername"/>
|
||||
<Button Name="LoginButton" Content="ENTER" Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Right" Width="100" Height="40" Click="Button_EnterUsername"/>
|
||||
|
||||
<Label Grid.Row="3" Grid.Column="0" Content="Tip of the century: base64 != UTF8!" FontSize="20" FontWeight="Bold"/>
|
||||
</Grid>
|
||||
|
||||
@@ -27,9 +27,12 @@ namespace Client.Views
|
||||
|
||||
private void Button_EnterUsername(object sender, RoutedEventArgs e)
|
||||
{
|
||||
User user = new User(usernameTextbox.Text);
|
||||
string name = usernameTextbox.Text;
|
||||
if (name == string.Empty) return;
|
||||
User user = new User(name);
|
||||
|
||||
Client client = new Client(user.Username);
|
||||
loginButton.IsEnabled = false;
|
||||
LoginButton.IsEnabled = false;
|
||||
client.OnSuccessfullConnect = () =>
|
||||
{
|
||||
// because we need to start the main window on a UI thread, we need to let the dispatcher handle it, which will execute the code on the ui thread
|
||||
|
||||
Reference in New Issue
Block a user