From b5dc3a1e681af3c8e423b2433342688710cdb61f Mon Sep 17 00:00:00 2001 From: Geir Okkenhaug Jerstad Date: Mon, 9 Dec 2024 10:46:01 +0100 Subject: [PATCH] Ltt Pokemon + Start student admin --- Emne 3/PokemonMarie/PokemonMarie/PokeGym.cs | 5 +- Emne 3/PokemonMarie/PokemonMarie/PokeShop.cs | 4 +- Emne 3/PokemonMarie/PokemonMarie/Pokemon.cs | 29 ++++++-- .../PokemonMarie/PokemonMarie/PokemonWorld.cs | 67 +++++++++++++++++-- Emne 3/PokemonMarie/PokemonMarie/Program.cs | 2 + Emne 3/PokemonMarie/PokemonMarie/Trainer.cs | 64 +++++++++++++++++- Emne 3/StudentAdmin/StudentAdmin.sln | 16 +++++ Emne 3/StudentAdmin/StudentAdmin/Fag.cs | 15 +++++ Emne 3/StudentAdmin/StudentAdmin/Karakter.cs | 24 +++++++ Emne 3/StudentAdmin/StudentAdmin/Program.cs | 3 + Emne 3/StudentAdmin/StudentAdmin/Student.cs | 27 ++++++++ .../StudentAdmin/StudentAdmin.csproj | 10 +++ 12 files changed, 249 insertions(+), 17 deletions(-) create mode 100644 Emne 3/StudentAdmin/StudentAdmin.sln create mode 100644 Emne 3/StudentAdmin/StudentAdmin/Fag.cs create mode 100644 Emne 3/StudentAdmin/StudentAdmin/Karakter.cs create mode 100644 Emne 3/StudentAdmin/StudentAdmin/Program.cs create mode 100644 Emne 3/StudentAdmin/StudentAdmin/Student.cs create mode 100644 Emne 3/StudentAdmin/StudentAdmin/StudentAdmin.csproj diff --git a/Emne 3/PokemonMarie/PokemonMarie/PokeGym.cs b/Emne 3/PokemonMarie/PokemonMarie/PokeGym.cs index 5bd9ed6..c829ec4 100644 --- a/Emne 3/PokemonMarie/PokemonMarie/PokeGym.cs +++ b/Emne 3/PokemonMarie/PokemonMarie/PokeGym.cs @@ -1,6 +1,7 @@ namespace PokemonMarie; -public class PokeGym +internal class PokeGym { + public Trainer GymTrainer { get; private set; } -} \ No newline at end of file +} diff --git a/Emne 3/PokemonMarie/PokemonMarie/PokeShop.cs b/Emne 3/PokemonMarie/PokemonMarie/PokeShop.cs index caf7243..5256c88 100644 --- a/Emne 3/PokemonMarie/PokemonMarie/PokeShop.cs +++ b/Emne 3/PokemonMarie/PokemonMarie/PokeShop.cs @@ -1,6 +1,6 @@ namespace PokemonMarie; -public class PokeShop +internal class PokeShop { - + public List StoreInventory { get; private set; } } \ No newline at end of file diff --git a/Emne 3/PokemonMarie/PokemonMarie/Pokemon.cs b/Emne 3/PokemonMarie/PokemonMarie/Pokemon.cs index b233b4c..e855ffc 100644 --- a/Emne 3/PokemonMarie/PokemonMarie/Pokemon.cs +++ b/Emne 3/PokemonMarie/PokemonMarie/Pokemon.cs @@ -1,8 +1,29 @@ namespace PokemonMarie; -public class Pokemon +internal class Pokemon { - int Levet { get; set; } - string Type { get; set; } - string Name { get; set; } + public int Level { get; private set; } + public string Type { get; private set; } + public string Name { get; private set; } + public int Health { get; private set; } + public int Strength { get; private set; } + + public Pokemon(int level, string name, string type, int health, int strength) + { + Level = level; + Name = name; + Type = type; + Health = health; + Strength = strength; + } + + public void Fight(Pokemon opponent) + { + opponent.LooseHealth(Strength); + } + + public void LooseHealth(int strength) + { + Health -= strength; + } } \ No newline at end of file diff --git a/Emne 3/PokemonMarie/PokemonMarie/PokemonWorld.cs b/Emne 3/PokemonMarie/PokemonMarie/PokemonWorld.cs index 79fb85b..0bf8ee0 100644 --- a/Emne 3/PokemonMarie/PokemonMarie/PokemonWorld.cs +++ b/Emne 3/PokemonMarie/PokemonMarie/PokemonWorld.cs @@ -2,25 +2,78 @@ using System.ComponentModel.Design; namespace PokemonMarie; -public class PokemonWorld +internal class PokemonWorld { public Trainer MyTrainer { get; set; } - public Pokemon StartPokemon { get; set; } public List WildPokemons { get; set; } + Random Random { get; set; } = new Random(); public PokemonWorld() { - MyTrainer = new Trainer("Ash"); + MyTrainer = new Trainer(this, , , "Ash"); WildPokemons = new List() { - new Pokemon(), - new Pokemon() + new Pokemon(11,"Lucario", "Grass",100,100), + new Pokemon(12,"Bulbasaur", "Grass",100,100), + new Pokemon(13,"Gyarados", "Water",100,100), + new Pokemon(14,"Oshawott", "Water",100,100), + new Pokemon(15,"Grimer", "Mud",100,100), + new Pokemon(16,"Diglett", "Mud",100,100), }; Menu(); } - public void Menu() { - Console.WriteLine("Welcome to Pokemon"); + bool appRunning = true; + while (appRunning) + { + Console.WriteLine("What do you want to do?"); + Console.WriteLine("1. Go to the Wilderness"); + Console.WriteLine("2. Go to the store"); + Console.WriteLine("3. Go to a pokemon gym"); + Console.WriteLine("4. Exit"); + var choice = Console.ReadLine(); + switch (choice) + { + case "1": + WildernessMenu(); + break; + case "2": + MyTrainer.EnterStore(); + break; + case "3": + MyTrainer.GoToGym(); + break; + case "4": + appRunning = false; + break; + default: + Console.WriteLine("Invalid choice"); + break; + } + } + } + + public void WildernessMenu() + { + var foundPokemon = MyTrainer.GoToWilderness(); + Console.WriteLine("You found " + foundPokemon.Name ); + Console.WriteLine("Do you want to (f) fight or (c) catch ?"); + var input = Console.ReadLine(); + if (input.ToLower() == "f") + { + MyTrainer.BattlePokemon(foundPokemon); + } + else + { + MyTrainer.CatchPokemon(foundPokemon); + } + } + + public Pokemon GetRandomPokemon(string type) + { + var pokemon = WildPokemons.Where(pokemon => pokemon.Type == type).ToList(); + var randomIndex = Random.Next(0, pokemon.Count); + return pokemon[randomIndex]; } } \ No newline at end of file diff --git a/Emne 3/PokemonMarie/PokemonMarie/Program.cs b/Emne 3/PokemonMarie/PokemonMarie/Program.cs index 0ea387b..725e50c 100644 --- a/Emne 3/PokemonMarie/PokemonMarie/Program.cs +++ b/Emne 3/PokemonMarie/PokemonMarie/Program.cs @@ -20,4 +20,6 @@ // PokeGym // GymTrainer +using PokemonMarie; +new PokemonWorld(); diff --git a/Emne 3/PokemonMarie/PokemonMarie/Trainer.cs b/Emne 3/PokemonMarie/PokemonMarie/Trainer.cs index 8bac23a..54b0c99 100644 --- a/Emne 3/PokemonMarie/PokemonMarie/Trainer.cs +++ b/Emne 3/PokemonMarie/PokemonMarie/Trainer.cs @@ -2,6 +2,66 @@ namespace PokemonMarie; internal class Trainer { - public List Inventory { get; set; } - public Pokemon Pokemon { get; private set; } + public PokemonWorld MyWorld { get; private set; } + public List Inventory { get; private set; } + public Pokemon StartPokemon { get; private set; } + public string Name { get; private set; } + + public Trainer(PokemonWorld myWorld, List inventory, Pokemon startPokemon, string name) + { + MyWorld = myWorld; + Inventory = new List(); + StartPokemon = new Pokemon(11,"Pikachu", "Lightning",100,100); + Name = name; + } + + public Pokemon GoToWilderness() + { + while (true) + { + Console.WriteLine("Where do you want to go?"); + Console.WriteLine("1. Water"); + Console.WriteLine("2. Grass"); + Console.WriteLine("3. Mud"); + var input = Console.ReadLine(); + + if (input == "1") + { + return MyWorld.GetRandomPokemon("Water"); + } else if (input == "2") + { + return MyWorld.GetRandomPokemon("Grass"); + } + else + { + return MyWorld.GetRandomPokemon("Mud"); + } + } + } + + public void GoToGym() + { + + } + + public void BattlePokemon(Pokemon pokemonToFight) + { + while (pokemonToFight.Health > 0) + { + + } + } + + public void CatchPokemon(Pokemon pokemonToCatch) + { + + } + public void EnterStore() + { + + } + public void BuyItem(string itemType) + { + + } } \ No newline at end of file diff --git a/Emne 3/StudentAdmin/StudentAdmin.sln b/Emne 3/StudentAdmin/StudentAdmin.sln new file mode 100644 index 0000000..e7c8ef1 --- /dev/null +++ b/Emne 3/StudentAdmin/StudentAdmin.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StudentAdmin", "StudentAdmin\StudentAdmin.csproj", "{1BFD45C7-2573-474A-B485-B547D49FA00B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1BFD45C7-2573-474A-B485-B547D49FA00B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1BFD45C7-2573-474A-B485-B547D49FA00B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1BFD45C7-2573-474A-B485-B547D49FA00B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1BFD45C7-2573-474A-B485-B547D49FA00B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Emne 3/StudentAdmin/StudentAdmin/Fag.cs b/Emne 3/StudentAdmin/StudentAdmin/Fag.cs new file mode 100644 index 0000000..a4ae7f0 --- /dev/null +++ b/Emne 3/StudentAdmin/StudentAdmin/Fag.cs @@ -0,0 +1,15 @@ +namespace StudentAdmin; + +internal class Fag +{ + public int FagKode{get;set;} + public string FagNavn{get;set;} + public int AntallStudiePoeng {get;set;} + + public Fag(int fagKode, string fagNavn, int antallStudiePoeng) + { + FagKode = fagKode; + FagNavn = fagNavn; + AntallStudiePoeng = antallStudiePoeng; + } +} \ No newline at end of file diff --git a/Emne 3/StudentAdmin/StudentAdmin/Karakter.cs b/Emne 3/StudentAdmin/StudentAdmin/Karakter.cs new file mode 100644 index 0000000..9590a0b --- /dev/null +++ b/Emne 3/StudentAdmin/StudentAdmin/Karakter.cs @@ -0,0 +1,24 @@ +namespace StudentAdmin; + +internal class Karakter +{ + public Student Student { get; set; } + public Fag Fag { get; set; } + public int KarakterVerdi { get; set; } + + public Karakter(Student student, Fag fag, int karakterVerdi) + { + Student = student; + Fag = fag; + KarakterVerdi = karakterVerdi; + } + + public void SkrivUtInfo(Karakter karakter) + { + Console.WriteLine( + $"Student: {karakter.Student}\n" + + $"Fag: {karakter.Fag}" + + $"Karakter: {karakter.KarakterVerdi}\n" + ); + } +} \ No newline at end of file diff --git a/Emne 3/StudentAdmin/StudentAdmin/Program.cs b/Emne 3/StudentAdmin/StudentAdmin/Program.cs new file mode 100644 index 0000000..e5dff12 --- /dev/null +++ b/Emne 3/StudentAdmin/StudentAdmin/Program.cs @@ -0,0 +1,3 @@ +// See https://aka.ms/new-console-template for more information + +Console.WriteLine("Hello, World!"); \ No newline at end of file diff --git a/Emne 3/StudentAdmin/StudentAdmin/Student.cs b/Emne 3/StudentAdmin/StudentAdmin/Student.cs new file mode 100644 index 0000000..9b7f131 --- /dev/null +++ b/Emne 3/StudentAdmin/StudentAdmin/Student.cs @@ -0,0 +1,27 @@ +namespace StudentAdmin; + +internal class Student +{ + public string Name { get; set; } + public int Age { get; set; } + public string StudieProgram { get; set; } + public int StudentID { get; set; } + + public Student(string name, int age, string studieProgram, int studentID) + { + Name = name; + Age = age; + StudieProgram = studieProgram; + StudentID = studentID; + + } + + public void SkrivUtInfo(Student student) + { + Console.WriteLine($"Student info: " + + $"\nNavn: {student.Name}" + + $"\nAlder: {student.Age}" + + $"\nProgram: {student.StudieProgram}" + ); + } +} \ No newline at end of file diff --git a/Emne 3/StudentAdmin/StudentAdmin/StudentAdmin.csproj b/Emne 3/StudentAdmin/StudentAdmin/StudentAdmin.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/Emne 3/StudentAdmin/StudentAdmin/StudentAdmin.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + +