Exemple #1
0
    /* Awake
     * @param none
     * @return none
     * Called to start the script and initializes canMove to false
     */
    void Awake()
    {
        canMove     = false;
        attackDelay = 0;

        IEnemy[] scripts = this.GetComponents <IEnemy>();

        foreach (IEnemy ie in scripts)
        {
            Debug.Log(ie.GetType().Name);
            enemyName = ie.GetType().Name;
            myEnemy   = ie;
        }

        if (enemyName == "MuffinMan")
        {
            muffinMan = GetComponent <MuffinMan>();
            moveSpeed = 1.0f;
        }
        else if (enemyName == "Jack")
        {
            jack      = GetComponent <Jack>();
            moveSpeed = 0.5f;
        }
    }
    // Untarget a jack
    public void UntargetJack(Jack target)
    {
        _targetedJacks.Remove(target.Id);

        // Free or fill accordingly
        FreeJack(target);
    }
Exemple #3
0
 public void ClearTarget()
 {
     if (_targetJack != null)
     {
         _targetJack.Untarget();
     }
     _targetJack = null;
 }
Exemple #4
0
 private void OnTriggerExit(Collider other)
 {
     if (other.GetComponent <Jack>() && currentJack != null)
     {
         print("Unplugged");
         currentJack = null;
     }
 }
Exemple #5
0
 public void Unplug()
 {
     if (IsTargetPlugged)
     {
         ClearTarget();
     }
     _pluggedJack = null;
 }
Exemple #6
0
 public static ICard Of(CardSuit cardSuit)
 {
     var jack = new Jack
     {
         _CardSuit = cardSuit
     };
     return jack;
 }
    // Tag jack as targeted
    public void TargetJack(Jack target)
    {
        _freeJacks.Remove(target.Id);

        // Dupe check
        if (!_targetedJacks.ContainsKey(target.Id))
        {
            _targetedJacks.Add(target.Id, target);
        }
    }
Exemple #8
0
 public void Send(string msg, IColleague coll)
 {
     if (coll == Jack)
     {
         Jhon.Notify(msg);
     }
     else if (coll == Jhon)
     {
         Jack.Notify(msg);
     }
 }
        public void WhenMakingATrade_JackShouldNotBeGreedy(int beans)
        {
            // Arrange
            Jack   jack;
            Action action;

            // Act
            jack   = new Jack();
            action = () => jack.TradeCowForBeans(beans);


            // Assert
            Assert.Throws <InvalidOperationException>(action);
        }
        public void WhenMakingATrade_JackCannotGiveHisCowAway()
        {
            // Arrange
            Jack   jack;
            Action action;

            // Act
            jack   = new Jack();
            action = () => jack.TradeCowForBeans(0);


            // Assert
            Assert.Throws <InvalidOperationException>(action);
        }
        public void WhenMakingATrade_JackShouldOnlyBeAbleToSellHisCowForBetweenOneAndFiveBeans(int beans)
        {
            // Arrange
            Jack jack;

            // Act
            jack = new Jack();
            jack.TradeCowForBeans(beans);


            // Assert
            Assert.Equal(0, jack.Cows);
            Assert.Equal(beans, jack.MagicBeans);
        }
    // Get an incoming call
    public void ReceiveCall(PhoneCall call)
    {
        // Check you are waiting for calls
        if (_state.GetType() == typeof(WaitForCall))
        {
            Jack inJack = _board.FindFreeJack();

            if (call != null)
            {
                _currCall = call;
                _incoming.Target(inJack);
                Operator.FillPhoneLine(this);
            }
        }
    }
        public void WhenCreatingANewInstance_JackShouldHasOneCowAndNoMagicBeans()
        {
            // Arrange
            Jack jack;
            int  cows  = 0;
            int  beans = 0;

            // Act
            jack  = new Jack();
            cows  = jack.Cows;
            beans = jack.MagicBeans;

            // Assert
            Assert.Equal(1, cows);
            Assert.Equal(0, beans);
        }
Exemple #14
0
 private void OnTriggerStay(Collider other)
 {
     if (other.GetComponent <Jack>())
     {
         if (!HELD && currentJack != other.GetComponent <Jack>())
         {
             print("Plugged in");
             currentJack             = other.GetComponent <Jack>();
             x                       = currentJack._jackPosition.X;
             y                       = currentJack._jackPosition.Y;
             this.transform.position = currentJack.lockLocation.position;
             this.transform.rotation = currentJack.lockLocation.rotation;
             //position code
         }
     }
 }
    // Register a jack with the switchboard
    public void RegisterJack(Jack jack)
    {
        jack.Id = _jacks.Count + 1;

        // Add to master list
        if (!_jacks.Contains(jack))
        {
            _jacks.Add(jack);
        }

        // Add to list of free jacks
        if (!_freeJacks.ContainsKey(jack.Id))
        {
            _freeJacks.Add(jack.Id, jack);
        }
        else
        {
            Debug.LogError("Jack already tagged as free");
        }
    }
