[ADDED] a begin for the turn base
This commit is contained in:
@@ -221,6 +221,18 @@ namespace Client
|
|||||||
int lobbyElapsedID = JSONConvert.GetLobbyID(payload);
|
int lobbyElapsedID = JSONConvert.GetLobbyID(payload);
|
||||||
|
|
||||||
//todo set next round
|
//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");
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ namespace Client.ViewModels
|
|||||||
public Queue<double[][]> linesQueue;
|
public Queue<double[][]> linesQueue;
|
||||||
private Timer queueTimer;
|
private Timer queueTimer;
|
||||||
|
|
||||||
|
private bool wordGuessed = false;
|
||||||
|
|
||||||
public static ObservableCollection<string> Messages { get; } = new ObservableCollection<string>();
|
public static ObservableCollection<string> Messages { get; } = new ObservableCollection<string>();
|
||||||
public ObservableCollection<string> Players { get; } = new ObservableCollection<string>();
|
public ObservableCollection<string> Players { get; } = new ObservableCollection<string>();
|
||||||
|
|
||||||
@@ -50,7 +52,23 @@ namespace Client.ViewModels
|
|||||||
private string _randomWord;
|
private string _randomWord;
|
||||||
public 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; }
|
set { _randomWord = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,10 +77,15 @@ namespace Client.ViewModels
|
|||||||
get { return data.User.Host; }
|
get { return data.User.Host; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool UserTurnToDraw
|
||||||
|
{
|
||||||
|
get { return data.User.TurnToDraw; }
|
||||||
|
}
|
||||||
|
|
||||||
public ViewModelGame(GameWindow window)
|
public ViewModelGame(GameWindow window)
|
||||||
{
|
{
|
||||||
this.window = window;
|
this.window = window;
|
||||||
|
_randomWord = "";
|
||||||
buffer = new double[maxLines][];
|
buffer = new double[maxLines][];
|
||||||
linesQueue = new Queue<double[][]>();
|
linesQueue = new Queue<double[][]>();
|
||||||
OnKeyDown = new RelayCommand(ChatBox_KeyDown);
|
OnKeyDown = new RelayCommand(ChatBox_KeyDown);
|
||||||
@@ -99,7 +122,7 @@ namespace Client.ViewModels
|
|||||||
|
|
||||||
public void Canvas_MouseDown(MouseButtonEventArgs e, GameWindow window)
|
public void Canvas_MouseDown(MouseButtonEventArgs e, GameWindow window)
|
||||||
{
|
{
|
||||||
if (e.ButtonState == MouseButtonState.Pressed)
|
if (e.ButtonState == MouseButtonState.Pressed && data.User.TurnToDraw)
|
||||||
{
|
{
|
||||||
currentPoint = e.GetPosition(window.CanvasForPaint);
|
currentPoint = e.GetPosition(window.CanvasForPaint);
|
||||||
}
|
}
|
||||||
@@ -107,7 +130,7 @@ namespace Client.ViewModels
|
|||||||
|
|
||||||
public void Canvas_MouseMove(MouseEventArgs e, GameWindow window)
|
public void Canvas_MouseMove(MouseEventArgs e, GameWindow window)
|
||||||
{
|
{
|
||||||
if (e.LeftButton == MouseButtonState.Pressed)
|
if (e.LeftButton == MouseButtonState.Pressed && data.User.TurnToDraw)
|
||||||
{
|
{
|
||||||
double[] coordinates = new double[4];
|
double[] coordinates = new double[4];
|
||||||
Line line = new Line();
|
Line line = new Line();
|
||||||
@@ -144,7 +167,9 @@ namespace Client.ViewModels
|
|||||||
|
|
||||||
public void Canvas_MouseUp(object sender, MouseButtonEventArgs e)
|
public void Canvas_MouseUp(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
sendArrayFromQueue(sender, null);
|
if (data.User.TurnToDraw)
|
||||||
|
sendArrayFromQueue(sender, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendArrayFromQueue(object sender, ElapsedEventArgs e)
|
private void sendArrayFromQueue(object sender, ElapsedEventArgs e)
|
||||||
|
|||||||
@@ -35,12 +35,12 @@
|
|||||||
<ColumnDefinition Width="100"/>
|
<ColumnDefinition Width="100"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Label Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" FontSize="20" Content="Pick a color -->"/>
|
<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" IsEnabled="{Binding UserTurnToDraw}"/>
|
||||||
|
|
||||||
|
|
||||||
<Label Name="GuessWord" Grid.Row="0" Grid.Column="2" Content="{Binding Path=RandomWord, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20"/>
|
<Label Name="GuessWord" Grid.Row="0" Grid.Column="2" Content="{Binding Path=RandomWord, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20"/>
|
||||||
|
|
||||||
<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" IsEnabled="{Binding UserTurnToDraw}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Button Name="StartGame" Grid.Row="0" Grid.Column="2" Content="Start Game" FontSize="20" Command="{Binding ButtonStartGame}" IsEnabled="{Binding IsHost}"/>
|
<Button Name="StartGame" Grid.Row="0" Grid.Column="2" Content="Start Game" FontSize="20" Command="{Binding ButtonStartGame}" IsEnabled="{Binding IsHost}"/>
|
||||||
|
|||||||
@@ -208,12 +208,14 @@ namespace Server.Models
|
|||||||
lobbyTimer.Elapsed += LobbyTimer_Elapsed;
|
lobbyTimer.Elapsed += LobbyTimer_Elapsed;
|
||||||
lobbyTimer.Start();
|
lobbyTimer.Start();
|
||||||
ServerCommunication.INSTANCE.sendToAll(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
|
ServerCommunication.INSTANCE.sendToAll(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
|
||||||
|
serverCom.SendToLobby(lobbyID, JSONConvert.ConstructGameInitializeData( serverCom.FindUserNameInLobby(lobbyID),lobbyID));
|
||||||
break;
|
break;
|
||||||
case GameCommand.TIMER_ELAPSED:
|
case GameCommand.TIMER_ELAPSED:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case GameCommand.NEXT_ROUND:
|
case GameCommand.NEXT_ROUND:
|
||||||
// The next round has been started, so we can start the timer again
|
// The next round has been started, so we can start the timer again
|
||||||
|
|
||||||
lobbyID = JSONConvert.GetLobbyID(payload);
|
lobbyID = JSONConvert.GetLobbyID(payload);
|
||||||
foreach (System.Timers.Timer timer in lobbyTimers.Keys)
|
foreach (System.Timers.Timer timer in lobbyTimers.Keys)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -298,8 +298,24 @@ namespace Server.Models
|
|||||||
if (lobby.ID == lobbyID)
|
if (lobby.ID == lobbyID)
|
||||||
{
|
{
|
||||||
lobby.LobbyJoinable = false;
|
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
|
public enum GameCommand
|
||||||
{
|
{
|
||||||
START_GAME,
|
START_GAME,
|
||||||
|
INITIALIZE,
|
||||||
TIMER_ELAPSED,
|
TIMER_ELAPSED,
|
||||||
NEXT_ROUND
|
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)
|
public static byte[] ConstructGameTimerElapsedMessage(int lobbyID)
|
||||||
{
|
{
|
||||||
return GetMessageToSend(GAME, new
|
return GetMessageToSend(GAME, new
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ namespace Client
|
|||||||
private bool _lobbyJoinable;
|
private bool _lobbyJoinable;
|
||||||
//private List<string> _usernames;
|
//private List<string> _usernames;
|
||||||
private List<User> _users;
|
private List<User> _users;
|
||||||
|
private int _userDrawing;
|
||||||
|
|
||||||
//public void AddUsername(string username, out bool success)
|
//public void AddUsername(string username, out bool success)
|
||||||
//{
|
//{
|
||||||
@@ -36,6 +37,7 @@ namespace Client
|
|||||||
//_usernames = new List<string>();
|
//_usernames = new List<string>();
|
||||||
_users = new List<User>();
|
_users = new List<User>();
|
||||||
_lobbyJoinable = true;
|
_lobbyJoinable = true;
|
||||||
|
_userDrawing = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddUser(string username, out bool succes)
|
public void AddUser(string username, out bool succes)
|
||||||
@@ -95,5 +97,11 @@ namespace Client
|
|||||||
set { _lobbyJoinable = value; }
|
set { _lobbyJoinable = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int UserDrawing
|
||||||
|
{
|
||||||
|
get { return _userDrawing; }
|
||||||
|
set { _userDrawing = value; }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user