コード例 #1
0
ファイル: Program.cs プロジェクト: ShakiMan/.NET-Applications
        static void Main(string[] args)
        {
            PrintInfo();

            object[] arr =
            {
                new Square(4.5,     6.0),
                new Triangle(-21,    12),
                new Circle(8.76,   3.12),
                new Pentagon(17.0, 8)
            };

            foreach (object obj in arr)
            {
                if (obj is IFigure)
                {
                    WriteLine($"Before: {obj}");
                    (obj as IFigure).moveTo(4, 5);
                    WriteLine($"After: {obj}");
                }
            }

            IHasInterior interior = (IHasInterior)arr[0];

            interior.InteriorColor = "White";
            interior = (IHasInterior)arr[1];
            interior.InteriorColor = "Black";

            PrintFigureColor(arr);
        }
コード例 #2
0
ファイル: Interior.cs プロジェクト: ede0m/GustoGame
 public Guid GetInteriorForId()
 {
     if (interiorForObj is IHasInterior)
     {
         IHasInterior obj = (IHasInterior)interiorForObj;
         return(obj.GetInteriorForId());
     }
     else
     {
         return(Guid.Empty);
     }
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: kogol99/dotNet-2020
 public static void PrintColor(object[] arr)
 {
     foreach (object obj in arr)
     {
         IHasInterior figure = obj as IHasInterior;
         if (figure != null)
         {
             Console.WriteLine($"{figure.InteriorColor}");
         }
         else
         {
             Console.WriteLine($"no color");
         }
     }
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: ShakiMan/.NET-Applications
 public static void PrintFigureColor(object[] arr)
 {
     foreach (object obj in arr)
     {
         IHasInterior interior = obj as IHasInterior;
         if (interior != null)
         {
             WriteLine($"{interior.InteriorColor}");
         }
         else
         {
             WriteLine($"no color");
         }
     }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: kogol99/dotNet-2020
        static void Main(string[] args)
        {
            object[] arr =
            {
                new Ring(1.1,        1),
                new Ring(2.5,     -2.5),
                new Triangle(3.2,   12),
                new Triangle(2,     10),
                new Trapeze(2.9,  1.09),
                new Trapeze(5,       5),
            };

            IHasInterior figure = (IHasInterior)arr[0];

            figure.InteriorColor = "Red";
            figure = (IHasInterior)arr[1];
            figure.InteriorColor = "Green";
            figure = (IHasInterior)arr[2];
            figure.InteriorColor = "Blue";

            PrintColor(arr);

            MovePostion(arr);
        }
コード例 #6
0
        private void InitializeLoadState(List <ISaveState> LoadFromState)
        {
            Dictionary <Guid, Interior> interiorForObjMap = new Dictionary <Guid, Interior>(); // key is the interiorObjFor and val is the interior that belongs to this obj

            foreach (ISaveState objState in LoadFromState)
            {
                // Interiors are deserialized first since they were serialized first
                if (objState.GetType() == typeof(InteriorState))
                {
                    InteriorState its = (InteriorState)objState;
                    Interior      i   = DeserializeInterior(its);
                    interiorForObjMap.Add(its.interiorForId, i);
                    BoundingBoxLocations.interiorMap.Add(i.interiorId, i);
                }

                if (objState.GetType() == typeof(PlayerState))
                {
                    PlayerState ps = (PlayerState)objState;
                    player.location  = ps.location;
                    player.inventory = DeserializeInventory(ps.inventory);
                    player.inHand    = (HandHeld)DeserializeInventoryItem(ps.inHandItemKey);

                    if (ps.playerInInteriorId == Guid.Empty)
                    {
                        player.playerOnShip     = null;
                        player.playerInInterior = null;
                    }
                    else
                    {
                        player.entranceLoc = ps.interiorEntranceLocation;
                        // check if the interior already exists
                        foreach (KeyValuePair <Guid, Interior> interior in BoundingBoxLocations.interiorMap)
                        {
                            if (ps.playerInInteriorId == interior.Key)
                            {
                                player.playerInInterior = interior.Value;
                                break;
                            }
                        }
                    }

                    player.onShip    = ps.onShip;
                    player.regionKey = ps.region;
                    player.health    = ps.health;
                    UpdateOrder.Add(player);
                }

                else if (objState.GetType() == typeof(NpcState))
                {
                    NpcState npcs = (NpcState)objState;
                    Npc      npc  = (Npc)DeserializeModel(npcs.objKey, npcs);
                    npc.location  = npcs.location;
                    npc.inventory = DeserializeInventory(npcs.inventory);

                    if (npcs.npcInInteriorId == Guid.Empty)
                    {
                        npc.npcInInterior = null;
                    }
                    else
                    {
                        // THIS SHOULD NEVER RUN BECAUSE NPCS THAT ARE IN INTERIORS ARE DESERIALIZED ELSEWHERE

                        // check if the interior already exists
                        foreach (KeyValuePair <Guid, Interior> interior in BoundingBoxLocations.interiorMap)
                        {
                            if (npcs.npcInInteriorId == interior.Key)
                            {
                                npc.npcInInterior = interior.Value;
                                break;
                            }
                        }
                    }

                    npc.onShip    = npcs.onShip;
                    npc.regionKey = npcs.region;
                    npc.health    = npcs.health;
                    UpdateOrder.Add(npc);
                }

                else if (objState.GetType() == typeof(ShipState))
                {
                    ShipState ss = (ShipState)objState;
                    Ship      s  = (Ship)DeserializeModel(ss.objKey, ss);
                    UpdateOrder.Add(s);
                }

                else if (objState.GetType() == typeof(StructureState))
                {
                    StructureState ss = (StructureState)objState;
                    Structure      s  = (Structure)DeserializeModel(ss.objKey, ss);
                    UpdateOrder.Add(s);
                }

                else if (objState.GetType() == typeof(WeatherSaveState))
                {
                    WeatherSaveState wss = (WeatherSaveState)objState;
                    WeatherState.currentLightIntensity = wss.currentLightIntensity;
                    WeatherState.currentMsOfDay        = wss.currentMsOfDay;
                    WeatherState.sunAngleX             = wss.sunAngleX;
                    WeatherState.shadowTransparency    = wss.shadowTransparency;
                    WeatherState.totalDays             = wss.nDays;
                    WeatherState.weatherDuration       = wss.weatherDuration;
                    WeatherState.msThroughWeather      = wss.msThroughWeather;
                    WeatherState.rainState             = wss.rainState;
                    WeatherState.rainIntensity         = wss.rainIntensity;
                    WeatherState.lightning             = wss.lightning;

                    // set the rain
                    for (int i = 0; i < WeatherState.rainIntensity; i++)
                    {
                        WeatherState.rain.Add(new RainDrop(_content, _graphics));
                    }
                }

                else if (objState.GetType() == typeof(OnGroundState))
                {
                    OnGroundState ogs = (OnGroundState)objState;
                    Sprite        sp  = null;
                    if (ogs.inventoryItem)
                    {
                        InventoryItem ii = DeserializeInventoryItem(ogs.objKey);
                        ii.amountStacked = ogs.amountStacked;
                        ii.onGround      = true;
                        sp = ii;
                    }
                    else
                    {
                        sp = DeserializeModel(ogs.objKey, objState);
                    }
                    sp.location  = ogs.location;
                    sp.regionKey = ogs.region;

                    ItemUtility.ItemsToUpdate.Add(sp);
                }
            }

            // go through newly created world state and set any interiors for the object that owns that interior
            foreach (Sprite sp in UpdateOrder)
            {
                if (sp is IHasInterior)
                {
                    IHasInterior hasInterior   = (IHasInterior)sp;
                    Guid         interiorForId = hasInterior.GetInteriorForId();

                    if (sp is IShip)
                    {
                        Ship sh = (Ship)sp;
                        sh.shipInterior = interiorForObjMap[interiorForId];
                    }
                    else if (sp is IStructure)
                    {
                        Structure st = (Structure)sp;
                        st.structureInterior = interiorForObjMap[interiorForId];
                    }

                    interiorForObjMap[interiorForId].interiorForObj = sp;
                }
            }

            // set player's current ship, the interior will be the ships interior
            if (player.onShip)
            {
                player.playerOnShip = (Ship)BoundingBoxLocations.interiorMap[player.playerInInterior.interiorId].interiorForObj;
            }
        }