Refactor Clicker game
This commit is contained in:
parent
13af9e740b
commit
6e80cd34cc
55
Emne 3/ClickerOOP/ClickerOOP/ClickerGame.cs
Normal file
55
Emne 3/ClickerOOP/ClickerOOP/ClickerGame.cs
Normal file
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
6
Emne 3/ClickerOOP/ClickerOOP/ICommand.cs
Normal file
6
Emne 3/ClickerOOP/ClickerOOP/ICommand.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace ClickerOOP;
|
||||
|
||||
public interface ICommand
|
||||
{
|
||||
public void Run();
|
||||
}
|
|
@ -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++;
|
||||
}
|
||||
}
|
||||
var game = new ClickerGame(0,1,1);
|
||||
game.Run();
|
||||
|
|
Loading…
Reference in a new issue