-
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.
#56 Started to do NewsFactory to create actual news into game.
Adds also JUnit for it.t
- Loading branch information
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/main/java/org/openRealmOfStars/starMap/newsCorp/NewsFactory.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,79 @@ | ||
package org.openRealmOfStars.starMap.newsCorp; | ||
|
||
import org.openRealmOfStars.player.PlayerInfo; | ||
import org.openRealmOfStars.starMap.planet.Planet; | ||
import org.openRealmOfStars.utilities.DiceGenerator; | ||
|
||
/** | ||
* | ||
* Open Realm of Stars game project | ||
* Copyright (C) 2017 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/ | ||
* | ||
* | ||
* News Factory to create news data about special events in game. | ||
* | ||
*/ | ||
public final class NewsFactory { | ||
|
||
/** | ||
* Just hiding the constructor | ||
*/ | ||
private NewsFactory() { | ||
// Nothing to do here | ||
} | ||
|
||
/** | ||
* Make War news. Aggressor makes war declaration to defender. | ||
* This diplomatic meeting happened in meeting place which | ||
* can be planet or fleet. | ||
* @param aggressor Player who is declaring the war | ||
* @param defender Player who is defending | ||
* @param meetingPlace Where meeting happened, fleet or planet | ||
* @return NewsData | ||
*/ | ||
public static NewsData makeWarNews(final PlayerInfo aggressor, | ||
final PlayerInfo defender, final Object meetingPlace) { | ||
NewsData news = new NewsData(); | ||
ImageInstruction instructions = new ImageInstruction(); | ||
instructions.addBackground(ImageInstruction.BACKGROUND_NEBULAE); | ||
if (meetingPlace instanceof Planet) { | ||
Planet planet = (Planet) meetingPlace; | ||
instructions.addPlanet(ImageInstruction.POSITION_CENTER, | ||
Planet.PLANET_NEWS_INSTRUCTIONS[planet.getPlanetImageIndex()], | ||
ImageInstruction.SIZE_FULL); | ||
} | ||
switch (DiceGenerator.getRandom(2)) { | ||
case 0: | ||
default: { | ||
instructions.addText("WAR DECLARATION!"); | ||
break; | ||
} | ||
case 1: { | ||
instructions.addText("WAR!"); | ||
break; | ||
} | ||
case 2: { | ||
instructions.addText("WAR BEGINS!"); | ||
break; | ||
} | ||
} | ||
instructions.addText(aggressor.getEmpireName()); | ||
instructions.addRelationSymbol(ImageInstruction.WAR); | ||
instructions.addText(defender.getEmpireName()); | ||
news.setImageInstructions(instructions.build()); | ||
return news; | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
src/test/java/org/openRealmOfStars/starMap/newsCorp/NewsFactoryTest.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,48 @@ | ||
package org.openRealmOfStars.starMap.newsCorp; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.mockito.Mockito; | ||
import org.openRealmOfStars.player.PlayerInfo; | ||
|
||
/** | ||
* | ||
* Open Realm of Stars game project | ||
* Copyright (C) 2017 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/ | ||
* | ||
* | ||
* News Factory Tests | ||
* | ||
*/ | ||
public class NewsFactoryTest { | ||
|
||
@Test | ||
@Category(org.openRealmOfStars.UnitTest.class) | ||
public void testWar() { | ||
PlayerInfo aggressor = Mockito.mock(PlayerInfo.class); | ||
Mockito.when(aggressor.getEmpireName()).thenReturn("Empire of Test"); | ||
PlayerInfo defender = Mockito.mock(PlayerInfo.class); | ||
Mockito.when(defender.getEmpireName()).thenReturn("Democracy of Defender"); | ||
NewsData news = NewsFactory.makeWarNews(aggressor, defender, null); | ||
assertEquals(true, news.getImageInstructions().contains( | ||
aggressor.getEmpireName())); | ||
assertEquals(true, news.getImageInstructions().contains( | ||
defender.getEmpireName())); | ||
} | ||
|
||
} |