├── .gitignore ├── App.xaml ├── App.xaml.cs ├── Assets ├── LockScreenLogo.scale-200.png ├── SplashScreen.scale-200.png ├── Square150x150Logo.scale-200.png ├── Square44x44Logo.scale-200.png ├── Square44x44Logo.targetsize-24_altform-unplated.png ├── StoreLogo.png ├── Wide310x150Logo.scale-200.png ├── dino.png ├── gamegrid.png └── ninjacat.png ├── Baddie.cs ├── CODE_OF_CONDUCT.md ├── Game.csproj ├── Game.csproj.user ├── Game.sln ├── LICENSE ├── MainPage.cs ├── MainPage.xaml ├── Maze.cs ├── Package.appxmanifest ├── Player.cs ├── Properties ├── AssemblyInfo.cs └── Default.rd.xml ├── README.md ├── SECURITY.md └── gamegridpic.png /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | -------------------------------------------------------------------------------- /App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.InteropServices.WindowsRuntime; 6 | using Windows.ApplicationModel; 7 | using Windows.ApplicationModel.Activation; 8 | using Windows.Foundation; 9 | using Windows.Foundation.Collections; 10 | using Windows.UI.Xaml; 11 | using Windows.UI.Xaml.Controls; 12 | using Windows.UI.Xaml.Controls.Primitives; 13 | using Windows.UI.Xaml.Data; 14 | using Windows.UI.Xaml.Input; 15 | using Windows.UI.Xaml.Media; 16 | using Windows.UI.Xaml.Navigation; 17 | 18 | namespace Game 19 | { 20 | /// 21 | /// Provides application-specific behavior to supplement the default Application class. 22 | /// 23 | sealed partial class App : Application 24 | { 25 | /// 26 | /// Initializes the singleton application object. This is the first line of authored code 27 | /// executed, and as such is the logical equivalent of main() or WinMain(). 28 | /// 29 | public App() 30 | { 31 | this.InitializeComponent(); 32 | this.Suspending += OnSuspending; 33 | } 34 | 35 | /// 36 | /// Invoked when the application is launched normally by the end user. Other entry points 37 | /// will be used such as when the application is launched to open a specific file. 38 | /// 39 | /// Details about the launch request and process. 40 | protected override void OnLaunched(LaunchActivatedEventArgs e) 41 | { 42 | Frame rootFrame = Window.Current.Content as Frame; 43 | 44 | // Do not repeat app initialization when the Window already has content, 45 | // just ensure that the window is active 46 | if (rootFrame == null) 47 | { 48 | // Create a Frame to act as the navigation context and navigate to the first page 49 | rootFrame = new Frame(); 50 | 51 | rootFrame.NavigationFailed += OnNavigationFailed; 52 | 53 | if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) 54 | { 55 | //TODO: Load state from previously suspended application 56 | } 57 | 58 | // Place the frame in the current Window 59 | Window.Current.Content = rootFrame; 60 | } 61 | 62 | if (e.PrelaunchActivated == false) 63 | { 64 | if (rootFrame.Content == null) 65 | { 66 | // When the navigation stack isn't restored navigate to the first page, 67 | // configuring the new page by passing required information as a navigation 68 | // parameter 69 | rootFrame.Navigate(typeof(MainPage), e.Arguments); 70 | } 71 | // Ensure the current window is active 72 | Window.Current.Activate(); 73 | } 74 | } 75 | 76 | /// 77 | /// Invoked when Navigation to a certain page fails 78 | /// 79 | /// The Frame which failed navigation 80 | /// Details about the navigation failure 81 | void OnNavigationFailed(object sender, NavigationFailedEventArgs e) 82 | { 83 | throw new Exception("Failed to load Page " + e.SourcePageType.FullName); 84 | } 85 | 86 | /// 87 | /// Invoked when application execution is being suspended. Application state is saved 88 | /// without knowing whether the application will be terminated or resumed with the contents 89 | /// of memory still intact. 90 | /// 91 | /// The source of the suspend request. 92 | /// Details about the suspend request. 93 | private void OnSuspending(object sender, SuspendingEventArgs e) 94 | { 95 | var deferral = e.SuspendingOperation.GetDeferral(); 96 | //TODO: Save application state and stop any background activity 97 | deferral.Complete(); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Win2DMazeGame/016e830c6f5b8ccf84ef74b3fdba384c5e3cad25/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Win2DMazeGame/016e830c6f5b8ccf84ef74b3fdba384c5e3cad25/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Win2DMazeGame/016e830c6f5b8ccf84ef74b3fdba384c5e3cad25/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Win2DMazeGame/016e830c6f5b8ccf84ef74b3fdba384c5e3cad25/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Win2DMazeGame/016e830c6f5b8ccf84ef74b3fdba384c5e3cad25/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Win2DMazeGame/016e830c6f5b8ccf84ef74b3fdba384c5e3cad25/Assets/StoreLogo.png -------------------------------------------------------------------------------- /Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Win2DMazeGame/016e830c6f5b8ccf84ef74b3fdba384c5e3cad25/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /Assets/dino.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Win2DMazeGame/016e830c6f5b8ccf84ef74b3fdba384c5e3cad25/Assets/dino.png -------------------------------------------------------------------------------- /Assets/gamegrid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Win2DMazeGame/016e830c6f5b8ccf84ef74b3fdba384c5e3cad25/Assets/gamegrid.png -------------------------------------------------------------------------------- /Assets/ninjacat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Win2DMazeGame/016e830c6f5b8ccf84ef74b3fdba384c5e3cad25/Assets/ninjacat.png -------------------------------------------------------------------------------- /Baddie.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Graphics.Canvas; 2 | using Microsoft.Graphics.Canvas.UI.Xaml; 3 | 4 | 5 | namespace Game 6 | { 7 | 8 | // This class contains the code that draws and moves the "badguy" image. 9 | 10 | public class Baddie 11 | { 12 | public int x; 13 | public int y; 14 | private int direction; 15 | 16 | // Call this to set starting position and the direction that the baddie will start going in. 17 | public Baddie(int start_x, int start_y, int start_direction) 18 | { 19 | x = start_x; 20 | y = start_y; 21 | direction = start_direction; 22 | } 23 | 24 | public void Move(int speed, Maze gamemaze) 25 | { 26 | // Update the position of the baddie depending on the direction. 27 | // We can change the speed to make them faster or slower, and so 28 | // make the game harder or easier. 29 | 30 | switch (direction) 31 | { 32 | case 1: y -= speed; break; 33 | case 2: x += speed; break; 34 | case 4: y += speed; break; 35 | case 8: x -= speed; break; 36 | 37 | default: break; 38 | } 39 | 40 | // Test to see if the baddie is in the middle of a square in the maze, and then we can decide 41 | // to change direction or not. 42 | 43 | if ((x % 64 == 0) && (y % 64 == 0)) 44 | { 45 | 46 | // Map the screen co-ordinates to the map co-ordinates 47 | // (the screen is 1024 by 1024, the maze data is 16 by 16) 48 | 49 | int mx = (x / 64); 50 | int my = (y / 64); 51 | 52 | // Get the number that tells us the possible directions at this tile 53 | int possible_directions = gamemaze.GetTile(my, mx); 54 | 55 | // Define the opposite value to the current direction, 56 | // because we don't want to double back 57 | 58 | int opposite_directon = 0; 59 | 60 | if (direction == 1) opposite_directon = 4; 61 | if (direction == 2) opposite_directon = 8; 62 | if (direction == 4) opposite_directon = 1; 63 | if (direction == 8) opposite_directon = 2; 64 | 65 | int new_direction = 1; 66 | 67 | // Pick a new direction that is both possible AND not doubling back. 68 | do 69 | { 70 | do 71 | { 72 | 73 | new_direction = gamemaze.NextDirection(); 74 | } while ((new_direction & possible_directions) == 0); 75 | } while (new_direction == opposite_directon); 76 | 77 | direction = new_direction; 78 | 79 | } 80 | } 81 | 82 | // Draw the baddie. Needs a reference to the canvas 83 | public void Draw(CanvasDrawEventArgs args, CanvasBitmap dino) 84 | { 85 | args.DrawingSession.DrawImage(dino, x + 4, y + 4); 86 | 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | -------------------------------------------------------------------------------- /Game.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x86 7 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9} 8 | AppContainerExe 9 | Properties 10 | Game 11 | Game 12 | en-US 13 | UAP 14 | 10.0.18362.0 15 | 10.0.17763.0 16 | 14 17 | 512 18 | {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 19 | true 20 | false 21 | 22 | 23 | true 24 | bin\x86\Debug\ 25 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 26 | ;2008 27 | full 28 | x86 29 | false 30 | prompt 31 | true 32 | 33 | 34 | bin\x86\Release\ 35 | TRACE;NETFX_CORE;WINDOWS_UWP 36 | true 37 | ;2008 38 | pdbonly 39 | x86 40 | false 41 | prompt 42 | true 43 | true 44 | 45 | 46 | true 47 | bin\ARM\Debug\ 48 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 49 | ;2008 50 | full 51 | ARM 52 | false 53 | prompt 54 | true 55 | 56 | 57 | bin\ARM\Release\ 58 | TRACE;NETFX_CORE;WINDOWS_UWP 59 | true 60 | ;2008 61 | pdbonly 62 | ARM 63 | false 64 | prompt 65 | true 66 | true 67 | 68 | 69 | true 70 | bin\ARM64\Debug\ 71 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 72 | ;2008 73 | full 74 | ARM64 75 | false 76 | prompt 77 | true 78 | true 79 | 80 | 81 | bin\ARM64\Release\ 82 | TRACE;NETFX_CORE;WINDOWS_UWP 83 | true 84 | ;2008 85 | pdbonly 86 | ARM64 87 | false 88 | prompt 89 | true 90 | true 91 | 92 | 93 | true 94 | bin\x64\Debug\ 95 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 96 | ;2008 97 | full 98 | x64 99 | false 100 | prompt 101 | true 102 | 103 | 104 | bin\x64\Release\ 105 | TRACE;NETFX_CORE;WINDOWS_UWP 106 | true 107 | ;2008 108 | pdbonly 109 | x64 110 | false 111 | prompt 112 | true 113 | true 114 | 115 | 116 | PackageReference 117 | 118 | 119 | 120 | App.xaml 121 | 122 | 123 | 124 | MainPage.xaml 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | Designer 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | MSBuild:Compile 151 | Designer 152 | 153 | 154 | MSBuild:Compile 155 | Designer 156 | 157 | 158 | 159 | 160 | 6.2.10 161 | 162 | 163 | 1.25.0 164 | 165 | 166 | 167 | 14.0 168 | 169 | 170 | 177 | -------------------------------------------------------------------------------- /Game.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 30f105c9-681e-420b-a277-7c086ead8a4e 5 | true 6 | 7 | -------------------------------------------------------------------------------- /Game.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30204.135 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Game", "Game.csproj", "{D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|ARM = Debug|ARM 11 | Debug|ARM64 = Debug|ARM64 12 | Debug|x64 = Debug|x64 13 | Debug|x86 = Debug|x86 14 | Release|ARM = Release|ARM 15 | Release|ARM64 = Release|ARM64 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Debug|ARM.ActiveCfg = Debug|ARM 21 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Debug|ARM.Build.0 = Debug|ARM 22 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Debug|ARM.Deploy.0 = Debug|ARM 23 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Debug|ARM64.ActiveCfg = Debug|ARM64 24 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Debug|ARM64.Build.0 = Debug|ARM64 25 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Debug|ARM64.Deploy.0 = Debug|ARM64 26 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Debug|x64.ActiveCfg = Debug|x64 27 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Debug|x64.Build.0 = Debug|x64 28 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Debug|x64.Deploy.0 = Debug|x64 29 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Debug|x86.ActiveCfg = Debug|x86 30 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Debug|x86.Build.0 = Debug|x86 31 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Debug|x86.Deploy.0 = Debug|x86 32 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Release|ARM.ActiveCfg = Release|ARM 33 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Release|ARM.Build.0 = Release|ARM 34 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Release|ARM.Deploy.0 = Release|ARM 35 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Release|ARM64.ActiveCfg = Release|ARM64 36 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Release|ARM64.Build.0 = Release|ARM64 37 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Release|ARM64.Deploy.0 = Release|ARM64 38 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Release|x64.ActiveCfg = Release|x64 39 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Release|x64.Build.0 = Release|x64 40 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Release|x64.Deploy.0 = Release|x64 41 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Release|x86.ActiveCfg = Release|x86 42 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Release|x86.Build.0 = Release|x86 43 | {D4F1EBEC-ECCE-4C6F-9B31-4CCEC38908A9}.Release|x86.Deploy.0 = Release|x86 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {77E9013A-583D-4F2F-AA20-76F95C209134} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /MainPage.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Graphics.Canvas; 2 | using Microsoft.Graphics.Canvas.UI.Xaml; 3 | using System; 4 | using System.Threading.Tasks; 5 | using Windows.UI; 6 | using Windows.UI.Xaml; 7 | using Windows.UI.Xaml.Controls; 8 | using Windows.UI.Xaml.Input; 9 | 10 | 11 | namespace Game 12 | { 13 | public sealed partial class MainPage : Page 14 | { 15 | // The Maze Game has three components: 16 | // 1. The player - an image which the player can move around the maze, eating dots. Player.cs 17 | // 2. The Baddies - an image which roams the maze, and will catch the player if close enough. Baddie.cs 18 | // 3. The Maze - an array which describes the maze. 19 | 20 | // Graphics are displayed using the Win2D library, which provides support for quickly drawing images and other shapes. 21 | 22 | // A timer fires 15 times a second and on every 'tick' the player and baddies are updated. 23 | 24 | // The Canvas object defined in mainpage.xaml also displays a single bitmap create in a paint program that renders 25 | // the maze. The player and baddies objects, and the dots in the maze the player must eat, are displayed on 26 | // top of this single image. The Maze object itself consists of an array of 16 by 16 numbers, each which tells 27 | // the moving objects which directions they are free to move. 28 | 29 | 30 | // The graphics for the player and the baddies 31 | CanvasBitmap ninjacat, dino; 32 | 33 | public DispatcherTimer Timer { get; private set; } 34 | 35 | // Declare the player object and three baddies 36 | private Player player = new Player(512, 512 - 64, 0); 37 | 38 | private Baddie Ringo = new Baddie(64, 64, 2); 39 | private Baddie George = new Baddie(64, 64, 2); 40 | private Baddie Paul = new Baddie(64, 64, 4); 41 | 42 | 43 | // Create the maze object 44 | private Maze GameMaze = new Maze(); 45 | 46 | 47 | public MainPage() 48 | { 49 | this.InitializeComponent(); 50 | 51 | // Set the score to zero - the game doesn't currently check that all dots are eaten! 52 | // But if this is 122, the player has cleared the level. 53 | player.Score = 0; 54 | 55 | // Start the timer going - this will update the display and move the characters around. 56 | // When the baddies catch the player, the timer is stopped. In a real game, the "game over" 57 | // message would be displayed. 58 | 59 | this.Timer = new DispatcherTimer(); 60 | this.Timer.Interval = new TimeSpan(0, 0, 0, 0, 15); 61 | this.Timer.Tick += timer_Tick; 62 | this.Timer.Start(); 63 | 64 | } 65 | 66 | 67 | 68 | private void timer_Tick(object sender, object e) 69 | { 70 | // Draw everything by making the canvas "invalid", triggering the redraw. 71 | canvas.Invalidate(); 72 | } 73 | 74 | 75 | 76 | // This is the Draw method used by the CanvasControl. The CanvasControl gives us the ability 77 | // to quickly draw images, other shapes and text. 78 | void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args) 79 | { 80 | // The screen is cleared, so we need to redraw everything (except the background, which is a separate image) 81 | 82 | // First, draw the dots the player needs to collect 83 | 84 | for (int y = 0; y < 16; y++) 85 | for (int x = 0; x < 16; x++) 86 | { 87 | if ((GameMaze.GetTile(y, x) & 16) != 0) 88 | { 89 | args.DrawingSession.DrawEllipse(32 + x * 64, 32 + y * 64, 4, 4, Colors.Blue, 8); 90 | } 91 | } 92 | 93 | 94 | 95 | // Move the player to the new position, draw it. 96 | // Do the same thing for the baddies. 97 | 98 | player.Move(GameMaze); 99 | player.Draw(args, ninjacat); 100 | 101 | Ringo.Move(4, GameMaze); // The first parameter is the speed - it must be 1, 2, 4,8, 16 or 32 102 | George.Move(8, GameMaze); 103 | Paul.Move(8, GameMaze); 104 | 105 | Ringo.Draw(args, dino); 106 | George.Draw(args, dino); 107 | Paul.Draw(args, dino); 108 | 109 | 110 | // Now draw the score 111 | 112 | args.DrawingSession.DrawText("Score: " + player.Score.ToString("0000"), 400, 20, Colors.Yellow); 113 | 114 | 115 | // Check to see if the player has been caught by a dino. 116 | // The simplest way is to check that the distance between 117 | // them is smaller than a specific threshold. 118 | 119 | if (player.Check(Ringo) || player.Check(George) || player.Check(Paul)) 120 | { 121 | // Player has been caught! 122 | // For now, just stop the timer. 123 | Timer.Stop(); 124 | } 125 | } 126 | 127 | 128 | 129 | // This is a method called by the CanvasControl, and we use it to call the routine that loads the graphics 130 | // for the player and baddies. 131 | private void canvas_CreateResources(CanvasControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args) 132 | { 133 | args.TrackAsyncAction(CreateResourcesAsync(sender).AsAsyncAction()); 134 | } 135 | 136 | // Load the images. Only needs doing once, when the CanvasControl is initialized. 137 | private async Task CreateResourcesAsync(CanvasControl sender) 138 | { 139 | ninjacat = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///Assets/ninjacat.png")); 140 | dino = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///Assets/dino.png")); 141 | } 142 | 143 | // The CanvasControl calls this method when the keyboard is pressed. 144 | private void canvas_KeyDown(object sender, KeyRoutedEventArgs e) 145 | { 146 | int d = 0; 147 | 148 | switch (e.Key) 149 | { 150 | case Windows.System.VirtualKey.W: d = 1; break; 151 | case Windows.System.VirtualKey.D: d = 2; break; 152 | case Windows.System.VirtualKey.S: d = 4; break; 153 | case Windows.System.VirtualKey.A: d = 8; break; 154 | default: d = 0; break; 155 | } 156 | 157 | player.NewDirection = d; 158 | 159 | } 160 | 161 | // A 'clean up' method required by the CanvasConrol 162 | void Page_Unloaded(object sender, RoutedEventArgs e) 163 | { 164 | this.canvas.RemoveFromVisualTree(); 165 | this.canvas = null; 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /MainPage.xaml: -------------------------------------------------------------------------------- 1 |  11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Maze.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | 4 | namespace Game 5 | { 6 | /// 7 | /// Maze Game page. 8 | /// 9 | /// 10 | 11 | public class Maze 12 | { 13 | // This array has a number for each tile in the maze. 14 | // To simplify the movement of the baddies, we use a 15 | // number that contains all the directions it's possible to 16 | // move toward. For example, if on this tile it's possible 17 | // to move UP and RIGHT, we use the number 3 (1 for UP + 2 for RIGHT). 18 | // A value of 0 is kept for the walls. 19 | 20 | // We use the Binary AND operator (&) to check directions and the presence of a dot. 21 | // Using & makes it easy to test for the presence of one or more values. For example, 22 | // if we encode the possible directions at one tile with the number 9, we can 23 | // check with AND 2 to see if Left (2) is allowed, AND Down (4) and so on. 24 | // BTW, when using Binary AND a non-Zero value means true. 25 | 26 | // Maze direction values: 27 | // 0 = A wall. 28 | // 1 = Up, 2 = Right, 4 = Down, 8 = Left 29 | // 16 = dot 30 | // e.g. a value of 19 means the player can move up, to the right and there is a dot present. 31 | 32 | 33 | // A random number object used to pick bad guy directions. 34 | Random rnd = new Random(); 35 | 36 | // The maze - an array of numbers describing the possible directions (and a dot) 37 | private int[,] maze = 38 | { 39 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 40 | {0,6,10,14,10,10,14,10,10,14,10,10,14,10,12,0}, 41 | {0,5,0,5,0,0,5,0,0,5,0,0,5,0,5,0}, 42 | {0,7,10,11,12,0,7,10,10,13,0,6,11,10,13,0}, 43 | 44 | {0,5,0,0,5,0,5,0,0,5,0,5,0,0,5,0}, 45 | {0,5,0,0,7,10,11,10,10,11,10,13,0,0,5,0}, 46 | {0,5,0,0,5,0,0,0,0,0,0,5,0,0,5,0}, 47 | {0,3,14,10,13,0,6,10,10,12,0,7,10,14,9,0}, 48 | 49 | {0,0,5,0,5,0,5,0,0,5,0,5,0,5,0,0}, 50 | {0,0,3,10,15,10,9,0,0,3,10,15,10,9,0,0}, 51 | {0,0,0,0,5,0,0,0,0,0,0,5,0,0,0,0}, 52 | {0,6,10,14,11,14,10,10,10,10,14,11,14,10,12,0}, 53 | 54 | {0,5,0,5,0,5,0,0,0,0,5,0,5,0,5,0}, 55 | {0,5,0,5,0,5,0,0,0,0,5,0,5,0,5,0}, 56 | {0,3,10,11,10,11,10,10,10,10,11,10,11,10,9,0}, 57 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 58 | }; 59 | 60 | public Maze() 61 | { 62 | // Add dots to the maze for the player to collect. 63 | // We do this by adding 16 to and non-zero value already present 64 | // in the maze. There are 122 dots in the current maze. 65 | 66 | for (int y = 0; y < 16; y++) 67 | for (int x = 0; x < 16; x++) 68 | { 69 | int tile = maze[y, x]; 70 | 71 | // If a tile isn't a wall, it can contain a dot. 72 | if (tile != 0) 73 | { 74 | maze[y, x] = tile + 16; 75 | } 76 | } 77 | } 78 | 79 | public int GetTile(int a, int b) 80 | { 81 | return maze[a, b]; 82 | } 83 | 84 | public void SetTile(int a, int b, int newTile) 85 | { 86 | maze[a, b] = newTile; 87 | } 88 | 89 | // This code provides our baddies with a new direction value, hopefully one that prevents them from 90 | // getting stuck in an infinite loop. This is something that needs improvement - and also is where 91 | // you could put code that makes the baddies specifically follow the player. 92 | 93 | private readonly int[] sequence = { 1, 2, 4, 8, 4, 2, 1, 1, 2, 2, 4, 4, 8, 8, 1, 2, 4, 8, 8, 4, 4, 2, 2, 1, 1, 2, 2, 4, 4, 8, 2, 4, 8, 4, 1, 2 }; 94 | private int sequenceCounter = 0; 95 | 96 | public int NextDirection() 97 | { 98 | sequenceCounter += 1; 99 | if (sequenceCounter >= sequence.Length) sequenceCounter = rnd.Next(sequence.Length); 100 | return sequence[sequenceCounter]; 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | Game 18 | jken 19 | Assets\StoreLogo.png 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 34 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Player.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Graphics.Canvas; 2 | using Microsoft.Graphics.Canvas.UI.Xaml; 3 | 4 | 5 | namespace Game 6 | { 7 | 8 | // This class controls and draws the player object. 9 | public class Player 10 | { 11 | private int x, y, direction; 12 | 13 | public int Score { get; set; } 14 | public int NewDirection { get; set; } 15 | 16 | // Call this method to set starting position and the direction that the baddie will start going in. 17 | public Player(int start_x, int start_y, int start_direction) 18 | { 19 | x = start_x; 20 | y = start_y; 21 | direction = start_direction; 22 | } 23 | 24 | 25 | public void Move(Maze gamemaze) 26 | { 27 | switch (direction) 28 | { 29 | case 1: y -= 8; break; 30 | case 2: x += 8; break; 31 | case 4: y += 8; break; 32 | case 8: x -= 8; break; 33 | 34 | default: break; 35 | } 36 | 37 | // Test to see if the player is in the middle of a square in the maze, and then we can decide 38 | // to change direction or not depending on whether a key is pressed or if they've run into a wall. 39 | // It turns out this is a little trickier than you might expect - the player might be trying to 40 | // turn in a direction that isn't good just yet, but will be soon - so we need to keep trying without 41 | // stopping them until it's good to go. 42 | 43 | if ((x % 64 == 0) && (y % 64 == 0)) 44 | { 45 | // Map the screen co-ordinates to the map co-ordinates 46 | // (the screen is 1024 by 1024, the maze data is 16 by 16) 47 | 48 | int mx = (x / 64); 49 | int my = (y / 64); 50 | 51 | // Check for a dot being eaten 52 | if ((gamemaze.GetTile(my, mx) & 16) != 0) 53 | { 54 | gamemaze.SetTile(my, mx, gamemaze.GetTile(my, mx) - 16); 55 | Score += 1; 56 | } 57 | 58 | 59 | // Get the number that tells us the possible directions at this tile 60 | int possible_directions = gamemaze.GetTile(my, mx); 61 | 62 | int current_direction = direction; 63 | 64 | 65 | // If the player has pressed a key, let's consider that a request to change direction. 66 | // We can check if it's possible because we know for any tile what directions are available. 67 | // If the player cannot change in that direction, they'll just stop. 68 | 69 | if (NewDirection == 0) 70 | { 71 | // The player hasn't requested a change in direction 72 | // So let's see if they can move in the current direction 73 | 74 | if ((direction & possible_directions) == 0) 75 | { 76 | // No, the player would hit a wall. Better stop! 77 | direction = 0; 78 | } 79 | } 80 | else // The player has requested a change in direction 81 | { 82 | // Is it ok? 83 | if ((NewDirection & possible_directions) != 0) 84 | { 85 | // yes, it's allowed 86 | direction = NewDirection; 87 | } 88 | else 89 | { 90 | // No, player can't change direction in that way, but we can't just stop 91 | // because the current direction might be good. 92 | 93 | if ((current_direction & possible_directions) == 0) 94 | { 95 | // No, carrying on isn't allowed! Better stop! 96 | direction = 0; 97 | } 98 | } 99 | } 100 | } 101 | } 102 | 103 | // Draw the player. Needs a reference to the canvas 104 | public void Draw(CanvasDrawEventArgs args, CanvasBitmap ninjacat) 105 | { 106 | args.DrawingSession.DrawImage(ninjacat, x, y); 107 | } 108 | 109 | public bool Check(Baddie badguy) 110 | { 111 | // Check the distance between the player and a Baddie 112 | if ((((x - badguy.x) * (x - badguy.x)) < 256) && (((y - badguy.y) * (y - badguy.y)) < 256)) 113 | { 114 | return true; 115 | } 116 | else 117 | { 118 | return false; 119 | } 120 | } 121 | 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Game")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Game")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Version information for an assembly consists of the following four values: 18 | // 19 | // Major Version 20 | // Minor Version 21 | // Build Number 22 | // Revision 23 | // 24 | // You can specify all the values or you can default the Build and Revision Numbers 25 | // by using the '*' as shown below: 26 | // [assembly: AssemblyVersion("1.0.*")] 27 | [assembly: AssemblyVersion("1.0.0.0")] 28 | [assembly: AssemblyFileVersion("1.0.0.0")] 29 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /Properties/Default.rd.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Win2D-MazeGame 2 | 3 | The skeleton of a classic maze chase game for Windows 10, written in C# and using Win2D. 4 | 5 | ![](gamegridpic.png) 6 | 7 | ## Introduction 8 | 9 | If you’re looking for a project to keep the kids happy, or a way to re-create the 1980’s home computer boom, you might want to try writing your own classic video game. 10 | 11 | A programming library for Windows 10 called [Win2D](https://github.com/Microsoft/Win2D) is perfect for drawing and animating the kind of graphics that defined early video games. 12 | 13 | This project uses Win2D to create the start of a maze chase game – one that you can use as the basis for your own game. It's written in C#, and comes complete with some basic graphics to start you off. 14 | 15 | ## Requirements 16 | 17 | This game was written on Windows 10 (Build 2004) using Visual Studio 2019. 18 | 19 | ## Instructions 20 | 21 | 1. Install the tools - you will need [Visual Studio](https://visualstudio.microsoft.com/). The free Community edition will work perfectly. 22 | 2. Download the project from this repo. The simplest way to do this is to select Download ZIP from the green CODE button, and extract all the files. 23 | 3. Load it into Visual Studio. You can double-click on game.sln to do this. 24 | 4. Build it and try it out! Make sure the target is set to x86 (in most cases) and press F5. The controls are W, A, S and D. 25 | 5. Adapt, improve and learn! 26 | 27 | ## Details 28 | 29 | This is a simple maze chase / eat the dots game that demonstrates using Win2D to display and move images. 30 | 31 | ### Maze.cs 32 | 33 | This class defines the maze object. The game screen is a 1024 by 1024 canvas object, and while a single bitmap contains the maze image, behind the scenes the maze 34 | is a 16 by 16 array of integers with each element defining the possible directions the player or baddie can move in. When a player or baddie reaches a new tile in the maze (they move pixel by pixel, but only when line up with a tile perfectly can they change direction) they look at the maze data for that location. The data tells them which directions they can move in, and also if there is a "dot" present. 35 | 36 | ### Player.cs 37 | 38 | The player object contains the code that draws and moves the player's game character. The most involved code defines the action to take when the player's sprite reaches a tile junction, depending on what the keys (W, A, S or D) are being held down and what directions are available. 39 | 40 | ### Baddie.cs 41 | 42 | The baddie object chases the player around the maze. In fact, the baddie currently picks a direction at random (as long as it's not doubling back), so this is a great opportunity to add some intelligence to make the baddie pick a direction that will move them closer to the player. As with the player object, a new direction is only considered when the sprite is at the tile junction. Baddies can move at different speeds, as long as the speeds are a power of 2. There are three baddies currently defined, and more can be added by copying the code already present in the MainPage.cs class. 43 | 44 | ### MainPage.cs 45 | 46 | This is the "code behind" file for the MainPage.xaml file which defines the Win2D canvas object (where graphics can be drawn) and also sets up keyboard input events. The purpose of the code in MainPage.cs is to load the image files, and also create the player and baddie objects, and then move them around the screen based on a timer. The test for collisions is also performed in this class. 47 | 48 | ## Suggestions for features 49 | 50 | Game states need to be defined: for example, these could be "get ready", "game running", and "game over". 51 | 52 | Lives need to be implemented. Traditionally you get three lives. 53 | 54 | At the moment nothing happens when the baddies get too close to the player - other than the game stops moving. This is where you would "lose a life" and go to a game over screen. Likewise, nothing happens when the player has passed over all the dots. You might want the next level to have more baddies, or baddies which move faster or both. 55 | 56 | As mentioned, the baddies are not smart and pick random directions. Adding some code that picks a direction closer to the player will make for a much more challenging game. 57 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd). 40 | 41 | -------------------------------------------------------------------------------- /gamegridpic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Win2DMazeGame/016e830c6f5b8ccf84ef74b3fdba384c5e3cad25/gamegridpic.png --------------------------------------------------------------------------------