Exemple #16
0
        public FooderBin(Jack player, ContentManager content, Vector2 initialPosition, Size2 size) : base(initialPosition, size)
        {
            _player  = player;
            _content = content;

            BoundingRectangle = new RectangleF(new Vector2(initialPosition.X - size.Width * 0.5f,
                                                           initialPosition.Y - size.Height * 0.5f),
                                               new Size2(size.Width, size.Height));

            X = initialPosition.X;
            Y = initialPosition.Y;

            Planked = true;

            Carryable = false;

            Interacts = true;

            TypeName = "fooder-bin";
        }
 // Tag jack as free
 public bool FreeJack(Jack target)
 {
     // Make sure the jack is on this board
     if (_jacks.Contains(target))
     {
         // Dupe check
         if (!_freeJacks.ContainsKey(target.Id))
         {
             _freeJacks.Add(target.Id, target);
         }
         else
         {
             Debug.LogWarning("Jack already tagged as empty");
         }
         return(true);
     }
     else
     {
         Debug.LogError("Jack not found on board.");
     }
     return(false);
 }
Exemple #18
0
        public Cow(Jack player, ContentManager content, Vector2 initialPosition, Size2 size)
            : base(initialPosition, size)
        {
            _player = player;
            Index   = -1;

            float frameDuration = 1.0f / 7.5f;

            _sprite = AnimationLoader.LoadAnimatedSprite(content,
                                                         "animations/animals",
                                                         "animations/cowMap",
                                                         "cow",
                                                         frameDuration,
                                                         true);

            _sprite.Play("walk_down_idle");

            X = initialPosition.X;
            Y = initialPosition.Y;

            BoundingBoxEnabled = true;
        }
Exemple #19
0
        public Fooder(Jack player, ContentManager content, Vector2 initialPosition, Size2 size) : base(initialPosition, size)
        {
            _player  = player;
            _content = content;

            BoundingRectangle = new RectangleF(new Vector2(initialPosition.X - size.Width * 0.5f,
                                                           initialPosition.Y - size.Height * 0.5f),
                                               new Size2(size.Width, size.Height));

            X = initialPosition.X;
            Y = initialPosition.Y;

            Planked = true;

            BoundingBoxEnabled = true;

            Carryable = false;

            Interacts = true;

            TypeName = "fooder";

            var cropItems = AnimationLoader.LoadAnimatedSprite(content,
                                                               "animations/iconSet",
                                                               "animations/cropItemsMap",
                                                               "wheatItem",
                                                               1.0f / 7.5f,
                                                               false);

            _sprite = cropItems;


            _sprite.Play("grass_normal");

            Index = -1;
        }
Exemple #20
0
        public RpcModule() : base("/{Type}/{Uuid}")
        {
            Post["/{MethodName}"] = parameters =>
            {
                object caller;

                if (parameters.Type == "jack")
                {
                    if (!Jack.TryGet(parameters.Uuid, out Jack jack))
                    {
                        return(new NotFoundResponse());
                    }
                    caller = jack;
                }
                else
                {
                    if (!Instrument.TryGet(parameters.Uuid, out Instrument instrument))
                    {
                        return(new NotFoundResponse());
                    }
                    caller = instrument;
                }

                var        type   = caller.GetType();
                MethodInfo method = type.GetMethod(parameters.MethodName);
                method.Invoke(caller, null);
                return(new Response());
            };
            Post["/{Property}/{Value}"] = parameters =>
            {
                if (!Storable.TryGet(parameters.Uuid, out Storable storable))
                {
                    return(new NotFoundResponse());
                }
                // TODO : Check type

                var    type       = storable.GetType();
                string property   = parameters.Property;
                var    methodName = $"Set{ToUpper(property[0])}{property.Substring(1)}";

                var method = type.GetMethod(methodName);
                if (method != null)
                {
                    var param = Convert.ChangeType(parameters.Value, method.GetParameters()[0].ParameterType);

                    var parameterArray = new[]
                    {
                        param,
                    };
                    method.Invoke(storable, parameterArray);
                    return(new Response());
                }
                var fieldName    = $"{ToUpper(property[0])}{property.Substring(1)}";
                var propertyInfo = type.GetProperty(fieldName);
                if (propertyInfo != null)
                {
                    var fieldType = propertyInfo.PropertyType;
                    var value     = Convert.ChangeType(parameters.Value, fieldType);
                    propertyInfo.SetValue(storable, value);
                    return(new Response());
                }

                return(new NotFoundResponse());
            };
        }
