Skip to content

Commit

Permalink
Refactored the repo to emphasize the NetworkHelper library (renamed f…
Browse files Browse the repository at this point in the history
…rom P2PHelper) and make QuizGame a Demo App. Also updated QuizGame to allow multiple games on the same network.
  • Loading branch information
msatranjr committed May 2, 2016
1 parent b9f7547 commit 7ac7f7a
Show file tree
Hide file tree
Showing 103 changed files with 1,271 additions and 2,907 deletions.
File renamed without changes.
23 changes: 13 additions & 10 deletions QuizGameClient/App.xaml.cs → DemoApps/QuizGame/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,10 @@
// ---------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace QuizGameClient
Expand Down Expand Up @@ -99,6 +89,19 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}

// Enable back navigation.
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, ea) =>
{
Frame frame = Window.Current.Content as Frame;

if (frame != null && frame.CanGoBack && ea.Handled == false)
{
ea.Handled = true;
frame.GoBack();
}
};

// Ensure the current window is active
Window.Current.Activate();
}
Expand Down
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public abstract class BindableBase : INotifyPropertyChanged
/// <summary>
/// Multicast event for property change notifications.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged = delegate { };
public event PropertyChangedEventHandler PropertyChanged;

/// <summary>
/// Checks if a property already matches a desired value. Sets the property and
Expand All @@ -58,7 +58,7 @@ protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] String
if (object.Equals(storage, value)) return false;

storage = value;
this.OnPropertyChanged(propertyName);
OnPropertyChanged(propertyName);
return true;
}

Expand All @@ -70,7 +70,7 @@ protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] String
/// that support <see cref="CallerMemberNameAttribute"/>.</param>
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
File renamed without changes.
32 changes: 13 additions & 19 deletions View/TestView.xaml → DemoApps/QuizGame/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,26 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<Page
<Page
x:Class="QuizGameClient.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:QuizGame"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:View="using:QuizGame.View"
x:Class="QuizGame.TestView"
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>

<View:HostView Grid.RowSpan="2"/>
<View:ClientView Grid.Column="1" x:Name="ClientView"/>
<View:ClientView Grid.Column="1" Grid.Row="1" x:Name="ClientView2"/>
<!-- Title Panel -->
<StackPanel Grid.Row="0" Margin="19,0,0,0">
<TextBlock Text="QUIZGAME" Style="{ThemeResource TitleTextBlockStyle}" Margin="0,12,0,0"/>
<TextBlock Text="Make a selection" Margin="0,-6.5,0,26.5" Style="{ThemeResource HeaderTextBlockStyle}" CharacterSpacing="{ThemeResource PivotHeaderItemCharacterSpacing}"/>
</StackPanel>

<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Name="CreateGame" Content="Start a new game" Click="OnCreateGameClicked"/>
<Button Name="JoinGame" Content="Join a game" Click="OnJoinGameClicked"/>
</StackPanel>
</Grid>

</Page>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
// THE SOFTWARE.
// ---------------------------------------------------------------------------------

using QuizGame.ViewModel;
using Windows.UI.Xaml.Controls;

namespace QuizGameClient
Expand All @@ -32,7 +31,16 @@ public sealed partial class MainPage : Page
public MainPage()
{
this.InitializeComponent();
this.ClientView.ViewModel = ViewModelLocator.ClientViewModel;
}

private void OnCreateGameClicked(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
this.Frame.Navigate(typeof(QuizGame.GamePage));
}

