コード例 #1
0
ファイル: AboutDelegates.cs プロジェクト: wk-j/DotNetKoans
		public void DelegatesAreImmutable()
		{
			//Like strings it looks like you can change what a delegate references, but really they are immutable objects
			MyMath m = new MyMath();
			BinaryOp a = m.Add;
			BinaryOp original = a;
			Assert.Same(a, original);
			a = MyMath.Subtract;
			//a is now a different instance
			Assert.Same(a, original);
		}
コード例 #2
0
ファイル: Program.cs プロジェクト: faksam/My_FPT_C-Sharp
 static void Main(string[] args)
 {
     Program p = new Program();
     //delegate named mm point to p.DoAdd
     MyMath mm = new MyMath(p.DoAdd);
     //mm point o p.DoSub and p.DoMul
     mm += p.DoSub;
     mm += p.DoMul;
     //call all methods which are pointed by mm
     mm(5, 9);
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: Slesa/Poseidon
        static void Main(string[] args)
        {
            MyMath math = new MyMath();


            // Check if 2 is the minimum of 2 or 3
            if (math.min(2, 3, 2))
            {
                Console.WriteLine("Yes");
            }

            // Calculate the factorial 
            AbstractTerm a = new AbstractTerm();
            math.factorial(3, a);
            Console.WriteLine("Factorial of 3 is: " + a);

            // calculate the fifth fibonacci (should be 8)
            AbstractTerm fibValue = new AbstractTerm();
            math.fib(5, fibValue);
            Console.WriteLine("Fibonacci of 3 is: " + fibValue);
        }
コード例 #4
0
 public void Update()
 {
     filterScroll += Time.GameTimeFrameSeconds * filterRate;
     filterScroll  = MyMath.Wrap(filterScroll);
 }
コード例 #5
0
 public IActionResult Get(float l1, float l2, float l3)
 {
     return(Ok(MyMath.TriangleType(l1, l2, l3)));
 }
コード例 #6
0
ファイル: StringUtil.cs プロジェクト: yangfan111/CsharpCode
        public static int GetDependency(string source, string word, int start)
        {
            int dependency = 0;

            if (word.Length > 0)
            {
                if (start == 0)
                {
                    dependency = dependency + 1;
                }
                else
                {
                    string left  = source[start - 1].ToString();
                    string left2 = Sharpen.Runtime.Substring(source, (int)MyMath.Min(0, start - 2), start);
                    if (!IsSameType(Sharpen.Runtime.Substring(word, 0, 1), left))
                    {
                        // aa-word
                        if (StringUtil.ContainsEnglishOrNumber(word) && left.Equals("-") && StringUtil.ContainsEnglishOrNumber(left2))
                        {
                            dependency = dependency + 0;
                        }
                        else
                        {
                            dependency = dependency + 1;
                        }
                    }
                }
                if (start + word.Length == source.Length)
                {
                    dependency = dependency + 1;
                }
                else
                {
                    string right  = Sharpen.Runtime.Substring(source, start + word.Length, start + word.Length + 1);
                    string right2 = Sharpen.Runtime.Substring(source, start + word.Length, (int)MyMath.Min(source.Length, start + word.Length + 2));
                    if (!IsSameType(Sharpen.Runtime.Substring(word, word.Length - 1), right))
                    {
                        // word-aa
                        if (StringUtil.ContainsEnglishOrNumber(word) && right.Equals("-") && StringUtil.ContainsEnglishOrNumber(right2))
                        {
                            dependency = dependency + 0;
                        }
                        else
                        {
                            dependency = dependency + 1;
                        }
                    }
                }
                return(dependency);
            }
            return(-1);
        }
コード例 #7
0
 private static IEnumerable <ulong> FilterPrimesByPrimalityTest(IEnumerable <ulong> candidates)
 {
     return(candidates.Where(candidate => MyMath.IsPrime(candidate)));
 }
コード例 #8
0
ファイル: TanFunction.cs プロジェクト: yangfan111/CsharpCode
 /// <summary>Returns the tangent of the angle value at index location 0.</summary>
 public virtual double Of(double[] d, int numParam)
 {
     return(MyMath.Tan(d[0]));
 }
コード例 #9
0
 public void FactorialTest()
 {
     Assert.AreEqual(120, MyMath.Factorial(5));
 }
コード例 #10
0
 public void AddTwoPositiveNumbers()
 {
     // Use the Assert class to test conditions
     Assert.AreEqual(1 + 2, MyMath.Add(1, 2));
 }
コード例 #11
0
ファイル: Program5.cs プロジェクト: Hendri-YAD/OOPWorkshop2
 public int Throw()
 {
     faceUp = MyMath.RNDInt(6) + 1;
     return(faceUp);
 }
コード例 #12
0
ファイル: GuitarGameplay.cs プロジェクト: hwsyy/DrumGame
    //开始倒计时五秒
    protected IEnumerator DisplayCountdown()
    {
        yield return(new WaitForSeconds(MyMath.BeatsToSeconds(0.5f, Player.Song.BeatsPerMinute)));

        StartCoroutine(DisplayText("4", 1f, 0f));
        yield return(new WaitForSeconds(MyMath.BeatsToSeconds(1f, Player.Song.BeatsPerMinute)));

        StartCoroutine(DisplayText("3", 1f, 0f));
        yield return(new WaitForSeconds(MyMath.BeatsToSeconds(1f, Player.Song.BeatsPerMinute)));

        StartCoroutine(DisplayText("2", 1f, 0f));
        yield return(new WaitForSeconds(MyMath.BeatsToSeconds(1f, Player.Song.BeatsPerMinute)));

        StartCoroutine(DisplayText("1", 1f, 0f));
        yield return(new WaitForSeconds(MyMath.BeatsToSeconds(1f, Player.Song.BeatsPerMinute)));

        StartCoroutine(DisplayText("Go", MyMath.BeatsToSeconds(1.5f, Player.Song.BeatsPerMinute), MyMath.BeatsToSeconds(1f, Player.Song.BeatsPerMinute)));
    }
コード例 #13
0
 public void DelegatesCanBeAssigned()
 {
     MyMath math = new MyMath();
     BinaryOp op = math.Add;
     Assert.AreEqual(FILL_ME_IN, op.Method.Name);
 }
コード例 #14
0
ファイル: Program.cs プロジェクト: chickenjun/OpenSourceDemo
        static void Main(string[] args)
        {
            int c = MyMath.Add(1, 2);

            Console.WriteLine("Result: " + c);
        }
コード例 #15
0
        /// <summary>
        /// Process the message for the specified client.
        /// </summary>
        /// <param name="aClient">The client who sent the message.</param>
        public override void Process(Client aClient)
        {
            if (aClient == null)
            {
                return;
            }

            switch (_Action)
            {
            case Action.Pick:
            {
                if (!World.AllFloorItems.ContainsKey(Id))
                {
                    return;
                }

                FloorItem floorItem = World.AllFloorItems[Id];
                Player    player    = aClient.Player;

                if (floorItem.X != PosX || floorItem.Y != PosY)
                {
                    return;
                }

                if (MyMath.GetDistance(player.X, player.Y, PosX, PosY) > 0)
                {
                    player.SendSysMsg(StrRes.STR_FAR_CANNOT_PICK);
                    return;
                }

                if (!player.IsAlive())
                {
                    return;
                }

                if (floorItem.Money == 0 && player.ItemInInventory() >= 40)
                {
                    player.SendSysMsg(StrRes.STR_FULL_CANNOT_PICK);
                    return;
                }

                if (floorItem.OwnerUID != 0)
                {
                    if (floorItem.OwnerUID != player.UniqId)
                    {
                        if ((DateTime.UtcNow - floorItem.DroppedTime).TotalSeconds < 10)
                        {
                            if (player.Team != null && player.Team.IsTeamMember(floorItem.OwnerUID))
                            {
                                if (floorItem.Money > 0 && player.Team.MoneyForbidden)
                                {
                                    player.SendSysMsg(StrRes.STR_OTHERS_ITEM);
                                    return;
                                }
                                else
                                {
                                    if (player.Team.ItemForbidden)
                                    {
                                        player.SendSysMsg(StrRes.STR_OTHERS_ITEM);
                                        return;
                                    }
                                    else if (floorItem.Item.Type == 1088000 || floorItem.Item.Type == 1088001)         //DB || Met
                                    {
                                        player.SendSysMsg(StrRes.STR_OTHERS_ITEM);
                                        return;
                                    }
                                }
                            }
                            else
                            {
                                player.SendSysMsg(StrRes.STR_OTHERS_ITEM);
                                return;
                            }
                        }
                    }
                }

                if (floorItem.Money > 0)
                {
                    if (player.Money + floorItem.Money > Player._MAX_MONEYLIMIT)
                    {
                        player.SendSysMsg(StrRes.STR_TOOMUCH_MONEY);
                        return;
                    }

                    player.Money += floorItem.Money;
                    player.Send(new MsgUserAttrib(player, player.Money, MsgUserAttrib.AttributeType.Money));

                    if (floorItem.Money > 1000)
                    {
                        player.Send(new Msg1029(floorItem.Money));
                        World.BroadcastRoomMsg(player, new MsgAction(player, floorItem.Money, MsgAction.Action.GetMoney), true);
                    }

                    player.SendSysMsg(StrRes.STR_PICK_MONEY, floorItem.Money);
                }
                else
                {
                    player.AddItem(floorItem.Item, true);
                    player.SendSysMsg(StrRes.STR_GOT_ITEM, floorItem.Item.Name);

                    floorItem.Item.Save();
                }

                World.BroadcastRoomMsg(player, this, false);
                floorItem.Destroy(floorItem.Money > 0);
                break;
            }

            default:
            {
                sLogger.Error("Action {0} is not implemented for MsgMapItem.", (UInt32)_Action);
                break;
            }
            }
        }
コード例 #16
0
        private int fillForStep(int rIndex, int stepIndex, int curVertex)
        {
            float   angle  = 2 * (float)Math.PI * rIndex / radiusSteps;
            Vector3 normal = rots[stepIndex].rotate(new Vector3(0, MyMath.sin(angle), MyMath.cos(angle)));

            if (!unityNormalCalculation)
            {
                normals[curVertex] = transform.InverseTransformVector(normal);
            }
            vertices[curVertex] = transform.InverseTransformPoint(displacement(normal, stepIndex, rIndex) + poss[stepIndex]);
            //normals[curIndex] = normal;
            //vertices[curIndex] = normal * radius + poss[stepIndex];
            uv[curVertex] = new Vector2((float)stepIndex / (poss.Count - 1), (float)rIndex / radiusSteps);
            curVertex++;
            return(curVertex);
        }
コード例 #17
0
        public void SpawnAtShip(MyPlayer player, string respawnShipId, MyBotDefinition botDefinition)
        {
            Debug.Assert(Sync.IsServer, "Spawning can only be called on the server!");
            if (!Sync.IsServer)
            {
                return;
            }

            ResetRespawnCooldown(player.Id);
            if (Sync.MultiplayerActive)
            {
                SyncCooldownToPlayer(player.Id.SteamId, player.Id.SteamId == Sync.MyId);
            }

            MyCharacter       character    = null;
            MyCockpit         cockpit      = null;
            List <MyCubeGrid> respawnGrids = new List <MyCubeGrid>();

            var respawnShipDef           = MyDefinitionManager.Static.GetRespawnShipDefinition(respawnShipId);
            MyPrefabDefinition prefabDef = respawnShipDef.Prefab;

            // Deploy ship
            Vector3D position = Vector3D.Zero;
            float    planetSpawnHeightRatio = 0.3f;
            float    spawnRangeMin          = 500f;
            float    spawnRangeMax          = 650f;

            if (prefabDef.CubeGrids != null && prefabDef.CubeGrids.Length > 0)
            {
                MyObjectBuilder_CubeGrid firstGrid = prefabDef.CubeGrids[0];
                if (firstGrid.UsePositionForSpawn)
                {
                    position = new Vector3D(
                        firstGrid.PositionAndOrientation.Value.Position.x,
                        firstGrid.PositionAndOrientation.Value.Position.y,
                        firstGrid.PositionAndOrientation.Value.Position.z);
                }

                planetSpawnHeightRatio = MyMath.Clamp(firstGrid.PlanetSpawnHeightRatio, 0.05f, 0.95f); // Clamped to prevent crazy data
                spawnRangeMin          = firstGrid.SpawnRangeMin;
                spawnRangeMax          = firstGrid.SpawnRangeMax;
            }
            Vector3D forward = Vector3.Forward;
            Vector3D up      = Vector3D.Up;

            GetSpawnPosition(prefabDef.BoundingSphere.Radius, ref position, out forward, out up, planetSpawnHeightRatio, spawnRangeMin, spawnRangeMax);

            MyPrefabManager.Static.SpawnPrefab(
                respawnGrids,
                prefabDef.Id.SubtypeName,
                position,
                forward,
                up,
                spawningOptions: VRage.Game.ModAPI.SpawningOptions.RotateFirstCockpitTowardsDirection,
                updateSync: true);

            // Find cockpits
            List <MyCockpit> shipCockpits = new List <MyCockpit>();

            foreach (MyCubeGrid grid in respawnGrids)
            {
                foreach (MyCockpit gridCockpit in grid.GetFatBlocks <MyCockpit>())
                {
                    // Ignore non-functional cockpits
                    if (!gridCockpit.IsFunctional)
                    {
                        continue;
                    }
                    shipCockpits.Add(gridCockpit);
                }
            }

            // First sort cockpits by order: Ship controlling cockpits set to main, then ship controlling cockpits not set to main, lastly whatever remains, e.g. CryoChambers and Passenger Seats
            if (shipCockpits.Count > 1)
            {
                shipCockpits.Sort(delegate(MyCockpit cockpitA, MyCockpit cockpitB)
                {
                    int controlCompare = cockpitB.EnableShipControl.CompareTo(cockpitA.EnableShipControl);
                    if (controlCompare != 0)
                    {
                        return(controlCompare);
                    }

                    int mainCompare = cockpitB.IsMainCockpit.CompareTo(cockpitA.IsMainCockpit);
                    if (mainCompare != 0)
                    {
                        return(mainCompare);
                    }

                    return(0);
                });
            }

            // Finally, select the most important cockpit
            if (shipCockpits.Count > 0)
            {
                cockpit = shipCockpits[0];
            }

            System.Diagnostics.Debug.Assert(cockpit != null, "character is spawning in ship without cockpit !");

            // Create character
            MatrixD matrix = MatrixD.Identity;

            if (cockpit != null)
            {
                matrix             = cockpit.WorldMatrix;
                matrix.Translation = cockpit.WorldMatrix.Translation - Vector3.Up - Vector3.Forward;
            }
            else if (respawnGrids.Count > 0)
            {
                matrix.Translation = respawnGrids[0].PositionComp.WorldAABB.Center + respawnGrids[0].PositionComp.WorldAABB.HalfExtents;
            }

            character = MyCharacter.CreateCharacter(matrix, Vector3.Zero, player.Identity.DisplayName, player.Identity.Model, null, botDefinition, cockpit: cockpit, playerSteamId: player.Id.SteamId);

            CloseRespawnShip(player);
            foreach (var respawnGrid in respawnGrids)
            {
                respawnGrid.ChangeGridOwnership(player.Identity.IdentityId, MyOwnershipShareModeEnum.None);
                respawnGrid.IsRespawnGrid = true;
                player.RespawnShip.Add(respawnGrid.EntityId);
            }

            if (cockpit != null)
            {
                cockpit.AttachPilot(character, false);
                MyMultiplayer.ReplicateImmediatelly(MyExternalReplicable.FindByObject(cockpit.CubeGrid), new EndpointId(player.Id.SteamId));
            }

            if (cockpit == null)
            {
                Sync.Players.SetPlayerCharacter(player, character, null);
            }
            else
            {
                character.SetPlayer(player);
                Sync.Players.SetPlayerToCockpit(player, cockpit);
            }
            Sync.Players.RevivePlayer(player);
        }
コード例 #18
0
            }   // end of RunSimUpdateObj MoveCameraEditMode()

            private void MoveCameraActorMode(bool inputFocus, bool ignoreRotation)
            {
                // Start with any first person actor.  If none then follow
                // the first one on the focus list.
                GameActor actor = CameraInfo.FirstPersonActor;

                if (actor == null)
                {
                    actor = CameraInfo.CameraFocusGameActor;
                }

                if (inputFocus)
                {
                    if (!ignoreRotation)
                    {
                        OrbitAndTrackCamera();
                    }

                    GamePadInput pad = GamePadInput.GetGamePad0();

                    if (actor != null)
                    {
                        shared.CursorPosition = actor.Movement.Position;

                        // If we're controlling an actor, align the camera with the actor's heading.
                        // The user is still able to use the right stick to orbit around the actor but
                        // as soon as the stick is let go the camera will return to being directly
                        // behind the actor.
                        if (actor.Chassis.HasFacingDirection)
                        {
                            // Normal, non-first person mode.
                            // Use lighter weighting if the user is pushing on the stick.
                            float lerpWeighting = Time.GameTimeFrameSeconds;
                            // Use the square of the spring strength to give a little more resolution at the low end.
                            lerpWeighting *= pad.RightStick.X == 0.0f ? InGame.CameraSpringStrength * InGame.CameraSpringStrength * 10.0f : 0.5f;
                            lerpWeighting  = Math.Min(lerpWeighting, 1.0f);
                            float dtheta = actor.Movement.RotationZ - parent.Camera.DesiredRotation;
                            if (dtheta > MathHelper.Pi)
                            {
                                dtheta -= MathHelper.TwoPi;
                            }
                            if (dtheta < -MathHelper.Pi)
                            {
                                dtheta += MathHelper.TwoPi;
                            }
                            parent.Camera.DesiredRotation = parent.Camera.DesiredRotation + dtheta * lerpWeighting;
                        }
                    }
                }
                else
                {
                    // We may not have input focus but we still need to move the
                    // camera.  This may be because we in PreGame mode and want
                    // the camera to snap to the right place before the game starts.
                    if (actor != null)
                    {
                        shared.CursorPosition = actor.Movement.Position;

                        // If we're controlling an actor, align the camera with the actor's heading.
                        float secs = Time.WallClockFrameSeconds;
                        float t    = Math.Max(1.0f, 10.0f * secs);
                        parent.Camera.DesiredRotation = MyMath.Lerp(parent.Camera.Rotation, actor.Movement.RotationZ, t);
                        parent.Camera.DesiredAt       = MyMath.Lerp(parent.Camera.At, actor.Movement.Position, t);
                    }
                }

                // Are we close enough for first person mode?
                if (CameraInfo.CameraFocusGameActor != null)
                {
                    float closeEnough = Math.Max(parent.Camera.FirstPersonDistance, 1.5f * CameraInfo.CameraFocusGameActor.CollisionRadius);
                    CameraInfo.FirstPersonViaZoom = parent.Camera.Distance < closeEnough;
                }

                shared.KeepCameraAboveGround();

                // If we're controlling a bot (or in first person mode) raise our target height by
                // the chassis eye offset.  This keeps the camera out of the ground for bots like
                // the Fastbot which have their origin at the bottom.
                if (actor != null)
                {
                    // Try and smooth out the vertical for the camera.
                    // Note that running into the ground will still cause the camera to jump upward.
                    Vector3 curAt  = shared.camera.DesiredAt;
                    Vector3 target = shared.CursorPosition + new Vector3(0, 0, actor.Chassis.EyeOffset);
                    // Only lerp in Z.
                    curAt.X = target.X;
                    curAt.Y = target.Y;
                    float dt = InGame.inGame.PreGameActive ? Time.WallClockFrameSeconds : Time.GameTimeFrameSeconds;
                    dt = Math.Min(1.0f, dt * 20.0f);
                    shared.camera.DesiredAt = MyMath.Lerp(curAt, target, dt);
                }
                else
                {
                    shared.camera.DesiredAt = shared.CursorPosition;
                }
            }   // end of RunSimUpdateObj MoveCameraActorMode()
