Разработка игрового приложения «Противостояние» на основе объектно-ориентированного подхода по дисциплине «Технологии программирования»

Заказать уникальную курсовую работу
Тип работы: Курсовая работа
Предмет: Программирование
  • 25 25 страниц
  • 2 + 2 источника
  • Добавлена 18.01.2024
1 496 руб.
  • Содержание
  • Часть работы
  • Список литературы
СОДЕРЖАНИЕ
Введение. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
I. Описание логики сражения. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3
1.1. Форты. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3
1.2. Боевые единицы («юниты»). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3
1.3. Исследования. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4
II. Описание логики работы программы. . . . . . . . . . . . . . . . . . . . . . .4
2.1. Запуск программы. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4
2.2. Захват форта и уничтожение игрока. . . . . . . . . . . . . . . . . . . . . . . . . .7
2.3. Окончание игры. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8
Заключение. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Список литературы . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Приложение. Листинг программы. . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Form1.cs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10
PlayerDataDialog.cs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
Фрагмент для ознакомления

Graphics.FillEllipse(HPBrush, 54 + 50 * X, 28 + 50 * Y, 8, 8);e.Graphics.DrawEllipse(DPen, 54 + 50 * X, 28 + 50 * Y, 8, 8); } break; case 2:e.Graphics.DrawRectangle(DPen, 34 + 50 * X, 24 + 50 * Y, 22, 42);e.Graphics.DrawRectangle(DPen, 24 + 50 * X, 34 + 50 * Y, 42, 22);e.Graphics.FillRectangle(PBrush, 35 + 50 * X, 35 + 50 * Y, 21, 21);e.Graphics.FillRectangle(PBrush, 35 + 50 * X, 25 + 50 * Y, 21, 9); if (CurrentHealth >= 2) e.Graphics.FillRectangle(PBrush, 25 + 50 * X, 35 + 50 * Y, 9, 21); if (CurrentHealth >= 3) e.Graphics.FillRectangle(PBrush, 35 + 50 * X, 57 + 50 * Y, 21, 9); if (CurrentHealth >= 4) e.Graphics.FillRectangle(PBrush, 57 + 50 * X, 35 + 50 * Y, 9, 21); if (CurrentHealth >= 5) {e.Graphics.FillEllipse(HPBrush, 41 + 50 * X, 25 + 50 * Y, 8, 8);e.Graphics.DrawEllipse(DPen, 41 + 50 * X, 25 + 50 * Y, 8, 8); } if (CurrentHealth >= 6) {e.Graphics.FillEllipse(HPBrush, 25 + 50 * X, 41 + 50 * Y, 8, 8);e.Graphics.DrawEllipse(DPen, 25 + 50 * X, 41 + 50 * Y, 8, 8); } if (CurrentHealth >= 7) {e.Graphics.FillEllipse(HPBrush, 41 + 50 * X, 57 + 50 * Y, 8, 8);e.Graphics.DrawEllipse(DPen, 41 + 50 * X, 57 + 50 * Y, 8, 8); } if (CurrentHealth >= 8) {e.Graphics.FillEllipse(HPBrush, 57 + 50 * X, 41 + 50 * Y, 8, 8);e.Graphics.DrawEllipse(DPen, 57 + 50 * X, 41 + 50 * Y, 8, 8); } if (CurrentHealth >= 9) { e.Graphics.FillRectangle(PBrush, 39 + 50 * X, 39 + 50 * Y, 12, 12);e.Graphics.DrawRectangle(DPen, 39 + 50 * X, 39 + 50 * Y, 12, 12); } if (CurrentHealth >= 10) {e.Graphics.FillEllipse(HPBrush, 41 + 50 * X, 41 + 50 * Y, 8, 8);e.Graphics.DrawEllipse(DPen, 41 + 50 * X, 41 + 50 * Y, 8, 8); } break; } } internal static bool IsFree(List UnitList, int UX, int UY) { return UnitAtXY(UnitList, UX, UY) == null; } internal static BattleUnitUnitAtXY(List UnitList, int UX, int UY) { for (int x = 0; x < UnitList.Count; x++) if (UnitList[x].X == UX && UnitList[x].Y == UY) return UnitList[x]; return null; } } internal class BattleFort { internal static int[] ConstructionCosts;CombatPlayer Owner; internal int X; internal int Y;intConstructionPoints;intConstructedUnitClass; //1 = Circle; 2 = Square; 3 = Crossint Index; string Name; bool RecentlyCaptured; static BattleFort() {ConstructionCosts = new int[3];ConstructionCosts[0] = 15;ConstructionCosts[1] = 22;ConstructionCosts[2] = 32; } internal BattleFort(CombatPlayerFOwner, int FX, int FY, intCIndex, string FName) { Owner = FOwner; X = FX; Y = FY;ConstructionPoints = 0;ConstructedUnitClass = 0; Index = CIndex; Name = FName;RecentlyCaptured = false; } internal bool IsOwner(CombatPlayer CP) { return Owner == CP; } internal void Construct(List UnitList, Random R) { if(RecentlyCaptured) {RecentlyCaptured = false; return; }ConstructionPoints += (int)(R.Next(1, 7) * Owner.PowerModifier); if (ConstructionPoints >= ConstructionCosts[ConstructedUnitClass]) { if (!BattleUnit.IsFree(UnitList, X, Y)) return;ConstructionPoints = 0;BattleUnitNewUnit = new BattleUnit(Owner, ConstructedUnitClass, X, Y);UnitList.Add(NewUnit);intMaxUnitLevel = Owner.TechLevel >= 3 ?3 :Owner.TechLevel;ConstructedUnitClass = R.Next(0, MaxUnitLevel); } } internal void Capture(CombatPlayer CP) {RecentlyCaptured = true; Owner = CP;ConstructionPoints = 0;SPlayer.SoundLocation = "Capture.wav";SPlayer.Play();MessageBox.Show(CP.PlayerName + " captures " + this.Name + "!", "Fort Capture", MessageBoxButtons.OK, MessageBoxIcon.Information); } internal static BattleFortFortAtXY(BattleFort[] FortList, int FX, int FY) { for (int x = 0; x < FortList.Length; x++) if (FortList[x].X == FX && FortList[x].Y == FY) return FortList[x]; return null; } internal void Draw(PaintEventArgs e, Pen DPen) {intIndexX = Index % 2;intIndexY = Index / 2;SolidBrushPBrush = new SolidBrush(CCB(Owner.UnitColor, -0.25f));e.Graphics.DrawRectangle(DPen, 22 + 50 * X, 22 + 50 * Y, 46, 46);e.Graphics.FillRectangle(PBrush, 23 + 50 * X, 23 + 50 * Y, 45, 45);e.Graphics.DrawRectangle(DPen, 20 + 150 * IndexX, 552 + 100 * IndexY, 100, 68);e.Graphics.DrawRectangle(DPen, 20 + 150 * IndexX, 570 + 100 * IndexY, 100, 50);e.Graphics.DrawRectangle(DPen, 70 + 150 * IndexX, 570 + 100 * IndexY, 50, 50);e.Graphics.DrawString(Name, new Font("Tahoma", 14), PBrush, 18 + 150 * IndexX, 550 + 100 * IndexY);BattleUnitUnitSample = new BattleUnit(Owner, ConstructedUnitClass, 3 * IndexX, 11 + 2 * IndexY);UnitSample.Draw(e, DPen); string CSTP = ConstructionPoints.ToString() + "/" + ConstructionCosts[ConstructedUnitClass];e.Graphics.DrawString(CSTP, new Font("Tahoma", 11), PBrush, 70 + 150 * IndexX, 585 + 100 * IndexY); } } static System.Media.SoundPlayerSPlayer; static Random RGen;CombatPlayer[] Players;BattleFort[] Forts; List Units; bool BattleFinished; public Form1() {SPlayer = new System.Media.SoundPlayer();RGen = new Random();BattleFinished = false;CombatPlayer.TechLevelRequirements = new int[5]; for (int x = 0; x < 5; x++) CombatPlayer.TechLevelRequirements[x] = 100 + 50 * x;this.Paint += new PaintEventHandler(OnPaint); Players = new CombatPlayer[4];PlayerDataDialog PDD = new PlayerDataDialog();DialogResult DR = PDD.ShowDialog(this); while (DR != DialogResult.OK) { PDD = new PlayerDataDialog(); DR = PDD.ShowDialog(this); }Players[0] = new CombatPlayer(PDD.Player1_Name.Text, Color.Lime, double.Parse(PDD.Player1_Grade.Text));Players[1] = new CombatPlayer(PDD.Player2_Name.Text, Color.HotPink, double.Parse(PDD.Player2_Grade.Text));Players[2] = new CombatPlayer(PDD.Player3_Name.Text, Color.FromArgb(0, 214, 255), double.Parse(PDD.Player3_Grade.Text));Players[3] = new CombatPlayer(PDD.Player4_Name.Text, Color.Gold, double.Parse(PDD.Player4_Grade.Text)); Forts = new BattleFort[4];Forts[0] = new BattleFort(Players[3], 0, 0, 0, "North-West");Forts[1] = new BattleFort(Players[2], 9, 0, 1, "North-East");Forts[2] = new BattleFort(Players[0], 0, 9, 2, "South-West");Forts[3] = new BattleFort(Players[1], 9, 9, 3, "South-East"); Units = new List();SPlayer.SoundLocation = "Start.wav";SPlayer.Play();InitializeComponent(); } void OnPaint(object Sender, PaintEventArgs e) { Pen BlackPen = new Pen(Color.Black, 1);e.Graphics.DrawRectangle(BlackPen, 18, 18, 504, 504);e.Graphics.DrawRectangle(BlackPen, 16, 16, 508, 508); for (int x = 0; x < 10; x++) for (int y = 0; y < 10; y++)e.Graphics.DrawRectangle(BlackPen, 20 + 50 * x, 20 + 50 * y, 50, 50); for (int x = 0; x < 4; x++) Forts[x].Draw(e, BlackPen); for (int x = 0; x < Units.Count; x++) Units[x].Draw(e, BlackPen); for (int x = 0; x < 4; x++) {e.Graphics.DrawRectangle(BlackPen, 320, 552 + 18 * x, 100, 18);e.Graphics.DrawRectangle(BlackPen, 420, 552 + 18 * x, 20, 18);e.Graphics.DrawRectangle(BlackPen, 440, 552 + 18 * x, 80, 18); Players[x].Output(e, 322, 550 + 18 * x); } } private intPlayersRemaining() {int PR = 4; for (int x = 0; x < 4; x++) if (Players[x].IsEliminated) PR -= 1; return PR; } private string GetVictorName() { for (int x = 0; x < 4; x++) if (!Players[x].IsEliminated) return Players[x].PlayerName; return ""; } private void TurnButton_Click(object sender, EventArgs e) { if (BattleFinished) this.Close(); for (int x = 0; x < 4; x++) { if (Players[x].IsEliminated) continue; if (Players[x].HasFort(Forts)) Players[x].DoResearch(RGen); //Player can research if he controls at least one fort for (int y = 0; y < Units.Count; y++) { if(Units[y].IsOwned(Players[x])) { if (Units[y].TryShoot(Units)) continue; //Unit doesn't move if they have made a shotintMoveDir = Units[y].ScanForEnemies(Units, Forts); Units[y].Move(Units, Forts, MoveDir); } }Units.RemoveAll(U => U.Killed); for (int y = 0; y < 4; y++) { if (Players[y].IsEliminated) continue; if (Players[y].HasFort(Forts)) continue; if (Players[y].HasUnit(Units)) continue; Players[y].Eliminate(); } for (int y = 0; y < Forts.Length; y++) if (Forts[y].IsOwner(Players[x])) Forts[y].Construct(Units, RGen); } for (int y = 0; y < Units.Count; y++) Units[y].Heal(); if (PlayersRemaining() <= 1) {SPlayer.SoundLocation = "Victory.wav";SPlayer.Play();MessageBox.Show(GetVictorName() + " conquers the world!", "VICTORY",MessageBoxButtons.OK, MessageBoxIcon.Information);TurnButton.Text = "Exit";BattleFinished = true; } else {SPlayer.SoundLocation = "Turn.wav";SPlayer.Play(); }this.Invalidate(); } }}PlayerDataDialog.csusing System;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceBattleSimulation{publicpartialclassPlayerDataDialog : Form {publicPlayerDataDialog() {InitializeComponent(); }internalvoidCheckInput(object Sender, KeyPressEventArgs e) {if (Char.IsDigit(e.KeyChar)) return;if (e.KeyChar == (char)0x08) return;TextBox TB = (TextBox)Sender;if (e.KeyChar == ',' && TB.Text.Contains(',')) e.Handled = true;elseif (e.KeyChar == ',') return;e.Handled = true; }privatevoidOK_Button_Click(object sender, EventArgs e) {if (Player1_Name.Text == "") return;if (Player1_Grade.Text == "") return;if (Player2_Name.Text == "") return;if (Player2_Grade.Text == "") return;if (Player3_Name.Text == "") return;if (Player3_Grade.Text == "") return;if (Player4_Name.Text == "") return;if (Player4_Grade.Text == "") return;this.DialogResult = DialogResult.OK;this.Close();} }}

Список литературы
I. Хейлсберг А, Витламут С., Голд П., Торгерсен М. Язык программирования C#. Четвертое издание. Санкт-Петербург, изд. «Питер», 2012.
II. Скит Дж. C# для профессионалов Тонкости программирования. Третье издание. Изд. «Вильямс», 2019.