Esempio n. 1
0
    public Game(IGrid grid, ISetting setting)
    {
        _setting = setting;
        _grid = grid;

        currentControl = _grid;
    }
Esempio n. 2
0
 /// <summary>
 /// Oblicza ścieżkę dla obiektu.
 /// </summary>
 /// <param name="start">Punkt początkowy ścieżki</param>
 /// <param name="goal">Puntk docelowy</param>
 /// <param name="objectRadius">Promień kuli, która jest w stanie objąć cały obiekt</param>
 /// <param name="controllable">Obiekt, dla którego obliczana jest ścieżka</param>
 /// <param name="gameObjects">Lista wszystkich obiektów na planszy</param>
 public void FindPath(Point start, Point goal, int objectRadius, IControllable controllable, IEnumerable<GameObject> gameObjects)
 {
     msg = "";
     DateTime dateTime = DateTime.Now;
     if(!radiuses.Contains(objectRadius))
     {
         curProcessed = ProcessMap(map, objectRadius, out curAvgDifficulty);
         lastRadius = objectRadius;
         lock (maps)
         {
             radiuses.Add(lastRadius);
             avgDifficulties.Add(curAvgDifficulty);
             maps.Add(curProcessed);
         }
     }
     else
     {
         lastRadius = objectRadius;
         curProcessed = maps[radiuses.IndexOf(objectRadius)];
         curAvgDifficulty = avgDifficulties[radiuses.IndexOf(objectRadius)];
     }
     msg += (DateTime.Now - dateTime).ToString() + "\r\n";
     Thread th = new Thread(new ParameterizedThreadStart(AStar));
     pathTime = DateTime.Now;
     th.Start(new AStarArg(start,goal,controllable, gameObjects));
     //AStar(start, goal, out path);
 }
 public GhostAIController(MyGame g, Ghost player, IControllable target)
     : base(g)
 {
     this.Target = target;
     this.Ghost = player;
     this.Ghost.ReadyToMove += Ghost_ReadyToMove;
     this.Ghost.Behavior.StateChanged += GhostBehavior_StateChanged;
 }
Esempio n. 4
0
        /// <summary>
        /// We've been asked if we will accept the role of camera mount.
        /// </summary>
        /// <returns>The index of the hotspot to use, or -1 if we aren't a valid camera mount
        /// OR if we are already the camera mount (since we only have one site available)</returns>
        public override int AssignCamera(IControllable currentOwner, int currentHotspot)
        {
            JointOutput[3] = 0.5f;                                              // start with camera pointing straight ahead
            JointOutput[4] = 0.5f;

            if (owner == currentOwner)											// if I'm being asked a second time
                return -1;														// say no
            return 0;															// otherwise, accept the camera
        }
        /// <summary>
        /// Mocks a new create controller.
        /// </summary>
        /// <param name="container"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static MockController New(IControllable container, Type type)
        {
            if (type.Name == "IEntity")
                throw new ArgumentException("The provided type cannot be 'IEntity'.");

            MockController controller = ControllerState.Controllers.Creator.New<MockController>(container);

            controller.Container = container;

            return controller;
        }
Esempio n. 6
0
 public override bool AddControllable(IControllable c)
 {
     string nm = c.GetName();
     SrgsDocument srgs = c.CreateGrammarDoc_SRGS();
     if (nm != null && nm != "" && srgs != null)
     {
         AddGrammar(nm, srgs);
         return true;
     }
     return false;
 }
Esempio n. 7
0
        public override bool AddControllable(IControllable c)
        {
            string nm = c.GetName();
            CMUSphinx_GrammarDict cmu = c.CreateGrammarDoc_FSG();
            if (nm != null && nm != "" && cmu != null && cmu.GrammarIsValid && cmu.DictIsValid)

            {
                AddGrammar(nm, cmu);
                return true;
            }
            return false;
        }
Esempio n. 8
0
 public void OnHoldRelease(float timeHeld, IControllable released)
 {
     _controllerEvents.onHoldRelease.Invoke();
 }
