Skip to content

Commit

Permalink
fix: 微調
Browse files Browse the repository at this point in the history
  • Loading branch information
takeiteasy23 committed Aug 8, 2023
1 parent 4a93d63 commit 665367d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
12 changes: 5 additions & 7 deletions Domain/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,22 @@ public virtual void Upgrade()
house++;
}

public List<DomainEvent> PayToll(Player payer)
public DomainEvent PayToll(Player payer)
{
// payer 應該付過路費給 payee
// 計算過路費

Player? payee = landContract.Owner;
List<DomainEvent> domainEvents = new();

if (payer.EndRoundFlag)
{
//throw new Exception("玩家不需要支付過路費");
domainEvents.Add(new PlayerDoesntNeedToPayTollEvent(payer.Monopoly.Id, payer.Id, payer.Money));
return new PlayerDoesntNeedToPayTollEvent(payer.Monopoly.Id, payer.Id, payer.Money);
}
else if (payee!.Chess.CurrentBlock.Id == "Jail" || payee.Chess.CurrentBlock.Id == "ParkingLot")
{
//throw new Exception("不需要支付過路費:Owner is in the " + payee.Chess.CurrentBlock.Id);
domainEvents.Add(new PlayerDoesntNeedToPayTollEvent(payer.Monopoly.Id, payer.Id, payer.Money));
return new PlayerDoesntNeedToPayTollEvent(payer.Monopoly.Id, payer.Id, payer.Money);
}
else
{
Expand All @@ -104,15 +103,14 @@ public List<DomainEvent> PayToll(Player payer)
{
payer.EndRoundFlag = true;
payer.PayToll(payee, amount);
domainEvents.Add(new PlayerPayTollEvent(payer.Monopoly.Id, payer.Id, payer.Money, payee.Id, payee.Money));
return new PlayerPayTollEvent(payer.Monopoly.Id, payer.Id, payer.Money, payee.Id, payee.Money);
}
else
{
//throw new Exception("錢包餘額不足!");
domainEvents.Add(new PlayerTooPoorToPayTollEvent(payer.Monopoly.Id, payer.Id, payer.Money, amount));
return new PlayerTooPoorToPayTollEvent(payer.Monopoly.Id, payer.Id, payer.Money, amount);
}
}
return domainEvents;
}

public virtual decimal CalcullateToll(Player payee)
Expand Down
3 changes: 0 additions & 3 deletions Domain/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,12 @@ internal DomainEvent MortgageLandContract(string landId)
}
}

#region 測試用
public void MortgageForTest(string landId)
{
var landContract = _landContractList.First(l => l.Land.Id == landId);
mortgages.Add(new Mortgage(this, landContract));
}

#endregion

public void PayToll(Player payee, decimal amount)
{
Money -= amount;
Expand Down
12 changes: 6 additions & 6 deletions Test/ServerTests/AcceptanceTests/BuildHouseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public async Task 玩家在自己的土地蓋房子()
// A 蓋房子
hub.Verify<string, string, decimal, int>(
nameof(IMonopolyResponses.PlayerBuildHouseEvent),
(playId, blockId, playerMoney, house)
=> playId == "A" && blockId == "A1" && playerMoney == 1000 && house == 2);
(playerId, blockId, playerMoney, house)
=> playerId == "A" && blockId == "A1" && playerMoney == 1000 && house == 2);
hub.VerifyNoElseEvent();
}

Expand Down Expand Up @@ -91,8 +91,8 @@ public async Task 土地最多蓋5間房子()
// A 蓋房子
hub.Verify<string, string, int>(
nameof(IMonopolyResponses.HouseMaxEvent),
(playId, blockId, house)
=> playId == "A" && blockId == "A1" && house == 5);
(playerId, blockId, house)
=> playerId == "A" && blockId == "A1" && house == 5);
hub.VerifyNoElseEvent();
}

Expand Down Expand Up @@ -129,8 +129,8 @@ public async Task 車站不能蓋房子()
// A 蓋房子
hub.Verify<string, string>(
nameof(IMonopolyResponses.PlayerCannotBuildHouseEvent),
(playId, blockId)
=> playId == "A" && blockId == "Station1");
(playerId, blockId)
=> playerId == "A" && blockId == "Station1");
hub.VerifyNoElseEvent();
}
}

0 comments on commit 665367d

Please sign in to comment.