├── Game Escape From Lab ├── Game Escape From Lab │ ├── App.config │ ├── Enumerations.cs │ ├── Player.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Program.cs │ ├── Game Escape From Lab.csproj │ └── Game.cs └── Game Escape From Lab.sln ├── .gitattributes ├── README.md └── .gitignore /Game Escape From Lab/Game Escape From Lab/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Game Escape From Lab/Game Escape From Lab/Enumerations.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Game_Escape_From_Lab 8 | { 9 | public enum LabirinthSize 10 | { 11 | Small, 12 | Medium, 13 | Large 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Game Escape From Lab/Game Escape From Lab/Player.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Game_Escape_From_Lab 8 | { 9 | public class Player 10 | { 11 | public int LocationX { get; set; } 12 | public int LocationY { get; set; } 13 | public Player(int x, int y) 14 | { 15 | LocationX = x; 16 | LocationY = y; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Game Escape From Lab/Game Escape From Lab.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Game Escape From Lab", "Game Escape From Lab\Game Escape From Lab.csproj", "{0864D576-3D3C-4FCE-8743-C184D3CFBBAC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {0864D576-3D3C-4FCE-8743-C184D3CFBBAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {0864D576-3D3C-4FCE-8743-C184D3CFBBAC}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {0864D576-3D3C-4FCE-8743-C184D3CFBBAC}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {0864D576-3D3C-4FCE-8743-C184D3CFBBAC}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Game Escape From Lab/Game Escape From Lab/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 Escape From Lab")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Game Escape From Lab")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0864d576-3d3c-4fce-8743-c184d3cfbbac")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /Game Escape From Lab/Game Escape From Lab/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace Game_Escape_From_Lab 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | Console.CursorVisible = false; 15 | Console.OutputEncoding = System.Text.Encoding.UTF8; 16 | 17 | do 18 | { 19 | Console.Clear(); 20 | Console.WriteLine("Select Level 1, 2, or 3"); 21 | string level = Console.ReadLine(); 22 | Game lab; 23 | switch (level) 24 | { 25 | case "1": 26 | lab = new Game(LabirinthSize.Small); 27 | break; 28 | case "2": 29 | lab = new Game(LabirinthSize.Medium); 30 | break; 31 | case "3": 32 | lab = new Game(LabirinthSize.Large); 33 | break; 34 | default: 35 | lab = new Game(LabirinthSize.Medium); 36 | break; 37 | } 38 | Console.Clear(); 39 | lab.DrawLife(); 40 | 41 | ThreadStart Player = new ThreadStart(lab.DrawPlayer); 42 | Thread thread = new Thread(Player); 43 | thread.Start(); 44 | lab.DrawLabirinth(); 45 | 46 | if (!lab.playing && lab.timer > 0) 47 | { 48 | Console.SetCursorPosition(lab.Player1.LocationY, lab.Player1.LocationX); 49 | Console.Write("\u263B"); 50 | Console.SetCursorPosition(22, 4); 51 | Console.WriteLine("CONGRATULATIONS YOU WON \u263B"); 52 | } 53 | if (lab.playing && lab.timer <= 0) 54 | { 55 | Console.SetCursorPosition(lab.Player1.LocationY, lab.Player1.LocationX); 56 | Console.Write("\u2628"); 57 | Console.SetCursorPosition(22, 4); 58 | Console.Write("Looser \u2620"); 59 | } 60 | 61 | do 62 | { 63 | Console.SetCursorPosition(22, 5); 64 | Console.WriteLine("Press Enter for Menu"); 65 | } 66 | while (Console.ReadKey().Key != ConsoleKey.Enter); 67 | 68 | Console.Clear(); 69 | Console.WriteLine("Press ENTER for NEW GAME, or ESC to extit game"); 70 | } while (Console.ReadKey().Key == ConsoleKey.Enter); 71 | 72 | 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Game Escape From Lab/Game Escape From Lab/Game Escape From Lab.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {0864D576-3D3C-4FCE-8743-C184D3CFBBAC} 8 | Exe 9 | Properties 10 | Game_Escape_From_Lab 11 | Game Escape From Lab 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Game Escape From Dynamic Labyrinth 2 | 3 | Just a funny game in console. I figured and solved this exercise to better understand threads. You need to escape from labyrinth that opens and closes its doors arbitrary. Choose difficulty(dimensions of labyrinth, lifetime, and opening doors duration) from 1 to 3 and enjoy it :) 4 | 5 | 6 | > Level 1 7 | 8 | ![small](https://cloud.githubusercontent.com/assets/24522089/22444148/38f63502-e75b-11e6-89eb-fb46962836d3.gif) 9 | 10 | 11 | > Level 2 12 | 13 | ![looser](https://cloud.githubusercontent.com/assets/24522089/22404958/977d82ae-e654-11e6-9fdf-7adbfcf2be93.gif) 14 | 15 | 16 | > Level 3 17 | 18 | ![big](https://cloud.githubusercontent.com/assets/24522089/22444224/76859ba6-e75b-11e6-83b4-f52756d64ebe.gif) 19 | 20 | 21 | ### About Threads 22 | 23 | The advantage of threading is the ability to create applications that use more than one thread of execution. For example, a process can have a user interface thread that manages interactions with the user and worker threads that perform other tasks while the user interface thread waits for user input. 24 | This game - example demonstrates how to create and start a thread, and shows the interaction between two threads running simultaneously within the same process. Note that you don't have to stop or free the thread. This is done automatically by the .NET Framework common language runtime. 25 | 26 | 27 | [Reed more about threads](https://msdn.microsoft.com/en-us/library/aa645740(v=vs.71).aspx) 28 | 29 | ```c# 30 | static void Main(string[] args) 31 | { 32 | Console.CursorVisible = false; 33 | Console.OutputEncoding = System.Text.Encoding.UTF8; 34 | 35 | do 36 | { 37 | Console.Clear(); 38 | Console.WriteLine("Select Level 1, 2, or 3"); 39 | string level = Console.ReadLine(); 40 | Game lab; 41 | switch (level) 42 | { 43 | case "1": 44 | lab = new Game(LabirinthSize.Small); 45 | break; 46 | case "2": 47 | lab = new Game(LabirinthSize.Medium); 48 | break; 49 | case "3": 50 | lab = new Game(LabirinthSize.Large); 51 | break; 52 | default: 53 | lab = new Game(LabirinthSize.Medium); 54 | break; 55 | } 56 | Console.Clear(); 57 | lab.DrawLife(); 58 | 59 | ThreadStart Player = new ThreadStart(lab.DrawPlayer); 60 | Thread thread = new Thread(Player); 61 | thread.Start(); 62 | lab.DrawLabirinth(); 63 | 64 | do 65 | { 66 | Console.SetCursorPosition(22, 5); 67 | Console.WriteLine("Press Enter for Menu"); 68 | } 69 | while (Console.ReadKey().Key != ConsoleKey.Enter); 70 | 71 | Console.Clear(); 72 | Console.WriteLine("Press ENTER for NEW GAME, or ESC to extit game"); 73 | } while (Console.ReadKey().Key == ConsoleKey.Enter); 74 | 75 | 76 | } 77 | ``` 78 | 79 | > This game is written on C# 6.0, .NET Framework 4.6 Visual Studio 2015 Comunity Edition 80 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | -------------------------------------------------------------------------------- /Game Escape From Lab/Game Escape From Lab/Game.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace Game_Escape_From_Lab 9 | { 10 | public class Game 11 | { 12 | private int[,] matrix; 13 | private int x; 14 | private int y; 15 | public Player Player1; 16 | public bool playing; 17 | public int timer; 18 | 19 | 20 | // constructor 21 | public Game(LabirinthSize S) 22 | { 23 | switch (S) 24 | { 25 | case LabirinthSize.Small: 26 | x = 5; 27 | y = 7; 28 | break; 29 | case LabirinthSize.Medium: 30 | x = 7; 31 | y = 11; 32 | break; 33 | case LabirinthSize.Large: 34 | x = 9; 35 | y = 21; 36 | break; 37 | default: 38 | Console.WriteLine("Default size !!!"); 39 | x = 10; 40 | y = 21; 41 | break; 42 | } 43 | 44 | matrix = new int[x, y]; 45 | Player1 = new Player(3, 1); 46 | matrix[3, 1] = 5; 47 | playing = true; 48 | timer = x * x * 150; 49 | 50 | for (int i = 0; i < x; i++) 51 | { 52 | for (int j = 0; j < y; j++) 53 | { 54 | if (i == 0 || i == x - 1) 55 | { 56 | matrix[i, j] = 2; 57 | } 58 | else 59 | { 60 | if (j % 2 == 0) matrix[i, j] = 1; 61 | } 62 | } 63 | } 64 | } 65 | 66 | // Methods for gaming 67 | public void DrawLabirinth() 68 | { 69 | while (playing && timer > 0) 70 | { 71 | Random rd = new Random(); 72 | int rdx = rd.Next(1, x - 1); 73 | int rdy0 = rd.Next(1, y - 1); 74 | int rdy = (rdy0 % 2 == 0) ? rdy0 : (rdy0 + 1 != y ? (rdy0 + 1) : (rdy0 - 1)); 75 | matrix[rdx, rdy] = 0; 76 | Draw(); 77 | Thread.Sleep(x * 150); 78 | timer -= 150; 79 | Timer(); 80 | 81 | while (matrix[rdx, rdy] == 5 && playing) 82 | { 83 | Thread.Sleep(x * 150); 84 | timer -= 150; 85 | Timer(); 86 | } 87 | matrix[rdx, rdy] = playing?1:5; 88 | Draw(); 89 | } 90 | } 91 | 92 | public void DrawPlayer() 93 | { 94 | while (playing && timer > 0) 95 | { 96 | Console.SetCursorPosition(20, 10); 97 | ConsoleKey move = Console.ReadKey().Key; 98 | switch (move) 99 | { 100 | case ConsoleKey.LeftArrow: 101 | if (matrix[Player1.LocationX, Player1.LocationY - 1] == 0) 102 | { 103 | matrix[Player1.LocationX, Player1.LocationY--] = 0; 104 | matrix[Player1.LocationX, Player1.LocationY] = 5; 105 | } 106 | break; 107 | case ConsoleKey.RightArrow: 108 | if ((matrix[Player1.LocationX, Player1.LocationY + 1] == 0)) 109 | { 110 | matrix[Player1.LocationX, Player1.LocationY++] = 0; 111 | matrix[Player1.LocationX, Player1.LocationY] = 5; 112 | 113 | if(Player1.LocationY == (y - 1)) 114 | { 115 | playing = false; 116 | break; 117 | } 118 | } 119 | break; 120 | case ConsoleKey.UpArrow: 121 | if (matrix[Player1.LocationX - 1, Player1.LocationY] == 0) 122 | { 123 | matrix[Player1.LocationX--, Player1.LocationY] = 0; 124 | matrix[Player1.LocationX, Player1.LocationY] = 5; 125 | } 126 | break; 127 | case ConsoleKey.DownArrow: 128 | if (matrix[Player1.LocationX + 1, Player1.LocationY] == 0) 129 | { 130 | matrix[Player1.LocationX++, Player1.LocationY] = 0; 131 | matrix[Player1.LocationX, Player1.LocationY] = 5; 132 | } 133 | break; 134 | default: 135 | break; 136 | } 137 | Draw(); 138 | Timer(); 139 | } 140 | } 141 | 142 | 143 | // Plotter 144 | private void Draw() 145 | { 146 | for (int i = 0; i < matrix.GetLength(0); i++) 147 | { 148 | for (int j = 0; j < matrix.GetLength(1); j++) 149 | { 150 | if (matrix[i, j] == 2) 151 | { 152 | Console.SetCursorPosition(j, i); 153 | Console.Write("\u22A0"); 154 | } 155 | if (matrix[i, j] == 1) 156 | { 157 | Console.SetCursorPosition(j, i); 158 | Console.Write("|"); 159 | } 160 | if (matrix[i, j] == 0) 161 | { 162 | Console.SetCursorPosition(j, i); 163 | Console.Write(' '); 164 | } 165 | if (matrix[i, j] == 5) 166 | { 167 | Console.SetCursorPosition(j, i); 168 | Console.Write("\u263B"); 169 | } 170 | } 171 | } 172 | 173 | } 174 | 175 | //Timer 176 | private void Timer() 177 | { 178 | Console.ForegroundColor = ConsoleColor.Red; 179 | Console.SetCursorPosition(22, 3); 180 | Console.WriteLine(new string('|', x * x - timer /150)); 181 | Console.ForegroundColor = ConsoleColor.Gray; 182 | } 183 | 184 | //Life Drawer 185 | public void DrawLife() 186 | { 187 | Console.SetCursorPosition(22, 2); 188 | Console.WriteLine("REMAINING LIFE"); 189 | Console.SetCursorPosition(22, 3); 190 | Console.WriteLine(new string('|', x * x)); 191 | } 192 | } 193 | } 194 | --------------------------------------------------------------------------------