private void OnJoinGameClicked(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
this.Frame.Navigate(typeof(QuizGame.PlayerPage));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
// THE SOFTWARE.
// ---------------------------------------------------------------------------------

using Windows.UI.Xaml.Controls;
using NetworkHelper;
using System;

namespace QuizGameHost
namespace QuizGame.Model
{
public sealed partial class MainPage : Page
public class GameHost
{
public MainPage()
{
this.InitializeComponent();
}
public string Name { get; set; }
public Guid Id { get; set; }
public ICommunicationChannel CommChannel { get; set; }
}
}
23 changes: 18 additions & 5 deletions Model/HostCommand.cs → DemoApps/QuizGame/Model/PlayerMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,31 @@
// THE SOFTWARE.
// ---------------------------------------------------------------------------------

using System.Runtime.Serialization;

namespace QuizGame.Model
{
public class HostCommand
/// <summary>
/// A message that is from a player to the game host.
/// </summary>
public class PlayerMessage
{
public Command Command { get; set; }
/// <summary>
/// The command requested by the player.
/// </summary>
public PlayerMessageType Command { get; set; }
/// <summary>
/// The name of the player that sent the command.
/// </summary>
public string PlayerName { get; set; }
/// <summary>
/// The index of the Question.Options list that the player chose.
/// </summary>
public int QuestionAnswer { get; set; }
}

public enum Command
/// <summary>
/// An enumeration representing the available commands that players can send to the game host.
/// </summary>
public enum PlayerMessageType
{
Join = 0,
Leave,
Expand Down
28 changes: 12 additions & 16 deletions Model/Question.cs → DemoApps/QuizGame/Model/Question.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,25 @@
// ---------------------------------------------------------------------------------

using System.Collections.Generic;
using System.Runtime.Serialization;

namespace QuizGame.Model
{

public class HostMessage
{
public HostMessageType Type { get; set; }
public bool IsJoined { get; set; }
public Question Question { get; set; }
}


public enum HostMessageType
{
Question,
JoinStatus
};

/// <summary>
/// A quiz question that is displayed in the game host UI and sent to players.
/// </summary>
public class Question
{
/// <summary>
/// The question text.
/// </summary>
public string Text { get; set; }
/// <summary>
/// List of available answers.
/// </summary>
public List<string> Options { get; set; }
/// <summary>
/// The index of the correct answer in Options.
/// </summary>
public int CorrectAnswerIndex { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Identity Name="001cb8da-c4c1-420d-a25f-bbffa3756477" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="001cb8da-c4c1-420d-a25f-bbffa3756477" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>QuizGameClient</DisplayName>
<DisplayName>QuizGame</DisplayName>
<PublisherDisplayName>Microsoft Corporation</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
Expand All @@ -15,7 +15,7 @@
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="QuizGameClient.App">
<uap:VisualElements DisplayName="QuizGameClient" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="QuizGameClient" BackgroundColor="transparent">
<uap:VisualElements DisplayName="QuizGame" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="QuizGame" BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png">
</uap:DefaultTile>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("QuizGameHost")]
[assembly: AssemblyTitle("QuizGame")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyProduct("QuizGameHost")]
[assembly: AssemblyProduct("QuizGame")]
[assembly: AssemblyCopyright("Copyright (c) 2015 Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{E6EEB9AE-9164-4C96-AEAE-BF87E30C1F3F}</ProjectGuid>
<OutputType>AppContainerExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>QuizGameClient</RootNamespace>
<AssemblyName>QuizGameClient</AssemblyName>
<RootNamespace>QuizGame</RootNamespace>
<AssemblyName>QuizGame</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
Expand Down Expand Up @@ -92,55 +92,26 @@
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Common\BindableBase.cs">
<Link>Common\BindableBase.cs</Link>
</Compile>
<Compile Include="..\Common\DelegateCommand.cs">
<Link>Common\DelegateCommand.cs</Link>
</Compile>
<Compile Include="..\Model\ClientCommunicator.cs">
<Link>Model\ClientCommunicator.cs</Link>
</Compile>
<Compile Include="..\Model\Game.cs">
<Link>Model\Game.cs</Link>
</Compile>
<Compile Include="..\Model\HostCommand.cs">
<Link>Model\HostCommand.cs</Link>
</Compile>
<Compile Include="..\Model\HostCommunicator.cs">
<Link>Model\HostCommunicator.cs</Link>
</Compile>
<Compile Include="..\Model\IClientCommunicator.cs">
<Link>Model\IClientCommunicator.cs</Link>
</Compile>
<Compile Include="..\Model\IGame.cs">
<Link>Model\IGame.cs</Link>
</Compile>
<Compile Include="..\Model\IHostCommunicator.cs">
<Link>Model\IHostCommunicator.cs</Link>
</Compile>
<Compile Include="..\Model\Question.cs">
<Link>Model\Question.cs</Link>
</Compile>
<Compile Include="..\ViewModel\ClientViewModel.cs">
<Link>ViewModel\ClientViewModel.cs</Link>
</Compile>
<Compile Include="..\ViewModel\HostViewModel.cs">
<Link>ViewModel\HostViewModel.cs</Link>
</Compile>
<Compile Include="..\ViewModel\ViewModelLocator.cs">
<Link>ViewModel\ViewModelLocator.cs</Link>
</Compile>
<Compile Include="..\View\ClientView.xaml.cs">
<Link>View\ClientView.xaml.cs</Link>
</Compile>
<Compile Include="Common\BindableBase.cs" />
<Compile Include="Common\DelegateCommand.cs" />
<Compile Include="Model\GameHost.cs" />
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Model\PlayerMessage.cs" />
<Compile Include="Model\Question.cs" />
<Compile Include="ViewModel\GameViewModel.cs" />
<Compile Include="ViewModel\PlayerViewModel.cs" />
<Compile Include="View\GamePage.xaml.cs">
<DependentUpon>GamePage.xaml</DependentUpon>
</Compile>
<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="View\PlayerPage.xaml.cs">
<DependentUpon>PlayerPage.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
Expand All @@ -162,20 +133,23 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="..\View\ClientView.xaml">
<Link>View\ClientView.xaml</Link>
<Generator>MSBuild:Compile</Generator>
<Page Include="View\GamePage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="View\PlayerPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\P2PHelper\P2PHelper.csproj">
<ProjectReference Include="..\..\NetworkHelper\NetworkHelper.csproj">
<Project>{737229ae-d189-4765-b37b-31a326996a70}</Project>
<Name>P2PHelper</Name>
<Name>NetworkHelper</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
Expand Down
Loading

0 comments on commit 7ac7f7a

Please sign in to comment.