Skip to content

Commit

Permalink
finetuning
Browse files Browse the repository at this point in the history
  • Loading branch information
Martijn Groeneveldt committed Oct 26, 2018
1 parent 370a6fd commit d302410
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions GoldRush/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Board
private int amountOfCarts = 1;
private Random random;
public WaterQuay quay { get; set; }
public int Score { get; private set; }
public int Score { get; private set; } = 0;
public WaterLink FirstRiver { get; set; }

public Track TrackEnd { get; private set; }
Expand Down Expand Up @@ -71,7 +71,7 @@ public bool HasAddedAShip()
{
return false;
}
if(random.Next(1, 2) ==1)
if(random.Next(1, 10) == 1)
{
Ship newShip = new Ship(FirstRiver);
FirstRiver.Occupant = newShip;
Expand Down
16 changes: 15 additions & 1 deletion GoldRush/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Game : IObservable<GameData>
public Board board { get; set; }
public InputController InputController { get; set; } = new InputController();
private Timer timer;
private Boolean isGameEnded;
private bool isGameEnded;
private View.ObserverList<IObserver<GameData>, GameData> ObserverList = new View.ObserverList<IObserver<GameData>, GameData>();

public void Play()
Expand All @@ -25,6 +25,7 @@ public void Play()

this.timer = new Timer(1000);
timer.Elapsed += OnTimedEvent;
timer.Elapsed += DecreaseTimerInterval;
timer.AutoReset = true;
timer.Enabled = true;
timer.Start();
Expand Down Expand Up @@ -99,5 +100,18 @@ public IDisposable Subscribe(IObserver<GameData> observer)
ObserverList.Add(observer);
return ObserverList;
}
private void DecreaseTimerInterval(Object source, ElapsedEventArgs e)
{
var interval = NewTimerMilisecondsTime( this.timer.Interval);
// Create a minimum.
if (interval < 50)
interval = 50;
this.timer.Interval = this.timer.Interval;
}
private double NewTimerMilisecondsTime(double Time)
{
const double PowerTo = 13 / 10;
return 1000 - Math.Ceiling(Math.Pow(Time, PowerTo));
}
}
}
5 changes: 4 additions & 1 deletion GoldRush/View/EndGameView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ namespace GoldRush.View
{
class EndGameView : IRenderable
{
public int Score { get;set;}
public void Render()
{
Console.Clear();
Console.Write(
"####################\n" +
" The game has ended.\n"
" The game has ended.\n" +
" Your score was: {0}",
Score
);
}
}
Expand Down
6 changes: 5 additions & 1 deletion GoldRush/View/MainViewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public void OnNext(GameData value)
{
if (value.IsGameEnded)
{
new EndGameView().Render();
new EndGameView
{
Score = value.score
}
.Render();
return;
}
View.Board = _viewStringsFactory.GetDisplayLines(value.Game);
Expand Down
Binary file added view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d302410

Please sign in to comment.