Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NOTE:!!!!!! This is broken code. WIthin Gamession class . the Current…
…Location constructor is incorrect. the line _currentTrader = CurrentLocation.TraderHere is WRONG!! Doing this push to document a bad bug that was not easily seen as debugging output gives no indication that there is a problem. I Believe the issue is that even though a trader is correctly assigned, the value is garbage collected as it goes out of scope once whatever MoveX() function is finished. By using the corrected line CurrentTrader = CurrentLocation.TraderHere; a new Trader object is created that doesn't go out of scope. I think??? Added trader class. Added traderfactory. Location: Added functions to get and set a trader in a location WorldFactory: added traders at locations (-1,0) , (0,1), (-1,-1) //TODO figure out a way to link words with the coords. Gamession: Added CurrentTrader property variable Added call to get the currentTrader in the currentLocation constructor. Added function to get and set CurrentTrader which boardcast properchange. Added function that returns if the location has a trader that will be used to control the visibility of a trade button by the UI. MainWIndow: Added trade button. Visability is controled by the HasTrader bool in Gamesession.
- Loading branch information
1 parent
a6381a1
commit 398ee58
Showing
7 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Engine.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Engine.Factories | ||
{ | ||
public static class TraderFactory | ||
{ | ||
private static readonly List<Trader> _traders = new List<Trader>(); | ||
|
||
static TraderFactory() | ||
{ | ||
Trader susan = new Trader("Susan"); | ||
susan.AddItemToInventory(ItemFactory.CreateGameItem(1001)); | ||
|
||
Trader farmerTed = new Trader("Framer Ted"); | ||
farmerTed.AddItemToInventory(ItemFactory.CreateGameItem(1001)); | ||
|
||
Trader peteTheHerbalist = new Trader("Pete the Herbalist"); | ||
peteTheHerbalist.AddItemToInventory(ItemFactory.CreateGameItem(1001)); | ||
|
||
AddTraderToList(susan); | ||
AddTraderToList(farmerTed); | ||
AddTraderToList(peteTheHerbalist); | ||
} | ||
|
||
public static Trader GetTraderByName(string name) | ||
{ | ||
return _traders.FirstOrDefault(t => t.Name == name); | ||
} | ||
|
||
private static void AddTraderToList(Trader trader) | ||
{ | ||
if(_traders.Any(t => t.Name == trader.Name)) // ensures only one of each trader gets added | ||
{ | ||
throw new ArgumentException($"Trader '{trader.Name}' already exists"); | ||
} | ||
|
||
_traders.Add(trader); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Engine.Models | ||
{ | ||
public class Trader : BaseNotificationClass | ||
{ | ||
public string Name { get; set; } | ||
|
||
public ObservableCollection<GameItem> Inventory { get; set; } | ||
|
||
public Trader(string name) | ||
{ | ||
Name = name; | ||
Inventory = new ObservableCollection<GameItem>(); | ||
} | ||
|
||
public void AddItemToInventory(GameItem item) | ||
{ | ||
Inventory.Add(item); | ||
} | ||
public void RemoveItemToInventory(GameItem item) | ||
{ | ||
Inventory.Remove(item); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters