public void PlaceHeldItemIn(Recepticle target) { if (target.AcceptNewItem(heldItem)) { heldItem = null; } }
/// <summary> /// Adds a recepticle to the level /// </summary> /// <param name="r">The recepticle to add</param> public void AddRecepticle(Recepticle r) { recepticles.Add(r); }
//private bool isFuture; /// <summary> /// Creates a level given a file name and a dictionary of tile textures to use /// </summary> public Level(String fileName, Dictionary <String, Texture2D> tileTextures) { myRNG = new Random(); tileVariant = 0; interactables = new List <Interactable>(); recepticles = new List <Recepticle>(); indicators = new List <Indicator>(); doors = new List <Point>(); tiles = new Tile[12, 16]; //finds file, creates holder string for reader StreamReader reader = new StreamReader(fileName); String line = ""; String[] words; //for every tile in the 2D array:\ //checks if this tile is a floor tile is past and/or future //if floor, make it non-collidable in that timeState //otherwise, it is collidable for (int h = 0; h < 12; h++) { for (int w = 0; w < 16; w++) { line = reader.ReadLine(); //ignore documented lines in Level files if (line[0] != '/') { tileVariant = myRNG.Next(20) + 1; if (tileVariant == 17) { tileVariant = 1; } else if (tileVariant == 18) { tileVariant = 2; } else if (tileVariant == 19) { tileVariant = 3; } else if (tileVariant == 20) { tileVariant = 4; } else { tileVariant = 0; } words = line.Split(' '); //handles situations where both, one, or neither time state is collidable //HEY YOURE GONNA HAVE TO FIX THIS LATER //^^this is bad documentation //I think I fixed this, because this only generates an error with out-of-date level files if (words[0] == "door" || words[0] == "OpenDoorExtHoriz" || words[0] == "OpenDoorExtVert" || words[0] == "OpenDoorIntVert" || words[0] == "OpenDoorIntVert" || words[2] == "door" || words[2] == "OpenDoorExtHoriz" || words[2] == "OpenDoorExtVert" || words[2] == "OpenDoorIntVert" || words[2] == "OpenDoorIntVert") { tiles[h, w] = new Door( new Rectangle((w * 64), (h * 64), 64, 64), new AnimatedTexture(0, 32, 32, tileTextures["Past" + words[0]]), int.Parse(words[1]), false, new AnimatedTexture(0, 32, 32, tileTextures["Future" + words[2] + tileVariant]), int.Parse(words[3]), false, 1); doors.Add(new Point(h, w)); } else if (words[0] == "LockedDoorExtHoriz" || words[0] == "LockedDoorExtVert" || words[0] == "LockedDoorIntVert" || words[0] == "LockedDoorIntVert" || words[2] == "LockedDoorExtHoriz" || words[2] == "LockedDoorExtVert" || words[2] == "LockedDoorIntVert" || words[2] == "LockedDoorIntVert") { tiles[h, w] = new Door( new Rectangle((w * 64), (h * 64), 64, 64), new AnimatedTexture(0, 32, 32, tileTextures["Past" + words[0]]), int.Parse(words[1]), true, new AnimatedTexture(0, 32, 32, tileTextures["Future" + words[2] + tileVariant]), int.Parse(words[3]), true, 1); doors.Add(new Point(h, w)); } else if (words[0] == "Floor" && words[2] == "Floor") { tiles[h, w] = new Tile( new Rectangle((w * 64), (h * 64), 64, 64), new AnimatedTexture(0, 32, 32, tileTextures["Past" + words[0]]), int.Parse(words[1]), false, new AnimatedTexture(0, 32, 32, tileTextures["Future" + words[2] + tileVariant]), int.Parse(words[3]), false, 1); } else if (words[0] == "Floor" && words[2] != "Floor") { tiles[h, w] = new Tile( new Rectangle((w * 64), (h * 64), 64, 64), new AnimatedTexture(0, 32, 32, tileTextures["Past" + words[0]]), int.Parse(words[1]), false, new AnimatedTexture(0, 32, 32, tileTextures["Future" + words[2] + tileVariant]), int.Parse(words[3]), true, 1); } else if (words[0] != "Floor" && words[2] == "Floor") { tiles[h, w] = new Tile( new Rectangle((w * 64), (h * 64), 64, 64), new AnimatedTexture(0, 32, 32, tileTextures["Past" + words[0]]), int.Parse(words[1]), true, new AnimatedTexture(0, 32, 32, tileTextures["Future" + words[2] + tileVariant]), int.Parse(words[3]), false, 1); } //HEY YOURE GONNA HAVE TO FIX THIS LATER //see above document else if (words[0] != "Floor" && words[2] != "Floor") { tiles[h, w] = new Tile( new Rectangle((w * 64), (h * 64), 64, 64), new AnimatedTexture(0, 32, 32, tileTextures["Past" + words[0]]), int.Parse(words[1]), true, new AnimatedTexture(0, 32, 32, tileTextures["Future" + words[2] + tileVariant]), int.Parse(words[3]), true, 1); } } //this part of if ladder just makes sure that skipping lines due to documentation in the level files //doesn't skip a tile else if (w == 0) { w = 15; h--; } else { w--; } } } //begin interactable stuff while (true) { line = reader.ReadLine(); if (line == null || line == "/recepticles") { break; } words = line.Split(' '); if (words.Length < 4) { continue; } string interactableName = words[0]; string interactableState = words[1]; int gridX = int.Parse(words[2]); int gridY = int.Parse(words[3]); Rectangle r = new Rectangle(gridX * 64, gridY * 64, 64, 64); switch (interactableName) { case "Chicken": interactables.Add(new Chicken(r, (ChickenState)Enum.Parse(typeof(ChickenState), interactableState), 1, this)); break; case "Flower": interactables.Add(new Flower(r, (FlowerState)Enum.Parse(typeof(FlowerState), interactableState), 1, this)); break; case "Tree": interactables.Add(new Tree(r, (TreeState)Enum.Parse(typeof(TreeState), interactableState), 1, this)); break; case "WateringCan": interactables.Add(new WateringCan(r, (WateringCanState)Enum.Parse(typeof(WateringCanState), interactableState), 1, this)); break; case "Shovel": interactables.Add(new Shovel(r, (ShovelState)Enum.Parse(typeof(ShovelState), interactableState), 1, this)); break; case "Axe": Interactables.Add(new Axe(r, (AxeState)Enum.Parse(typeof(AxeState), interactableState), 1, this)); break; } } //skip documentation line in level file line = reader.ReadLine(); //handles recepticles while (line != null) { //to store coordinates of the door String[] doorCoord; //a temporary reference to a door that needs to be linked to this recepticle Tile door; //a temporary reference to this recepticle Recepticle r; words = line.Split(' '); if (words[0] == "Past") { r = new Recepticle( TimeState.Past, (words[1] + "_" + words[2]), new Rectangle(int.Parse(words[4]) * 64, int.Parse(words[3]) * 64, 64, 64)); //loops through remainder of words //which are only coordinates for doors to link to the recepticles for (int i = 5; i < words.Length; i++) { doorCoord = words[i].Split(','); //find that door door = tiles[int.Parse(doorCoord[1]), int.Parse(doorCoord[0])]; ((Door)(door)).LinkRecepticle(r); } recepticles.Add(r); } else if (words[0] == "Future") { r = new Recepticle( TimeState.Future, (words[1] + "_" + words[2]), new Rectangle(int.Parse(words[4]) * 64, int.Parse(words[3]) * 64, 64, 64)); //loops through remainder of words //which are only coordinates for doors to link to the recepticles for (int i = 5; i < words.Length; i++) { doorCoord = words[i].Split(','); //find that door door = tiles[int.Parse(doorCoord[1]), int.Parse(doorCoord[0])]; ((Door)(door)).LinkRecepticle(r); } recepticles.Add(r); } //go to next line line = reader.ReadLine(); } }
//public bool Open //{ // get // { // return open; // } //} /// <summary> /// Links a new recepticle to the door /// </summary> /// <param name="r">The recepticle to add a link to</param> public void LinkRecepticle(Recepticle r) { recepticles.Add(r); }