Esempio n. 9
0
 public void RemoveControl()
 {
     controlActor = null;
 }
Esempio n. 10
0
 public void TargetHarpooner()
 {
     target = GlobalScript.Instance.Harpooner;
             Camera.transform.position = target.transform.TransformPoint (Utils.SphereCoordinates (target.Theta, target.Phi, target.Radius));
             ResetCameraPosition ();
 }
Esempio n. 11
0
 public void OnDragDrop(Vector3 position, IControllable dragged, IControllable droppedOn, ControllerHitInfo hitInfo)
 {
     _controllerEvents.onDragDrop.Invoke();
 }
Esempio n. 12
0
 public bool AddControllable(IControllable c)
 {
     if (!mControllables.Add(c.GetName())) return true; //duplicate
     foreach (AudioRecog r in RecogEngines)
     {
         if (!r.AddControllable(c))
             return false;
     }
     return true;
 }
Esempio n. 13
0
 /// <summary>
 /// See if our cell type will accept the role of camera mount. (See Physiology.AssignCamera() for info).
 /// </summary>
 /// <param name="currentOwner">The cell that currently has the camera</param>
 /// <param name="currentHotspot">The hotspot that currently has the camera</param>
 /// <returns>The index of the hotspot to use, or -1 if our cell type isn't a valid camera mount</returns>
 public int AssignCamera(IControllable currentOwner, int currentHotspot)
 {
     return physiology.AssignCamera(currentOwner, currentHotspot);
 }
Esempio n. 14
0
 public CreateController(IControllable container) : base()
 {
     Container = container;
 }
Esempio n. 15
0
 private void Start()
 {
     controlable = controlableCharacter.GetComponent <IControllable>();
 }
Esempio n. 16
0
 public void OnDrop(IControllable dropped, ControllerHitInfo hitInfo)
 {
 }
Esempio n. 17
0
 public static CreateController New(IControllable container, string uniquePropertyName)
 {
     return(New(container));
 }
Esempio n. 18
0
 public Game(ISetting setting)
 {
     _setting = setting;
     currentControl = NullControl.Instance;
 }
Esempio n. 19
0
    void CreateGrid()
    {
        if (GridFactory != null)
        {
            var grid = GridFactory.Create();
            _grid = grid;

            currentControl = _grid;
        }
    }
 public static CreateController New(IControllable container, string uniquePropertyName)
 {
     return New(container);
 }
Esempio n. 21
0
 // if (player.health.Value <= 0f) {
 //   player.controllable.Value.MatchSome(c => c.Destroy());
 //   player.controllable.Value = Option.None<IControllable>();
 // }
 public Option <Guid> GetPlayerForControllable(IControllable controllable) =>
 playerState.GetPlayerBy(player => player.controllable == controllable.Some()).Map(p => p.id);
 void Awake()
 {
     _pawn            = GetComponent <IControllable>();
     _nearestNeighbor = GetComponent <NearestNeighbor>();
 }
Esempio n. 23
0
 public void AddPlayer(IControllable player)
 {
     _players.Add(player);
 }
Esempio n. 24
0
 public void SetTarget(IControllable target)
 {
     controlTarget = target;
 }
 public void StartAndStop(IControllable controllable)
 {
     controllable.Start();
     controllable.Stop();
 }
Esempio n. 26
0
 private void StartDrag()
 {
     _dragSelected  = _selected;
     _dragStartInfo = _hitInfo;
     _isDragging    = true;
 }
Esempio n. 27
0
 /// <summary>
 /// We've been asked if we will accept the role of camera mount.
 /// </summary>
 public override int AssignCamera(IControllable currentOwner, int currentHotspot)
 {
     if (owner.CurrentPanel() == 0) return 0;                            // if panel[0] (main control panel) is showing, our camera looks out the front
     if (owner.CurrentPanel() == 1) return 1;                            // if panel[1] (observation bubble) is showing, we look out the top
     return -1;															// else don't accept camera
 }
