Skip to content

Commit

Permalink
整理
Browse files Browse the repository at this point in the history
PlayerTime.Consumeで時間切れの場合は時間を減らさないようにした。
  • Loading branch information
ak110 committed Jan 30, 2016
1 parent aff8c77 commit 8a4d08f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 12 additions & 4 deletions ShogiCore/PlayerTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,31 @@ public void Reset() {
}

/// <summary>
/// 時間を使用する。足りない場合はfalseを返す
/// 時間を使用する。足りない場合は消費させずにfalseを返す
/// </summary>
/// <param name="time">消費時間</param>
public bool Consume(int time) {
return Consume(ref time);
}

/// <summary>
/// 時間を使用する。足りない場合はfalseを返す
/// 時間を使用する。足りない場合は消費させずにfalseを返す
/// </summary>
/// <param name="time">消費時間</param>
public bool Consume(ref int time) {
time = GetFixedTime(time);
bool timeUp = GetLimitTime() <= time;
if (GetLimitTime() <= time)
return false;
Remain = Math.Max(0, Remain - time);
Remain += Increment;
return !timeUp;
return true;
}

/// <summary>
/// 消費時間を使いつくす。時間切れでも構わず続行する場合などに使う。
/// </summary>
public void Exhaust() {
Remain = 0 + Increment;
}

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions ShogiCoreTest/PlayerTimeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ private void ConsumeTestImpl2(int time, int byoyomi, int nextTime, int ngTime) {
playerTime.Reset();

Assert.IsFalse(playerTime.Consume(ngTime));
playerTime.Reset();
Assert.IsTrue(playerTime.Consume(ngTime - 1));
Assert.AreEqual(nextTime, playerTime.Remain);
}
Expand All @@ -53,7 +52,6 @@ public void ConsumeTest2() {
playerTime.Increment = 1234;
// 持ち時間+秒読みを超えるとNG
Assert.IsFalse(playerTime.Consume(1500));
playerTime.Remain = 1000;
// ぎりぎりOK
Assert.IsTrue(playerTime.Consume(1499));
// 持ち時間が尽きたけどIncrementの分増える
Expand Down

0 comments on commit 8a4d08f

Please sign in to comment.