コード例 #19
0
ファイル: MotorBean.cs プロジェクト: jlankitus/Midi-Madness
 public float getAccel(float targetPos, float curPos, float curSpeed, float externalAccel, float maxAccelMultiplier)
 {
     return(MyMath.clamp((MyMath.clamp((targetPos - curPos) * distanceToSpeed, maxSpeed) - curSpeed) * speedDifToAccel + externalAccel, maxAccel * maxAccelMultiplier));
 }
コード例 #20
0
 public void MethodCanBePassedDirectly()
 {
     MyMath math = new MyMath();
     Assert.Equal(FILL_ME_IN, PassMeTheDelegate(math.Add));
 }
コード例 #21
0
 public float MapTo(float input, float min, float max)
 {
     return(MyMath.Map(input, min, max, this.min, this.max));
 }
コード例 #22
0
 public static int Main()
 {
     Console.WriteLine(MyMath.Add <double>(3.6, 2.12));
     return(0);
 }
コード例 #23
0
        void DrawPerpendicularEdgeControlPoints(PixelFarm.Drawing.Painter painter, OutsideEdgeLine internalEdgeLine)
        {
            //Vector2 regen0 = edge._newRegen0 * _pxscale;
            //Vector2 regen1 = edge._newRegen1 * _pxscale;
            //painter.FillRectLBWH(regen0.X, regen0.Y, 5, 5, PixelFarm.Drawing.Color.Green);
            //painter.FillRectLBWH(regen1.X, regen1.Y, 5, 5, PixelFarm.Drawing.Color.Blue);

            bool foundSomePerpendicularEdge = false;

            if (internalEdgeLine.ControlEdge_P != null && internalEdgeLine.ControlEdge_Q != null)
            {
                Vector2 m0 = internalEdgeLine.ControlEdge_P.GetMidPoint();
                Vector2 m1 = internalEdgeLine.ControlEdge_Q.GetMidPoint();

                //find angle from m0-> m1

                Vector2 v2 = (m0 + m1) / 2;
                //find perpendicular line  from  midpoint_m0m1 to edge
                Vector2 cutpoint;
                if (MyMath.FindPerpendicularCutPoint(internalEdgeLine, v2, out cutpoint))
                {
                    painter.Line(
                        v2.X * _pxscale, v2.Y * _pxscale,
                        cutpoint.X * _pxscale, cutpoint.Y * _pxscale,
                        PixelFarm.Drawing.Color.Red);
                    foundSomePerpendicularEdge = true;
                }

                //Vector2 e0_fitpos = internalEdgeLine.ControlEdge_P.GetFitPos() * _pxscale;
                //Vector2 e1_fitpos = internalEdgeLine.ControlEdge_Q.GetFitPos() * _pxscale;

                //painter.Line(
                //      e0_fitpos.X, e0_fitpos.Y,
                //      regen0.X, regen0.Y,
                //      PixelFarm.Drawing.Color.Yellow);
                //painter.Line(
                //    e1_fitpos.X, e1_fitpos.Y,
                //    regen1.X, regen1.Y,
                //    PixelFarm.Drawing.Color.Yellow);
            }

            if (internalEdgeLine.ControlEdge_P != null)
            {
                Vector2 v2 = internalEdgeLine.ControlEdge_P.GetMidPoint();
                //Vector2 cutpoint = internalEdgeLine._ctrlEdge_P_cutAt;
                //painter.Line(
                //    v2.X * _pxscale, v2.Y * _pxscale,
                //    cutpoint.X * _pxscale, cutpoint.Y * _pxscale,
                //    PixelFarm.Drawing.Color.Green);
                //foundSomePerpendicularEdge = true;
            }
            if (internalEdgeLine.ControlEdge_Q != null)
            {
                Vector2 v2 = internalEdgeLine.ControlEdge_Q.GetMidPoint();
                //Vector2 cutpoint = internalEdgeLine._ctrlEdge_Q_cutAt;
                //painter.Line(
                //    v2.X * _pxscale, v2.Y * _pxscale,
                //    cutpoint.X * _pxscale, cutpoint.Y * _pxscale,
                //    PixelFarm.Drawing.Color.Green);
                //foundSomePerpendicularEdge = true;
            }

            if (!foundSomePerpendicularEdge)
            {
                //TODO: reimplement this again
                //Vector2 midpoint = edge.GetMidPoint();
                //painter.FillRectLBWH(midpoint.X, midpoint.Y, 5, 5, PixelFarm.Drawing.Color.White);
            }
        }
