Browse Source
			
			
			
			
				
		new file: compile.cmd new file: game.cs new file: game.exe new file: gameCore.cs new file: gameModel.cs new file: share.jpgmaster
commit
					e66c6a1c0e
				
				 6 changed files with 247 additions and 0 deletions
			
			
		@ -0,0 +1,6 @@ | 
				
			|||||||
 | 
					@echo off | 
				
			||||||
 | 
					set CSC=C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%CSC% game.cs gameCore.cs gameModel.cs | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pause | 
				
			||||||
@ -0,0 +1,78 @@ | 
				
			|||||||
 | 
					using System; | 
				
			||||||
 | 
					using TEC.Model; | 
				
			||||||
 | 
					using System.Windows.Forms; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace TEC | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
						public class Program | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							public static void Main() | 
				
			||||||
 | 
							{			 | 
				
			||||||
 | 
								Player[] players = new Player[2]; | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
								Human player1 = new Human(); | 
				
			||||||
 | 
								Alien player2 = new Alien(); | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
								player1.SetPosition(3, 3); | 
				
			||||||
 | 
								player2.SetPosition(55, 3); | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
								players[0] = player1; | 
				
			||||||
 | 
								players[1] = player2; | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
								Game g = new Game(players); | 
				
			||||||
 | 
								g.eventPlayersOnSamePoint += OnRaise_eventPlayersOnSamePoint; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								g.PrintField(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								ConsoleKeyInfo key; | 
				
			||||||
 | 
								bool isReadingKeys = true; | 
				
			||||||
 | 
								while (isReadingKeys) | 
				
			||||||
 | 
								{ | 
				
			||||||
 | 
									key = Console.ReadKey(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (key.Key == ConsoleKey.Q) | 
				
			||||||
 | 
									{ | 
				
			||||||
 | 
										isReadingKeys = false; | 
				
			||||||
 | 
									} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (key.Key == ConsoleKey.RightArrow) | 
				
			||||||
 | 
									{ | 
				
			||||||
 | 
										g.MoveMainPlayer(Game.Movement.Forward); | 
				
			||||||
 | 
									} | 
				
			||||||
 | 
									if (key.Key == ConsoleKey.LeftArrow) | 
				
			||||||
 | 
									{ | 
				
			||||||
 | 
										g.MoveMainPlayer(Game.Movement.Backward); | 
				
			||||||
 | 
									} | 
				
			||||||
 | 
								} | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							static void OnRaise_eventPlayersOnSamePoint() | 
				
			||||||
 | 
							{ | 
				
			||||||
 | 
								//Console.WriteLine("BOOM"); | 
				
			||||||
 | 
								Console.Beep(); | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
								MessageBox.Show( | 
				
			||||||
 | 
									"BOOM", | 
				
			||||||
 | 
									"Что-то случилось", | 
				
			||||||
 | 
									System.Windows.Forms.MessageBoxButtons.YesNo, | 
				
			||||||
 | 
									System.Windows.Forms.MessageBoxIcon.Warning, | 
				
			||||||
 | 
									System.Windows.Forms.MessageBoxDefaultButton.Button2);		 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								System.Windows.Forms.Form frm = new System.Windows.Forms.Form(); | 
				
			||||||
 | 
								frm.FormBorderStyle = FormBorderStyle.FixedDialog; | 
				
			||||||
 | 
								frm.MaximizeBox = false; | 
				
			||||||
 | 
								frm.MinimizeBox = false; | 
				
			||||||
 | 
								frm.StartPosition = FormStartPosition.CenterScreen; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								System.Windows.Forms.Button btn1 = new System.Windows.Forms.Button(); | 
				
			||||||
 | 
								btn1.Width = 80; | 
				
			||||||
 | 
								btn1.Height = 30; | 
				
			||||||
 | 
								btn1.Location = new System.Drawing.Point(10, 10); | 
				
			||||||
 | 
								btn1.Text = "test"; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								frm.Controls.Add(btn1); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								frm.ShowDialog(); | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
									
										Binary file not shown.
									
								
							
						@ -0,0 +1,105 @@ | 
				
			|||||||
 | 
					using System; | 
				
			||||||
 | 
					using TEC.Model; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace TEC | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
						public class Game	 | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							private Player[] players; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public Game(Player[] inputPlayers) | 
				
			||||||
 | 
							{ | 
				
			||||||
 | 
								this.players = inputPlayers; | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public enum Movement | 
				
			||||||
 | 
							{ | 
				
			||||||
 | 
								Up = 1, | 
				
			||||||
 | 
								Down = 2, | 
				
			||||||
 | 
								Forward = 3,  | 
				
			||||||
 | 
								Backward = 4 | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public void MoveMainPlayer(Movement move) | 
				
			||||||
 | 
							{ | 
				
			||||||
 | 
								if (this.players.Length <= 0) { return; } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								int lastPosX = this.players[0].GetPositionX(); | 
				
			||||||
 | 
								int lastPosY = this.players[0].GetPositionY(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (move == Movement.Forward) | 
				
			||||||
 | 
								{ | 
				
			||||||
 | 
									this.players[0].SetPosition(lastPosX + 1, lastPosY); | 
				
			||||||
 | 
								} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (move == Movement.Backward) | 
				
			||||||
 | 
								{ | 
				
			||||||
 | 
									this.players[0].SetPosition(lastPosX - 1, lastPosY); | 
				
			||||||
 | 
								} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								CheckConditions(); | 
				
			||||||
 | 
								PrintField(); | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public delegate void eventPlayersOnSamePointDelegate(); | 
				
			||||||
 | 
							public event eventPlayersOnSamePointDelegate eventPlayersOnSamePoint; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public void CheckConditions() | 
				
			||||||
 | 
							{ | 
				
			||||||
 | 
								if (this.players.Length > 1) | 
				
			||||||
 | 
								{ | 
				
			||||||
 | 
									if (this.players[0].GetPositionX() == this.players[1].GetPositionX() && | 
				
			||||||
 | 
									    this.players[0].GetPositionY() == this.players[1].GetPositionY() ) | 
				
			||||||
 | 
									{ | 
				
			||||||
 | 
										if (this.eventPlayersOnSamePoint != null) | 
				
			||||||
 | 
										{ | 
				
			||||||
 | 
											this.eventPlayersOnSamePoint(); | 
				
			||||||
 | 
										} | 
				
			||||||
 | 
									} | 
				
			||||||
 | 
								} | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public void PrintField() | 
				
			||||||
 | 
							{ | 
				
			||||||
 | 
								Console.Clear(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								string[] lines = new string[20]; | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
								for (int i = 0; i < 20; i++) | 
				
			||||||
 | 
								{ | 
				
			||||||
 | 
									string line = string.Empty; | 
				
			||||||
 | 
									 | 
				
			||||||
 | 
									for (int j = 0; j < 75; j++) | 
				
			||||||
 | 
									{ | 
				
			||||||
 | 
										string c = "."; | 
				
			||||||
 | 
										 | 
				
			||||||
 | 
										foreach(Player player in players) | 
				
			||||||
 | 
										{ | 
				
			||||||
 | 
											if (player.GetPositionX() == j && player.GetPositionY() == i) | 
				
			||||||
 | 
											{ | 
				
			||||||
 | 
												c = "#"; | 
				
			||||||
 | 
												if (player is Alien) | 
				
			||||||
 | 
												{ | 
				
			||||||
 | 
													c = "@"; | 
				
			||||||
 | 
												} | 
				
			||||||
 | 
											}						 | 
				
			||||||
 | 
										} | 
				
			||||||
 | 
										 | 
				
			||||||
 | 
										line = line + c; | 
				
			||||||
 | 
									} | 
				
			||||||
 | 
									 | 
				
			||||||
 | 
									lines[i] = line; | 
				
			||||||
 | 
								} | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
								for (int i = lines.Length - 1; i >= 0; i--) | 
				
			||||||
 | 
								{ | 
				
			||||||
 | 
									Console.WriteLine(lines[i]); | 
				
			||||||
 | 
								} | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
								for(int p = 0; p < players.Length; p++) | 
				
			||||||
 | 
								{ | 
				
			||||||
 | 
									Console.WriteLine("Игрок №" + (p+1) + " - " + players[p].name); | 
				
			||||||
 | 
								}	 | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,58 @@ | 
				
			|||||||
 | 
					using System; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace TEC.Model | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
						public class Human : Player | 
				
			||||||
 | 
						{		 | 
				
			||||||
 | 
							public Human() | 
				
			||||||
 | 
							{ | 
				
			||||||
 | 
								base.name = "Человек"; | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public class Alien : Player | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							public Alien() | 
				
			||||||
 | 
							{ | 
				
			||||||
 | 
								base.name = "Пришелец"; | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public class Player : Ability | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							public string name; | 
				
			||||||
 | 
							int health; | 
				
			||||||
 | 
							int score; | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							int positionX; | 
				
			||||||
 | 
							int positionY; | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							public int GetPositionX() { return positionX; } | 
				
			||||||
 | 
							public int GetPositionY() { return positionY; } | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							public void SetPosition(int x, int y) | 
				
			||||||
 | 
							{ | 
				
			||||||
 | 
								positionX = x; | 
				
			||||||
 | 
								positionY = y; | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public class Ability | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							bool canMoveForward; | 
				
			||||||
 | 
							bool canMoveBackward; | 
				
			||||||
 | 
							bool canFly; | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							public Ability() | 
				
			||||||
 | 
							{			 | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							public Ability(bool canMoveForward, bool canMoveBackward, bool canFly) | 
				
			||||||
 | 
							{ | 
				
			||||||
 | 
								this.canMoveForward = canMoveForward; | 
				
			||||||
 | 
								this.canMoveBackward = canMoveBackward; | 
				
			||||||
 | 
								this.canFly = canFly; | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
| 
		 After Width: | Height: | Size: 16 KiB  | 
					Loading…
					
					
				
		Reference in new issue