1
0
forked from s425077/PotatoPlan

implemented getHighestProductionRate(x, y) per tile

This commit is contained in:
Joel 2020-05-07 20:06:34 +02:00
parent 4ab4abaa89
commit a54a7f914c
4 changed files with 183 additions and 144 deletions

View File

@ -14,7 +14,7 @@ namespace Game1
SpriteBatch spriteBatch; SpriteBatch spriteBatch;
SpriteFont Bold; SpriteFont Bold;
private Texture2D[] tile = new Texture2D[5]; private Texture2D[] tile = new Texture2D[5];
private Texture2D[] Crops = new Texture2D[11]; private Texture2D[] Crops = new Texture2D[12];
private Texture2D tractor; private Texture2D tractor;
private Texture2D house; private Texture2D house;
private Texture2D markers; private Texture2D markers;
@ -50,17 +50,18 @@ namespace Game1
// TODO: Add your initialization logic here // TODO: Add your initialization logic here
base.Initialize(); base.Initialize();
cropTypesNames[0] = "Barley"; cropTypesNames[0] = "None";
cropTypesNames[1] = "Cotton"; cropTypesNames[1] = "Barley";
cropTypesNames[2] = "Ground Nuts"; cropTypesNames[2] = "Cotton";
cropTypesNames[3] = "Maize"; cropTypesNames[3] = "Ground Nuts";
cropTypesNames[4] = "Millets"; cropTypesNames[4] = "Maize";
cropTypesNames[5] = "Oil Seeds"; cropTypesNames[5] = "Millets";
cropTypesNames[6] = "Paddy"; cropTypesNames[6] = "Oil Seeds";
cropTypesNames[7] = "Pulses"; cropTypesNames[7] = "Paddy";
cropTypesNames[8] = "Sugarcane"; cropTypesNames[8] = "Pulses";
cropTypesNames[9] = "Tobacco"; cropTypesNames[9] = "Sugarcane";
cropTypesNames[10] = "Wheat"; cropTypesNames[10] = "Tobacco";
cropTypesNames[11] = "Wheat";
@ -101,18 +102,18 @@ namespace Game1
Crops[0] = Content.Load<Texture2D>("Markers");
Crops[0] = Content.Load<Texture2D>("BarleyIcon"); Crops[1] = Content.Load<Texture2D>("BarleyIcon");
Crops[1] = Content.Load<Texture2D>("CottonIcon"); Crops[2] = Content.Load<Texture2D>("CottonIcon");
Crops[2] = Content.Load<Texture2D>("GroundNutsIcon"); Crops[3] = Content.Load<Texture2D>("GroundNutsIcon");
Crops[3] = Content.Load<Texture2D>("MaizeIcon"); Crops[4] = Content.Load<Texture2D>("MaizeIcon");
Crops[4] = Content.Load<Texture2D>("MilletsIcon"); Crops[5] = Content.Load<Texture2D>("MilletsIcon");
Crops[5] = Content.Load<Texture2D>("SeedOilIcon"); Crops[6] = Content.Load<Texture2D>("SeedOilIcon");
Crops[6] = Content.Load<Texture2D>("PaddyIcon"); Crops[7] = Content.Load<Texture2D>("PaddyIcon");
Crops[7] = Content.Load<Texture2D>("PulsesIcon"); Crops[8] = Content.Load<Texture2D>("PulsesIcon");
Crops[8] = Content.Load<Texture2D>("SugarcaneIcon"); Crops[9] = Content.Load<Texture2D>("SugarcaneIcon");
Crops[9] = Content.Load<Texture2D>("TobaccoIcon"); Crops[10] = Content.Load<Texture2D>("TobaccoIcon");
Crops[10] = Content.Load<Texture2D>("WheatIcon"); Crops[11] = Content.Load<Texture2D>("WheatIcon");
ProgressionBar = Content.Load<Texture2D>("ProgressionBar"); ProgressionBar = Content.Load<Texture2D>("ProgressionBar");

