Skip to content

Commit

Permalink
#56 Adds second list for upcoming news.
Browse files Browse the repository at this point in the history
Another one is kept which is being to shown to player.
Updates also JUnits because of this.
  • Loading branch information
tuomount committed Jul 30, 2017
1 parent 0e70d64 commit 218fe70
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public class NewsCorpData {
*/
private ArrayList<NewsData> newsData;

/**
* News data to show on next turn
*/
private ArrayList<NewsData> upComingNewsData;

/**
* How many turns when new news is published
*/
Expand Down Expand Up @@ -109,6 +114,7 @@ public NewsCorpData(final int numberOfPlayers) {
credit = new GalaxyStat(numberOfPlayers, STAT_CREDIT);
research = new GalaxyStat(numberOfPlayers, STAT_RESEARCH);
newsData = new ArrayList<>();
upComingNewsData = new ArrayList<>();
}

/**
Expand Down Expand Up @@ -308,11 +314,11 @@ public int getStatNumbers() {
}

/**
* Add news into array
* Add news into array up coming news array
* @param news to add
*/
public void addNews(final NewsData news) {
newsData.add(news);
upComingNewsData.add(news);
}

/**
Expand All @@ -324,9 +330,11 @@ public NewsData[] getNewsList() {
}

/**
* Clear list of news. This should be called after each turn.
* Puts upcoming news into current news list and clears the
* upcoming news list. This should be called just before new turn starts.
*/
public void clearNewsList() {
newsData.clear();
newsData = upComingNewsData;
upComingNewsData = new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,12 @@ public void testNewsData() {
NewsData[] newsList = data.getNewsList();
assertEquals(0, newsList.length);
data.addNews(newsData);
data.clearNewsList();
newsList = data.getNewsList();
assertEquals(1, newsList.length);
data.addNews(newsData);
data.addNews(newsData);
data.clearNewsList();
newsList = data.getNewsList();
assertEquals(2, newsList.length);
data.clearNewsList();
Expand Down

0 comments on commit 218fe70

Please sign in to comment.