Compare commits
10 Commits
feature/pl
...
hotfix/fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7df48ab322 | ||
|
|
80d970da35 | ||
|
|
2c7bf3e217 | ||
|
|
92f57a87bc | ||
|
|
da5528c7b2 | ||
|
|
c16f7cf68f | ||
|
|
5c2dea3ab4 | ||
|
|
24eb43239b | ||
|
|
335d17838c | ||
|
|
242c435ac7 |
@@ -20,6 +20,7 @@ namespace Client
|
|||||||
public delegate void CanvasDataReceived(double[][] coordinates, Color color);
|
public delegate void CanvasDataReceived(double[][] coordinates, Color color);
|
||||||
public delegate void CanvasReset();
|
public delegate void CanvasReset();
|
||||||
public delegate void LobbyCallback(int id);
|
public delegate void LobbyCallback(int id);
|
||||||
|
|
||||||
|
|
||||||
class Client : ObservableObject
|
class Client : ObservableObject
|
||||||
{
|
{
|
||||||
@@ -48,6 +49,7 @@ namespace Client
|
|||||||
private ClientData data = ClientData.Instance;
|
private ClientData data = ClientData.Instance;
|
||||||
public CanvasDataReceived CanvasDataReceived;
|
public CanvasDataReceived CanvasDataReceived;
|
||||||
public CanvasReset CReset;
|
public CanvasReset CReset;
|
||||||
|
public HandleIncomingPlayer UpdateUserScores;
|
||||||
public Lobby[] Lobbies { get; set; }
|
public Lobby[] Lobbies { get; set; }
|
||||||
|
|
||||||
public Client(string username)
|
public Client(string username)
|
||||||
@@ -92,7 +94,6 @@ namespace Client
|
|||||||
throw new OutOfMemoryException("buffer too small");
|
throw new OutOfMemoryException("buffer too small");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Array.Copy(buffer, 0, totalBuffer, totalBufferReceived, amountReceived);
|
Array.Copy(buffer, 0, totalBuffer, totalBufferReceived, amountReceived);
|
||||||
totalBufferReceived += amountReceived;
|
totalBufferReceived += amountReceived;
|
||||||
|
|
||||||
@@ -190,7 +191,6 @@ namespace Client
|
|||||||
|
|
||||||
case JSONConvert.CANVAS_WRITING:
|
case JSONConvert.CANVAS_WRITING:
|
||||||
CanvasDataReceived?.Invoke(JSONConvert.getCoordinates(payload), JSONConvert.getCanvasDrawingColor(payload));
|
CanvasDataReceived?.Invoke(JSONConvert.getCoordinates(payload), JSONConvert.getCanvasDrawingColor(payload));
|
||||||
// we hebben gedrawed, dus stuur dat we weer kunnen drawen
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -216,11 +216,16 @@ namespace Client
|
|||||||
|
|
||||||
private void updateGameLobby()
|
private void updateGameLobby()
|
||||||
{
|
{
|
||||||
|
Debug.WriteLine("[CLIENT] updating game lobby");
|
||||||
foreach (var item in Lobbies)
|
foreach (var item in Lobbies)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("[CLIENT] lobby data: {0}", item.Users.Count);
|
Debug.WriteLine("[CLIENT] lobby data: {0}", item.Users.Count);
|
||||||
if (item.ID == data.Lobby?.ID)
|
if (item.ID == data.Lobby?.ID)
|
||||||
IncomingPlayer?.Invoke(item);
|
{
|
||||||
|
//IncomingPlayer?.Invoke(item);
|
||||||
|
UpdateUserScores?.Invoke(item as Lobby);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ namespace Client
|
|||||||
Debug.WriteLine("attempting to host game for " + ClientData.Instance.User.Username);
|
Debug.WriteLine("attempting to host game for " + ClientData.Instance.User.Username);
|
||||||
client.SendMessage(JSONConvert.ConstructLobbyHostMessage());
|
client.SendMessage(JSONConvert.ConstructLobbyHostMessage());
|
||||||
client.OnLobbyCreated = becomeHostForLobby;
|
client.OnLobbyCreated = becomeHostForLobby;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void becomeHostForLobby(int id)
|
private void becomeHostForLobby(int id)
|
||||||
@@ -68,6 +69,7 @@ namespace Client
|
|||||||
Debug.WriteLine($"got host succes with data {id} ");
|
Debug.WriteLine($"got host succes with data {id} ");
|
||||||
wantToBeHost = true;
|
wantToBeHost = true;
|
||||||
wantToBeHostId = id;
|
wantToBeHostId = id;
|
||||||
|
ClientData.Instance.User.Host = true;
|
||||||
client.OnLobbiesReceivedAndWaitingForHost = hostLobbiesReceived;
|
client.OnLobbiesReceivedAndWaitingForHost = hostLobbiesReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +114,7 @@ namespace Client
|
|||||||
|
|
||||||
private void updateLobbies()
|
private void updateLobbies()
|
||||||
{
|
{
|
||||||
Debug.WriteLine("updating lobbies...");
|
Debug.WriteLine("[VIEWMODEL] updating lobbies...");
|
||||||
Lobby[] lobbiesArr = client.Lobbies;
|
Lobby[] lobbiesArr = client.Lobbies;
|
||||||
Application.Current.Dispatcher.Invoke(delegate
|
Application.Current.Dispatcher.Invoke(delegate
|
||||||
{
|
{
|
||||||
@@ -122,6 +124,11 @@ namespace Client
|
|||||||
foreach (Lobby l in lobbiesArr)
|
foreach (Lobby l in lobbiesArr)
|
||||||
{
|
{
|
||||||
_lobbies.Add(l);
|
_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;
|
private string _randomWord;
|
||||||
|
|
||||||
public string RandomWord
|
public string RandomWord
|
||||||
{
|
{
|
||||||
get { return _randomWord; }
|
get { return _randomWord; }
|
||||||
set { _randomWord = value; }
|
set { _randomWord = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string Word
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsHost
|
public bool IsHost
|
||||||
{
|
{
|
||||||
get { return data.User.Host; }
|
get { return data.User.Host; }
|
||||||
@@ -69,17 +62,6 @@ namespace Client.ViewModels
|
|||||||
public ViewModelGame(GameWindow window)
|
public ViewModelGame(GameWindow window)
|
||||||
{
|
{
|
||||||
this.window = 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][];
|
buffer = new double[maxLines][];
|
||||||
linesQueue = new Queue<double[][]>();
|
linesQueue = new Queue<double[][]>();
|
||||||
@@ -91,6 +73,7 @@ namespace Client.ViewModels
|
|||||||
data.Client.RandomWord = HandleRandomWord;
|
data.Client.RandomWord = HandleRandomWord;
|
||||||
data.Client.IncomingMsg = HandleIncomingMsg;
|
data.Client.IncomingMsg = HandleIncomingMsg;
|
||||||
data.Client.IncomingPlayer = HandleIncomingPlayer;
|
data.Client.IncomingPlayer = HandleIncomingPlayer;
|
||||||
|
data.Client.UpdateUserScores = UpdateUserScores;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICommand OnKeyDown { get; set; }
|
public ICommand OnKeyDown { get; set; }
|
||||||
@@ -227,7 +210,7 @@ namespace Client.ViewModels
|
|||||||
data.Client.SendMessage(JSONConvert.GetMessageToSend(JSONConvert.MESSAGE, _payload));
|
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
|
Application.Current.Dispatcher.Invoke(delegate
|
||||||
{
|
{
|
||||||
@@ -240,12 +223,12 @@ namespace Client.ViewModels
|
|||||||
data.Client.SendMessage(JSONConvert.ConstructLobbyLeaveMessage(data.Lobby.ID));
|
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!");
|
Debug.WriteLine("[CLIENT] Reached the handle random word method!");
|
||||||
Application.Current.Dispatcher.Invoke(delegate
|
Application.Current.Dispatcher.Invoke(delegate
|
||||||
{
|
{
|
||||||
Word = randomWord;
|
RandomWord = randomWord;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public void HandleIncomingPlayer(Lobby lobby)
|
public void HandleIncomingPlayer(Lobby lobby)
|
||||||
@@ -255,9 +238,34 @@ namespace Client.ViewModels
|
|||||||
Players.Clear();
|
Players.Clear();
|
||||||
foreach (var item in lobby.Users)
|
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"/>
|
<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"/>
|
<Button Name="CanvasReset" Click="CanvasReset_Click" Grid.Row="0" Grid.Column="3" Content="RESET"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
<Label Grid.Row="2" FontSize="15" Content="(max amount of characters for the username is 10)"/>
|
<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"/>
|
<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"/>
|
<Label Grid.Row="3" Grid.Column="0" Content="Tip of the century: base64 != UTF8!" FontSize="20" FontWeight="Bold"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -27,8 +27,12 @@ namespace Client.Views
|
|||||||
|
|
||||||
private void Button_EnterUsername(object sender, RoutedEventArgs e)
|
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);
|
Client client = new Client(user.Username);
|
||||||
|
LoginButton.IsEnabled = false;
|
||||||
client.OnSuccessfullConnect = () =>
|
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
|
// 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
|
||||||
@@ -42,6 +46,7 @@ namespace Client.Views
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user