diff --git a/Emne 3/ClickerOOP/ClickerOOP/ClickerGame.cs b/Emne 3/ClickerOOP/ClickerOOP/ClickerGame.cs new file mode 100644 index 0000000..145f1cb --- /dev/null +++ b/Emne 3/ClickerOOP/ClickerOOP/ClickerGame.cs @@ -0,0 +1,55 @@ +namespace ClickerOOP; + +public class ClickerGame : ICommand +{ + public int Points {get; private set;} + public int PointsPerClick {get; private set;} + public int PointsPerClickIncrease {get; private set;} + + public ClickerGame(int points, int pointsPerClick, int pointsPerClickIncrease) + { + Points = points; + PointsPerClick = pointsPerClick; + PointsPerClickIncrease = pointsPerClickIncrease; + } + + public void Run() + { + while (true) + { + Console.Clear(); + Console.WriteLine("Kommandoer:\r\n" + + "- SPACE = klikk (og få poeng)\r\n" + + "- K = kjøp oppgradering \r\nØker poeng per klikk koster 10 poeng\r\n" + + "- S = kjøp superoppgradering øker \"poeng per klikk\" for den vanlige oppgraderingen. koster 100 poeng\r\n" + + "- X = avslutt applikasjonen"); + Console.WriteLine($"Du har {Points} poeng."); + Console.WriteLine("Trykk tast for ønsket kommando."); + var command = Console.ReadKey().KeyChar; + if (command == 'x'){ Exit(); } + else if (command == ' ') { Click(); } + else if (command == 'k' && Points >= 10) { Upgrade(); } + else if (command == 's' && Points >= 100) { SuperUpgrade(); } } + } + void Click() + { + Points += PointsPerClick; + } + void Upgrade() + { + Points -= 10; + PointsPerClick += PointsPerClickIncrease; + } + + void SuperUpgrade() + { + Points -= 100; + PointsPerClickIncrease++; + } + void Exit() + { + Environment.Exit(0); + } + + +} \ No newline at end of file diff --git a/Emne 3/ClickerOOP/ClickerOOP/ICommand.cs b/Emne 3/ClickerOOP/ClickerOOP/ICommand.cs new file mode 100644 index 0000000..81d79cd --- /dev/null +++ b/Emne 3/ClickerOOP/ClickerOOP/ICommand.cs @@ -0,0 +1,6 @@ +namespace ClickerOOP; + +public interface ICommand +{ + public void Run(); +} \ No newline at end of file diff --git a/Emne 3/ClickerOOP/ClickerOOP/Program.cs b/Emne 3/ClickerOOP/ClickerOOP/Program.cs index 4c771a0..b48376c 100644 --- a/Emne 3/ClickerOOP/ClickerOOP/Program.cs +++ b/Emne 3/ClickerOOP/ClickerOOP/Program.cs @@ -1,28 +1,4 @@ -int points = 0; -int pointsPerClick = 1; -int pointsPerClickIncrease = 1; +using ClickerOOP; -while (true) -{ - Console.Clear(); - Console.WriteLine("Kommandoer:\r\n" + - "- SPACE = klikk (og få poeng)\r\n" + - "- K = kjøp oppgradering \r\nØker poeng per klikk koster 10 poeng\r\n" + - "- S = kjøp superoppgradering øker \"poeng per klikk\" for den vanlige oppgraderingen. koster 100 poeng\r\n" + - "- X = avslutt applikasjonen"); - Console.WriteLine($"Du har {points} poeng."); - Console.WriteLine("Trykk tast for ønsket kommando."); - var command = Console.ReadKey().KeyChar; - if (command == 'x') Environment.Exit(0); - else if (command == ' ') points += pointsPerClick; - else if (command == 'k' && points >= 10) - { - points -= 10; - pointsPerClick += pointsPerClickIncrease; - } - else if (command == 's' && points >= 100) - { - points -= 100; - pointsPerClickIncrease++; - } -} \ No newline at end of file +var game = new ClickerGame(0,1,1); +game.Run();