diff --git a/Game1/Content/BerriesIcon.png b/Game1/Content/BerriesIcon.png new file mode 100644 index 0000000..e1df741 Binary files /dev/null and b/Game1/Content/BerriesIcon.png differ diff --git a/Game1/Content/CarronIcon.png b/Game1/Content/CarronIcon.png new file mode 100644 index 0000000..b699c9a Binary files /dev/null and b/Game1/Content/CarronIcon.png differ diff --git a/Game1/Content/Content.mgcb b/Game1/Content/Content.mgcb index 0b600c6..73c3ac3 100644 --- a/Game1/Content/Content.mgcb +++ b/Game1/Content/Content.mgcb @@ -13,6 +13,30 @@ #---------------------------------- Content ---------------------------------# +#begin BerriesIcon.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:BerriesIcon.png + +#begin CarronIcon.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:CarronIcon.png;CarrotIcon.png + #begin Crop.png /importer:TextureImporter /processor:TextureProcessor @@ -68,6 +92,18 @@ /processorParam:TextureFormat=Color /build:Mountain.png +#begin MouseCursor.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:MouseCursor.png + #begin Plantable.png /importer:TextureImporter /processor:TextureProcessor @@ -92,6 +128,30 @@ /processorParam:TextureFormat=Color /build:Planted.png +#begin ProgressionBar.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:ProgressionBar.png + +#begin ProgressionBarStatus.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:ProgressionBarStatus.png + #begin Tile.png /importer:TextureImporter /processor:TextureProcessor @@ -128,3 +188,27 @@ /processorParam:TextureFormat=Color /build:Tractor.png +#begin TreePlantationIcon.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:TreePlantationIcon.png + +#begin WheatIcon.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:WheatIcon.png + diff --git a/Game1/Content/MouseCursor.png b/Game1/Content/MouseCursor.png new file mode 100644 index 0000000..022df8b Binary files /dev/null and b/Game1/Content/MouseCursor.png differ diff --git a/Game1/Content/ProgressionBar.png b/Game1/Content/ProgressionBar.png new file mode 100644 index 0000000..3fbd568 Binary files /dev/null and b/Game1/Content/ProgressionBar.png differ diff --git a/Game1/Content/ProgressionBarStatus.png b/Game1/Content/ProgressionBarStatus.png new file mode 100644 index 0000000..45b8979 Binary files /dev/null and b/Game1/Content/ProgressionBarStatus.png differ diff --git a/Game1/Content/TreePlantationIcon.png b/Game1/Content/TreePlantationIcon.png new file mode 100644 index 0000000..b9164db Binary files /dev/null and b/Game1/Content/TreePlantationIcon.png differ diff --git a/Game1/Content/WheatIcon.png b/Game1/Content/WheatIcon.png new file mode 100644 index 0000000..0f4ccd6 Binary files /dev/null and b/Game1/Content/WheatIcon.png differ diff --git a/Game1/Game1.cs b/Game1/Game1.cs index 95cb3c4..beb1396 100644 --- a/Game1/Game1.cs +++ b/Game1/Game1.cs @@ -14,13 +14,21 @@ namespace Game1 SpriteBatch spriteBatch; SpriteFont Bold; private Texture2D[] tile = new Texture2D[5]; + private Texture2D[] Crops = new Texture2D[5]; private Texture2D tractor; private Texture2D house; private Texture2D markers; + private Texture2D mouseCursor; + + private Texture2D ProgressionBar; + private Texture2D ProgressionBarStatus; + private Tractor tractorUnit = new Tractor(); private Input input = new Input(); private House houseUnit = new House(); - private Vector2 mousePosition; + private Rectangle mousePosition; + + MouseState state; public Game1() @@ -62,7 +70,17 @@ namespace Game1 tile[2] = Content.Load("Plantable"); tile[3] = Content.Load("Planted"); tile[4] = Content.Load("Crop"); + + Crops[0] = Content.Load("CarrotIcon"); + Crops[1] = Content.Load("WheatIcon"); + Crops[2] = Content.Load("BerriesIcon"); //Replace 2 and 3 with the new crop Textures + Crops[3] = Content.Load("TreePlantationIcon"); + + ProgressionBar = Content.Load("ProgressionBar"); + ProgressionBarStatus = Content.Load("ProgressionBarStatus"); + tractor = Content.Load("Tractor"); + mouseCursor = Content.Load("MouseCursor"); Bold = Content.Load("Font"); house = Content.Load("house"); markers = Content.Load("Markers"); @@ -82,15 +100,15 @@ namespace Game1 Exit(); - MouseState state = Mouse.GetState(); - mousePosition = new Vector2(state.X, state.Y); + state = Mouse.GetState(); + mousePosition = new Rectangle(state.X, state.Y, 1, 1); tractorUnit.updateSizing(input, 0, houseUnit.getVector()); //Updates the size tractorUnit.setSpeed(input.changeSpeed(tractorUnit.getSpeed())); //Updates the Simulation Speed tractorUnit.setTractorSpeed(input.changeTractorSpeed(tractorUnit.getTractorSpeed(), tractorUnit.getPos())); //Updates the Tractor Speed input.controlWindowSize(); //Controls the size of the screen depending on the number of tiles houseUnit.updateRectangle(input.getSize(), input.getTileSize(), input.getSpacing()); //Updates the position of the house if the house appears out of bound - + tractorUnit.updateCrops(); base.Update(gameTime); @@ -103,13 +121,8 @@ namespace Game1 spriteBatch.Begin(); - for(int i = 0; i < input.getSize().X; i++) //Draw the tiles - { - for (int j = 0; j < input.getSize().Y; j++) - { - spriteBatch.Draw(tile[tractorUnit.getFarm().getCrop(i, j).Status], new Rectangle(i * (input.getSpacingTile()), j * (input.getSpacingTile()), input.getTileSize(), input.getTileSize()), Color.White); - } - } + DrawTiles(); + spriteBatch.Draw(markers, new Rectangle((int)tractorUnit.getTargetPosition().X / input.getSpacingTile() * (input.getTileSize() + input.getSpacing()) + input.getTileSize() / 4, (int)tractorUnit.getTargetPosition().Y / input.getSpacingTile() * (input.getTileSize() + input.getSpacing()) + input.getTileSize() / 4, input.getTileSize()/2, input.getTileSize()/2), Color.Green); for (int i = 0; i < tractorUnit.getPath().getCount() + 1; i++) { @@ -131,14 +144,48 @@ namespace Game1 spriteBatch.DrawString(Bold, "Tile Size:" + input.getTileSize().ToString() + "pix", new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 40), Color.White); //Draws the tile size spriteBatch.DrawString(Bold, "Matrix Size: " + input.getSize().X.ToString() + " X " + input.getSize().Y.ToString(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 60), Color.White);spriteBatch.DrawString(Bold, "Tile Size:" + input.getTileSize().ToString() + "pix", new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 40), Color.White); spriteBatch.DrawString(Bold, "Tractor Rotation:" + tractorUnit.getRotation().ToString() + " Degrees", new Vector2(250, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20), Color.White); - spriteBatch.DrawString(Bold, tractorUnit.getCurrentTask(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 80), Color.White); //Draws the tile size + //spriteBatch.DrawString(Bold, tractorUnit.getCurrentTask(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 80), Color.White); //Draws the tile size spriteBatch.DrawString(Bold, tractorUnit.getScore().ToString(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 100), Color.White); - spriteBatch.Draw(tractor, new Rectangle((int)mousePosition.X, (int)mousePosition.Y, input.getTileSize() / 4, input.getTileSize() / 4), Color.White); + spriteBatch.Draw(mouseCursor, new Rectangle((int)mousePosition.X, (int)mousePosition.Y, 14, 21), Color.White); spriteBatch.End(); base.Draw(gameTime); } + + + public void DrawTiles() + { + for (int i = 0; i < input.getSize().X; i++) //Draw the tiles + { + for (int j = 0; j < input.getSize().Y; j++) + { + Rectangle tilePos = new Rectangle(i * (input.getSpacingTile()), j * (input.getSpacingTile()), input.getTileSize(), input.getTileSize()); + spriteBatch.Draw(tile[tractorUnit.getFarm().getCrop(i, j).getStatus()], tilePos, Color.White); + if (tilePos.Intersects(mousePosition)) + { + spriteBatch.Draw(tile[tractorUnit.getFarm().getCrop(i, j).getStatus()], tilePos, Color.FromNonPremultiplied(0, 0, 20, 40)); + if (state.LeftButton == ButtonState.Pressed && !tractorUnit.getFarm().getCrop(i, j).getHousePos()) + { + tractorUnit.setNewHousePos(new Vector2(i, j), true); + tractorUnit.setNewHousePos(houseUnit.getVector() / input.getSpacingTile(), false); + houseUnit.setRectangle(i, j, input.getTileSize(), input.getSpacing()); + } + + } + if ((tractorUnit.getFarm().getCrop(i, j).getStatus() == 4)) + { + spriteBatch.Draw(ProgressionBar, new Rectangle(i * (input.getSpacingTile()) + input.getTileSize() - input.getTileSize() / 3, j * (input.getSpacingTile()), input.getTileSize() / 3, input.getTileSize()), Color.White); + spriteBatch.Draw(ProgressionBarStatus, new Rectangle(i * (input.getSpacingTile()) + input.getTileSize() - input.getTileSize() / 4, j * (input.getSpacingTile()) + input.getTileSize() / 3, input.getTileSize() / 4, tractorUnit.getFarm().getCrop(i, j).getCropTimerBar((input.getTileSize())) + 1), Color.White); + } + if (tractorUnit.getFarm().getCrop(i, j).getStatus() != 0 && tractorUnit.getFarm().getCrop(i, j).getStatus() != 1) + { + spriteBatch.Draw(Crops[tractorUnit.getFarm().getCrop(i, j).getCropType()], new Rectangle(i * (input.getSpacingTile()) + input.getTileSize() - input.getTileSize() / 3, j * (input.getSpacingTile()), input.getTileSize() / 3, input.getTileSize() / 3), Color.White); + } + + } + } + } } } diff --git a/Game1/Game1.csproj b/Game1/Game1.csproj index e42dde1..5c21f33 100644 --- a/Game1/Game1.csproj +++ b/Game1/Game1.csproj @@ -53,6 +53,7 @@ + @@ -60,6 +61,7 @@ + @@ -123,6 +125,8 @@ + + diff --git a/Game1/Sources/Crops/Crops.cs b/Game1/Sources/Crops/Crops.cs index a9bb2f7..6f5aa89 100644 --- a/Game1/Sources/Crops/Crops.cs +++ b/Game1/Sources/Crops/Crops.cs @@ -8,20 +8,17 @@ using Microsoft.Xna.Framework.Graphics; class Crops { - public int x; - public int y; - public int Status; - private int cropType; - private int Timer; - private Random r; + private int Status; + private int originalStatus; + private int cropType = 0; + private int Timer = 1; + private int fullTimer; + private bool housePos = false; public void updateCrop() { - if (Status != 0) - { Timer--; - } } public int getCropTimer() @@ -29,6 +26,40 @@ class Crops return Timer; } + public int getCropTimerBar(int tileSize) + { + + int x = (int)(( 1 - ((float)Timer / fullTimer)) * (tileSize - tileSize / 3)); + return x; + } + + + + // Changes the time required for the crops to be harvestable + public void setCropTimer() + { + if (cropType == 0) // Carrots + { + Timer = 300; + fullTimer = Timer; + } + else if (cropType == 1) // Wheat + { + Timer = 600; + fullTimer = Timer; + } + else if (cropType == 2) // Berries + { + Timer = 1200; + fullTimer = Timer; + } + else // Fruit Trees + { + Timer = 2400; + fullTimer = Timer; + } + } + public int getCostOnMovement() { if (Status == 1) //grass @@ -41,23 +72,93 @@ class Crops } else if (Status == 3) //crops { - return 15; + if (cropType == 0) + { + return 15; //Carrots + } + else if (cropType == 1) + { + return 30; //Wheat + } + else if (cropType == 2) + { + return 40; //Berries + } + else + { + return 50; //Fruit Trees + } } - else + else //Harvestable Crops { - return 30; + if (cropType == 0) + { + return 30; //Carrots + } + else if (cropType == 1) + { + return 40; //Wheat + } + else if (cropType == 2) + { + return 50; //Berries + } + else + { + return 100; //Fruit Trees + } } } - public void setPosition(int newx, int newy) - { - x = newx; - y = newy; - } - public void setCropType(int Type) { - + cropType = Type; + } + + public int getStatus() + { + if (Status != 4) + { + return Status; + } + else + { + return Status; // + cropType; When unique crop textures have been added + } + } + + public int getCropType() + { + return cropType; + } + + public void setStatus(int newStatus) + { + Status = newStatus; + } + + public void setOriginalStatus() + { + originalStatus = Status; + } + + + public void setHousePos(bool state) + { + housePos = state; + if (state) + { + Status = 1; + } + else + { + Status = originalStatus; + } + } + + public bool getHousePos() + { + return housePos; } } diff --git a/Game1/Sources/Crops/Farm.cs b/Game1/Sources/Crops/Farm.cs index b84c36d..a7b5172 100644 --- a/Game1/Sources/Crops/Farm.cs +++ b/Game1/Sources/Crops/Farm.cs @@ -30,21 +30,25 @@ class Farm x = r.Next(1, 3); } crops[i, j] = new Crops(); - crops[i, j].Status = x; + crops[i, j].setStatus(x); + crops[i, j].setOriginalStatus(); + crops[i, j].setCropType(x = r.Next(0, 4)); } } } public void updateFarm(Vector2 Size) { - for (int i = 0; i > Size.X; i++) + for (int i = 0; i < Size.X; i++) { - for (int j = 0; j > Size.Y; j++) + for (int j = 0; j < Size.Y; j++) { - crops[i, j].updateCrop(); + if (crops[i, j].getStatus() == 4 && crops[i, j].getCropTimer() != 1) + { + crops[i, j].updateCrop(); + } } } - } //Changes the properties of the tile when the tractor reaches this tile. @@ -52,21 +56,22 @@ class Farm { int x = (int)xfloat / Spacing; int y = (int)yfloat / Spacing; - if (crops[x, y].Status == 4) + if (crops[x, y].getStatus() >= 4) { - crops[x, y].Status = 2; + crops[x, y].setStatus(2); } - else if(crops[x, y].Status == 0) + else if(crops[x, y].getStatus() == 0) { //do nothing } - else if (crops[x, y].Status == 2) + else if (crops[x, y].getStatus() == 2) { - crops[x, y].Status = 3; + crops[x, y].setStatus(3); } - else if (crops[x, y].Status == 3) + else if (crops[x, y].getStatus() == 3) { - crops[x, y].Status = 4; + crops[x, y].setStatus(4); + crops[x, y].setCropTimer(); } } @@ -87,10 +92,15 @@ class Farm { for (int j = 0; j < (int)Size.Y; j++) { - crops[i, j].x = (tileSize + Spacing) * i; - crops[i, j].y = (tileSize + Spacing) * j; + //crops[i, j].x = (tileSize + Spacing) * i; + //crops[i, j].y = (tileSize + Spacing) * j; } } } - + + public void setNewHousePos(Vector2 pos, bool newState) + { + crops[(int)pos.X, (int)pos.Y].setHousePos(newState); + } + } diff --git a/Game1/Sources/Objects/House.cs b/Game1/Sources/Objects/House.cs index 02560d3..ea2cdf6 100644 --- a/Game1/Sources/Objects/House.cs +++ b/Game1/Sources/Objects/House.cs @@ -43,6 +43,12 @@ class House return housePos; } + public void setRectangle(int x, int y, int tileSize, int Spacing) + { + pos = new Vector2(x, y); + housePos = new Rectangle(x * (tileSize + Spacing), y * (tileSize + Spacing), tileSize, tileSize); + } + public Vector2 getVector() { return new Vector2(housePos.X, housePos.Y); diff --git a/Game1/Sources/Objects/Inventory.cs b/Game1/Sources/Objects/Inventory.cs new file mode 100644 index 0000000..6ac641f --- /dev/null +++ b/Game1/Sources/Objects/Inventory.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Game1.Sources.Objects +{ + class Inventory + { + } +} diff --git a/Game1/Sources/Objects/Tractor.cs b/Game1/Sources/Objects/Tractor.cs index 97a6813..9626035 100644 --- a/Game1/Sources/Objects/Tractor.cs +++ b/Game1/Sources/Objects/Tractor.cs @@ -77,13 +77,10 @@ class Tractor public void updatePosition(Vector2 Size, int Status) /// updates the position { - farm.updateSize(Size, sizeTile, Spacing); + //farm.updateSize(Size, sizeTile, Spacing); for (int i = 0; i < Speed; i++) //Where all the choices the tractor does comes from { - smartTractor.updateMap(Position, housePos, farm.getCrops(), Size, sizeTile, Spacing, scoreSystem.getScore(), Rotation); - updateDirection(Size, Position); - } @@ -93,22 +90,23 @@ class Tractor { if (path.getCount() == 0) { - if (housePos != Position) + if (Position.X / (sizeTile + Spacing) > Size.X) { - //Returns to the farm - int x = (int)Position.X / (sizeTile + Spacing); - int y = (int)Position.Y / (sizeTile + Spacing); - currentTask = scoreSystem.MessageAndScore(farm.getCrop(x, y).Status, 0); - farm.setCropStatus(x, y, Spacing); - path = smartTractor.returnChoice(0); + Position.X = (Size.X - 1) * (sizeTile + Spacing); } - else + else if (Position.Y / (sizeTile + Spacing) > Size.Y) { - //Sets a random Target - int xTarget = (int)TargetPosition.X / (sizeTile + Spacing); - int yTarget = (int)TargetPosition.Y / (sizeTile + Spacing); - currentTask = scoreSystem.MessageAndScore(farm.getCrop(xTarget, yTarget).Status, 1); - path = smartTractor.returnChoice(1); + Position.Y = (Size.Y - 1) * (sizeTile + Spacing); + } + + smartTractor.updateMap(Position, housePos, farm.getCrops(), Size, sizeTile, Spacing, scoreSystem.getScore(), Rotation); + path = smartTractor.returnChoice(); + + + // Changes the status of a tile when the tractor reaches its destination + if (path.getFinalDest() == null && farm.getCrop((int)Position.X / (sizeTile + Spacing), (int)Position.Y / (sizeTile + Spacing)).getCropTimer() == 1) + { + farm.setCropStatus(Position.X / (sizeTile + Spacing), Position.Y / (sizeTile + Spacing), Spacing); } TargetPosition = path.Reduce().getCords() * (sizeTile + Spacing); @@ -237,6 +235,14 @@ class Tractor } + public void updateCrops() + { + for (int i = 0; i < Speed; i++) + { + farm.updateFarm(Size); + } + } + public Vector2 getPos() { return Position; @@ -306,4 +312,9 @@ class Tractor { return path; } + + public void setNewHousePos(Vector2 pos, bool newState) + { + farm.setNewHousePos(pos, newState); + } } diff --git a/Game1/Sources/Pathing/A-Star/Astar.cs b/Game1/Sources/Pathing/A-Star/Astar.cs index 9ab7ae1..bdb83d4 100644 --- a/Game1/Sources/Pathing/A-Star/Astar.cs +++ b/Game1/Sources/Pathing/A-Star/Astar.cs @@ -56,7 +56,7 @@ class Astar } // return if not an obstacle return adjacentNodes.Where( - item => crops[(int)item.getCords().X, (int)item.getCords().Y].Status != 0).ToList(); + item => (crops[(int)item.getCords().X, (int)item.getCords().Y].getStatus()) != 0).ToList(); } // Heuristic function, Manhattan method. diff --git a/Game1/Sources/Smart/AI.cs b/Game1/Sources/Smart/AI.cs new file mode 100644 index 0000000..1d9d0c8 --- /dev/null +++ b/Game1/Sources/Smart/AI.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; + + +class AI +{ + + private Vector2 tractorPos; + private Vector2 housePos; + private Crops[,] crops; + private Vector2 Size; + private Vector2 targetPos; + private int Rotation; + + + + + private Random r = new Random(); + + + + + + public void update(Crops[,] newCrops, Vector2 newSize, Vector2 newTractorPos, Vector2 newHousePos, Vector2 newtargetPos, int rotation) + { + tractorPos = new Vector2((int)newTractorPos.X, (int)newTractorPos.Y); + housePos = new Vector2((int)newHousePos.X, (int)newHousePos.Y); + targetPos = newtargetPos; + crops = newCrops; + Size = newSize; + Rotation = rotation; + } + + + public Vector2 newTarget() + { + return new Vector2(r.Next(0, (int)Size.X), r.Next(0, (int)Size.Y)); + } +} diff --git a/Game1/Sources/Smart/SmartTractor.cs b/Game1/Sources/Smart/SmartTractor.cs index fa7112c..a5c5284 100644 --- a/Game1/Sources/Smart/SmartTractor.cs +++ b/Game1/Sources/Smart/SmartTractor.cs @@ -9,30 +9,31 @@ class SmartTractor private Vector2 tractorPos; private Vector2 Size; private Vector2 Target; - private Path path; + private int tileSize; private int Score; private int Spacing; - private Random r = new Random(); private Astar astar = new Astar(); private int Rotation; + private AI ai = new AI(); //What to do next - public Path returnChoice(int task) + public Path returnChoice() { - if (task == 0) - { - //To the house - getTargetPosition((int)housePos.X / (tileSize + Spacing), (int)housePos.Y / (tileSize + Spacing)); - } - else - { - //To the fields - getTargetPosition(r.Next(0, (int)Size.X), r.Next(0, (int)Size.Y)); - } + ai.update(crops, Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target / (tileSize + Spacing), Rotation); + + + + + getTargetPosition(ai.newTarget()); + + + + + astar.update(crops, Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target/(tileSize+Spacing), Rotation); - //astar.FindPath(); + return astar.FindPath(); } @@ -55,66 +56,8 @@ class SmartTractor } - private void getTargetPosition(int x, int y) + private void getTargetPosition(Vector2 newTarget) { - Target = new Vector2(x, y) * (tileSize + Spacing); + Target = newTarget * (tileSize + Spacing); } - - - - - - - /* - //Only for testing without obstacles - private void createPath() - { - path = new Path(); - Vector2 targetPos = Target / (tileSize + Spacing); - Vector2 currentPath = tractorPos / tileSize; - currentPath.X = (float)Math.Round(currentPath.X); - currentPath.Y = (float)Math.Round(currentPath.Y); - do - { - if (currentPath.X == targetPos.X) - { - //found X pos - if (currentPath.Y == targetPos.Y) - { - //found y pos - } - else if (currentPath.Y < targetPos.Y) - { - currentPath = new Vector2(currentPath.X, currentPath.Y + 1); - path.setNode(currentPath, crops); - } - else if (currentPath.Y > targetPos.Y) - { - currentPath = new Vector2(currentPath.X, currentPath.Y - 1); - path.setNode(currentPath, crops); - } - } - else if (currentPath.X < targetPos.X) - { - currentPath = new Vector2(currentPath.X + 1, currentPath.Y); - path.setNode(currentPath, crops); - } - else if (currentPath.X > targetPos.X) - { - currentPath = new Vector2(currentPath.X - 1, currentPath.Y); - path.setNode(currentPath, crops); - } - } while (currentPath != targetPos); - - - } - - public void setNode(Vector2 newNode, Crops[,] Crop) - { - - nodes[Count] = new Nodes(Crop[(int)newNode.X, (int)newNode.Y].getCostOnMovement(), newNode); - Count++; - } - - */ }