コード例 #24
0
        public override void DoAction(IEventArgs args)
        {
            Ini(args);

            List <FreeData> list = new List <FreeData>();

            foreach (PlayerEntity unit in args.GameContext.player.GetInitializedPlayerEntities())
            {
                if (unit.hasFreeData)
                {
                    FreeData fd = (FreeData)unit.freeData.FreeData;
                    args.TempUse(selectedName, fd);
                    if (con == null || con.Meet(args))
                    {
                        list.Add(fd);
                    }
                    args.Resume(selectedName);
                }
            }

            if (!StringUtil.IsNullOrEmpty(order))
            {
                DataBlock bl = new DataBlock();
                foreach (FreeData fd in list)
                {
                    bl.AddData(fd);
                }
                if (method == null || FreeUtil.IsVar(order))
                {
                    method = new SelectMethod(order);
                }
                list.Clear();
                foreach (IFeaturable fe in method.Select(bl).GetAllDatas())
                {
                    list.Add((FreeData)fe);
                }
            }
            if (list.Count > 0)
            {
                if (count > 0)
                {
                    int[] ids = RandomUtil.Random(0, list.Count - 1, count);
                    if (!StringUtil.IsNullOrEmpty(order))
                    {
                        ids = new int[(int)MyMath.Min(count, list.Count)];
                        for (int i = 0; i < ids.Length; i++)
                        {
                            ids[i] = i;
                        }
                    }
                    for (int i = 0; i < ids.Length; i++)
                    {
                        int      id   = ids[i];
                        FreeData unit = list[id];
                        args.TempUsePara(new IntPara("index", i + 1));
                        args.TempUsePara(new IntPara("count", ids.Length));
                        args.TempUse(selectedName, unit);
                        action.Act(args);
                        args.Resume(selectedName);
                        args.ResumePara("index");
                        args.ResumePara("count");
                    }
                }
                else
                {
                    int i = 1;
                    foreach (FreeData unit in list)
                    {
                        args.TempUsePara(new IntPara("index", i++));
                        args.TempUsePara(new IntPara("count", list.Count));
                        args.TempUse(selectedName, unit);
                        action.Act(args);
                        args.Resume(selectedName);
                        args.ResumePara("index");
                        args.ResumePara("count");
                    }
                }
            }
            else
            {
                if (noneAction != null)
                {
                    noneAction.Act(args);
                }
            }
        }
