Example #1
0
    public static IEquipable makeSword()
    {
        HashSet <IEquipable> behaviors = new HashSet <IEquipable>();

        Flagable f = new Flagable();

        f.addFlag(BattleStats.ATTACK);
        Pipe <int> attackup          = new PipeSum(new ExpireNever <Pipe <int> >(), f, 2);
        IEquipable addAttachBehavior = new EquipablePipe(EquipSlots.MAIN_HAND, attackup);

        PMAction   slashAction   = new ActionAttack(3);
        IEquipable slashBehavior = new ActionEquipable(EquipSlots.MAIN_HAND, slashAction);

        behaviors.Add(addAttachBehavior);
        behaviors.Add(slashBehavior);

        MultiBehaviorEquipable sword = new MultiBehaviorEquipable(EquipSlots.MAIN_HAND, behaviors);

        return(sword);
    }
    public void test()
    {
        // 1 make a Pipe
        IExpire <Pipe <int> > expire = new ExpireNever <Pipe <int> >();
        IFlagable             flags  = new Flagable();
        Pipe <int>            p      = new PipeSum(expire, flags, 10);

        // 2 Pump the pipe
        assert(p.pump(5) == 15, "Pump produced the wrong value during pump operation!");

        // 3 Jsonify
        JsonObject jo = p.toJson();

        assert(jo["Type"] == "PipeSum");


        string directory = "TempDirectory";
        string fileName  = "TestFile";
        // NOTE: PersistantFilePath =  C:\Users\Arthur\AppData\LocalLow\DefaultCompany\StandAloneCon(plex)versation
        // 4 write to disk
        JsonOrigamist jsonOrigamist = new JsonOrigamist(directory, fileName);

        jsonOrigamist.add(jo);
        jsonOrigamist.writeToDisk();

        // 4.1 Simulate power down
        CentralRegistry.deregister(p.getNocabName());

        // 5 read from disk
        JsonArray  ja         = jsonOrigamist.readFromDisk();
        JsonObject joFromDisk = ja[0];

        assert(joFromDisk.ToString() == jo.ToString());

        // 6 Load the new pipe
        Pipe <int> pFromDisk = new PipeSum(joFromDisk);

        // 7 pump the new pipe
        assert(p.pump(5) == pFromDisk.pump(5));
    }