Archived
Start of UI part, beginning of grid implementation
This commit is contained in:
1 parent
493e507b63
commit
ccba4b009a
45 files changed
+234
-17
No files matched your search
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
+147
-2
@@ -3,12 +3,157 @@
|
||||
*/
|
||||
package projet.approche.objet;
|
||||
|
||||
//import projet.approche.objet.domain.*;
|
||||
import projet.approche.objet.domain.valueObject.game.GameStarter;
|
||||
import projet.approche.objet.domain.aggregates.*;
|
||||
import projet.approche.objet.domain.entities.building.Building;
|
||||
import projet.approche.objet.domain.valueObject.building.BuildingList;
|
||||
import projet.approche.objet.domain.valueObject.building.BuildingType;
|
||||
|
||||
import java.util.Scanner;
|
||||
import java.io.Console;
|
||||
|
||||
|
||||
public class App {
|
||||
public String getGreeting() {
|
||||
return "Hello World!";
|
||||
return "Welcome !!!";
|
||||
}
|
||||
|
||||
public static void gameMode(){
|
||||
System.out.println("------------------------------------");
|
||||
System.out.println("-Choose the game diffculty-");
|
||||
System.out.println("-Depending on your choice you will have a varying quantity of resources-");
|
||||
System.out.println("- E : EASY : 10 inhabitants + 6 workers -- Food (15)| Gold(15) | Wood (15) -- Wooden Cabin (2) + House");
|
||||
System.out.println("- N : NORMAL : 6 inhabitants + 2 workers -- Food (10)| Gold(10) | Wood (10) -- Wooden Cabin + House ");
|
||||
System.out.println("- H : HARD : 2 inhabitants + 2 workers -- Food (5)| Gold(5) | Wood (5) -- Wooden Cabin");
|
||||
System.out.println("------------------------------------");
|
||||
}
|
||||
|
||||
public static void printGame(Manager game){
|
||||
|
||||
BuildingList buildings = game.getBuildings();
|
||||
|
||||
int gridSize = 25;
|
||||
|
||||
for(Building b : buildings){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void printBuildingTypes(){
|
||||
System.out.println("------------------------------------");
|
||||
System.out.println("- WC : Wooden Cabin");
|
||||
System.out.println("- H : House");
|
||||
System.out.println("- AB : Apartment Building");
|
||||
System.out.println("- F : Farm");
|
||||
System.out.println("- Q : Quarry");
|
||||
System.out.println("- LM : Lumber Mill");
|
||||
System.out.println("- CP : Cement Plant");
|
||||
System.out.println("- SM : Steel Mill");
|
||||
System.out.println("- TF : Tool Factory");
|
||||
System.out.println("------------------------------------");
|
||||
}
|
||||
|
||||
public static Building buildingType(Console console, Scanner scanner, int id) {
|
||||
printBuildingTypes();
|
||||
String b_type = console.readLine("What type of building do you wish to build/destroy ?");
|
||||
|
||||
Building building;
|
||||
|
||||
switch (b_type.toUpperCase()) {
|
||||
case "WC":
|
||||
building = new Building(BuildingType.WOODENCABIN, id);
|
||||
break;
|
||||
case "H":
|
||||
building = new Building(BuildingType.HOUSE, id);
|
||||
break;
|
||||
case "AB":
|
||||
building = new Building(BuildingType.APARTMENTBUILDING, id);
|
||||
break;
|
||||
case "F":
|
||||
building = new Building(BuildingType.FARM, id);
|
||||
break;
|
||||
case "Q":
|
||||
building = new Building(BuildingType.QUARRY, id);
|
||||
break;
|
||||
case "LM":
|
||||
building = new Building(BuildingType.LUMBERMILL, id);
|
||||
break;
|
||||
case "CP":
|
||||
building = new Building(BuildingType.CEMENTPLANT, id);
|
||||
break;
|
||||
case "SM":
|
||||
building = new Building(BuildingType.STEELMILL, id);
|
||||
break;
|
||||
case "TF":
|
||||
building = new Building(BuildingType.TOOLFACTORY, id);
|
||||
break;
|
||||
default:
|
||||
System.out.println("Invalid building type. Defaulting to Wooden Cabin.");
|
||||
building = new Building(BuildingType.WOODENCABIN, id);
|
||||
break;
|
||||
}
|
||||
|
||||
return building;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
return;
|
||||
|
||||
// Game starter with the default number of inhabitants and workers and buildings
|
||||
// depending on the chosen difficulty :
|
||||
// EASY : 10 inhabitants + 6 workers -- Food (15)| Gold(15) | Wood (15) -- Wooden Cabin (2) + House
|
||||
// NORMAL : 6 inhabitants + 2 workers -- Food (10)| Gold(10) | Wood (10) -- Wooden Cabin + House
|
||||
// HARD : 2 inhabitants + 2 workers -- Food (5)| Gold(5) | Wood (5) -- Wooden Cabin
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
Console console = System.console();
|
||||
|
||||
GameStarter game;
|
||||
String diff;
|
||||
int b_id = 3; // building id
|
||||
|
||||
gameMode();
|
||||
diff = console.readLine("Which difficulty do you choose ?");
|
||||
|
||||
if(diff.equals("E")){
|
||||
game = GameStarter.EASY;
|
||||
} else if (diff.equals("N")){
|
||||
game = GameStarter.NORMAL;
|
||||
} else {
|
||||
game = GameStarter.HARD;
|
||||
}
|
||||
|
||||
Manager GM = new Manager(game, 20);
|
||||
GM.startGame();
|
||||
|
||||
|
||||
while(true){
|
||||
// messages()
|
||||
String ui = scanner.nextLine(); // User input
|
||||
|
||||
switch(ui){
|
||||
case "B":
|
||||
// ask for type of building, coordinates to put it on grid
|
||||
Building building = buildingType(console, scanner, b_id+1);
|
||||
//update grid
|
||||
if(GM.updateGrid()){
|
||||
GM.buildBuilding(building);
|
||||
}
|
||||
|
||||
|
||||
|
||||
case "RB":
|
||||
// ask for type of building to destroy, and its coordinates on grid
|
||||
Building buildingR = buildingType(console, scanner, b_id+1);
|
||||
GM.destroyBuilding(buildingR);
|
||||
case "Q":
|
||||
System.out.println("You are quitting the game. ");
|
||||
GM.endGame();
|
||||
break;
|
||||
default:
|
||||
System.out.println("Input another query. ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Regular → Executable
+58
-1
@@ -26,19 +26,51 @@ public class Manager {
|
||||
private BuildingList buildings = new BuildingList();
|
||||
private ResourceList resources = new ResourceList();
|
||||
|
||||
private int gridSize;
|
||||
private String[][] grid;
|
||||
|
||||
/**
|
||||
* Manager of the game, it will manage the buildings, the resources, the
|
||||
* inhabitants and the workers
|
||||
*
|
||||
* @param gameStarter the game starter
|
||||
*/
|
||||
public Manager(GameStarter gameStarter) {
|
||||
public Manager(GameStarter gameStarter, int gridSize) {
|
||||
this.inhabitants = gameStarter.inhabitants;
|
||||
this.workers = gameStarter.workers;
|
||||
this.resources = gameStarter.startingResources;
|
||||
for (BuildingType buildingType : gameStarter.startingBuildings) {
|
||||
this.buildings = this.buildings.add(new Building(buildingType, ++idBuildings));
|
||||
}
|
||||
|
||||
this.gridSize = gridSize;
|
||||
this.grid = new String [gridSize][gridSize];
|
||||
|
||||
for(int i = 0; i < gridSize; i++){
|
||||
for(int j = 0; j < gridSize; j++){
|
||||
if(gameStarter == GameStarter.EASY){
|
||||
if((i== 0 && j==0) || (i== 1 && j==0)){
|
||||
this.grid[i][j] = "C";
|
||||
}
|
||||
if((i== 0 && j==2) || (i== 0 && j==3)){
|
||||
this.grid[i][j] = "H";
|
||||
}
|
||||
} else if (gameStarter == GameStarter.NORMAL){
|
||||
if((i== 0 && j==0)){
|
||||
this.grid[i][j] = "C";
|
||||
}
|
||||
if((i== 0 && j==2) || (i== 0 && j==3)){
|
||||
this.grid[i][j] = "H";
|
||||
}
|
||||
} else {
|
||||
if((i== 0 && j==0)){
|
||||
this.grid[i][j] = "C";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
@@ -145,4 +177,29 @@ public class Manager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateGrid(int c_i; int c_j, Building building){
|
||||
// everytime a building is created the grid is updated
|
||||
/*for(int i = 0; i < this.gridSize; i++){
|
||||
for(int j = 0; j < this.gridSize; j++){
|
||||
|
||||
}
|
||||
}*/
|
||||
if( c_i >= this.gridSize){
|
||||
// c_i too big
|
||||
return false;
|
||||
}
|
||||
|
||||
if( c_j >= this.gridSize){
|
||||
// c_j too big
|
||||
|
||||
}
|
||||
|
||||
//think of size of building, if the j coordinate is to close to the right edge the building can not be built on this line
|
||||
// and if there is no building overlap
|
||||
if(this.gridSize-c_j-1 > building.buildingSize()){
|
||||
// can building the building on this line
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Regular → Executable
+4
@@ -117,4 +117,8 @@ public class Building implements BuildingItf {
|
||||
public String toShortString() {
|
||||
return this.type.shortName + ":" + this.id;
|
||||
}
|
||||
|
||||
public int buildingSize(){
|
||||
return this.type.buildingSize;
|
||||
}
|
||||
}
|
||||
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
+25
-14
@@ -15,9 +15,10 @@ public enum BuildingType {
|
||||
2,
|
||||
2,
|
||||
new Consumption(1), // needs for production
|
||||
new Production(1, // production
|
||||
new Production(1, // prfoduction
|
||||
new Resource(WOOD, 2),
|
||||
new Resource(FOOD, 2))),
|
||||
new Resource(FOOD, 2)),
|
||||
1),
|
||||
HOUSE("House",
|
||||
"H",
|
||||
new ConstructionNeeds(4,
|
||||
@@ -27,7 +28,8 @@ public enum BuildingType {
|
||||
0,
|
||||
4,
|
||||
new Consumption(1), // needs for production
|
||||
new Production(1) // production
|
||||
new Production(1), // plroduction
|
||||
2
|
||||
),
|
||||
APARTMENTBUILDING("Apartment Building",
|
||||
"AB",
|
||||
@@ -38,7 +40,8 @@ public enum BuildingType {
|
||||
0,
|
||||
60,
|
||||
new Consumption(1), // needs for production
|
||||
new Production(1) // production
|
||||
new Production(1) ,// production
|
||||
4
|
||||
),
|
||||
FARM("Farm",
|
||||
"F",
|
||||
@@ -50,7 +53,8 @@ public enum BuildingType {
|
||||
5,
|
||||
new Consumption(1), // needs for production
|
||||
new Production(1, // production
|
||||
new Resource(FOOD, 10))),
|
||||
new Resource(FOOD, 10)),
|
||||
3),
|
||||
QUARRY("Quarry",
|
||||
"Q",
|
||||
new ConstructionNeeds(2,
|
||||
@@ -63,7 +67,8 @@ public enum BuildingType {
|
||||
new Resource(STONE, 4),
|
||||
new Resource(IRON, 1),
|
||||
new Resource(COAL, 4),
|
||||
new Resource(GOLD, 2))),
|
||||
new Resource(GOLD, 2)),
|
||||
4),
|
||||
LUMBERMILL("Lumber Mill",
|
||||
"LM",
|
||||
new ConstructionNeeds(4,
|
||||
@@ -75,7 +80,8 @@ public enum BuildingType {
|
||||
new Consumption(1, // needs for production
|
||||
new Resource(WOOD, 4)),
|
||||
new Production(1, // production
|
||||
new Resource(LUMBER, 4))),
|
||||
new Resource(LUMBER, 4)),
|
||||
4),
|
||||
CEMENTPLANT("Cement Plant",
|
||||
"CP",
|
||||
new ConstructionNeeds(4,
|
||||
@@ -88,7 +94,8 @@ public enum BuildingType {
|
||||
new Resource(STONE, 4),
|
||||
new Resource(COAL, 4)),
|
||||
new Production(1, // production
|
||||
new Resource(CEMENT, 4))),
|
||||
new Resource(CEMENT, 4)),
|
||||
4),
|
||||
STEELMILL("Steel Mill",
|
||||
"SM",
|
||||
new ConstructionNeeds(6,
|
||||
@@ -101,7 +108,8 @@ public enum BuildingType {
|
||||
new Resource(IRON, 4),
|
||||
new Resource(COAL, 2)),
|
||||
new Production(1, // production
|
||||
new Resource(STEEL, 4))),
|
||||
new Resource(STEEL, 4)),
|
||||
5),
|
||||
TOOLFACTORY("Tool Factory",
|
||||
"TF",
|
||||
new ConstructionNeeds(8,
|
||||
@@ -114,7 +122,8 @@ public enum BuildingType {
|
||||
new Resource(STEEL, 4),
|
||||
new Resource(COAL, 4)),
|
||||
new Production(1, // production
|
||||
new Resource(TOOLS, 4)));
|
||||
new Resource(TOOLS, 4)),
|
||||
4);
|
||||
|
||||
public final String name;
|
||||
public final String shortName;
|
||||
@@ -124,12 +133,13 @@ public enum BuildingType {
|
||||
public final int inhabitantsNeeded; // min number of inhabitants
|
||||
public final int inhabitantsMax; // max number of inhabitants
|
||||
public final Consumption consumption; // needs for production
|
||||
public final Production production; // production
|
||||
public final Production production; // prloduction
|
||||
public final int buildingSize; // size of building on grid
|
||||
|
||||
private BuildingType(String name, String shotName, ConstructionNeeds constructionNeeds, int workersNeeded,
|
||||
int inhabitantsNeeded, Consumption consumption, Production production) {
|
||||
private BuildingType(String name, String shortName, ConstructionNeeds constructionNeeds, int workersNeeded,
|
||||
int inhabitantsNeeded, Consumption consumption, Production production, int buildingSize) {
|
||||
this.name = name;
|
||||
this.shortName = shotName;
|
||||
this.shortName = shortName;
|
||||
this.constructionNeeds = constructionNeeds;
|
||||
this.workersNeeded = workersNeeded;
|
||||
this.workersMax = 2 * workersNeeded;
|
||||
@@ -137,6 +147,7 @@ public enum BuildingType {
|
||||
this.inhabitantsMax = 2 * inhabitantsNeeded;
|
||||
this.consumption = consumption;
|
||||
this.production = production;
|
||||
this.buildingSize = buildingSize;
|
||||
}
|
||||
|
||||
public static BuildingType fromString(String name) {
|
||||
|
||||
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
File mode changed.
File mode changed.
File mode changed.
Regular → Executable
File mode changed.
Reference in new issue
Block a user