コード例 #25
0
ファイル: Nuke.cs プロジェクト: Volday/NPlanet
    private void Update()
    {
        if (teamIndex != -2 && GetComponent <Move>().target == Vector3.zero)
        {
            GameObject planet = GameObject.FindGameObjectWithTag("Planet");
            Instantiate(planet.GetComponent <Teams>().NukeExplosion, transform.position, Quaternion.identity);

            if (partOfPlanet.teamIndex != teamIndex && partOfPlanet.teamIndex != -1)
            {
                planet.GetComponent <Teams>().teams[partOfPlanet.teamIndex].TakeDamage(planet.GetComponent <Teams>().nukeDamage, partOfPlanet, teamIndex);
            }

            List <GameObject> toDestroy = new List <GameObject>();
            for (int t = 0; t < planet.GetComponent <Teams>().teams.Length; t++)
            {
                for (int i = 0; i < planet.GetComponent <Teams>().teams[t].buildings.Count; i++)
                {
                    if (planet.GetComponent <Teams>().teams[t].buildings[i] != null &&
                        planet.GetComponent <Teams>().teams[t].buildings[i].teamIndex != teamIndex &&
                        MyMath.sqrDistanceFromPointToPoint(planet.GetComponent <Teams>().teams[t].buildings[i].transform.position,
                                                           partOfPlanet.GetPart().transform.position) < 4)
                    {
                        toDestroy.Add(planet.GetComponent <Teams>().teams[t].buildings[i].gameObject);
                    }
                }
            }

            for (int t = 0; t < planet.GetComponent <Teams>().teams.Length; t++)
            {
                for (int i = 0; i < planet.GetComponent <Teams>().teams[t].carriers.Count; i++)
                {
                    if (planet.GetComponent <Teams>().teams[t].carriers[i] != null &&
                        planet.GetComponent <Teams>().teams[t].carriers[i].teamIndex != teamIndex &&
                        MyMath.sqrDistanceFromPointToPoint(planet.GetComponent <Teams>().teams[t].carriers[i].transform.position,
                                                           partOfPlanet.GetPart().transform.position) < 5)
                    {
                        toDestroy.Add(planet.GetComponent <Teams>().teams[t].carriers[i].gameObject);
                    }
                }
            }

            for (int t = toDestroy.Count - 1; t > -1; t--)
            {
                if (toDestroy[t].GetComponent <Building>() != null)
                {
                    planet.GetComponent <Teams>().teams[toDestroy[t].GetComponent <Building>().teamIndex].buildings.Remove(toDestroy[t].GetComponent <Building>());
                    toDestroy[t].GetComponent <Building>().partOfPlanet.building = null;
                    toDestroy[t].GetComponent <Building>().partOfPlanet.full     = false;
                    toDestroy[t].GetComponent <Building>().LossBuilding();
                    toDestroy.RemoveAt(t);
                }
                else
                {
                    if (toDestroy[t].GetComponent <Ship>() != null)
                    {
                        toDestroy[t].GetComponent <Ship>().LossShip();
                        toDestroy.RemoveAt(t);
                    }
                }
            }
            Destroy(gameObject);
        }
    }
