예제 #1
0
 public IItem MakeItem(ItemEnum spriteType, Vector2 location)
 {
     return(spriteType switch
     {
         ItemEnum.MagicalBoomerang => new BlueBoomerangItem(texture1, location),
         ItemEnum.Boomerang => new BoomerangItem(texture1, location),
         ItemEnum.BlueRing => new BlueRing(texture1, location),
         ItemEnum.RedRing => new Ring(texture1, location),
         ItemEnum.BlueCandle => new BlueCandle(texture1, location),
         ItemEnum.RedCandle => new Candle(texture1, location),
         ItemEnum.Food => new Meat(texture1, location),
         ItemEnum.Letter => new BlueMap(texture1, location),
         ItemEnum.Map => new Map(texture1, location),
         ItemEnum.BluePotion => new BluePotion(texture1, location),
         ItemEnum.RedPotion => new Potion(texture1, location),
         ItemEnum.BlueRupee => new BlueRupee(texture1, location),
         ItemEnum.Rupee => new Rupee(texture1, location),
         ItemEnum.Clock => new Clock(texture1, location),
         ItemEnum.Bow => new Bow(texture1, location),
         ItemEnum.HeartContainer => new HeartContainer(texture1, location),
         ItemEnum.TriforcePiece => new TriforcePiece(texture1, location, game),
         ItemEnum.Compass => new Compass(texture1, location),
         ItemEnum.Key => new Key(texture1, location),
         ItemEnum.Fairy => new Fairy(texture1, location, game),
         ItemEnum.FairyDistract => new FairyDistract(texture1, location, game),
         ItemEnum.Arrow => new ArrowItem(texture1, location),
         ItemEnum.Bomb => new BombItem(texture1, location),
         ItemEnum.PowerBracelet => new PowerBracelet(texture1, location),
         ItemEnum.BookOfMagic => new BookOfMagic(texture1, location),
         ItemEnum.Flute => new Flute(texture1, location),
         ItemEnum.Raft => new Raft(texture1, location),
         ItemEnum.Stepladder => new StepLadder(texture1, location),
         ItemEnum.MagicalKey => new MagicalKey(texture1, location),
         ItemEnum.MagicalRod => new MagicalRod(texture1, location),
         ItemEnum.MagicalSword => new MagicalSword(texture1, location),
         ItemEnum.WhiteSword => new WhiteSword(texture1, location),
         ItemEnum.WoodenSword => new WoodenSword(texture1, location),
         ItemEnum.GanonTriforceAshes => new GanonTriforceAshes(texture2, location, game),
         _ => throw new ArgumentException("Invalid sprite! " + spriteType.ToString() + " Sprite factory failed."),
     });
예제 #2
0
        private void LoadTiles(string fileName)
        {
            string[] loadPathDirs      = fileName.Split('\\');
            string   relativeNotesPath = "notes_" + loadPathDirs.Last();

            string notesLoadPath = "";

            foreach (string dir in loadPathDirs)
            {
                if (dir != loadPathDirs.Last())
                {
                    notesLoadPath += dir + '\\';
                }
            }

            notesLoadPath += relativeNotesPath;

            using (StreamReader sr = new StreamReader(fileName)) {
                // Exception: Get first two lines differently
                // Line 1
                string   line        = sr.ReadLine();
                string[] line1Values = line.Split(' ');
                levelWidthInTiles  = Convert.ToInt32(line1Values[0]);
                levelHeightInTiles = Convert.ToInt32(line1Values[1]);

                textboxLevelWidth.Text  = levelWidthInTiles.ToString();
                textboxLevelHeight.Text = levelHeightInTiles.ToString();
                textboxNumLayers.Text   = (line1Values.Length - 2).ToString();

                // Line 2
                line = sr.ReadLine();
                Console.WriteLine(line);

                setImageSource(line);
                createTables();

                int count = 0;

                while ((line = sr.ReadLine()) != null)
                {
                    string[] splitLine = line.Split(' ');

                    if (splitLine[0].StartsWith("-"))
                    {
                        int skipValue = int.Parse(splitLine[0].Split('-').Last());
                        count += skipValue;
                        continue;
                    }

                    List <Button> buttonsAtLocation = new List <Button>(numLayers);
                    for (int i = 0; i < numLayers; i++)
                    {
                        buttonsAtLocation.Add(gameboardButtons[i][count]);
                    }

                    List <Tile> tilesAtLocation = new List <Tile>(numLayers);
                    for (int i = 0; i < numLayers; i++)
                    {
                        tilesAtLocation.Add(null);
                    }

                    int       currentLayer        = 0;
                    const int tileCoordFirstIndex = 10;
                    int       tileCoordLastIndex  = tileCoordFirstIndex - 1 + numLayers * 2;
                    for (int i = tileCoordFirstIndex; i <= tileCoordLastIndex; i++)
                    {
                        if (i >= splitLine.Length)
                        {
                            break;
                        }

                        if (splitLine[i] == "-1")
                        {
                            tileCoordLastIndex--;
                            currentLayer++;
                            continue;
                        }

                        if (i + 1 >= splitLine.Length)
                        {
                            Console.WriteLine("Looking past splitLine's length for the y-coord of a tile. This shouldn't happen.");
                            break;
                        }

                        tilesAtLocation[currentLayer] = srcTiles.SingleOrDefault(t => t.x * tileWidth == int.Parse(splitLine[i]) && t.y * tileHeight == int.Parse(splitLine[i + 1]));
                        currentLayer++;
                        i++;
                    }

                    UnitEnum unit = UnitEnum.None;
                    ItemEnum item = ItemEnum.None;

                    unit = (UnitEnum)Enum.Parse(typeof(UnitEnum), splitLine[8]);
                    item = (ItemEnum)Enum.Parse(typeof(ItemEnum), splitLine[9]);

                    // If has unit or item, indicate this via string in the button
                    // For now, let's assume that the best button to indicate this in is in the foremost layer
                    if (unit != UnitEnum.None)
                    {
                        foreach (Button button in buttonsAtLocation)
                        {
                            button.Content = unit.ToString();
                        }

                        int numNullsAtLocation    = numLayers - tilesAtLocation.Count(tile => tile != null);
                        int numNotNullsAtLocation = numLayers - numNullsAtLocation;

                        // If moving platform, set up that object as well
                        if (unit == UnitEnum.MovingPlatformRed || unit == UnitEnum.MovingPlatformPink)
                        {
                            int            platformDestFirstIndex = tileCoordFirstIndex + numNotNullsAtLocation * 2 + numNullsAtLocation;
                            MovingPlatform platform = GetOrCreatePlatform(count);

                            // Read in destinations from the last expected property to the end of the line
                            for (int i = platformDestFirstIndex; i < splitLine.Length; i += 2)
                            {
                                platform.tileDests.Add(new Tuple <int, int>(int.Parse(splitLine[i]), int.Parse(splitLine[i + 1])));
                            }

                            for (int i = 0; i < platform.tileDests.Count; i++)
                            {
                                Button destButton = (Button)FindName("levelTile" + GetButtonIndexFromCoordinates(platform.tileDests[i]));
                                destButton.Content = "D" + (i + 1);
                            }

                            platforms.Add(platform);
                        }
                    }
                    if (item != ItemEnum.None)
                    {
                        foreach (Button button in buttonsAtLocation)
                        {
                            button.Content = item.ToString();
                        }
                    }

                    // Set location properties
                    LocationData location = locations[count];
                    if (location != null)
                    {
                        location.unit = unit;
                        location.item = item;
                    }

                    // Set button images for each tile at location
                    for (int i = 0; i < tilesAtLocation.Count; i++)
                    {
                        if (tilesAtLocation[i] != null)
                        {
                            buttonsAtLocation[i].Background = new ImageBrush(tilesAtLocation[i].image.Source);
                        }
                    }

                    int?lastNonNullIndex = null;
                    for (int i = 0; i < tilesAtLocation.Count; i++)
                    {
                        if (tilesAtLocation[i] == null)
                        {
                            continue;
                        }

                        placedTiles[i][count] = tilesAtLocation[i];
                        lastNonNullIndex      = i;
                    }

                    // Set foremost-layer tile's properties
                    if (lastNonNullIndex.HasValue)
                    {
                        Tile lastTile = placedTiles[lastNonNullIndex.Value][count];
                        lastTile.leftHeight      = int.Parse(splitLine[0]);
                        lastTile.rightHeight     = int.Parse(splitLine[1]);
                        lastTile.topCollision    = splitLine[2].ToString() == "1" ? true : false;
                        lastTile.rightCollision  = splitLine[3].ToString() == "1" ? true : false;
                        lastTile.bottomCollision = splitLine[4].ToString() == "1" ? true : false;
                        lastTile.leftCollision   = splitLine[5].ToString() == "1" ? true : false;
                        lastTile.isEdge          = splitLine[6].ToString() == "1" ? true : false;

                        // Mutex properties will default to false, so only need to think about setting them to true
                        string mutexProperty = splitLine[7].ToString();
                        if (mutexProperty == "1")
                        {
                            lastTile.isPole = true;
                        }
                        else if (mutexProperty == "2")
                        {
                            lastTile.isPoleEdge = true;
                        }
                        else if (mutexProperty == "3")
                        {
                            lastTile.isDeadly = true;
                        }
                    }

                    count++;
                }
            }

            Console.WriteLine("File loaded.");
            isLevelLoaded = true;
        }