View File

@ -7,152 +7,164 @@ using System.Threading.Tasks;
class CropTypesHolder class CropTypesHolder
{ {
private CropTypes[] cropTypes = new CropTypes[11]; private CropTypes[] cropTypes = new CropTypes[12];
public void init() public void init()
{ {
// Barley // None
cropTypes[0] = new CropTypes(); cropTypes[0] = new CropTypes();
cropTypes[0].soilType[0] = "Sandy"; cropTypes[0].soilType[0] = "None";
cropTypes[0].soilType[1] = null; cropTypes[0].soilType[1] = null;
cropTypes[0].soilType[2] = null; cropTypes[0].soilType[2] = null;
cropTypes[0].Temparature = 30.1f; cropTypes[0].Temparature = 0f;
cropTypes[0].Humidity = 59.0f; cropTypes[0].Humidity = 0f;
cropTypes[0].Moisture = 41.7f; cropTypes[0].Moisture = 0f;
cropTypes[0].Nitrogen = 12.6f; cropTypes[0].Nitrogen = 0f;
cropTypes[0].Potassium = 5.3f; cropTypes[0].Potassium = 0f;
cropTypes[0].Phosphorous = 26.0f; cropTypes[0].Phosphorous = 0f;
// Barley
cropTypes[1] = new CropTypes();
cropTypes[1].soilType[0] = "Sandy";
cropTypes[1].soilType[1] = null;
cropTypes[1].soilType[2] = null;
cropTypes[1].Temparature = 30.1f;
cropTypes[1].Humidity = 59.0f;
cropTypes[1].Moisture = 41.7f;
cropTypes[1].Nitrogen = 12.6f;
cropTypes[1].Potassium = 5.3f;
cropTypes[1].Phosphorous = 26.0f;
// Cotton // Cotton
cropTypes[1] = new CropTypes();
cropTypes[1].soilType[0] = "Red";
cropTypes[1].Times[0] = 5;
cropTypes[1].soilType[1] = "Black";
cropTypes[1].Times[1] = 4;
cropTypes[1].soilType[2] = "Loamy";
cropTypes[1].Times[2] = 3;
cropTypes[1].Temparature = 30.4f;
cropTypes[1].Humidity = 59.6f;
cropTypes[1].Moisture = 63.2f;
cropTypes[1].Nitrogen = 16.4f;
cropTypes[1].Potassium = 3.3f;
cropTypes[1].Phosphorous = 23.8f;
// Ground Nuts
cropTypes[2] = new CropTypes(); cropTypes[2] = new CropTypes();
cropTypes[2].soilType[0] = "Red"; cropTypes[2].soilType[0] = "Red";
cropTypes[2].soilType[1] = null; cropTypes[2].Times[0] = 5;
cropTypes[2].soilType[2] = null; cropTypes[2].soilType[1] = "Black";
cropTypes[2].Temparature = 30.1f; cropTypes[2].Times[1] = 4;
cropTypes[2].Humidity = 59.1f; cropTypes[2].soilType[2] = "Loamy";
cropTypes[2].Moisture = 33.1f; cropTypes[2].Times[2] = 3;
cropTypes[2].Nitrogen = 23.3f; cropTypes[2].Temparature = 30.4f;
cropTypes[2].Potassium = 2.0f; cropTypes[2].Humidity = 59.6f;
cropTypes[2].Phosphorous = 21.6f; cropTypes[2].Moisture = 63.2f;
cropTypes[2].Nitrogen = 16.4f;
cropTypes[2].Potassium = 3.3f;
cropTypes[2].Phosphorous = 23.8f;
// Ground Nuts
cropTypes[3] = new CropTypes();
cropTypes[3].soilType[0] = "Red";
cropTypes[3].soilType[1] = null;
cropTypes[3].soilType[2] = null;
cropTypes[3].Temparature = 30.1f;
cropTypes[3].Humidity = 59.1f;
cropTypes[3].Moisture = 33.1f;
cropTypes[3].Nitrogen = 23.3f;
cropTypes[3].Potassium = 2.0f;
cropTypes[3].Phosphorous = 21.6f;
// Maize // Maize
cropTypes[3] = new CropTypes();
cropTypes[3].soilType[0] = "Sandy";
cropTypes[3].soilType[1] = null;
cropTypes[3].soilType[2] = null;
cropTypes[3].Temparature = 29.0f;
cropTypes[3].Humidity = 57.3f;
cropTypes[3].Moisture = 42.2f;
cropTypes[3].Nitrogen = 18.3f;
cropTypes[3].Potassium = 5.7f;
cropTypes[3].Phosphorous = 18.7f;
// Millets
cropTypes[4] = new CropTypes(); cropTypes[4] = new CropTypes();
cropTypes[4].soilType[0] = "Sandy"; cropTypes[4].soilType[0] = "Sandy";
cropTypes[4].Times[0] = 7; cropTypes[4].soilType[1] = null;
cropTypes[4].soilType[1] = "Black";
cropTypes[4].Times[0] = 4;
cropTypes[4].soilType[2] = null; cropTypes[4].soilType[2] = null;
cropTypes[4].Temparature = 29.5f; cropTypes[4].Temparature = 29.0f;
cropTypes[4].Humidity = 57.3f; cropTypes[4].Humidity = 57.3f;
cropTypes[4].Moisture = 38.5f; cropTypes[4].Moisture = 42.2f;
cropTypes[4].Nitrogen = 23.2f; cropTypes[4].Nitrogen = 18.3f;
cropTypes[4].Potassium = 0.1f; cropTypes[4].Potassium = 5.7f;
cropTypes[4].Phosphorous = 14.4f; cropTypes[4].Phosphorous = 18.7f;
// Millets
cropTypes[5] = new CropTypes();
cropTypes[5].soilType[0] = "Sandy";
cropTypes[5].Times[0] = 7;
cropTypes[5].soilType[1] = "Black";
cropTypes[5].Times[0] = 4;
cropTypes[5].soilType[2] = null;
cropTypes[5].Temparature = 29.5f;
cropTypes[5].Humidity = 57.3f;
cropTypes[5].Moisture = 38.5f;
cropTypes[5].Nitrogen = 23.2f;
cropTypes[5].Potassium = 0.1f;
cropTypes[5].Phosphorous = 14.4f;
//Oil Seeds //Oil Seeds
cropTypes[5] = new CropTypes();
cropTypes[5].soilType[0] = "Black";
cropTypes[5].soilType[1] = null;
cropTypes[5].soilType[2] = null;
cropTypes[5].Temparature = 30.3f;
cropTypes[5].Humidity = 59.1f;
cropTypes[5].Moisture = 32.1f;
cropTypes[5].Nitrogen = 19.0f;
cropTypes[5].Potassium = 2.3f;
cropTypes[5].Phosphorous = 17.3f;
//Paddys
cropTypes[6] = new CropTypes(); cropTypes[6] = new CropTypes();
cropTypes[6].soilType[0] = "Clayey"; cropTypes[6].soilType[0] = "Black";
cropTypes[6].soilType[1] = null; cropTypes[6].soilType[1] = null;
cropTypes[6].soilType[2] = null; cropTypes[6].soilType[2] = null;
cropTypes[6].Temparature = 31.2f; cropTypes[6].Temparature = 30.3f;
cropTypes[6].Humidity = 60.4f; cropTypes[6].Humidity = 59.1f;
cropTypes[6].Moisture = 41.5f; cropTypes[6].Moisture = 32.1f;
cropTypes[6].Nitrogen = 20.8f; cropTypes[6].Nitrogen = 19.0f;
cropTypes[6].Potassium = 3.7f; cropTypes[6].Potassium = 2.3f;
cropTypes[6].Phosphorous = 16.3f; cropTypes[6].Phosphorous = 17.3f;
//Pulses //Paddys
cropTypes[7] = new CropTypes(); cropTypes[7] = new CropTypes();
cropTypes[7].soilType[0] = "Clayey"; cropTypes[7].soilType[0] = "Clayey";
cropTypes[7].soilType[1] = null; cropTypes[7].soilType[1] = null;
cropTypes[7].soilType[2] = null; cropTypes[7].soilType[2] = null;
cropTypes[7].Temparature = 27.8f; cropTypes[7].Temparature = 31.2f;
cropTypes[7].Humidity = 54.9f; cropTypes[7].Humidity = 60.4f;
cropTypes[7].Moisture = 34.1f; cropTypes[7].Moisture = 41.5f;
cropTypes[7].Nitrogen = 18.4f; cropTypes[7].Nitrogen = 20.8f;
cropTypes[7].Potassium = 4.2f; cropTypes[7].Potassium = 3.7f;
cropTypes[7].Phosphorous = 17.5f; cropTypes[7].Phosphorous = 16.3f;
//Pulses
cropTypes[8] = new CropTypes();
cropTypes[8].soilType[0] = "Clayey";
cropTypes[8].soilType[1] = null;
cropTypes[8].soilType[2] = null;
cropTypes[8].Temparature = 27.8f;
cropTypes[8].Humidity = 54.9f;
cropTypes[8].Moisture = 34.1f;
cropTypes[8].Nitrogen = 18.4f;
cropTypes[8].Potassium = 4.2f;
cropTypes[8].Phosphorous = 17.5f;
//Sugarcane //Sugarcane
cropTypes[8] = new CropTypes(); cropTypes[9] = new CropTypes();
cropTypes[8].soilType[0] = "Loamy"; cropTypes[9].soilType[0] = "Loamy";
cropTypes[8].Times[0] = 9; cropTypes[9].Times[0] = 9;
cropTypes[8].soilType[1] = "Black"; cropTypes[9].soilType[1] = "Black";
cropTypes[8].Times[0] = 4; cropTypes[9].Times[0] = 4;
cropTypes[8].soilType[2] = null; cropTypes[9].soilType[2] = null;
cropTypes[8].Temparature = 30.0f; cropTypes[9].Temparature = 30.0f;
cropTypes[8].Humidity = 58.6f; cropTypes[9].Humidity = 58.6f;
cropTypes[8].Moisture = 51.2f; cropTypes[9].Moisture = 51.2f;
cropTypes[8].Nitrogen = 14.6f; cropTypes[9].Nitrogen = 14.6f;
cropTypes[8].Potassium = 4.2f; cropTypes[9].Potassium = 4.2f;
cropTypes[8].Phosphorous = 17.6f; cropTypes[9].Phosphorous = 17.6f;
//Tobacco //Tobacco
cropTypes[9] = new CropTypes(); cropTypes[10] = new CropTypes();
cropTypes[9].soilType[0] = "Red"; cropTypes[10].soilType[0] = "Red";
cropTypes[9].soilType[1] = null; cropTypes[10].soilType[1] = null;
cropTypes[9].soilType[2] = null; cropTypes[10].soilType[2] = null;
cropTypes[9].Temparature = 31.9f; cropTypes[10].Temparature = 31.9f;
cropTypes[9].Humidity = 62.4f; cropTypes[10].Humidity = 62.4f;
cropTypes[9].Moisture = 31.6f; cropTypes[10].Moisture = 31.6f;
cropTypes[9].Nitrogen = 19.1f; cropTypes[10].Nitrogen = 19.1f;
cropTypes[9].Potassium = 4.9f; cropTypes[10].Potassium = 4.9f;
cropTypes[9].Phosphorous = 19.3f; cropTypes[10].Phosphorous = 19.3f;
//Wheat //Wheat
cropTypes[10] = new CropTypes(); cropTypes[11] = new CropTypes();
cropTypes[10].soilType[0] = "Loamy"; cropTypes[11].soilType[0] = "Loamy";
cropTypes[10].soilType[1] = null; cropTypes[11].soilType[1] = null;
cropTypes[10].soilType[2] = null; cropTypes[11].soilType[2] = null;
cropTypes[10].Temparature = 33.1f; cropTypes[11].Temparature = 33.1f;
cropTypes[10].Humidity = 63.8f; cropTypes[11].Humidity = 63.8f;
cropTypes[10].Moisture = 50.0f; cropTypes[11].Moisture = 50.0f;
cropTypes[10].Nitrogen = 23.3f; cropTypes[11].Nitrogen = 23.3f;
cropTypes[10].Potassium = 2.9f; cropTypes[11].Potassium = 2.9f;
cropTypes[10].Phosphorous = 14.4f; cropTypes[11].Phosphorous = 14.4f;
} }

View File

@ -19,29 +19,30 @@ class Crops
private Vector2 Size; private Vector2 Size;
private CropTypes DataSet; private CropTypes DataSet;
SoilProperties soilProperties = new SoilProperties(); SoilProperties soilProperties = new SoilProperties();
private float ProductionRate = 0; private float ProductionRate;
public void updateCrop(Vector2 newSize) public void updateCrop(Vector2 newSize)
{ {
getProductionRate(); getProductionRate();
if (UpdateCrop == 60)
{
degradeSoil();
UpdateCrop = 0;
}
if (Status == 3 && Timer != 1) if (Status == 3 && Timer != 1)
{ {
Timer = Timer - 1f * ProductionRate; Timer = Timer - 1f * ProductionRate;
} }
Size = newSize; Size = newSize;
UpdateCrop++; UpdateCrop++;
if (UpdateCrop == 60)
{
degradeSoil();
UpdateCrop = 0;
}
if (Timer < 1) if (Timer < 1)
{ {
Timer = 1; Timer = 1;
} }
} }
public SoilProperties getSoilProperties() public SoilProperties getSoilProperties()
@ -193,7 +194,7 @@ class Crops
return housePos; return housePos;
} }
public void getProductionRate() public float getProductionRate(CropTypes Sample)
{ {
ProductionRate = 1; ProductionRate = 1;
if (DataSet != null) if (DataSet != null)
@ -210,6 +211,7 @@ class Crops
} }
ProductionRate = ProductionRate / 20; ProductionRate = ProductionRate / 20;
} }
return ProductionRate;
} }
public float compareToDatset(float i, float j) public float compareToDatset(float i, float j)

