public void SqrtTest() { //check Sqrt(int a) Assert.AreEqual(3, Math.Sqrt(9)); Assert.AreEqual(0, Math.Sqrt(0)); Assert.ThrowsException <Exception>(() => OwnMath.sqrt(-9)); }
public void SquareTest() { //check Square() Assert.AreEqual(0, OwnMath.square(0)); Assert.AreEqual(16, OwnMath.square(4)); Assert.AreEqual(16, OwnMath.square(-4)); }
public void DivTest() { //check div(int a, int b) Assert.AreEqual(5, OwnMath.div(10, 2)); Assert.AreEqual(-5, OwnMath.div(-10, 2)); Assert.AreEqual(0, OwnMath.div(0, 2)); Assert.ThrowsException <Exception>(() => (OwnMath.div(2, 0))); //check div(double a, int b) Assert.AreEqual(5.25, OwnMath.div(10.5, 2)); Assert.AreEqual(-5.25, OwnMath.div(-10.5, 2)); Assert.AreEqual(0, OwnMath.div(0.0, 2)); Assert.ThrowsException <Exception>(() => (OwnMath.div(2.5, 0))); //check div(int a, double b) Assert.AreEqual(4, OwnMath.div(10, 2.5)); Assert.AreEqual(-4, OwnMath.div(-10, 2.5)); Assert.AreEqual(0, OwnMath.div(0, 2.5)); //check mul(double a, double b) Assert.AreEqual(4.2, OwnMath.div(10.5, 2.5)); Assert.AreEqual(-4.2, OwnMath.div(-10.5, 2.5)); //check divInt(int a, int b) Assert.AreEqual(5, OwnMath.divInt(10, 2)); Assert.AreEqual(-5, OwnMath.divInt(-10, 2)); Assert.AreEqual(0, OwnMath.divInt(0, 2)); Assert.ThrowsException <Exception>(() => (OwnMath.divInt(2, 0))); }
public void ReverseTest() { //check Reverse() Assert.ThrowsException <Exception>(() => (OwnMath.reverse(0))); Assert.AreEqual(0.5, OwnMath.reverse(2)); Assert.AreEqual(-0.5, OwnMath.reverse(-2)); }
public override void DoPhysics() { // get direction to the current target Vector2 direction = OwnMath.GetDirectionToPoint(Position.ToPoint(), targetPos.ToPoint()); // get the angle between the zombie and the player float angle = OwnMath.CalculateAngleBetweenPoints(Position.ToPoint(), targetPos.ToPoint()); float distance = direction.Length(); // distance equals the length of the vector direction.Normalize(); // normalize the direction to units // move the zombie and set the animation if the zombie didnt reach the player // basically follow the player if (distance > ATTACK_DISTANCE) { currentAnimationKey = MOVE_ANIMATION_KEY; _physics.position.X += direction.X * _physics.speed; _physics.position.Y += direction.Y * _physics.speed; } else // if reached invoke the attack according to the fire rate { currentAnimationKey = ATTACK_ANIMATION_KEY; // set the animation to attack attackTimer += gameTime.ElapsedGameTime.Milliseconds; // increase time if (attackTimer >= ATTACK_ANIMATION_TIMER) { // Attack zombieAttack.Invoke(); attackTimer = 0; // reset timer after reaching max } } _physics.rotation = angle; }
public void FactorialTest() { //check Factorial(int a) Assert.AreEqual(Convert.ToUInt32(6), OwnMath.Factorial(3)); Assert.AreEqual(Convert.ToUInt32(1), OwnMath.Factorial(0)); Assert.ThrowsException <Exception>(() => OwnMath.Factorial(-2)); }
public void RootTest() { //check Root() Assert.AreEqual(2, OwnMath.root(8, 3)); Assert.AreEqual(0.5, OwnMath.root(8, -3)); Assert.AreEqual(0, OwnMath.root(0, 3)); Assert.ThrowsException <Exception>(() => (OwnMath.root(-8, 3))); Assert.ThrowsException <Exception>(() => (OwnMath.root(8, 0))); }
public void AbsTest() { //check Abs(int a) Assert.AreEqual(10, OwnMath.Abs(10)); Assert.AreEqual(10, OwnMath.Abs(-10)); Assert.AreEqual(0, OwnMath.Abs(0)); //check Abs(double a) Assert.AreEqual(10.5, OwnMath.Abs(10.5)); Assert.AreEqual(10.5, OwnMath.Abs(-10.5)); }
public override void DoPhysics() { Input.Cursor.Update(gameTime); // Rotation regarding the cursor class _physics.rotation = OwnMath.CalculateAngleBetweenPoints(Position.ToPoint(), Input.Cursor.Position.ToPoint()); // Make sure that the player does not go out of bounds Position = new Vector2(MathHelper.Clamp(Position.X, 80, gameWidth - 80), MathHelper.Clamp(Position.Y, 80, gameHeight - 80)); }
public void CeilTest() { //check Ceil(double a) Assert.AreEqual(6, OwnMath.ceil(5.3)); Assert.AreEqual(-4, OwnMath.ceil(-4.4)); Assert.AreEqual(1, OwnMath.ceil(0.25)); //check CeilInt(double a) Assert.AreEqual(6, OwnMath.ceilInt(5.3)); Assert.AreEqual(-4, OwnMath.ceilInt(-4.4)); Assert.AreEqual(1, OwnMath.ceilInt(0.25)); }
public void PowTest() { //check Pow(int a, int power) Assert.AreEqual(9, OwnMath.pow(3, 2)); Assert.AreEqual(9, OwnMath.pow(-3, 2)); Assert.AreEqual(27, OwnMath.pow(3, 3)); Assert.AreEqual(0, OwnMath.pow(0, 2)); //check Pow(double a, double power) Assert.AreEqual(10.889999999999999, OwnMath.pow(3.3, 2)); Assert.AreEqual(10.889999999999999, OwnMath.pow(-3.3, 2)); Assert.AreEqual(0.0, OwnMath.pow(0.0, 2)); }
public void MemLoadIntTest() { OwnMath.memDel(); //check memLoadInt() OwnMath.memAdd(25.4); Assert.AreEqual(25, OwnMath.memLoadInt()); OwnMath.memAdd(0.5); Assert.AreEqual(26, OwnMath.memLoadInt()); OwnMath.memDel(); }
public void RoundTest() { //check Round(double a, int decimalPlace) Assert.AreEqual(6.4, OwnMath.round(6.42, 1)); Assert.AreEqual(6.5, OwnMath.round(6.46, 1)); Assert.AreEqual(-1.5, OwnMath.round(-1.53, 1)); Assert.AreEqual(-1.6, OwnMath.round(-1.58, 1)); Assert.AreEqual(6, OwnMath.round(6.2, 0)); //check Round(double a) Assert.AreEqual(6, OwnMath.round(6.4)); Assert.AreEqual(7, OwnMath.round(6.6)); }
public void FloorTest() { //check Floor(double a) Assert.AreEqual(5, OwnMath.floor(5.3)); Assert.AreEqual(-5, OwnMath.floor(-4.4)); Assert.AreEqual(0, OwnMath.floor(0.25)); Assert.IsInstanceOfType(OwnMath.floor(0.25), typeof(double)); //check FloorInt(double a) Assert.AreEqual(5, OwnMath.floorInt(5.3)); Assert.AreEqual(-5, OwnMath.floorInt(-4.4)); Assert.AreEqual(0, OwnMath.floorInt(0.25)); Assert.IsInstanceOfType(OwnMath.floorInt(0.25), typeof(int)); }
public void MemDelTest() { OwnMath.memDel(); //check memDel() OwnMath.memAdd(25); OwnMath.memDel(); Assert.AreEqual(0, OwnMath.memLoad()); OwnMath.memAdd(-25); OwnMath.memDel(); Assert.AreEqual(0, OwnMath.memLoad()); OwnMath.memDel(); }
public void MulTest() { //check mul(int a, int b) Assert.AreEqual(10, OwnMath.mul(5, 2)); Assert.AreEqual(-10, OwnMath.mul(-5, 2)); Assert.AreEqual(0, OwnMath.mul(10, 0)); //check mul(double a, int b) Assert.AreEqual(11, OwnMath.mul(5.5, 2)); Assert.AreEqual(-11, OwnMath.mul(-5.5, 2)); Assert.AreEqual(0, OwnMath.mul(10.5, 0)); //check mul(double a, double b) Assert.AreEqual(30.25, OwnMath.mul(5.5, 5.5)); Assert.AreEqual(-30.25, OwnMath.mul(-5.5, 5.5)); }
public void AddTest() { //check add(int a, int b) Assert.AreEqual(10, OwnMath.add(5, 5)); Assert.AreEqual(-10, OwnMath.add(-5, -5)); Assert.AreEqual(10, OwnMath.add(0, 10)); Assert.AreEqual(-10, OwnMath.add(0, -10)); //check add(double a, int b) Assert.AreEqual(10.5, OwnMath.add(5.5, 5)); Assert.AreEqual(-10.5, OwnMath.add(-5.5, -5)); Assert.AreEqual(10.5, OwnMath.add(10.5, 0)); Assert.AreEqual(-10.5, OwnMath.add(-10.5, 0)); //check add(double a, double b) Assert.AreEqual(11, OwnMath.add(5.5, 5.5)); Assert.AreEqual(-11, OwnMath.add(-5.5, -5.5)); }
public void MemAddTest() { //check memAdd(int a) OwnMath.memDel(); OwnMath.memAdd(10); Assert.AreEqual(10, OwnMath.memLoad()); OwnMath.memAdd(5); Assert.AreEqual(15, OwnMath.memLoad()); //check memAdd(double a) OwnMath.memDel(); OwnMath.memAdd(10.5); Assert.AreEqual(10.5, OwnMath.memLoad()); OwnMath.memAdd(5.5); Assert.AreEqual(16, OwnMath.memLoad()); OwnMath.memDel(); }
public void MemSubTest() { OwnMath.memDel(); //check memSub(int a) OwnMath.memSub(10); Assert.AreEqual(-10, OwnMath.memLoad()); OwnMath.memAdd(-5); Assert.AreEqual(-15, OwnMath.memLoad()); //check memSub(double a) OwnMath.memDel(); OwnMath.memSub(10.5); Assert.AreEqual(-10.5, OwnMath.memLoad()); OwnMath.memSub(5.5); Assert.AreEqual(-16, OwnMath.memLoad()); OwnMath.memDel(); }
static void Main(string[] args) { double output; List <double> numbers = new List <double>(); string[] inputs = Console.ReadLine().Replace('.', ',').Split(Separator); int strlen = inputs.Length; double tmp = 0; for (int i = 0; i < strlen; i++) { if (inputs[i] != string.Empty) { if (!double.TryParse(inputs[i], out tmp)) { continue; } numbers.Add(tmp); } } double N = numbers.Count; double x_carka; tmp = 0; for (int i = 0; i < N; i++) { tmp = OwnMath.add(tmp, numbers[i]); } x_carka = OwnMath.mul(OwnMath.div(1, N), tmp); tmp = 0; for (int i = 0; i < N; i++) { tmp = OwnMath.add(tmp, OwnMath.pow(numbers[i], 2)); } output = OwnMath.sqrt(OwnMath.mul(OwnMath.div(1, OwnMath.sub(N, 1)), OwnMath.sub(tmp, OwnMath.mul(N, OwnMath.pow(x_carka, 2))))); Console.WriteLine(output); }
public Bullet(Texture2D Texture, Player player) { Random r = new Random(); this.Texture = Texture; this.player = player; damage = player.Damage; Console.WriteLine(damage); // spawn from the origin of the player Position = player.Position; // calculcate which direction the bullet will go direction = OwnMath.GetDirectionToPoint(player.Position.ToPoint(), player.Input.Cursor.Position.ToPoint()); // get the rotation to the mouse pointer (equal be the player._physics.rotation) rotation = OwnMath.CalculateAngleBetweenPoints(player.Position.ToPoint(), player.Input.Cursor.Position.ToPoint()); // default speed speed = 5f; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region Memory_Buttons private void ButtonMC_Click(object sender, EventArgs e) { OwnMath.memDel(); }
private void ButtonMR_Click(object sender, EventArgs e) { UserInput.Text = OwnMath.memLoad().ToString(); }
public void SubTest() { //check sub(double a, double b) Assert.AreEqual(10, OwnMath.sub(15.5, 5.5)); Assert.AreEqual(-10, OwnMath.sub(-15.5, -5.5)); }
private void ButtonMemoryminus_Click(object sender, EventArgs e) { OwnMath.memSub(ParseNumber(UserInput.Text)); }
private void ButtonMS_Click(object sender, EventArgs e) { OwnMath.memDel(); OwnMath.memAdd(ParseNumber(UserInput.Text)); }
public void Update(GameTime gameTime) { SpawnZombie(gameTime); // if any blood is animated then we make it disapear bloodAnimations.RemoveAll((b) => { return(b.Active == false); }); // animate the bullets the player fired foreach (var bullet in bulletsFired) { bullet.Update(gameTime); } // animate all blood that is activated foreach (var blood in bloodAnimations) { blood.Update(gameTime); } // checks and remove the zombie with 0 health (or dead) from the list for (int i = 0; i < zombies.Count; i++) { if (!zombies[i].IsAlive) { // increase kill points zombiesKilledCounter++; // remove zombie from zombie list zombies.RemoveAt(i); // when removing from a list, the zombie count decreases i--; } } // update the zombie (important to do it after, so we wont animate the dead zombies) foreach (var zombie in zombies) { zombie.Update(gameTime, currentPlayer.Position); } // Checks the collision between the bullets and the zombies for (int i = 0; i < bulletsFired.Count; i++) { // the current bullet var bullet = bulletsFired[i]; for (int j = 0; j < zombies.Count; j++) { // current zombie var zombie = zombies[j]; // the distance between the zombie and the bullet var dist = OwnMath.GetDirectionToPoint(bullet.Position.ToPoint(), zombie.Position.ToPoint()); // if the distance is less than 20 (about zombie width) // and the bullet is not removed already for other reason if (dist.Length() < 20 && bulletsFired.Count > i) { // bullet hits, add points to the fighter ability charge currentPlayer.abilityCharge += (int)bullet.damage; bulletsFired.RemoveAt(i); zombie.TakeDamage(bullet.damage); bloodAnimations.Add(new Blood(Content, zombie.Position)); } } for (int j = 0; j < CurrentRoom.collideables.Count; j++) { var col = CurrentRoom.collideables[j]; if (bullet.Rectangle.Intersects(col.Rectangle)) { bulletsFired.Remove(bullet); if (col.TakeDamage()) { CurrentRoom.collideables.Remove(col); if (col.Type == Component.ObjectType.SPAWN_POINT) { CurrentRoom.spawnPlaces.Remove(col.Position); } } } } // if the bullet reached the screen bounds, remove it from the list if (bullet.Position.X > width - 50 || bullet.Position.Y > height - 50 || bullet.Position.X < 50 || bullet.Position.Y < 50) { // if the bullet is not removed already for other reason if (bulletsFired.Count > i) { bulletsFired.RemoveAt(i); } } } if (CurrentRoom.DoorOpened) { Rectangle r1 = new Rectangle((int)currentPlayer.Position.X, (int)currentPlayer.Position.Y, currentPlayer.GetAnimation().Width / 2, currentPlayer.GetAnimation().Height / 2); if (r1.Intersects(CurrentRoom.Exit.Rectangle)) { Data.SetScore(Data.GetScore() + zombiesKilledCounter); CurrentRoom.LoadMap(); ResetGame(); } } }