Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Martijn Groeneveldt committed Oct 26, 2018
2 parents 778ff2c + f5b5914 commit 370a6fd
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 36 deletions.
39 changes: 34 additions & 5 deletions GoldRush/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Board(int score, Track TrackEnd, List<Hangar> hangars, Dictionary<char, T
{
Score = score;
this.quay = quay;
TrackEnd = TrackEnd;
this.TrackEnd = TrackEnd;
Hangars = hangars;
Turnouts = turnouts;
random = new Random();
Expand All @@ -37,6 +37,13 @@ public Board(int score, Track TrackEnd, List<Hangar> hangars, Dictionary<char, T
FirstRiver.Occupant = new Ship(FirstRiver);
Ships.Add(FirstRiver.Occupant);
_GameBoard = GameBoard;
foreach (var t in turnouts)
{
for (int i = random.Next(1, 3); i >= 0; i--)
{
t.Value.ChangeDirection();
}
}
}

public bool HasAddedACart()
Expand All @@ -51,7 +58,7 @@ public bool HasAddedACart()
{
while(AddedCart == null)
{
ChosenHangar = Hangars[random.Next(0, 1)];
ChosenHangar = Hangars[random.Next(0, 3)];
AddedCart = ChosenHangar.AddCart();
}
Carts.Add(AddedCart);
Expand Down Expand Up @@ -79,8 +86,21 @@ public void MoveCarts()
}
public void MoveShips()
{
if(Ships.Count > 0)
if (Ships.Count > 0)
{
Ships.ForEach(s => s.Move());
Ships.RemoveAll(s => s.location == null);
}
}

public void removeTrackEndCart()
{
if(TrackEnd.Occupant != null)
{
Cart removeableCart = TrackEnd.Occupant;
Carts.Remove(removeableCart);
TrackEnd.Occupant = null;
}
}

public void KeepScore()
Expand All @@ -97,15 +117,15 @@ public void KeepScore()
{
return;
}
if(!quay.track.Occupant.isLoaded)
if(!(quay.track.Occupant.isLoaded))
{
Score += 1;
}
}

public double GetTimeInterval()
{
double result = 5000;
double result = 2000;
for(int i = Score%10; i > 0; i--)
{
result -= 100;
Expand All @@ -131,5 +151,14 @@ public void ToggleTurnout(Char c)
t.ChangeDirection();
}
}

public void ExchangeLoad()
{
if (quay.Occupant == null || quay.track.Occupant == null)
return;
Ship ship = quay.Occupant;
Cart cart = quay.track.Occupant;
ship.ExchangeLoad(cart);
}
}
}
7 changes: 5 additions & 2 deletions GoldRush/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ private void OnTimedEvent(Object source, ElapsedEventArgs e)
public void Tick()
{
//Tel het aantal intervallen met elkaar op en verklein het interval daarmee
board.ExchangeLoad();
board.KeepScore();
board.MoveShips();
board.removeTrackEndCart();
try
{
board.MoveCarts();
Expand All @@ -75,9 +78,8 @@ public void Tick()

board.HasAddedACart();
board.HasAddedAShip();
board.KeepScore();
board.AdjustAmountOfCarts();
//timer.Interval = board.GetTimeInterval();
timer.Interval = board.GetTimeInterval();
}

public void Render()
Expand All @@ -88,6 +90,7 @@ public void Render()
{
Game = board.GetGameBoard(),
IsGameEnded = isGameEnded,
score = board.Score
});
}

Expand Down
1 change: 1 addition & 0 deletions GoldRush/GameData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public struct GameData
{
public HasNext[][] Game;
public bool IsGameEnded;
public int score;
}
}
12 changes: 0 additions & 12 deletions GoldRush/IsEnd.cs

This file was deleted.

21 changes: 9 additions & 12 deletions GoldRush/Ship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ public override bool canMove()
{
if(location is WaterQuay)
{
Cart Occupant = ((WaterQuay)location).track.Occupant;
if(Occupant != null)
{
ExchangeLoad(Occupant);
}
if (isLoaded)
{
return true;
}
return false;
}
else
{
WaterLink nextWaterLink = (WaterLink)location.Next;
if(nextWaterLink == null)
{
//TODO remove ship
location.Occupant = null;
this.location = null;
return false;
}
if(nextWaterLink.Occupant == null)
Expand All @@ -40,12 +41,6 @@ public override bool canMove()
}
return false;
}

if(load == 8)
{
return true;
}
return false;
}

public override void Move()
Expand All @@ -64,6 +59,8 @@ public void ExchangeLoad(Cart Occupant)
{
Occupant.isLoaded = false;
load++;
if (load == 8)
isLoaded = true;
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions GoldRush/Turnout2To1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ public override void ChangeDirection()
if (isGoingUp)
{
isGoingUp = false;
previous = optionUp;
previous.Next = this;
optionUp.Next = this;
optionDown.Next = null;
}
else
{
isGoingUp = true;
previous = optionDown;
previous.Next = this;
optionDown.Next = this;
optionUp.Next = null;
}
}
Expand Down
2 changes: 2 additions & 0 deletions GoldRush/View/MainView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace GoldRush.View
class MainView : IRenderable
{
public string[] Board { get; set; }
public int score;
public void Render()
{
// TODO: modify the displaybuffer instead of rewriting everything.
Expand Down Expand Up @@ -39,6 +40,7 @@ private void DrawFooter()
{
// TODO: Can be refactored to a file read.
Console.Write(
"##### Score " + score + " #####\n"+
"###################\n" +
" Use Q W E R T to\n" +
" Change the carts path\n"
Expand Down
1 change: 1 addition & 0 deletions GoldRush/View/MainViewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void OnNext(GameData value)
return;
}
View.Board = _viewStringsFactory.GetDisplayLines(value.Game);
View.score = value.score;
View.Render();
}
}
Expand Down
2 changes: 1 addition & 1 deletion GoldRush/levels/Level.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
Ξ>>^.>⌄.>^...
......S>s....
Ξ>>>>>^.>>>⌄.
۝۝۝۝۝۝۝۝<<<.
۝۝۝۝۝۝۝۝<<<<.

0 comments on commit 370a6fd

Please sign in to comment.