Add: Board Setup (Game Init)
This commit is contained in:
@@ -12,11 +12,12 @@ public abstract class TribeCard extends PlayableCard {
|
|||||||
public int getNMin() {
|
public int getNMin() {
|
||||||
return nMin;
|
return nMin;
|
||||||
}
|
}
|
||||||
public TribeCard(int Era,boolean IsEventCard) {
|
public TribeCard(int Era,boolean isEventCard) {
|
||||||
super(Era);
|
this(Era,isEventCard,0);
|
||||||
}
|
}
|
||||||
public TribeCard(int Era,boolean IsEventCard,int nMin) {
|
public TribeCard(int Era,boolean isEventCard,int nMin) {
|
||||||
super(Era);
|
super(Era);
|
||||||
this.nMin=nMin;
|
this.nMin=nMin;
|
||||||
|
this.isEventCard=isEventCard;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,15 @@ import java.util.*;
|
|||||||
|
|
||||||
public class DecksCreator {
|
public class DecksCreator {
|
||||||
|
|
||||||
|
public static List<TribeCard> loadTribeDeckByEra(int era) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
return switch (era) {
|
||||||
|
case 1 -> loadTribeDeck("/Cards/cards_era1.json");
|
||||||
|
case 2 -> loadTribeDeck("/Cards/cards_era2.json");
|
||||||
|
case 3 -> loadTribeDeck("/Cards/cards_era3.json");
|
||||||
|
default -> throw new IllegalArgumentException();
|
||||||
|
};
|
||||||
|
}
|
||||||
public static List<TribeCard> loadTribeDeck(String resourcePath) {
|
public static List<TribeCard> loadTribeDeck(String resourcePath) {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
Type listType = new com.google.gson.reflect.TypeToken<List<TribeCardDefinition>>(){}.getType();
|
Type listType = new com.google.gson.reflect.TypeToken<List<TribeCardDefinition>>(){}.getType();
|
||||||
@@ -39,7 +48,11 @@ public class DecksCreator {
|
|||||||
throw new RuntimeException("Errore caricamento mazzo: " + resourcePath, e);
|
throw new RuntimeException("Errore caricamento mazzo: " + resourcePath, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static List<BuildingCard> loadBuildingDeckByEra(int era) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
if(era<=0 || era>3) throw new IllegalArgumentException();
|
||||||
|
return loadBuildingDeck("/Cards/buildingCards.json").stream().filter(x->x.getEra()==era).toList();
|
||||||
|
}
|
||||||
public static List<BuildingCard> loadBuildingDeck(String resourcePath) {
|
public static List<BuildingCard> loadBuildingDeck(String resourcePath) {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
Type listType = new com.google.gson.reflect.TypeToken<List<BuildingCardDefinition>>(){}.getType();
|
Type listType = new com.google.gson.reflect.TypeToken<List<BuildingCardDefinition>>(){}.getType();
|
||||||
|
|||||||
@@ -2,18 +2,19 @@ package it.polimi.ingsw.gc14.Model;
|
|||||||
|
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
||||||
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.ShamanicRitual;
|
||||||
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.Sustenance;
|
||||||
import it.polimi.ingsw.gc14.Model.Orders.Order2;
|
import it.polimi.ingsw.gc14.Model.Orders.Order2;
|
||||||
import it.polimi.ingsw.gc14.Model.Orders.Order3;
|
import it.polimi.ingsw.gc14.Model.Orders.Order3;
|
||||||
import it.polimi.ingsw.gc14.Model.Orders.Order4;
|
import it.polimi.ingsw.gc14.Model.Orders.Order4;
|
||||||
import it.polimi.ingsw.gc14.Model.Orders.Order5;
|
import it.polimi.ingsw.gc14.Model.Orders.Order5;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Game {
|
public class Game {
|
||||||
private List<Slot> slotList;
|
private List<Slot> slotList;
|
||||||
private List<TribeCard> tribeDeck;
|
private Queue<TribeCard> tribeDeck;
|
||||||
private List<BuildingCard> buildingDeck;
|
|
||||||
private List<TribeCard> upperListTribe;
|
private List<TribeCard> upperListTribe;
|
||||||
private List<TribeCard> lowerListTribe;
|
private List<TribeCard> lowerListTribe;
|
||||||
private List<BuildingCard> upperListBuilding;
|
private List<BuildingCard> upperListBuilding;
|
||||||
@@ -25,12 +26,17 @@ public class Game {
|
|||||||
private OrderLogicCard orderLogicCard;
|
private OrderLogicCard orderLogicCard;
|
||||||
public Game(int nPlayers) {
|
public Game(int nPlayers) {
|
||||||
this.nPlayers = nPlayers;
|
this.nPlayers = nPlayers;
|
||||||
|
this.slotList = DecksCreator.loadSlotDeck().stream().filter(x->x.getNMinPlayer()<=nPlayers).sorted().toList();
|
||||||
//Manca generazione slot ->this.slotList = slotList.stream().filter(slot -> slot.getNMinPlayer()>= nPlayers).toList();
|
this.tribeDeck= getTribeDeck(nPlayers);
|
||||||
|
ArrayList<BuildingCard> buildingDeck = new ArrayList<>(DecksCreator.loadBuildingDeckByEra(1));
|
||||||
|
Collections.shuffle(buildingDeck);
|
||||||
|
if(nPlayers==2)
|
||||||
|
this.upperListBuilding= buildingDeck.subList(0,1);
|
||||||
|
else
|
||||||
|
this.upperListBuilding= buildingDeck.subList(0,2);
|
||||||
|
|
||||||
upperListTribe = new ArrayList<>();
|
upperListTribe = new ArrayList<>();
|
||||||
lowerListTribe = new ArrayList<>();
|
lowerListTribe = new ArrayList<>();
|
||||||
upperListBuilding = new ArrayList<>();
|
|
||||||
lowerListBuilding = new ArrayList<>();
|
lowerListBuilding = new ArrayList<>();
|
||||||
playersList = new ArrayList<>();
|
playersList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
@@ -51,7 +57,42 @@ public class Game {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(int i=0;i<nPlayers+1;i++)
|
||||||
|
{
|
||||||
|
TribeCard tempCard = tribeDeck.remove();
|
||||||
|
if(tempCard.IsEventCard())
|
||||||
|
{
|
||||||
|
upperListTribe.add(tempCard);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lowerListTribe.add(tempCard);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int i=upperListTribe.size();i<nPlayers+5;i++)
|
||||||
|
{
|
||||||
|
TribeCard tempCard = tribeDeck.remove();
|
||||||
|
upperListTribe.add(tempCard);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
private Queue<TribeCard> getTribeDeck(int nPlayers)
|
||||||
|
{
|
||||||
|
ArrayList<TribeCard> era1= DecksCreator.loadTribeDeckByEra(1).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
List<TribeCard> era2= DecksCreator.loadTribeDeckByEra(2).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
List<TribeCard> era3= DecksCreator.loadTribeDeckByEra(3).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
Collections.shuffle(era1);
|
||||||
|
Collections.shuffle(era2);
|
||||||
|
Collections.shuffle(era3);
|
||||||
|
Queue<TribeCard> tribeDeck_temp=new LinkedList<>();
|
||||||
|
tribeDeck_temp.addAll(era1);
|
||||||
|
tribeDeck_temp.addAll(era2);
|
||||||
|
tribeDeck_temp.addAll(era3);
|
||||||
|
tribeDeck_temp.add(new Sustenance(3,3));
|
||||||
|
tribeDeck_temp.add(new ShamanicRitual(3,15,7));
|
||||||
|
return tribeDeck_temp;
|
||||||
}
|
}
|
||||||
public void addPlayer(Player player)
|
public void addPlayer(Player player)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,6 +11,6 @@ public class Main {
|
|||||||
Inventor inventor= new Inventor(1,0);
|
Inventor inventor= new Inventor(1,0);
|
||||||
System.out.println(inventor);
|
System.out.println(inventor);
|
||||||
List<TribeCard>cards= DecksCreator.loadTribeDeck("/Cards/tribe_era1.json");
|
List<TribeCard>cards= DecksCreator.loadTribeDeck("/Cards/tribe_era1.json");
|
||||||
List<BuildingCard> buildingCards = DecksCreator.loadBuildingDeck("/Cards/buildingcards.json");
|
List<BuildingCard> buildingCards = DecksCreator.loadBuildingDeck("/Cards/buildingCards.json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user