Esempio n. 1
0
        public void ClampFloatTest3()
        {
            float f        = 0;
            float expected = 30;
            float result   = SharedUtilities.Clamp(f, 30, 101);

            Assert.AreEqual(expected, result);
        }
Esempio n. 2
0
        public void ClampIntTest2()
        {
            int f        = 100;
            int expected = 50;
            int result   = SharedUtilities.Clamp(f, 0, 50);

            Assert.AreEqual(expected, result);
        }
Esempio n. 3
0
        public void ClampFloatTest2()
        {
            float f        = 100;
            float expected = 50;
            float result   = SharedUtilities.Clamp(f, 0, 50);

            Assert.AreEqual(expected, result);
        }
Esempio n. 4
0
        public void ClampIntTest3()
        {
            int f        = 0;
            int expected = 30;
            int result   = SharedUtilities.Clamp(f, 30, 101);

            Assert.AreEqual(expected, result);
        }
Esempio n. 5
0
        public virtual void Move(int direction)
        {
            float multiplier = PowerUppedData.ChangePaddleSpeed ?
                               (PowerUppedData.RndSpeed > 1 ? 2f : 0.5f) : 1;
            float posChange = MaxAngularSpeed * direction * multiplier;

            AngularPosition = SharedUtilities.Clamp(AngularPosition + posChange, MinAngle, MaxAngle);
        }
Esempio n. 6
0
        private NetworkMessage GetResponse(ServerSidePlayer sender, NetworkMessage networkMessage)
        {
            switch (networkMessage.Type)
            {
            case NetworkMessage.MessageType.Chat:
            case NetworkMessage.MessageType.PlayerSync:
            case NetworkMessage.MessageType.BallSync:
            case NetworkMessage.MessageType.GameEnd:
            case NetworkMessage.MessageType.ObstacleSpawned:
            case NetworkMessage.MessageType.PowerupSpawned:
            case NetworkMessage.MessageType.BallPoweredUp:
            case NetworkMessage.MessageType.PaddlePowerUp:
                return(networkMessage.ShallowClone());

            case NetworkMessage.MessageType.GameStart:
            {
                NetworkMessage message     = networkMessage.DeepClone();
                byte[]         playerIds   = Players.Select(p => p.Id).ToArray();
                byte[]         paddleTypes = RandomNumber.GetArray(playerIds.Length,
                                                                   () => RandomNumber.NextByte((byte)PaddleType.Normal, (byte)(PaddleType.Short + 1)));
                byte   ballType  = (byte)BallType.Normal;
                byte[] byteArray = Converter.EncodeGameStartMessage(playerIds, paddleTypes, ballType, RoomMaster.Id);
                message.ByteContents = byteArray;
                return(message);
            }

            case NetworkMessage.MessageType.RoundReset:
            {
                NetworkMessage message = networkMessage.DeepClone();
                Converter.DecodeRoundOverData(networkMessage.ByteContents, out BallType[] oldBalls, out byte[] oldIds, out byte[] playerIDs, out byte[] playerLifes);

                int ballCount = SharedUtilities.Clamp(
                    playerIDs.Length + RandomNumber.NextInt(-1, 2), 1, playerIDs.Length + 1);

                BallType[] newBallTypes = new BallType[ballCount];
                byte[]     newIds       = new byte[newBallTypes.Length];
                for (int i = 0; i < newBallTypes.Length; i++)
                {
                    newBallTypes[i] = i == 1 ? BallType.Normal :
                                      (BallType)RandomNumber.NextByte((byte)BallType.Normal, (byte)(BallType.Deadly + 1));
                    newIds[i] = (byte)i;
                }
                byte[] byteArray = Converter.EncodeRoundOverData(newBallTypes, newIds, playerIDs, playerLifes);
                message.ByteContents = byteArray;
                return(message);
            }

            default:
                Debug.WriteLine($"Exception: could not get repsonse to message of type {networkMessage.Type}");
                break;
            }
            return(null);
        }
Esempio n. 7
0
 public virtual void AddLife(int amount)
 {
     SetLife(SharedUtilities.Clamp(Life + amount, 0, byte.MaxValue));
 }
Esempio n. 8
0
 public void ClampTest()
 {
     Assert.IsTrue(SharedUtilities.Clamp(10, 0, 20) == 10 && SharedUtilities.Clamp(10, 15, 20) == 15 && SharedUtilities.Clamp(30, 0, 20) == 20 &&
                   SharedUtilities.Clamp(10f, 0f, 20f) == 10f && SharedUtilities.Clamp(10f, 15f, 20f) == 15f && SharedUtilities.Clamp(30f, 0f, 20f) == 20f);
 }