コード例 #26
0
        }   // end of HeightMap GetHeightUnsafe()

        public float GetHeight(Vector2 position)
        {
            // Remap to "texel" coordinates.
            position.X *= (size.X - 1) / scale.X;
            position.Y *= (size.Y - 1) / scale.Y;

            // Get the integral and fraction parts of the position.
            int   i  = (int)position.X;
            int   j  = (int)position.Y;
            float dx = position.X - i;
            float dy = position.Y - j;

            // Calc the bilinearly weighted sample.
            float result = MyMath.Lerp(MyMath.Lerp(GetHeight(i, j), GetHeight(i + 1, j), dx), MyMath.Lerp(GetHeight(i, j + 1), GetHeight(i + 1, j + 1), dx), dy);

            return(result);
        }   // end of HeightMap GetHeight()
コード例 #27
0
 static double cos(int a)
 {
     return(MyMath.sqrt(1 - MyMath.pow(MyMath.sin(a), 2)));
 }
コード例 #28
0
        public static void MovePosition(ItemInventory fromIn, ItemInventory toIn, SimpleInventoryUI fromUI, SimpleInventoryUI toUI, ItemPosition ip, int x, int y, ISkillArgs args)
        {
            FreeRuleEventArgs fr = (FreeRuleEventArgs)args;
            int oneX             = toUI.GetWidth(args) / toIn.GetColumn();
            int countX           = x / (oneX);
            int remain           = x % (oneX);

            if (fromIn == toIn)
            {
                if (MyMath.Abs(remain) > oneX / 2)
                {
                    if (remain > 0)
                    {
                        countX++;
                    }
                    else
                    {
                        countX--;
                    }
                }
                countX = countX + ip.GetX();
            }
            else
            {
                if (countX < 0)
                {
                    countX = 0;
                }
            }
            int oneY   = toUI.GetHeight(args) / toIn.GetRow();
            int countY = y / (oneY);

            remain = y % (oneY);
            if (fromIn == toIn)
            {
                if (MyMath.Abs(remain) > oneY / 2)
                {
                    if (remain > 0)
                    {
                        countY++;
                    }
                    else
                    {
                        countY--;
                    }
                }
                countY = countY + ip.GetY();
            }
            else
            {
                if (countY < 0)
                {
                    countY = 0;
                }
                //countY = toIn.row - countY - 1;
            }
            if (MoveOut(fromIn, toIn, ip, countX, countY, args, fr, fromUI, toUI))
            {
                return;
            }
            Move(fromIn, toIn, ip, countX, countY, args, fr, fromUI, toUI);
        }
コード例 #29
0
 static double tan(int a)
 {
     return(MyMath.sin(a) / MyMath.cos(a));
 }
