-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#676 Start implementation of timed planetary status.
- Loading branch information
Showing
3 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
src/main/java/org/openRealmOfStars/starMap/planet/status/TimedStatus.java
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,90 @@ | ||
package org.openRealmOfStars.starMap.planet.status; | ||
/* | ||
* Open Realm of Stars game project | ||
* Copyright (C) 2024 Tuomo Untinen | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, see http://www.gnu.org/licenses/ | ||
*/ | ||
|
||
|
||
/** | ||
* Timed planetary status. This tells when timed planetary status is | ||
* activated and starts counting time to zero. When count enters zero, status | ||
* became applied. | ||
* | ||
*/ | ||
public class TimedStatus { | ||
|
||
/** Planetary Status. */ | ||
private PlanetaryStatus status; | ||
/** Timed Typed */ | ||
private TimedStatusType timedType; | ||
/** Actual counter, this is number turns or star years */ | ||
private int count; | ||
|
||
/** | ||
* Constructor for TimedStatus. | ||
* @param status PlanetaryStatus | ||
* @param timedType TimedStatusType | ||
* @param count How many turns before status activates. | ||
*/ | ||
public TimedStatus(final PlanetaryStatus status, | ||
final TimedStatusType timedType, final int count) { | ||
this.status = status; | ||
this.timedType = timedType; | ||
this.count = count; | ||
} | ||
|
||
/** | ||
* Decrease counter by one only if not active yet. | ||
*/ | ||
public void decrease() { | ||
if (count > 0) { | ||
count--; | ||
} | ||
} | ||
|
||
/** | ||
* Is Status active? | ||
* @return True if status should be active and applied. | ||
*/ | ||
public boolean isActive() { | ||
if (count == 0) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Get planetary status. | ||
* @return Planetary status | ||
*/ | ||
public PlanetaryStatus getStatus() { | ||
return status; | ||
} | ||
|
||
/** | ||
* Get timed status type. | ||
* @return TimedStatusType | ||
*/ | ||
public TimedStatusType getTimedStatus() { | ||
return timedType; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return status.getId() + " " + timedType + " count: " + count; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/org/openRealmOfStars/starMap/planet/status/TimedStatusType.java
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,35 @@ | ||
package org.openRealmOfStars.starMap.planet.status; | ||
/* | ||
* Open Realm of Stars game project | ||
* Copyright (C) 2024 Tuomo Untinen | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, see http://www.gnu.org/licenses/ | ||
*/ | ||
|
||
|
||
/** | ||
* Timed planetary status types. This tells when timed planetary status is | ||
* activated and starts counting time to zero. When count enters zero, status | ||
* became applied. | ||
* | ||
*/ | ||
public enum TimedStatusType { | ||
|
||
/** Timed from start of the game. This means star year 2400. */ | ||
GAME_START, | ||
/** Timed from after colonization. */ | ||
AFTER_COLONIZATION, | ||
/** Timed from after colonization or immediately after away team visit */ | ||
AFTER_COLONIZATION_OR_AWAY_TEAM; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/test/java/org/openRealmOfStars/starMap/planet/status/TimedStatusTest.java
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,36 @@ | ||
package org.openRealmOfStars.starMap.planet.status; | ||
/* | ||
* Open Realm of Stars game project | ||
* Copyright (C) 2024 Tuomo Untinen | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, see http://www.gnu.org/licenses/ | ||
*/ | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.mockito.Mockito; | ||
|
||
public class TimedStatusTest { | ||
|
||
@Test | ||
@Category(org.openRealmOfStars.UnitTest.class) | ||
public void testBasic() { | ||
PlanetaryStatus planetaryStatus = Mockito.mock(PlanetaryStatus.class); | ||
Mockito.when(planetaryStatus.getId()).thenReturn("TestStatus"); | ||
TimedStatus status = new TimedStatus(planetaryStatus, TimedStatusType.GAME_START, 5); | ||
assertEquals("TestStatus GAME_START count: 5", status.toString()); | ||
} | ||
|
||
} |