commit e66c6a1c0e17424284c2c73c4d6355ae0a046366 Author: George Date: Thu Jan 26 14:51:14 2023 +0300 Первоначальное размещение файлов проекта new file: compile.cmd new file: game.cs new file: game.exe new file: gameCore.cs new file: gameModel.cs new file: share.jpg diff --git a/compile.cmd b/compile.cmd new file mode 100644 index 0000000..5683270 --- /dev/null +++ b/compile.cmd @@ -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 \ No newline at end of file diff --git a/game.cs b/game.cs new file mode 100644 index 0000000..1163022 --- /dev/null +++ b/game.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/game.exe b/game.exe new file mode 100644 index 0000000..492376d Binary files /dev/null and b/game.exe differ diff --git a/gameCore.cs b/gameCore.cs new file mode 100644 index 0000000..0e7942e --- /dev/null +++ b/gameCore.cs @@ -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); + } + } + } +} \ No newline at end of file diff --git a/gameModel.cs b/gameModel.cs new file mode 100644 index 0000000..81fba7e --- /dev/null +++ b/gameModel.cs @@ -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; + } + } +} diff --git a/share.jpg b/share.jpg new file mode 100644 index 0000000..f16809e Binary files /dev/null and b/share.jpg differ