コード例 #30
0
ファイル: Problem421.cs プロジェクト: omikad/omikad-stuff
        public static void SolveInternal()
        {
            // Number of primes less than 1e8 is 5 761 455

            const ulong maxn = 100000000000;

//			const ulong maxprime = 100000000;	// S = 2304215802083466198, time =  2 062 029
//			const ulong maxprime = 10000000;	// S =  265739204055448802, time =     36 430
            const ulong maxprime = 1000000;                     // S =   31388381276205144, time =        919
//			const ulong maxprime = 100000;		// S =    3821999778506561, time =         49
//			const ulong maxprime = 10000;		// S =     489099997157400, time =         10
//			const ulong maxprime = 1000;		// S =      63199999956190
//			const ulong maxprime = 300;			// S =      23399999996126
//			const ulong maxprime = 100;         // S =       8299999999481

            var sieve  = MyMath.CreatePrimesSieve(maxprime);
            var primes = MyMath.ConvertSieveToPrimes(sieve);
            var invertedPrimeFactorsArray = new ulong[(int)Math.Sqrt(maxprime) + 1];

//			for (ulong num = 0; num < (ulong) primeFactorsTable.Length; num++)
//				Console.WriteLine("{0}: {1}", num, string.Join(", ", primeFactorsTable[num]));

            Console.WriteLine("Done precalc");

            var S = 0ul;

            foreach (var prime in primes)
            {
                // cnt будет равно количеству подходящих остатков
                var prime1 = prime - 1;
                var cnt    = GCD15(prime1);

                if (cnt == 1)
                {
                    var inverse = MyMath.ModularInverse(15, prime1);
                    var i       = MyMath.ModularPow(prime1, inverse, prime);

                    S += (1ul + (maxn - i) / prime) * prime;

                    continue;
                }

                if (((prime1 / cnt) & 1) == 1)
                {
                    continue;
                }

                ulong invertedPrimeFactorsLength;
                MyMath.FindInvertedPrimeFactors(prime1, primes, invertedPrimeFactorsArray, out invertedPrimeFactorsLength);

                var primitiveRoot = MyMath.FindPrimitiveRootForPrime(prime, invertedPrimeFactorsArray, invertedPrimeFactorsLength);

                var powerdelta = (prime1 / cnt) / 2;
                var power      = powerdelta;

                for (ulong k = 0; k < cnt; k++)
                {
                    var solution = MyMath.ModularPow(primitiveRoot, power, prime);

                    S += (1ul + (maxn - solution) / prime) * prime;

                    power += powerdelta * 2;
                }
            }

            Console.WriteLine(S);
        }
コード例 #31
0
 public void DelegatesCanBeAssigned()
 {
     MyMath math = new MyMath();
     BinaryOp op = math.Add;
     Assert.Equal("Add", op.Method.Name);
 }
コード例 #32
0
        //TODO: Fix ranged weapons

        public Vec?Dir(Entity attacker, Entity defender)
        {
            Vec delta = (defender.Pos - attacker.Pos);

            return(new Vec(MyMath.Clamp(delta.X, -1, 1), MyMath.Clamp(delta.Y, -1, 1)));
        }
コード例 #33
0
 public void DelegatesCanBeInstantiated()
 {
     MyMath math = new MyMath();
     BinaryOp op = new BinaryOp(math.Add);
     Assert.Equal("Add", op.Method.Name);
 }
コード例 #34
0
        //override this method for radius modification or smthng
        //  don't forget to use 'unityNormalCalculation' then
        //  iU, iV - is the indices within [0, stepsCount + 2] and [0, radiusSteps]
        public virtual Vector3 displacement(Vector3 normal, int iU, int iV)
        {
            float r = useDifferentFinishRadius ? MyMath.mix(radius, finishRadius, (float)iU / (poss.Count - 1)) : radius;

            return(normal * r);
        }
コード例 #35
0
 public void DelegatesCanBePassed()
 {
     MyMath math = new MyMath();
     BinaryOp op = math.Add;
     PassMeTheDelegate(op);
 }
コード例 #36
0
 public void UpdateMyRank()
 {
     Name_Text.text  = Player.Name;
     Score_Text.text = Player.BestScore.ToString();
     if (Player.Rank > LeaderboardUI.MaxItemNum)
     {
         Score_Text.text = string.Format("{0} {1}{2}", GameDictionary.String_UIDic["CurrentRank"].GetString(Player.UseLanguage), MyMath.GetTopProportionInTotal(Player.Rank, ChampionData.TotalChampionNum), "%");
     }
     else
     {
         Score_Text.text = string.Format("{0} {1}", GameDictionary.String_UIDic["CurrentRank"].GetString(Player.UseLanguage), Player.Rank.ToString());
     }
 }
コード例 #37
0
 public void MethodCanBePassedDirectly()
 {
     MyMath math = new MyMath();
     PassMeTheDelegate(math.Add);
 }