View File

@ -36,7 +36,7 @@ class Farm
crops[i, j] = new Crops(); crops[i, j] = new Crops();
crops[i, j].setStatus(x); crops[i, j].setStatus(x);
crops[i, j].setOriginalStatus(); crops[i, j].setOriginalStatus();
x = r.Next(0, 11); x = r.Next(0, 12);
crops[i, j].setCropType(x, PresetCrops.getPresetCropTypes(x)); crops[i, j].setCropType(x, PresetCrops.getPresetCropTypes(x));
crops[i, j].init(); crops[i, j].init();
} }
@ -98,6 +98,30 @@ class Farm
public CropTypes getPresetCropTypes(int Index) public CropTypes getPresetCropTypes(int Index)
{ {
return PresetCrops.getPresetCropTypes(Index); return PresetCrops.getPresetCropTypes(Index - 1);
}
public void setCropType(int x, int y, int Type)
{
crops[x, y].setCropType(Type, PresetCrops.getPresetCropTypes(Type));
}
public int getHighestProductionRate(int x, int y)
{
int i = 1, holder = 0, holderIndex;
do
{
if (getProductionRate(x, y, i) > holder);
{
holderIndex = i;
}
i++;
} while (i < 12);
return holderIndex;
}
public float getProductionRate(int x, int y, int Type)
{
return crops[x, y].getProductionRate(PresetCrops.getPresetCropTypes(Type));
} }
} }