Esempio n. 28
0
    private void Update()
    {
        //if (_paused) return;
        var           mousePressed = Input.GetMouseButton(0);
        IControllable controllable = null;
        var           hitInfo      = new ControllerHitInfo(true);

        if (mousePressed)
        {
            var hitUI = false;
            if (_canvas != null)
            {
                hitUI = HandleUIRaycast(out hitInfo);
            }
            if (hitUI)
            {
                controllable = hitInfo.gameObject.GetComponent <IControllable>();
                _selected    = controllable;
            }
            else //if UI wasn't hit, try on world objects
            {
                RaycastHit hit;
                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
                {
                    if (_debugLog)
                    {
                        Debug.Log("Hitcast hit: " + hit.transform.gameObject);
                    }
                    if (hit.transform.gameObject.TryGetComponent <IControllable>(out controllable))
                    {
                        hitInfo = new ControllerHitInfo(controllable, hit);
                        HitControllable(controllable, new ControllerHitInfo(controllable, hit));
                    }
                    else
                    {
                        controllable = hit.transform.gameObject.GetComponentInParent <IControllable>();

                        if (controllable != null)
                        {
                            hitInfo = new ControllerHitInfo(controllable, hit);
                            HitControllable(controllable, new ControllerHitInfo(controllable, hit));
                        }
                        else
                        {
                            HitNonControllable(new ControllerHitInfo(null, hit));
                        }
                    }
                }
                else
                {
                    ResetPressAndHold();
                }
            }
        }
        else
        {
            ResetPressAndHold();
        }

        HandleDragCalls();
        HandleSwipe(mousePressed, controllable != null);
    }
        /// <summary>
        /// Creates a new create controller.
        /// </summary>
        /// <param name="container"></param>
        /// <returns></returns>
        public static CreateController New(IControllable container)
        {
            CreateController controller = null;

            using (LogGroup logGroup = LogGroup.Start("Instantiating a new create controller.", NLog.LogLevel.Debug))
            {
                controller = ControllerState.Controllers.Creator.New<CreateController>(container);

                LogWriter.Debug("Type name: " + container.Command.TypeName);
            }

            return controller;
        }
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="url">登陆的链接</param>
 /// <param name="browser">浏览器</param>
 /// <param name="controllable">可控制程序</param>
 public ManualWebDriverCookieInjector(string url, Browser browser, IControllable controllable) : base(browser, controllable)
 {
     _url = url;
 }
Esempio n. 31
0
 public void OnDragDropFailed(Vector3 position, IControllable dragged)
 {
 }
Esempio n. 32
0
 public LookLeftCommand(IControllable controllable)
 {
     this.controllable = controllable;
 }
Esempio n. 33
0
 public void OnDragDropFailed(Vector3 position, IControllable dragged)
 {
     _controllerEvents.onDragDropFailed.Invoke();
 }
Esempio n. 34
0
 private void Awake()
 {
     rigidbody      = GetComponent <Rigidbody2D>();
     playerControls = GetComponent <IControllable>();
     movementVector = new Vector2(playerControls.Horizontal, playerControls.Vertical);
 }
Esempio n. 35
0
 public void TakeControl(IControllable actor)
 {
     controlActor = actor;
     actor.SetCam(PlayerCamera.instance);
 }
 public WebDriverCookieInjector(Browser browser, IControllable controllable) : base(controllable)
 {
     _browser = browser;
 }
