Compare commits
6 Commits
master
...
setupBranc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ce04447d0 | ||
|
|
2d64accf09 | ||
|
|
1d8963ec60 | ||
|
|
13cf0e44ee | ||
|
|
eee4f0347f | ||
|
|
fd59368c03 |
@@ -221,6 +221,23 @@ namespace Client
|
||||
int lobbyElapsedID = JSONConvert.GetLobbyID(payload);
|
||||
|
||||
//todo set next round
|
||||
break;
|
||||
|
||||
case JSONConvert.GameCommand.INITIALIZE:
|
||||
int lobbyID = JSONConvert.GetLobbyID(payload);
|
||||
string userName = JSONConvert.GetUsernameLogin(payload);
|
||||
if (lobbyID == clientData.Lobby.ID)
|
||||
{
|
||||
if (userName == clientData.User.Username)
|
||||
{
|
||||
clientData.User.TurnToDraw = true;
|
||||
Debug.WriteLine("[CLIENT] Setting a player's turnToDraw to true");
|
||||
}
|
||||
clientData.Client.UpdateUserScores?.Invoke(clientData.Lobby);
|
||||
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
@@ -121,13 +121,18 @@ namespace Client
|
||||
|
||||
_lobbies.Clear();
|
||||
|
||||
Lobby clientLobby = ClientData.Instance.Lobby;
|
||||
foreach (Lobby l in lobbiesArr)
|
||||
{
|
||||
_lobbies.Add(l);
|
||||
Lobby clientLobby = ClientData.Instance.Lobby;
|
||||
if (l.ID == clientLobby?.ID)
|
||||
{
|
||||
clientLobby = l;
|
||||
clientLobby.Users.Clear();
|
||||
|
||||
foreach (User user in l.Users)
|
||||
{
|
||||
clientLobby.Users.Add(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace Client.ViewModels
|
||||
public Queue<double[][]> linesQueue;
|
||||
private Timer queueTimer;
|
||||
|
||||
private bool wordGuessed = false;
|
||||
|
||||
public static ObservableCollection<string> Messages { get; } = new ObservableCollection<string>();
|
||||
public ObservableCollection<string> Players { get; } = new ObservableCollection<string>();
|
||||
|
||||
@@ -50,7 +52,23 @@ namespace Client.ViewModels
|
||||
private string _randomWord;
|
||||
public string RandomWord
|
||||
{
|
||||
get { return _randomWord; }
|
||||
get {
|
||||
if (data.User.TurnToDraw)
|
||||
return _randomWord;
|
||||
|
||||
if (!wordGuessed)
|
||||
{
|
||||
string hiddenWord = "";
|
||||
for (int i = 0; i < _randomWord.Length; i++)
|
||||
{
|
||||
hiddenWord += "_ ";
|
||||
}
|
||||
return hiddenWord;
|
||||
}
|
||||
else
|
||||
return _randomWord;
|
||||
}
|
||||
|
||||
set { _randomWord = value; }
|
||||
}
|
||||
|
||||
@@ -59,10 +77,15 @@ namespace Client.ViewModels
|
||||
get { return data.User.Host; }
|
||||
}
|
||||
|
||||
public bool UserTurnToDraw
|
||||
{
|
||||
get { return data.User.TurnToDraw; }
|
||||
}
|
||||
|
||||
public ViewModelGame(GameWindow window)
|
||||
{
|
||||
this.window = window;
|
||||
|
||||
_randomWord = "";
|
||||
buffer = new double[maxLines][];
|
||||
linesQueue = new Queue<double[][]>();
|
||||
OnKeyDown = new RelayCommand(ChatBox_KeyDown);
|
||||
@@ -144,7 +167,9 @@ namespace Client.ViewModels
|
||||
|
||||
public void Canvas_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
sendArrayFromQueue(sender, null);
|
||||
|
||||
sendArrayFromQueue(sender, null);
|
||||
|
||||
}
|
||||
|
||||
private void sendArrayFromQueue(object sender, ElapsedEventArgs e)
|
||||
@@ -238,7 +263,7 @@ namespace Client.ViewModels
|
||||
Players.Clear();
|
||||
foreach (var item in lobby.Users)
|
||||
{
|
||||
Players.Add(item.Username + "\n" + item.Score);
|
||||
Players.Add(item.Username + "\n" + item.Score + "\n" + item.TurnToDraw);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<ColumnDefinition Width="100"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" FontSize="20" Content="Pick a color -->"/>
|
||||
<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="2" Content="{Binding Path=RandomWord, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20"/>
|
||||
|
||||
@@ -20,8 +20,10 @@ namespace Client.Views
|
||||
public partial class LoginScreen : Window
|
||||
{
|
||||
ClientData data = ClientData.Instance;
|
||||
private LoginViewModel loginViewModel;
|
||||
public LoginScreen()
|
||||
{
|
||||
loginViewModel = new LoginViewModel(this);
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@@ -29,22 +31,8 @@ namespace Client.Views
|
||||
{
|
||||
string name = usernameTextbox.Text;
|
||||
if (name == string.Empty) return;
|
||||
User user = new User(name);
|
||||
|
||||
Client client = new Client(user.Username);
|
||||
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
|
||||
Application.Current.Dispatcher.Invoke(delegate {
|
||||
data.User = user;
|
||||
data.Client = client;
|
||||
client.SendMessage(JSONConvert.ConstructLobbyRequestMessage());
|
||||
MainWindow startWindow = new MainWindow();
|
||||
startWindow.Show();
|
||||
this.Close();
|
||||
});
|
||||
};
|
||||
loginViewModel.UsernameEntered(name);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace Server.Models
|
||||
coords = JSONConvert.getCoordinates(payload),
|
||||
color = JSONConvert.getCanvasDrawingColor(payload)
|
||||
};
|
||||
serverCom.SendToLobby(serverCom.GetLobbyForUser(User),JSONConvert.GetMessageToSend(JSONConvert.CANVAS,canvasData));
|
||||
serverCom.SendCanvasDataToLobby(serverCom.GetLobbyForUser(User),User.Username,JSONConvert.GetMessageToSend(JSONConvert.CANVAS,canvasData));
|
||||
break;
|
||||
|
||||
case JSONConvert.CANVAS_RESET:
|
||||
@@ -208,12 +208,14 @@ namespace Server.Models
|
||||
lobbyTimer.Elapsed += LobbyTimer_Elapsed;
|
||||
lobbyTimer.Start();
|
||||
ServerCommunication.INSTANCE.sendToAll(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
|
||||
serverCom.SendToLobby(lobbyID, JSONConvert.ConstructGameInitializeData( serverCom.FindUserNameInLobby(lobbyID),lobbyID));
|
||||
break;
|
||||
case GameCommand.TIMER_ELAPSED:
|
||||
|
||||
break;
|
||||
case GameCommand.NEXT_ROUND:
|
||||
// The next round has been started, so we can start the timer again
|
||||
|
||||
lobbyID = JSONConvert.GetLobbyID(payload);
|
||||
foreach (System.Timers.Timer timer in lobbyTimers.Keys)
|
||||
{
|
||||
|
||||
@@ -174,7 +174,8 @@ namespace Server.Models
|
||||
{
|
||||
foreach (ServerClient sc in serverClientsInlobbies[l])
|
||||
{
|
||||
sc.sendMessage(message);
|
||||
if (sc.User.Username != username)
|
||||
sc.sendMessage(message);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -298,8 +299,24 @@ namespace Server.Models
|
||||
if (lobby.ID == lobbyID)
|
||||
{
|
||||
lobby.LobbyJoinable = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string FindUserNameInLobby(int lobbyID)
|
||||
{
|
||||
Lobby lobbyFound = null;
|
||||
foreach (Lobby lobby in lobbies)
|
||||
{
|
||||
if (lobby.ID == lobbyID)
|
||||
{
|
||||
lobbyFound = lobby;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return lobbyFound?.Users[lobbyFound.UserDrawing]?.Username;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace SharedClientServer
|
||||
public enum GameCommand
|
||||
{
|
||||
START_GAME,
|
||||
INITIALIZE,
|
||||
TIMER_ELAPSED,
|
||||
NEXT_ROUND
|
||||
}
|
||||
@@ -220,6 +221,17 @@ namespace SharedClientServer
|
||||
}); ;
|
||||
}
|
||||
|
||||
public static byte[] ConstructGameInitializeData(string userName, int lobbyID)
|
||||
{
|
||||
dynamic payload = new
|
||||
{
|
||||
id = lobbyID,
|
||||
command = GameCommand.INITIALIZE,
|
||||
username = userName
|
||||
};
|
||||
return GetMessageToSend(GAME, payload);
|
||||
}
|
||||
|
||||
public static byte[] ConstructGameTimerElapsedMessage(int lobbyID)
|
||||
{
|
||||
return GetMessageToSend(GAME, new
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Client
|
||||
private bool _lobbyJoinable;
|
||||
//private List<string> _usernames;
|
||||
private List<User> _users;
|
||||
private int _userDrawing;
|
||||
|
||||
//public void AddUsername(string username, out bool success)
|
||||
//{
|
||||
@@ -36,6 +37,7 @@ namespace Client
|
||||
//_usernames = new List<string>();
|
||||
_users = new List<User>();
|
||||
_lobbyJoinable = true;
|
||||
_userDrawing = 0;
|
||||
}
|
||||
|
||||
public void AddUser(string username, out bool succes)
|
||||
@@ -95,5 +97,11 @@ namespace Client
|
||||
set { _lobbyJoinable = value; }
|
||||
}
|
||||
|
||||
public int UserDrawing
|
||||
{
|
||||
get { return _userDrawing; }
|
||||
set { _userDrawing = value; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user