コード例 #38
0
            }   // end of RunSimUpdateObj c'tor

            /// <summary>
            /// RunSimUpdateObj Update()
            /// </summary>
            /// <param name="camera"></param>
            public override void Update()
            {
                base.Update();

                parent.Camera.Update();

                float secs = Time.WallClockFrameSeconds;

                ThoughtBalloonManager.Update(shared.camera);
                SaidStringManager.Update();
#if !NETFX_CORE
                MicrobitManager.Update();
#endif

                // Start with visible cursor.
                parent.cursor3D.Activate();
                parent.cursor3D.Rep    = Cursor3D.Visual.RunSim;
                parent.cursor3D.Hidden = false;

                //
                // Determine the correct camera mode.
                //

                //
                //  The priorities used to determine the camera mode when the game is running are:
                //
                //  1)  First person.  This can be either via programming or because the user zoomed
                //      into a bot the camera was following.
                //  2)  Follow mode caused by bot(s) programmed with "follow" camera view.
                //  3)  World tweak screen fixed camera or fixed offset camera.
                //  4)  Follow mode caused by user controlled bot(s).
                //  5)  Free camera.
                //

                // Start with a fake loop to break out of.
                while (true)
                {
                    Terrain terrain = InGame.inGame.Terrain;    // Just a shortcut.

                    //
                    // Always use edit mode when the game is paused except during victory on level with one of the fixed cameras
                    // or when game is paused for a bot to speak (modal text display).
                    //
                    bool victoryActive = VictoryOverlay.ActiveGameOver || VictoryOverlay.ActiveWinner;
                    bool speaking      = InGame.inGame.shared.smallTextDisplay.Active || InGame.inGame.shared.scrollableTextDisplay.Active;
                    if (Time.Paused && !((terrain.FixedCamera || terrain.FixedOffsetCamera) && victoryActive) && !speaking)
                    {
                        CameraInfo.Mode = CameraInfo.Modes.Edit;
                        CameraInfo.CameraFocusGameActor = null;
                        break;
                    }

                    //
                    // 1) First person
                    //
                    if (CameraInfo.FirstPersonActive)
                    {
                        CameraInfo.Mode = CameraInfo.Modes.Actor;

                        // We're following a single actor so update the FollowActor camera values.
                        shared.camera.FollowCameraValid = false;

                        // Turn off 3d cursor since we don't need it.
                        parent.cursor3D.Deactivate();
                        if (parent.cursorClone != null)
                        {
                            parent.cursorClone.Deactivate();
                            parent.cursorClone = null;
                        }
                        break;
                    }

                    //
                    // 2)  Follow mode caused by bot(s) programmed with "follow" camera view.
                    //
                    if (CameraInfo.ProgrammedFollowList.Count > 0)
                    {
                        // Note that even though we looked at the count of bot programmed to
                        // have the camera follow them, for this mode we want to keep all
                        // deserving bots in camera.  So, the rest of this section will use
                        // the merged follow list instead of just the programmed follow list.

                        SetUpCameraFollowMode();

                        break;
                    }

                    //
                    // 3) World tweak fixed cameras.  Note for fixed offset we have to let
                    //    the later modes do their stuff and then override the camera.
                    //

                    if (terrain.FixedCamera)
                    {
                        CameraInfo.Mode = CameraInfo.Modes.FixedTarget;
                        CameraInfo.CameraFocusGameActor = null;

                        // Turn off 3d cursor since we don't need it.
                        parent.cursor3D.Deactivate();
                        if (parent.cursorClone != null)
                        {
                            parent.cursorClone.Deactivate();
                            parent.cursorClone = null;
                        }

                        break;
                    }

                    //
                    // 4) Follow mode caused by user controlled bot(s).
                    //
                    if (CameraInfo.MergedFollowList.Count > 0)
                    {
                        SetUpCameraFollowMode();

                        break;
                    }

                    //
                    // 5) Free!
                    //
                    // Not following an actor.
                    CameraInfo.Mode = CameraInfo.Modes.Edit;
                    CameraInfo.CameraFocusGameActor = null;

                    // Turn on 3d cursor in case we previously disabled it.
                    parent.cursor3D.Activate();
                    parent.CreateCursorClone();
                    parent.cursor3D.Hidden = false;

                    // We have no camera restrictions, so keep track of what the user is doing.
                    shared.camera.PlayValid      = true;
                    shared.camera.PlayCameraFrom = shared.camera.From;
                    shared.camera.PlayCameraAt   = shared.camera.At;

                    shared.camera.FollowCameraValid = false;


                    // Final break just to be sure the loop exits.
                    break;
                }

                //
                // Now that we're done, we need to check again to see if
                // we should be in FixedOffsetMode.
                //
                if (!Time.Paused && InGame.inGame.Terrain.FixedOffsetCamera && !CameraInfo.FirstPersonActive)
                {
                    CameraInfo.Mode = CameraInfo.Modes.FixedOffset;
                }

                // Zero out any offset while running.
                float t = Math.Min(Time.GameTimeFrameSeconds, 1.0f);
                shared.camera.HeightOffset = MyMath.Lerp(shared.camera.HeightOffset, 0.0f, t);

                //
                bool inputFocus = CommandStack.Peek() == commandMap;

                // Move the camera.
                switch (CameraInfo.Mode)
                {
                case CameraInfo.Modes.Edit:
                    MoveCameraEditMode(inputFocus, false);
                    break;

                case CameraInfo.Modes.Actor:
                    MoveCameraActorMode(true, false);
                    break;

                case CameraInfo.Modes.FixedTarget:
                    MoveCameraFixedTargetMode(inputFocus);
                    break;

                case CameraInfo.Modes.FixedOffset:
                    MoveCameraFixedOffsetMode(inputFocus);
                    break;

                case CameraInfo.Modes.MultiTarget:
                    MoveCameraMultiTargetMode(inputFocus, false);
                    break;
                }

                shared.camera.Update();

                // Update terrain.
                parent.terrain.Update(shared.camera);

                // Update the list of objects using our local camera.
                for (int i = 0; i < updateList.Count; i++)
                {
                    UpdateObject obj = (UpdateObject)updateList[i];
                    obj.Update();
                }
                parent.UpdateObjects();

                /// Pregame must update after parent.UpdateObjects, in case it
                /// decides to switchToMiniHub
                if (InGame.inGame.preGame != null)
                {
                    InGame.inGame.preGame.Update();
                }

                // Update the particle system.
                shared.particleSystemManager.Update();
                DistortionManager.Update();
                FirstPersonEffectMgr.Update();

                // This must be done after all brains are updated.
                Scoreboard.Update(shared.camera);

                // Update the TextDisplays.  Ignored if not active.
                shared.scrollableTextDisplay.Update(shared.camera);
                shared.smallTextDisplay.Update(shared.camera);

                VictoryOverlay.Update();

                // Do the input processing after object update because there will be order of operation issue if we don't
                //
                // Check if we have input focus.  Don't do any input
                // related update if we don't.
                if (inputFocus)
                {
                    // Grab the current state of the gamepad.
                    GamePadInput pad = GamePadInput.GetGamePad0();

                    // Switch to Mini-Hub?
                    if (Actions.MiniHub.WasPressed)
                    {
                        Actions.MiniHub.ClearAllWasPressedState();

                        //parent.ResetSim(CurrentLevelFilename());

                        // Needed to make sure that deactivated objects are actually removed from
                        // the list otherwise they may get saved along with the newly activated ones.
                        //parent.Refresh(BokuGame.gameListManager.updateList, BokuGame.gameListManager.renderList);

                        parent.SwitchToMiniHub();
                        return;
                    }

                    //handle swipe to return to edit for touch input
                    if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch)
                    {
                        SwipeGestureRecognizer swipeGesture = TouchGestureManager.Get().SwipeGesture;
                        if (swipeGesture.WasRecognized &&
                            swipeGesture.SwipeDirection == Directions.North)
                        {
#if NETFX_CORE
                            float halfWidth = (float)BokuGame.bokuGame.Window.ClientBounds.Width * 0.5f;
                            float height    = (float)BokuGame.bokuGame.Window.ClientBounds.Height;
#else
                            float halfWidth = (float)XNAControl.Instance.ClientSize.Width * 0.5f;
                            float height    = (float)XNAControl.Instance.ClientSize.Height;
#endif

                            //center half of the screen width-wise
                            float minX = halfWidth - (halfWidth * k_TouchExitAreaWidthPercent);
                            float maxX = halfWidth + (halfWidth * k_TouchExitAreaWidthPercent);

                            //bottom 20% height-wise
                            float minY = height - (height * k_TouchExitAreaHeightPercent);


                            Vector2 pos = swipeGesture.InitialPosition;
                            if (pos.X >= minX && pos.X <= maxX && pos.Y >= minY)
                            {
                                // User did a swipe from the bottom of the screen, enter edit mode
                                InGame.inGame.CurrentUpdateMode = UpdateMode.EditObject;
                                InGame.inGame.CurrentUpdateMode = UpdateMode.TouchEdit;

                                Foley.PlayPressStart();
                                return;
                            }
                        }

                        // HACKHACK (****) Put in a tap recognizer since swipe seems to fail.
                        {
                            TapGestureRecognizer hackTapGesture = TouchGestureManager.Get().TapGesture;
                            if (hackTapGesture.WasTapped())
                            {
#if NETFX_CORE
                                float halfWidth = (float)BokuGame.bokuGame.Window.ClientBounds.Width * 0.5f;
                                float height    = (float)BokuGame.bokuGame.Window.ClientBounds.Height;
#else
                                float halfWidth = (float)XNAControl.Instance.ClientSize.Width * 0.5f;
                                float height    = (float)XNAControl.Instance.ClientSize.Height;
#endif

                                //center area of the screen width-wise
                                float minX = halfWidth - (halfWidth * 0.1f);
                                float maxX = halfWidth + (halfWidth * 0.1f);

                                //bottom 10% height-wise
                                float minY = height - (height * 0.1f);

                                Vector2 pos = hackTapGesture.Position;
                                if (pos.X >= minX && pos.X <= maxX && pos.Y >= minY)
                                {
                                    // User did a tap on the bottom of the screen, enter edit mode
                                    InGame.inGame.CurrentUpdateMode = UpdateMode.EditObject;
                                    InGame.inGame.CurrentUpdateMode = UpdateMode.TouchEdit;

                                    Foley.PlayPressStart();
                                    return;
                                }
                            }
                        }
                    }

                    bool gameOver = VictoryOverlay.GameOver;

                    if (Time.Paused && !gameOver)
                    {
                        // We must be in user induced pause mode.
                        if (Actions.Unpause.WasPressed)
                        {
                            Actions.Unpause.ClearAllWasPressedState();

                            Time.Paused = false;
                            HelpOverlay.Pop();
                        }
                    }
                    else
                    {
                        if (gameOver)
                        {
                            // Game over man!  Let the user restart if they want.
                            if (Actions.Restart.WasPressed)
                            {
                                Actions.Restart.ClearAllWasPressedState();

                                InGame.inGame.ResetSim(preserveScores: false, removeCreatablesFromScene: true, keepPersistentScores: false);
                                // Since we're going right back into RunSim mode we need to first inline.
                                ApplyInlining();
                            }
                        }

                        // Open ToolMenu.
                        if (Actions.ToolMenu.WasPressed)
                        {
                            Actions.ToolMenu.ClearAllWasPressedState();

                            parent.CurrentUpdateMode = UpdateMode.ToolMenu;
                            Foley.PlayPressStart();
                            return;
                        }

                        // Pause?
                        // We want to make pause hard to get into so it requires both triggers and both stickButtons to be pressed.
                        if ((pad.LeftStickButton.IsPressed && pad.RightStickButton.IsPressed && pad.LeftTriggerButton.IsPressed && pad.RightTriggerButton.IsPressed) || Actions.Pause.WasPressed)
                        {
                            Actions.Pause.ClearAllWasPressedState();

                            if (!Time.Paused)
                            {
                                Time.Paused = true;
                                HelpOverlay.Push("PauseGame");
                                GamePadInput.GetGamePad0().IgnoreLeftStickUntilZero();
                                GamePadInput.GetGamePad0().IgnoreRightStickUntilZero();
                            }
                        }
                    }
                }

                // Force the the HelpOverlay to be correct.
                if (!Time.Paused || VictoryOverlay.Active)
                {
                    if (InGame.inGame.PreGame != null && InGame.inGame.PreGame.Active)
                    {
                        if (HelpOverlay.Depth() != 1 || HelpOverlay.Peek() != "RunSimulationPreGame")
                        {
                            HelpOverlay.Clear();
                            HelpOverlay.Push("RunSimulationPreGame");
                        }
                    }
                    else
                    {
                        if (HelpOverlay.Depth() != 1 || HelpOverlay.Peek() != "RunSimulation")
                        {
                            HelpOverlay.Clear();
                            HelpOverlay.Push("RunSimulation");
                        }
                    }
                }
                else
                {
                    // We're paused.
                    if (HelpOverlay.Depth() != 2 || HelpOverlay.Peek(1) != "RunSimulation")
                    {
                        HelpOverlay.Clear();
                        HelpOverlay.Push("RunSimulation");
                        HelpOverlay.Push("PauseGame");
                    }
                }

                // When in run mode, allow the user to click on the "Press [esc] to edit" text as if it was a button.
                if (MouseInput.Left.WasPressed)
                {
                    Point mousePos = MouseInput.Position;
                    if (HelpOverlay.MouseHitBottomText(mousePos))
                    {
                        // Switch to edit mode.
                        InGame.inGame.CurrentUpdateMode = UpdateMode.EditObject;
                    }
                }
                TapGestureRecognizer tapGesture = TouchGestureManager.Get().TapGesture;
                if (tapGesture.WasTapped())
                {
                    // JW - Until we have proper Touch help overlays, we are still using the mouse/keyboard
                    // overlays. The mouse handling code for these depends on being able to 'absorb' pressed
                    // info to hide it from later callers. Our touch stuff doesn't (and really shouldn't)
                    // do this. So, we handle cases here based on what type of overlay is being displayed.
                    if (HelpOverlay.Peek() == "RunSimulationPreGame")
                    {
                        // Tap during instructions: just begin game.
                        InGame.inGame.PreGame.Active = false;
                    }

                    // Also test if running sim for tapping on "tap to edit" at bottom.
                    if (HelpOverlay.Peek() == "RunSimulation")
                    {
                        Point pos = new Point((int)tapGesture.Position.X, (int)tapGesture.Position.Y);
                        if (HelpOverlay.MouseHitBottomText(pos))
                        {
                            // Switch to edit mode.
                            InGame.inGame.CurrentUpdateMode = UpdateMode.EditObject;
                        }
                    }
                }
            }   // end of RunSimUpdateObj Update()
コード例 #39
0
 public void MethodsCalledViaDelegate()
 {
     MyMath math = new MyMath();
     BinaryOp op = math.Add;
     Assert.Equal(6, op(3,3));
 }
コード例 #40
0
 public void ChooseTest()
 {
     Assert.AreEqual(15, MyMath.Choose(6, 2));
 }
コード例 #41
0
 public void DelegatesCanBePassed()
 {
     MyMath math = new MyMath();
     BinaryOp op = math.Add;
     Assert.Equal(FILL_ME_IN, PassMeTheDelegate(op));
 }