Esempio n. 37
0
        public static List <ControlAction> ParseControlPolicy(this IControllable controllable, string controlPolicy, out string errorMsg)
        {
            errorMsg = "";
            int start    = 0;
            int position = 0;
            List <ControlAction> controlActions = new List <ControlAction>();

            while (start < controlPolicy.Length)
            {
                string command;
                position = controlPolicy.IndexOf(';', start);
                if (position > 0)
                {
                    command = controlPolicy.Substring(start, position - start).Trim();
                    start   = position + 1;
                }
                else
                {
                    command = controlPolicy.Substring(start).Trim();
                    start   = controlPolicy.Length;
                }

                string key;
                string value;
                if (command.Contains("="))
                {
                    var args = command.Split("=".ToCharArray(), 2);
                    key   = args[0];
                    value = args[1];
                }
                else
                {
                    key   = command;
                    value = null;
                }

                if (controllable.ValidStates.Contains(key))
                {
                    controlActions.Add(new ControlAction()
                    {
                        Action = "state", Value = key
                    });

                    if (value != null)
                    {
                        if (float.TryParse(value, out float num) && num >= 0f)
                        {
                            controlActions.Add(new ControlAction()
                            {
                                Action = "wait", Value = value
                            });
                        }
                        else
                        {
                            errorMsg = $"Invalid control policy '{command}': Argument must be greater than or equal to zero for '{key}' of '{controllable.ControlType}'";
                            return(null);
                        }
                    }
                }
                else if (controllable.ValidActions.Contains(key))
                {
                    switch (key)
                    {
                    case "trigger":
                    case "wait":
                        if (value != null && float.TryParse(value, out float num) && num >= 0f)
                        {
                            controlActions.Add(new ControlAction()
                            {
                                Action = key, Value = value
                            });
                        }
                        else
                        {
                            errorMsg = $"Invalid control policy '{command}': Argument must be greater than or equal to zero for '{key}' of '{controllable.ControlType}'";
                            return(null);
                        }
                        break;

                    case "loop":
                        if (value == null)
                        {
                            controlActions.Add(new ControlAction()
                            {
                                Action = key, Value = value
                            });
                        }
                        else
                        {
                            errorMsg = $"Invalid control policy '{command}': Cannot have an argument for '{key}' of '{controllable.ControlType}'";
                            return(null);
                        }
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    errorMsg = $"Invalid control policy: '{key}' is an unknown action for '{controllable.ControlType}'";
                    return(null);
                }
            }

            return(controlActions);
        }
Esempio n. 38
0
 public BackwardCommand(IControllable c)
 {
     controlled = c;
 }
Esempio n. 39
0
 // set the controllable object of a given player
 public void SetPlayerControllable(int playerIndex, IControllable c)
 {
     _controllers[playerIndex].Controllable = c;
 }
Esempio n. 40
0
 /// <summary>
 /// We've been asked if we will accept the role of camera mount.
 /// </summary>
 /// <returns>The index of the hotspot to use, or -1 if we aren't a valid camera mount
 /// OR if we are already the camera mount (since we only have one site available)</returns>
 public override int AssignCamera(IControllable currentOwner, int currentHotspot)
 {
     if (owner == currentOwner)											// if I'm being asked a second time
         return -1;														// say no
     return 0;															// otherwise, accept the camera
 }
Esempio n. 41
0
 private void Start()
 {
     _controllable = controlledObject.GetComponent <IControllable> ();
 }
Esempio n. 42
0
        /// <summary>
        /// Create and return an object derived from Physiology, containing the functionality of the cell.
        /// The name of the appropriate DLL is supplied in the Genome: <type> DLLname.celltype </type>
        /// If no explicit DLL name is supplied, then the cell type is presumed to exist in this DLL
        /// NOTE: If the name ends in a number, this is removed before searching for a Physiology subclass.
        /// That way, different variants can share the same code. E.g. Muscle1 and Muscle2 both find their 
        /// functionality in the Muscle class.
        /// </summary>
        /// <param name="group">The name of the DLL containing the class (no extension)</param>
        /// <param name="type">The name of the Physiology-derived class</param>
        /// <param name="variantName">The name of the .X file</param>
        /// <param name="owner">The Cell that will own the resulting object</param>
        /// <param name="numJoints">The number of animatable joints in this cell</param>
        /// <param name="numSockets">The number of sockets in this cell</param>
        /// <returns></returns>
        public static Physiology LoadPhysiology(string group, string type, string variantName,
            IControllable owner,
            int numJoints, int numSockets)
        {
            Physiology phys = null;

            // Get full name so that we can store it in celltype and use when writing genes
            string name = group + ":" + type + "." + variantName;

            // Attempt to construct the specified object from its named DLL
            try
            {
                System.Runtime.Remoting.ObjectHandle obj = null;
                obj = Activator.CreateInstance(group, "Simbiosis." + type);
                phys = (Physiology)obj.Unwrap();							// convert the handle into an actual object
            }
            // If we fail, report the error and construct an instance of the base class instead. This will simply do nothing.
            // That way, trivial structural cells needn't have any associated code. Note that the default properties such as
            // mass, water resistance etc. may not be appropriate though.
            catch (Exception e)
            {
                Trace.WriteLine("WARNING: Physiology.LoadPhysiology() was unable to find/create a cell type of " + type + " in " + group + ".dll");
                Trace.WriteLine("         Using default Physiology class instead.");
                phys = new Physiology();
                // HACK: For now, throw an exception in case I meant to have such a cell type - remove this line later
                throw new SDKException("No Physiology class exists for cell type: " + group + "." + type,e);
            }
            finally
            {
                // Store the full name for ToString() to use.
                phys.name = name;
                // Initialise the new Physiology object's base and subclass members.
                // (can't do this in constr because I'm using the overload of CreateInstance that needs a parameterless constr)
                phys.Construct(owner, numJoints, numSockets);
            }
            return phys;
        }
Esempio n. 43
0
 public KeyboardController(MyGame g, IControllable player)
     : base(g)
 {
     this.player = player;
     this.player.ReadyToMove += player_ReadyToMove;
 }
Esempio n. 44
0
        /// <summary>
        /// Since the class is instantiated using reflection it can only have a default constructor (or at least, it's easier and more
        /// typesafe that way). So, immediately after creation, call this method to set up the base class members (owner, etc.).
        /// </summary>
        /// <param name="owner">An IControllable interface to our owning Cell</param>
        /// <param name="numJoints">Number of joint frames in the cell</param>
        /// <param name="numSockets">Number of sockets in the cell</param>
        private void Construct(IControllable owner, int numJoints, int numSockets)
        {
            this.owner = owner;										// reference to our cell, so that we can send it commands/requests
            JointOutput = new float[numJoints];						// size of our JointOutput array depends on # joint frames in cell

            this.numSockets = numSockets;							// store # sockets (needed for some operations on nerves etc.)
        }
Esempio n. 45
0
 public ControllableController(IControllable iControllable)
 {
     Controllable = iControllable;
 }
 public CreateController(IControllable container)
     : base()
 {
     Container = container;
 }
Esempio n. 47
0
        /// <summary>
        /// We've been asked if we will accept the role of camera mount.
        /// Most cell types won't need to override this, but any cells that can play the part
        /// of a creatures-eye view, plus of course the main submarine or other camera objects,
        /// should override this and return a valid hotspot number that will be used to carry the camera.
        /// The parameters to this method show which cell and hotspot is currently carrying the camera. 
        /// When a command to cycle through the views is issued, the current camera ship will be asked AGAIN
        /// whether it will accept the camera. This gives it the opportunity to offer a second or subsequent
        /// hotspots (e.g. side views, or an outside view). If this cell type has only the one hotspot it
        /// should return -1 if this is the hotspot already in use, thus passing the opportunity along to
        /// other cells in this organism or other organisms entirely.
        /// </summary>
        /// <param name="currentOwner">The cell that currently has the camera</param>
        /// <param name="currentHotspot">The hotspot that currently has the camera</param>
        /// <returns>The index of the hotspot to use, or -1 if we aren't a valid camera mount</returns>
        public virtual int AssignCamera(IControllable currentOwner, int currentHotspot)
        {
            // Sample code for a valid camera mount with only one hotspot...
            //	if (owner==currentOwner)											// if I'm being asked a second time
            //		return -1;														// say no
            //	return 0;															// otherwise, accept the camera

            // Sample code for a cell type with two camera hotspots...
            //	if ((owner==currentOwner)&&(currentHotspot==0))						// if my hotspot 0 is already in use
            //		return 1;														// transfer camera to hotspot 1
            //	if ((owner==currentOwner)&&(currentHotspot==1))						// if my hotspot 1 is already in use
            //		return -1;														// let someone else have a go
            //	return 0;															// else offer hotspot 0

            // the default is never to accept a camera
            return -1;
        }
Esempio n. 48
0
 protected void Awake()
 {
     controllable = shipController;
 }
Esempio n. 49
0
 public AStarArg(Point start, Point goal, IControllable controllable, IEnumerable<GameObject> gameObjects)
 {
     Start = start;
     Goal = goal;
     Controllable = controllable;
     GameObjects = gameObjects.ToList();
 }
Esempio n. 50
0
 void OnControllableEvent(IControllable from, IControllableEventArgs Event)
 {
     if (ControllableEvent != null)
     {
         ControllableEvent(from, Event);
     }
 }
 public void SetControllable(IControllable controllable)
 {
     this.controllable = controllable;
 }
Esempio n. 52
0
        private void HandleGatherCommand(IControllable current)
        {
            var currentAsGatherer = current as IGatherer;
            if (currentAsGatherer != null)
            {
                //List<WorldObject> objectsAtGathererPosition = new List<WorldObject>();
                IResource resource = null;
                foreach (var obj in this.resources)
                {
                    if (obj.Position == current.Position)
                    {
                        resource = obj;
                        break;
                    }
                }

                if (resource != null)
                {
                    HandleGathering(currentAsGatherer, resource);
                }
                else
                {
                    Console.WriteLine("No resource to gather at {0}'s position", current);
                }
            }
            else
            {
                Console.WriteLine("{0} can't do that", current);
            }
        }
 public LinearProjectileController(IControllable controlled, int XVelocity, int YVelocity) : base(controlled)
 {
     xVelocity = XVelocity;
     yVelocity = YVelocity;
 }
Esempio n. 54
0
 public abstract bool AddControllable(IControllable c);
Esempio n. 55
0
 public void OnHoldRelease(float timeHeld, IControllable released)
 {
 }
Esempio n. 56
0
 public void OnDrag(Vector3 position, IControllable dragged, ControllerHitInfo hitInfo)
 {
 }
Esempio n. 57
0
        private void HandleAttackCommand(IControllable current)
        {
            var currentAsFighter = current as IFighter;
            if (currentAsFighter != null)
            {
                List<WorldObject> availableTargets = new List<WorldObject>();
                foreach (var obj in this.allObjects)
                {
                    if (obj.Position == current.Position)
                    {
                        availableTargets.Add(obj);
                    }
                }

                int targetIndex = currentAsFighter.GetTargetIndex(availableTargets);
                if (targetIndex != -1)
                {
                    this.HandleBattle(currentAsFighter, availableTargets[targetIndex]);
                }
                else
                {
                    Console.WriteLine("No targets to attack at {0}'s position", current);
                }
            }
            else
            {
                Console.WriteLine("{0} can't do that", current);
            }
        }
Esempio n. 58
0
 public void OnDragDrop(Vector3 position, IControllable dragged, IControllable droppedOn, ControllerHitInfo hitInfo)
 {
 }
Esempio n. 59
0
 private void HandleGoCommand(string[] commandWords, IControllable current)
 {
     var currentAsMoving = current as MovingObject;
     currentAsMoving.GoTo(Point.Parse(commandWords[2]));
     Console.WriteLine("{0} is now at position {1}", current, current.Position);
 }
Esempio n. 60
0
        public static IndexController New(IControllable container, PagingLocation location)
        {
            container.CheckCommand();

            IndexController controller = ControllerState.Controllers.Creator.NewIndexer(container.Command.TypeName);

            controller.Container = container;
            controller.EnablePaging = true;
            controller.Indexer.Location = location;

            return controller;
        }