Implement client side game logic
This commit is contained in:
@@ -74,7 +74,7 @@
|
||||
<ListBoxItem Name="NavListHome" ManipulationMode="TranslateX" ManipulationCompleted="Pane_ManipulationCompleted">
|
||||
<StackPanel Style="{StaticResource NavStackPanel}">
|
||||
<TextBlock Style="{StaticResource NavIcon}" Text=""/>
|
||||
<TextBlock Style="{StaticResource NavText}" Text="Match"/>
|
||||
<TextBlock Style="{StaticResource NavText}" Text="Game"/>
|
||||
</StackPanel>
|
||||
</ListBoxItem>
|
||||
<ListBoxItem Name="NavListStatistics" ManipulationMode="TranslateX" ManipulationCompleted="Pane_ManipulationCompleted">
|
||||
@@ -116,7 +116,7 @@
|
||||
<TextBlock Style="{StaticResource GameInfoText}" Text="{Binding Players}"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Style="{StaticResource GameInfoPanel}" HorizontalAlignment="Stretch">
|
||||
<StackPanel Style="{StaticResource GameInfoPanel}">
|
||||
<Button Content="Back to Game" Click="BackToGame_Click" Style="{StaticResource Green}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@@ -43,13 +43,19 @@ namespace YJMPD_UWP
|
||||
this.InitializeComponent();
|
||||
|
||||
Frame.Navigated += Frame_Navigated;
|
||||
Frame.Navigate(typeof(MatchView));
|
||||
Frame.Navigate(typeof(GameView));
|
||||
}
|
||||
|
||||
private void OnBackRequested(object sender, BackRequestedEventArgs e)
|
||||
{
|
||||
if (e.Handled) return;
|
||||
|
||||
if (App.Game.Status == Model.GameHandler.GameStatus.STARTED)
|
||||
{
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Frame.CanGoBack)
|
||||
{
|
||||
e.Handled = true;
|
||||
@@ -92,7 +98,7 @@ namespace YJMPD_UWP
|
||||
|
||||
switch (pagename.ToLower())
|
||||
{
|
||||
case "matchview":
|
||||
case "gameview":
|
||||
NavList.SelectedIndex = 0;
|
||||
break;
|
||||
case "statisticsview":
|
||||
@@ -122,7 +128,7 @@ namespace YJMPD_UWP
|
||||
{
|
||||
if (Frame.BackStack.Count >= 1)
|
||||
Frame.BackStack.Clear();
|
||||
Frame.Navigate(typeof(MatchView));
|
||||
Frame.Navigate(typeof(GameView));
|
||||
}
|
||||
else
|
||||
if (NavListStatistics.IsSelected)
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Devices.Geolocation;
|
||||
using YJMPD_UWP.Helpers;
|
||||
using YJMPD_UWP.Views;
|
||||
|
||||
@@ -22,7 +23,10 @@ namespace YJMPD_UWP.Model
|
||||
Msg,
|
||||
PlayerJoined,
|
||||
PlayerRemoved,
|
||||
PictureUrl
|
||||
PictureUrl,
|
||||
DestinationReached,
|
||||
GameEnded,
|
||||
PlayerReady
|
||||
}
|
||||
|
||||
public ApiHandler()
|
||||
@@ -60,7 +64,33 @@ namespace YJMPD_UWP.Model
|
||||
if (!App.Game.Selected)
|
||||
App.Photo.SetPhoto(o[Command.PictureUrl.ToString()].ToString());
|
||||
|
||||
App.Game.MoveToStarted();
|
||||
double lat = (double)o["lat"];
|
||||
double lon = (double)o["lon"];
|
||||
|
||||
BasicGeoposition bgps = new BasicGeoposition() { Latitude = lat, Longitude = lon };
|
||||
|
||||
App.Game.MoveToStarted(bgps);
|
||||
break;
|
||||
case Command.GameEnded:
|
||||
string winner = o["winner"].ToString();
|
||||
|
||||
if (winner == Settings.Username)
|
||||
winner = "You";
|
||||
|
||||
Util.ShowToastNotification(winner + " won!", "Press Ready or Leave");
|
||||
|
||||
JArray players = (JArray)o["players"];
|
||||
|
||||
foreach(JToken pl in players)
|
||||
{
|
||||
string username = o["username"].ToString();
|
||||
double points = (double)o["points"];
|
||||
double pointstotal = (double)o["pointstotal"];
|
||||
|
||||
App.Game.UpdatePlayer(username, pointstotal, points);
|
||||
}
|
||||
|
||||
App.Game.StopMatch();
|
||||
break;
|
||||
default:
|
||||
//Do nothing
|
||||
@@ -130,5 +160,29 @@ namespace YJMPD_UWP.Model
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> DestinationReached()
|
||||
{
|
||||
JObject obj = JObject.FromObject(new
|
||||
{
|
||||
command = Command.DestinationReached.ToString(),
|
||||
username = Settings.Username
|
||||
});
|
||||
await App.Network.Write(obj.ToString(Formatting.None));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> Ready()
|
||||
{
|
||||
JObject obj = JObject.FromObject(new
|
||||
{
|
||||
command = Command.PlayerReady.ToString(),
|
||||
ready = true
|
||||
});
|
||||
await App.Network.Write(obj.ToString(Formatting.None));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Devices.Geolocation;
|
||||
using Windows.Devices.Geolocation.Geofencing;
|
||||
using Windows.Foundation;
|
||||
using Windows.Services.Maps;
|
||||
@@ -22,6 +23,12 @@ namespace YJMPD_UWP.Model
|
||||
public delegate void OnPlayersUpdateHandler(object sender, GamePlayersUpdatedEventArgs e);
|
||||
public event OnPlayersUpdateHandler OnPlayersUpdate;
|
||||
|
||||
public delegate void OnDestinationEnteredHandler(object sender, EventArgs e);
|
||||
public event OnDestinationEnteredHandler OnDestinationEnter;
|
||||
|
||||
public delegate void OnDestinationLeftHandler(object sender, EventArgs e);
|
||||
public event OnDestinationLeftHandler OnDestinationLeave;
|
||||
|
||||
public enum GameStatus { STARTED, SEARCHING, WAITING, ENDED, STOPPED }
|
||||
public GameStatus Status { get; private set; }
|
||||
|
||||
@@ -48,12 +55,56 @@ namespace YJMPD_UWP.Model
|
||||
|
||||
OnPlayersUpdate(this, new GamePlayersUpdatedEventArgs(player));
|
||||
}
|
||||
private void UpdateDestinationEnter()
|
||||
{
|
||||
if (OnDestinationEnter == null) return;
|
||||
|
||||
OnDestinationEnter(this, new EventArgs());
|
||||
}
|
||||
private void UpdateDestinationLeave()
|
||||
{
|
||||
if (OnDestinationLeave == null) return;
|
||||
|
||||
OnDestinationLeave(this, new EventArgs());
|
||||
}
|
||||
|
||||
public GameHandler()
|
||||
{
|
||||
Players = new List<Player>();
|
||||
Status = GameStatus.STOPPED;
|
||||
App.Photo.OnStatusUpdate += Photo_OnStatusUpdate;
|
||||
GeofenceMonitor.Current.GeofenceStateChanged += Current_GeofenceStateChanged;
|
||||
}
|
||||
|
||||
private void Current_GeofenceStateChanged(GeofenceMonitor sender, object args)
|
||||
{
|
||||
if (Status != GameStatus.STARTED) return;
|
||||
|
||||
var reports = sender.ReadReports();
|
||||
|
||||
foreach (GeofenceStateChangeReport report in reports)
|
||||
{
|
||||
GeofenceState state = report.NewState;
|
||||
Geofence geofence = report.Geofence;
|
||||
|
||||
if (geofence.Id != "destination") continue;
|
||||
|
||||
else if (state == GeofenceState.Entered)
|
||||
{
|
||||
UpdateDestinationEnter();
|
||||
|
||||
if (!Selected)
|
||||
App.Api.DestinationReached();
|
||||
}
|
||||
|
||||
else if (state == GeofenceState.Exited)
|
||||
{
|
||||
UpdateDestinationLeave();
|
||||
|
||||
if (Selected)
|
||||
Util.ShowToastNotification("Left Area", "Please return to your location!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Photo_OnStatusUpdate(object sender, PhotoStatusUpdatedEventArgs e)
|
||||
@@ -93,9 +144,12 @@ namespace YJMPD_UWP.Model
|
||||
UpdateGameStatus(GameStatus.WAITING);
|
||||
}
|
||||
|
||||
public void MoveToStarted()
|
||||
public void MoveToStarted(BasicGeoposition bgps)
|
||||
{
|
||||
App.Navigate(typeof(GameView));
|
||||
|
||||
GeofenceMonitor.Current.Geofences.Add(new Geofence("destination", new Geocircle(bgps, 50), MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited, false, TimeSpan.FromSeconds(1)));
|
||||
|
||||
UpdateGameStatus(GameStatus.STARTED);
|
||||
}
|
||||
|
||||
@@ -120,7 +174,7 @@ namespace YJMPD_UWP.Model
|
||||
GeofenceMonitor.Current.Geofences.Clear();
|
||||
UpdateGamePlayers(null);
|
||||
|
||||
App.Navigate(typeof(MatchView));
|
||||
App.Navigate(typeof(GameView));
|
||||
}
|
||||
|
||||
public void UpdatePlayer(string username, double pointstotal, double points)
|
||||
@@ -136,13 +190,30 @@ namespace YJMPD_UWP.Model
|
||||
}
|
||||
}
|
||||
|
||||
public Player GetPlayer(string username)
|
||||
{
|
||||
foreach(Player p in Players)
|
||||
{
|
||||
if(p.Username == username)
|
||||
return p;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//Ending
|
||||
|
||||
public async Task<bool> End()
|
||||
public async Task<bool> StopMatch()
|
||||
{
|
||||
CalculateDistanceWalked();
|
||||
Settings.Statistics.Matches += 1;
|
||||
|
||||
Settings.Statistics.AddPoints(GetPlayer(Settings.Username).Points);
|
||||
|
||||
GeofenceMonitor.Current.Geofences.Clear();
|
||||
Selected = false;
|
||||
|
||||
App.Navigate(typeof(ScoreView));
|
||||
UpdateGameStatus(GameStatus.ENDED);
|
||||
|
||||
return true;
|
||||
@@ -156,23 +227,13 @@ namespace YJMPD_UWP.Model
|
||||
|
||||
//Starting and Stopping
|
||||
|
||||
public async Task<bool> Start()
|
||||
{
|
||||
return await StartGame();
|
||||
}
|
||||
|
||||
public async Task<bool> Stop()
|
||||
{
|
||||
return await StopGame();
|
||||
}
|
||||
|
||||
private async Task<bool> StartGame()
|
||||
public async Task<bool> StartGame()
|
||||
{
|
||||
UpdateGameStatus(GameStatus.SEARCHING);
|
||||
return await App.Api.JoinGame();
|
||||
}
|
||||
|
||||
private async Task<bool> StopGame()
|
||||
public async Task<bool> StopGame()
|
||||
{
|
||||
App.Api.LeaveGame();
|
||||
|
||||
@@ -191,7 +252,7 @@ namespace YJMPD_UWP.Model
|
||||
case GameStatus.STOPPED:
|
||||
break;
|
||||
case GameStatus.SEARCHING:
|
||||
App.Navigate(typeof(MatchView));
|
||||
App.Navigate(typeof(GameView));
|
||||
break;
|
||||
case GameStatus.WAITING:
|
||||
if (Selected)
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace YJMPD_UWP.Model
|
||||
Debug.WriteLine("Disconnecting...");
|
||||
|
||||
if (App.Game.Status != GameHandler.GameStatus.STOPPED)
|
||||
await App.Game.Stop();
|
||||
await App.Game.StopGame();
|
||||
|
||||
UpdateNetworkStatus(NetworkStatus.DISCONNECTED);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using YJMPD_UWP.Model.Object;
|
||||
|
||||
namespace YJMPD_UWP.ViewModels
|
||||
{
|
||||
@@ -7,14 +8,135 @@ namespace YJMPD_UWP.ViewModels
|
||||
{
|
||||
public GameVM() : base("Game")
|
||||
{
|
||||
|
||||
App.Geo.OnStatusUpdate += Geo_OnStatusUpdate;
|
||||
App.Network.OnStatusUpdate += Network_OnStatusUpdate;
|
||||
App.Game.OnStatusUpdate += Game_OnStatusUpdate;
|
||||
App.Game.OnPlayersUpdate += Game_OnPlayersUpdate;
|
||||
}
|
||||
|
||||
public ImageSource Photo
|
||||
private void Game_OnPlayersUpdate(object sender, Helpers.EventArgs.GamePlayersUpdatedEventArgs e)
|
||||
{
|
||||
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
NotifyPropertyChanged(nameof(Players));
|
||||
NotifyPropertyChanged(nameof(PlayersCount));
|
||||
});
|
||||
}
|
||||
|
||||
private void Game_OnStatusUpdate(object sender, Helpers.EventArgs.GameStatusUpdatedEventArgs e)
|
||||
{
|
||||
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
NotifyPropertyChanged(nameof(StartGame));
|
||||
NotifyPropertyChanged(nameof(StopGame));
|
||||
});
|
||||
}
|
||||
|
||||
private void Network_OnStatusUpdate(object sender, Helpers.EventArgs.NetworkStatusUpdatedEventArgs e)
|
||||
{
|
||||
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
NotifyPropertyChanged(nameof(GameAvailable));
|
||||
NotifyPropertyChanged(nameof(ServerAvailable));
|
||||
NotifyPropertyChanged(nameof(ServerMessage));
|
||||
});
|
||||
}
|
||||
|
||||
private void Geo_OnStatusUpdate(object sender, Helpers.EventArgs.PositionStatusUpdatedEventArgs e)
|
||||
{
|
||||
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
NotifyPropertyChanged(nameof(GameAvailable));
|
||||
NotifyPropertyChanged(nameof(ServerAvailable));
|
||||
NotifyPropertyChanged(nameof(ServerMessage));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public List<Player> Players
|
||||
{
|
||||
get
|
||||
{
|
||||
return new BitmapImage(new System.Uri(App.Photo.Photo));
|
||||
return new List<Player>(App.Game.Players);
|
||||
}
|
||||
}
|
||||
|
||||
public string PlayersCount
|
||||
{
|
||||
get
|
||||
{
|
||||
if (App.Game.Players.Count == 1)
|
||||
return "There is currently " + App.Game.Players.Count + " player in the game.";
|
||||
else
|
||||
return "There are currently " + App.Game.Players.Count + " players in the game.";
|
||||
}
|
||||
}
|
||||
|
||||
public bool GameAvailable
|
||||
{
|
||||
get
|
||||
{
|
||||
return App.Geo.Status == Windows.Devices.Geolocation.PositionStatus.Ready && App.Network.Status == Model.NetworkHandler.NetworkStatus.CONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ServerAvailable
|
||||
{
|
||||
get
|
||||
{
|
||||
return !GameAvailable;
|
||||
}
|
||||
}
|
||||
|
||||
public string ServerMessage
|
||||
{
|
||||
get
|
||||
{
|
||||
string str = "";
|
||||
|
||||
switch (App.Network.Status)
|
||||
{
|
||||
case Model.NetworkHandler.NetworkStatus.DISCONNECTED:
|
||||
str = "Disconnected";
|
||||
break;
|
||||
case Model.NetworkHandler.NetworkStatus.CONNECTING:
|
||||
str = "Connecting to server...";
|
||||
break;
|
||||
}
|
||||
|
||||
switch(App.Geo.Status)
|
||||
{
|
||||
case Windows.Devices.Geolocation.PositionStatus.Disabled:
|
||||
case Windows.Devices.Geolocation.PositionStatus.NotAvailable:
|
||||
case Windows.Devices.Geolocation.PositionStatus.NoData:
|
||||
str = "GPS not available";
|
||||
break;
|
||||
case Windows.Devices.Geolocation.PositionStatus.NotInitialized:
|
||||
case Windows.Devices.Geolocation.PositionStatus.Initializing:
|
||||
str = "Waiting on GPS...";
|
||||
break;
|
||||
}
|
||||
|
||||
if (str == "")
|
||||
str = "Connected";
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public bool StartGame
|
||||
{
|
||||
get
|
||||
{
|
||||
return App.Game.Status == Model.GameHandler.GameStatus.STOPPED;
|
||||
}
|
||||
}
|
||||
|
||||
public bool StopGame
|
||||
{
|
||||
get
|
||||
{
|
||||
return !StartGame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using YJMPD_UWP.Model.Object;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
|
||||
namespace YJMPD_UWP.ViewModels
|
||||
{
|
||||
@@ -8,135 +7,71 @@ namespace YJMPD_UWP.ViewModels
|
||||
{
|
||||
public MatchVM() : base("Match")
|
||||
{
|
||||
App.Geo.OnStatusUpdate += Geo_OnStatusUpdate;
|
||||
App.Network.OnStatusUpdate += Network_OnStatusUpdate;
|
||||
App.Game.OnStatusUpdate += Game_OnStatusUpdate;
|
||||
App.Game.OnPlayersUpdate += Game_OnPlayersUpdate;
|
||||
|
||||
App.Game.OnDestinationEnter += Game_OnDestinationEnter;
|
||||
App.Game.OnDestinationLeave += Game_OnDestinationLeave;
|
||||
}
|
||||
|
||||
private void Game_OnPlayersUpdate(object sender, Helpers.EventArgs.GamePlayersUpdatedEventArgs e)
|
||||
private void Game_OnDestinationLeave(object sender, System.EventArgs e)
|
||||
{
|
||||
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
NotifyPropertyChanged(nameof(Players));
|
||||
NotifyPropertyChanged(nameof(PlayersCount));
|
||||
if (App.Game.Selected)
|
||||
Error = "Return to location!";
|
||||
|
||||
NotifyPropertyChanged(nameof(ErrorVisible));
|
||||
NotifyPropertyChanged(nameof(Error));
|
||||
});
|
||||
}
|
||||
|
||||
private void Game_OnStatusUpdate(object sender, Helpers.EventArgs.GameStatusUpdatedEventArgs e)
|
||||
private void Game_OnDestinationEnter(object sender, System.EventArgs e)
|
||||
{
|
||||
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
NotifyPropertyChanged(nameof(StartMatch));
|
||||
NotifyPropertyChanged(nameof(StopMatch));
|
||||
});
|
||||
if (App.Game.Selected)
|
||||
Error = "";
|
||||
|
||||
if (!App.Game.Selected)
|
||||
Message = "You reached the destination!";
|
||||
|
||||
NotifyPropertyChanged(nameof(ErrorVisible));
|
||||
NotifyPropertyChanged(nameof(Error));
|
||||
NotifyPropertyChanged(nameof(MessageVisible));
|
||||
NotifyPropertyChanged(nameof(Message));
|
||||
});
|
||||
}
|
||||
|
||||
private void Network_OnStatusUpdate(object sender, Helpers.EventArgs.NetworkStatusUpdatedEventArgs e)
|
||||
{
|
||||
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
NotifyPropertyChanged(nameof(MatchAvailable));
|
||||
NotifyPropertyChanged(nameof(ServerAvailable));
|
||||
NotifyPropertyChanged(nameof(ServerMessage));
|
||||
});
|
||||
}
|
||||
|
||||
private void Geo_OnStatusUpdate(object sender, Helpers.EventArgs.PositionStatusUpdatedEventArgs e)
|
||||
{
|
||||
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
NotifyPropertyChanged(nameof(MatchAvailable));
|
||||
NotifyPropertyChanged(nameof(ServerAvailable));
|
||||
NotifyPropertyChanged(nameof(ServerMessage));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public List<Player> Players
|
||||
public bool MessageVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
return new List<Player>(App.Game.Players);
|
||||
return Message != "";
|
||||
}
|
||||
}
|
||||
|
||||
public string PlayersCount
|
||||
public bool ErrorVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
if (App.Game.Players.Count == 1)
|
||||
return "There is currently " + App.Game.Players.Count + " player in the match.";
|
||||
else
|
||||
return "There are currently " + App.Game.Players.Count + " players in the match.";
|
||||
return Error != "";
|
||||
}
|
||||
}
|
||||
|
||||
public bool MatchAvailable
|
||||
public string Message
|
||||
{
|
||||
get
|
||||
{
|
||||
return App.Geo.Status == Windows.Devices.Geolocation.PositionStatus.Ready && App.Network.Status == Model.NetworkHandler.NetworkStatus.CONNECTED;
|
||||
}
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public bool ServerAvailable
|
||||
public string Error
|
||||
{
|
||||
get
|
||||
{
|
||||
return !MatchAvailable;
|
||||
}
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public string ServerMessage
|
||||
public ImageSource Photo
|
||||
{
|
||||
get
|
||||
{
|
||||
string str = "";
|
||||
|
||||
switch (App.Network.Status)
|
||||
{
|
||||
case Model.NetworkHandler.NetworkStatus.DISCONNECTED:
|
||||
str = "Disconnected";
|
||||
break;
|
||||
case Model.NetworkHandler.NetworkStatus.CONNECTING:
|
||||
str = "Connecting to server...";
|
||||
break;
|
||||
}
|
||||
|
||||
switch(App.Geo.Status)
|
||||
{
|
||||
case Windows.Devices.Geolocation.PositionStatus.Disabled:
|
||||
case Windows.Devices.Geolocation.PositionStatus.NotAvailable:
|
||||
case Windows.Devices.Geolocation.PositionStatus.NoData:
|
||||
str = "GPS not available";
|
||||
break;
|
||||
case Windows.Devices.Geolocation.PositionStatus.NotInitialized:
|
||||
case Windows.Devices.Geolocation.PositionStatus.Initializing:
|
||||
str = "Waiting on GPS...";
|
||||
break;
|
||||
}
|
||||
|
||||
if (str == "")
|
||||
str = "Connected";
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public bool StartMatch
|
||||
{
|
||||
get
|
||||
{
|
||||
return App.Game.Status == Model.GameHandler.GameStatus.STOPPED;
|
||||
}
|
||||
}
|
||||
|
||||
public bool StopMatch
|
||||
{
|
||||
get
|
||||
{
|
||||
return !StartMatch;
|
||||
return new BitmapImage(new System.Uri(App.Photo.Photo));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace YJMPD_UWP.ViewModels
|
||||
secondsleft--;
|
||||
if(secondsleft <= 0)
|
||||
{
|
||||
App.Game.Stop();
|
||||
App.Game.StopGame();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,9 +37,9 @@ namespace YJMPD_UWP.ViewModels
|
||||
get
|
||||
{
|
||||
if (App.Game.Players.Count == 1)
|
||||
return "There is currently " + App.Game.Players.Count + " player in the match.";
|
||||
return "There is currently " + App.Game.Players.Count + " player in the game.";
|
||||
else
|
||||
return "There are currently " + App.Game.Players.Count + " players in the match.";
|
||||
return "There are currently " + App.Game.Players.Count + " players in the game.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,51 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:YJMPD_UWP.Views"
|
||||
xmlns:convert="using:YJMPD_UWP.Helpers.Converter"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid Style="{StaticResource BaseGrid}">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" ZoomMode="Enabled">
|
||||
<Image Name="Photo" Source="{Binding Photo}"/>
|
||||
<Page.Resources>
|
||||
<convert:BoolToVisibilityConverter x:Key="BoolToVisConverter" />
|
||||
</Page.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ScrollViewer Grid.Row="0">
|
||||
<StackPanel Style="{StaticResource BaseStackPanel}" >
|
||||
<StackPanel>
|
||||
<TextBlock Text="Start a Game" Style="{StaticResource Header}" />
|
||||
<Button Content="Start Game" Style="{StaticResource Green}" Click="StartGameButton_Click" IsEnabled="{Binding GameAvailable}" Visibility="{Binding StartGame, Converter={StaticResource BoolToVisConverter}}" />
|
||||
<Button Content="Leave Game" Style="{StaticResource Red}" Click="StopGameButton_Click" Visibility="{Binding StopGame, Converter={StaticResource BoolToVisConverter}}" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Visibility="{Binding StopGame, Converter={StaticResource BoolToVisConverter}}" Margin="0,10,0,0">
|
||||
<TextBlock Text="Current players in game" Style="{StaticResource Header}" />
|
||||
|
||||
<TextBlock Text="{Binding PlayersCount}" />
|
||||
|
||||
<ListView x:Name="PlayersList" ItemsSource="{Binding Players}" SelectionMode="None" IsTapEnabled="False">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:Name="ListViewDataTemplate">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding Username}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="1" Visibility="{Binding ServerAvailable, Converter={StaticResource BoolToVisConverter}}" Padding="20" Background="Gray">
|
||||
<ProgressRing Width="20" Height="20" IsActive="True" Margin="0,0,10,0" Foreground="White"/>
|
||||
<TextBlock Text="{Binding ServerMessage}" Foreground="White" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Page>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using YJMPD_UWP.ViewModels;
|
||||
|
||||
namespace YJMPD_UWP.Views
|
||||
@@ -13,5 +14,15 @@ namespace YJMPD_UWP.Views
|
||||
this.DataContext = gamevm;
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void StartGameButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
App.Game.StartGame();
|
||||
}
|
||||
|
||||
private void StopGameButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
App.Game.StopGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,42 +12,17 @@
|
||||
<convert:BoolToVisibilityConverter x:Key="BoolToVisConverter" />
|
||||
</Page.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ScrollViewer Grid.Row="0">
|
||||
<StackPanel Style="{StaticResource BaseStackPanel}" >
|
||||
<StackPanel>
|
||||
<TextBlock Text="Start a match" Style="{StaticResource Header}" />
|
||||
<Button Content="Start match" Style="{StaticResource Green}" Click="StartMatchButton_Click" IsEnabled="{Binding MatchAvailable}" Visibility="{Binding StartMatch, Converter={StaticResource BoolToVisConverter}}" />
|
||||
<Button Content="Leave match" Style="{StaticResource Red}" Click="StopMatchButton_Click" Visibility="{Binding StopMatch, Converter={StaticResource BoolToVisConverter}}" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Visibility="{Binding StopMatch, Converter={StaticResource BoolToVisConverter}}" Margin="0,10,0,0">
|
||||
<TextBlock Text="Current players in match" Style="{StaticResource Header}" />
|
||||
|
||||
<TextBlock Text="{Binding PlayersCount}" />
|
||||
|
||||
<ListView x:Name="PlayersList" ItemsSource="{Binding Players}" SelectionMode="None" IsTapEnabled="False">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:Name="ListViewDataTemplate">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding Username}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
<Grid Style="{StaticResource BaseGrid}">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" ZoomMode="Enabled">
|
||||
<Image Name="Photo" Stretch="UniformToFill" Source="{Binding Photo}"/>
|
||||
</ScrollViewer>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="1" Visibility="{Binding ServerAvailable, Converter={StaticResource BoolToVisConverter}}" Padding="20" Background="Gray">
|
||||
<ProgressRing Width="20" Height="20" IsActive="True" Margin="0,0,10,0" Foreground="White"/>
|
||||
<TextBlock Text="{Binding ServerMessage}" Foreground="White" />
|
||||
<StackPanel Visibility="{Binding MessageVisible, Converter={StaticResource BoolToVisConverter}}" Background="DarkGreen" Padding="20" VerticalAlignment="Bottom">
|
||||
<TextBlock Foreground="White" Text="{Binding Message}" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Visibility="{Binding ErrorVisible, Converter={StaticResource BoolToVisConverter}}" Background="DarkRed" Padding="20" VerticalAlignment="Bottom">
|
||||
<TextBlock Foreground="White" Text="{Binding Error}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Page>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using YJMPD_UWP.ViewModels;
|
||||
|
||||
namespace YJMPD_UWP.Views
|
||||
@@ -14,15 +13,5 @@ namespace YJMPD_UWP.Views
|
||||
this.DataContext = matchvm;
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void StartMatchButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
App.Game.Start();
|
||||
}
|
||||
|
||||
private void StopMatchButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
App.Game.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,12 @@ namespace YJMPD_UWP.Views
|
||||
ReadyCheck.Visibility = Visibility.Visible;
|
||||
ReadyButton.IsEnabled = false;
|
||||
|
||||
Task.Delay(TimeSpan.FromMilliseconds(1500));
|
||||
App.Api.Ready();
|
||||
|
||||
App.Navigate(typeof(WaitingView));
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(500));
|
||||
|
||||
App.Game.MoveToWaiting();
|
||||
App.Navigate(typeof(WaitingView), "Waiting on other players...");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,9 +119,9 @@
|
||||
<Compile Include="Model\PhotoHandler.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ViewModels\AboutVM.cs" />
|
||||
<Compile Include="ViewModels\GameVM.cs" />
|
||||
<Compile Include="ViewModels\MainPageVM.cs" />
|
||||
<Compile Include="ViewModels\MatchVM.cs" />
|
||||
<Compile Include="ViewModels\MainPageVM.cs" />
|
||||
<Compile Include="ViewModels\GameVM.cs" />
|
||||
<Compile Include="ViewModels\PhotoVM.cs" />
|
||||
<Compile Include="ViewModels\ScoreVM.cs" />
|
||||
<Compile Include="ViewModels\SettingsVM.cs" />
|
||||
@@ -130,12 +130,12 @@
|
||||
<Compile Include="Views\AboutView.xaml.cs">
|
||||
<DependentUpon>AboutView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\GameView.xaml.cs">
|
||||
<DependentUpon>GameView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\MatchView.xaml.cs">
|
||||
<DependentUpon>MatchView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\GameView.xaml.cs">
|
||||
<DependentUpon>GameView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\PhotoView.xaml.cs">
|
||||
<DependentUpon>PhotoView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -196,11 +196,11 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="Views\GameView.xaml">
|
||||
<Page Include="Views\MatchView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\MatchView.xaml">
|
||||
<Page Include="Views\GameView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
|
||||
Reference in New Issue
Block a user