Checked out the solution
This commit is contained in:
parent
6e80cd34cc
commit
85921091f9
16
Emne 3/ClickerOOP/ClickerOOP/Click.cs
Normal file
16
Emne 3/ClickerOOP/ClickerOOP/Click.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
namespace ClickerOOP;
|
||||
|
||||
public class Click: ICommand
|
||||
{
|
||||
private ClickerGame _game;
|
||||
public char Character { get; } = ' ';
|
||||
|
||||
public Click(ClickerGame game)
|
||||
{
|
||||
_game = game;
|
||||
}
|
||||
public void Run()
|
||||
{
|
||||
_game.Click();
|
||||
}
|
||||
}
|
|
@ -1,55 +1,30 @@
|
|||
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)
|
||||
public class ClickerGame
|
||||
{
|
||||
public int Points { get; private set; } = 0;
|
||||
private int _pointsPerClick = 1;
|
||||
private int _pointsPerClickIncrease = 1;
|
||||
public void Click()
|
||||
{
|
||||
Points = points;
|
||||
PointsPerClick = pointsPerClick;
|
||||
PointsPerClickIncrease = pointsPerClickIncrease;
|
||||
Points += _pointsPerClick;
|
||||
}
|
||||
|
||||
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()
|
||||
public void Upgrade()
|
||||
{
|
||||
if(Points < 10) return;
|
||||
Points -= 10;
|
||||
PointsPerClick += PointsPerClickIncrease;
|
||||
_pointsPerClick += _pointsPerClickIncrease;
|
||||
|
||||
}
|
||||
|
||||
void SuperUpgrade()
|
||||
public void SuperUpgrade()
|
||||
{
|
||||
if (Points < 100) return;
|
||||
Points -= 100;
|
||||
PointsPerClickIncrease++;
|
||||
}
|
||||
void Exit()
|
||||
{
|
||||
Environment.Exit(0);
|
||||
_pointsPerClickIncrease++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
33
Emne 3/ClickerOOP/ClickerOOP/Commands.cs
Normal file
33
Emne 3/ClickerOOP/ClickerOOP/Commands.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
namespace ClickerOOP;
|
||||
|
||||
public class Commands
|
||||
{
|
||||
private ICommand[] _commands;
|
||||
|
||||
public Commands(ClickerGame game)
|
||||
{
|
||||
_commands = new ICommand[]
|
||||
{
|
||||
new ExitCommand(),
|
||||
new Upgrade(game),
|
||||
new Click(game),
|
||||
new SuperUpgrade(game),
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public void Run(char commandChar)
|
||||
{
|
||||
var command = FindCommand(commandChar);
|
||||
if(command != null) command.Run();
|
||||
}
|
||||
|
||||
private ICommand FindCommand(char commandChar)
|
||||
{
|
||||
foreach (var command in _commands)
|
||||
{
|
||||
if (command.Character == commandChar){ return command; }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
11
Emne 3/ClickerOOP/ClickerOOP/ExitCommand.cs
Normal file
11
Emne 3/ClickerOOP/ClickerOOP/ExitCommand.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
namespace ClickerOOP;
|
||||
|
||||
public class ExitCommand: ICommand
|
||||
{
|
||||
public char Character { get; } = 'X';
|
||||
|
||||
public void Run()
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
|
@ -3,4 +3,5 @@ namespace ClickerOOP;
|
|||
public interface ICommand
|
||||
{
|
||||
public void Run();
|
||||
char Character { get; }
|
||||
}
|
|
@ -1,4 +1,18 @@
|
|||
using ClickerOOP;
|
||||
|
||||
var game = new ClickerGame(0,1,1);
|
||||
game.Run();
|
||||
var game = new ClickerGame();
|
||||
var commands = new Commands(game);
|
||||
|
||||
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 {game.Points} poeng.");
|
||||
Console.WriteLine("Trykk tast for ønsket kommando.");
|
||||
var command = Console.ReadKey().KeyChar;
|
||||
commands.Run(command);
|
||||
}
|
17
Emne 3/ClickerOOP/ClickerOOP/SuperUpgrade.cs
Normal file
17
Emne 3/ClickerOOP/ClickerOOP/SuperUpgrade.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
namespace ClickerOOP;
|
||||
|
||||
public class SuperUpgrade: ICommand
|
||||
{
|
||||
private ClickerGame _game;
|
||||
public char Character { get; } = 'S';
|
||||
|
||||
public SuperUpgrade(ClickerGame game)
|
||||
{
|
||||
_game = game;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
_game.SuperUpgrade();
|
||||
}
|
||||
}
|
18
Emne 3/ClickerOOP/ClickerOOP/Upgrade.cs
Normal file
18
Emne 3/ClickerOOP/ClickerOOP/Upgrade.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
namespace ClickerOOP;
|
||||
|
||||
public class Upgrade: ICommand
|
||||
{
|
||||
private ClickerGame _game;
|
||||
|
||||
public Upgrade(ClickerGame game)
|
||||
{
|
||||
_game = game;
|
||||
}
|
||||
|
||||
public char Character { get; } = 'K';
|
||||
|
||||
public void Run()
|
||||
{
|
||||
_game.Upgrade();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue