From c9743b0b59048ff73662d85baea92dce29f87a69 Mon Sep 17 00:00:00 2001 From: DreadMaks <92202592+DreadMaks@users.noreply.github.com> Date: Fri, 13 Jan 2023 20:15:22 +0300 Subject: [PATCH] Create Assignment to classes.cs --- Assignment to classes.cs | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Assignment to classes.cs diff --git a/Assignment to classes.cs b/Assignment to classes.cs new file mode 100644 index 0000000..97199a0 --- /dev/null +++ b/Assignment to classes.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; + +class GameCharacter +{ + // class variables + public static string Race = "human"; + public static string ClassType = "warrior"; + public int Level = 1; + + // instance variables + public string Name { get; set; } + + // constructors + public GameCharacter(string name, int level) + { + Name = name; + Level = level; + } + + public GameCharacter(string name) + { + Name = name; + } + + // methods + public void SetRace(string race) + { + Race = race; + } + + public void SetClassType(string classType) + { + ClassType = classType; + } + + public void DisplayCharacterInfo() + { + Console.WriteLine("Name: " + Name); + Console.WriteLine("Race: " + Race); + Console.WriteLine("Class: " + ClassType); + Console.WriteLine("Level: " + Level); + } +} + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Enter character name: "); + string name = Console.ReadLine(); + + List classTypes = new List { "Warrior", "Mage", "Rogue" }; + Console.WriteLine("Select a class: "); + for (int i = 0; i < classTypes.Count; i++) + { + Console.WriteLine($"{i + 1}. {classTypes[i]}"); + } + int classChoice = int.Parse(Console.ReadLine()); + string classType = classTypes[classChoice - 1]; + + List races = new List { "Human", "Elf", "Orc" }; + Console.WriteLine("Select a race: "); + for (int i = 0; i < races.Count; i++) + { + Console.WriteLine($"{i + 1}. {races[i]}"); + } + int raceChoice = int.Parse(Console.ReadLine()); + string race = races[raceChoice - 1]; + + GameCharacter gameCharacter = new GameCharacter(name); + gameCharacter.SetRace(race); + gameCharacter.SetClassType(classType); + gameCharacter.DisplayCharacterInfo(); + } +}