Exemple #21
0
 public void Target(Jack target)
 {
     Debug.Log("Connect to " + target.name);
     _targetJack = target;
     _targetJack.Target();
 }
Exemple #22
0
        public static void TestMain(string[] args)
        {
            Jack jack = new Jack();

            if (jack.Person == null)
            {
                //将会进入
                //对于C#默认的组合field是null
                Console.WriteLine("default value for combined message field is null");
            }

            //ToString()是用于测试的代码,很慢
            //{}
            string str    = jack.ToString();
            Person person = new Person();

            person.Id    = 1;
            person.Email = "";
            person.Name  = "jack";
            //Phones已经实例化
            // One point to highlight is that any properties corresponding to repeated fields are read-only.
            //repeated的Phones是只读的
            //The collection type for repeated fields is always RepeatedField<T>.
            person.Phones.Add(new Person.Types.PhoneNumber {
                Number = "555-1212"
            });
            //{ "name": "jack", "id": 1, "phones": [ { "number": "555-1212" } ] }
            str = person.ToString();

            #region TimeStamp

            //传入的参数必须是Utc时间
            person.CreateTime = Timestamp.FromDateTime(DateTime.UtcNow);

            //返回的时间一定是utc时间
            DateTime createTime = person.CreateTime.ToDateTime();

            //{ "name": "jack", "id": 1, "createTime": "2018-06-09T01:31:37.489723400Z", "phones": [ { "number": "555-1212" } ] }
            str = person.ToString();


            //Google.Protobuf.WellKnownTypes.Timestamp有两部分组成:1、自 UTC time since Unix epoch 1970-01-01T00:00:00Z.的秒数  2、Negative second values with fractions must still have non-negative nanos values that count forward in time. Must be from 0 to 999,999,999 inclusive.


            #endregion


            #region 将对象序列化

            byte[] bytes = null;
            //方式1
            using (MemoryStream stream = new MemoryStream())
            {
                //写入流中
                person.WriteTo(stream);
                bytes = stream.ToArray();
            }

            //转换为字节
            //方式2
            byte[] byte2 = person.ToByteArray();
            //转换为字节
            //方式3
            ByteString byteString = person.ToByteString();
            byte2 = byteString.ToByteArray();
            #endregion

            #region 将字节反序列化

            person = Person.Parser.ParseFrom(bytes);
            person = Person.Parser.ParseFrom(byteString);

            #endregion

            #region 反射

            var descriptor = Person.Descriptor;

            string tab = "\t";
            foreach (var field in descriptor.Fields.InDeclarationOrder())
            {
                //获取类的字段,并从实例获取字段值
                Console.WriteLine($"{field.FieldNumber}{tab}{field.Name}{tab}{field.Accessor.GetValue(person)}");
            }

            #endregion
        }
Exemple #23
0
 public void PlugIn(Jack target)
 {
     _pluggedJack = target;
 }
Exemple #24
0
 public void error()
 {
     currentJack = null;
     HELD        = true;
 }
Exemple #25
0
 // Use this for initialization
 void Start()
 {
     _pluggedJack = null;
 }
Exemple #26
0
    //public static Board b = new Board(8,4);
    //private void Awake()
    //{
    //    if (b == null)
    //    {
    //        b = this;
    //    }
    //    else if(b!=null && b != this)
    //    {
    //        Destroy(this);
    //    }
    //}
    //private void OnDestroy()
    //{
    //    if (b == this)
    //    {
    //        Destroy(this);
    //    }
    //}

    public void AddJack(Jack j)
    {
        jacks[j._jackPosition.X, j._jackPosition.Y] = j;
    }
    // Get a request to connect to a line
    public void GetRequest()
    {
        Jack tJack = _board.FindFreeJack();

        _outgoing.Target(tJack);
    }
Exemple #28
0
 void SpawnJack(Vector2 JackPos)
 {
     this.Jack = new Jack(JackPos, this);
 }
Exemple #29
0
 private void Start()
 {
     speaker     = GameObject.FindGameObjectWithTag("Speaker").GetComponent <AudioSource>();
     source      = b.GetJack(Sx, Sy);
     destination = b.GetJack(dx, dy);
 }