Exemple #1
0
        public static Unit getUnit(unitType t)
        {
            UnitAttribute local = getAtribute(t);
            Unit          r     = new Unit(local.AS, local.DS, local.size);

            return(r);
        }
Exemple #2
0
    public IEnumerator spawnUnit(unitType unitType)                                                            //this function spawns a unit, of type unitType, in sector spawningSector if there is available space
    {
        bool isSpace = false;                                                                                  //this bool is used to keep track of when an empty space in the sector is found

        for (int positionIndex = 0; positionIndex < 3; positionIndex++)                                        //search all possible standing positions on spawning sector too see if the sector is full
        {
            if (spawnSector.GetComponent <sectorScript>().unitsContained[positionIndex] == null && !isSpace)   //if an empty space is found
            {
                gameMainScript GameMainScript = gameMain.GetComponent <gameMainScript>();                      //set reference to gameMain's gameMainScript
                gameMapScript  GameMapScript  = gameMain.transform.GetChild(0).GetComponent <gameMapScript>(); //set reference to gameMap's gameMapScript

                GameMapScript.createUnit(unitType, GameMainScript.currentPlayer, spawnSector);                 //use the "createUnit" funtion in the gameMapScript to spawn a new unit

                isSpace = true;                                                                                //stop searching for spaces
            }
        }

        if (!isSpace)                                   //if no space was found for the unit to stand on the sector show a warning message to the user
        {
            warningMessage.gameObject.SetActive(true);  //show warning message

            yield return(new WaitForSeconds(2));        //show message for 2 seconds

            warningMessage.gameObject.SetActive(false); //stop showing warning message
        }
    }
        public IHttpActionResult PutunitType(int id, unitType unitType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != unitType.unitTypeID)
            {
                return(BadRequest());
            }

            db.Entry(unitType).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!unitTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #4
0
        public static Unit getUnit(unitType t)
        {
            UnitAttribute local = getAtribute(t);
            Unit          r     = new Unit(local.armor, local.health, local.size, local.damage, local.acuracy, local.attackradius, local.attackspeed, local.dexterity, local.movementspeed, local.attackrange, local.x, local.y);

            return(r);
        }
Exemple #5
0
    public void createUnit(unitType unitType, player owner, GameObject sectorToSpawn)                           //this function creates a unit of type "unitType" at "sectorToSpawn" and sets it's owner to "owner"
    {
        GameObject newUnit = Instantiate(unit, new Vector3(0, 0, 0), Quaternion.identity);                      //instantate unit prefab

        newUnit.GetComponent <unitScript>().Init(unitType, owner, sectorToSpawn, fightCanvas, this.gameObject); //perform unit initialization
        //fight canvas is passed so that any unit can start playing the battle animation
    }
Exemple #6
0
 public UnitInfo(unitType unitType, int myID, int innerX, int innerY, bool forward)
 {
     type         = unitType;
     id           = myID;
     this.forward = forward;
     this.innerX  = innerX;
     this.innerY  = innerY;
 }
Exemple #7
0
        private void Initialize(DataRow dr, bool LoadImage)
        {
            _cID       = dr["cardID"].ToString();
            _name      = dr["name"].ToString();
            _uclass    = UnitType.Parse(dr["uclass"].ToString());
            _trigger   = TriggerType.Parse(dr["trigger"].ToString());
            _grade     = Convert.ToInt32(dr["grade"]);
            _origPower = Convert.ToInt32(dr["power"]);
            _critical  = Convert.ToInt32(dr["critical"]);
            try { _origShield = Convert.ToInt32(dr["shield"]); }
            catch { _origShield = 0; }

            //Set Power and Shield
            _power  = _origPower;
            _shield = _origShield;

            //Text Values
            _clan      = dr["clan"].ToString();
            _race      = dr["race"].ToString().Split('/');
            _abilities = dr["effect"].ToString();
            _flavour   = dr["flavour"].ToString();
            _nation    = dr["nation"].ToString();
            _illust    = dr["illustrator"].ToString();

            //Location Default
            if (_uclass == unitType.G)
            {
                _location = "G Zone-0";
            }
            else
            {
                _location = "Deck-0";
            }

            //Get Image
            if (LoadImage)
            {
                try { cardImage = new Bitmap(@"Images/" + _cID.Replace('/', '-') + ".jpg"); }
                catch (FileNotFoundException)
                {
                    //Create New Card
                    cardImage = new Bitmap(ImageConverter.ToBitmap(Properties.Settings.Default.GSleeve));
                }
                catch (Exception ex) { Console.WriteLine(ex.Message); }

                redImage = new Bitmap(cardImage);

                using (Graphics g = Graphics.FromImage(redImage))
                {
                    Rectangle rect = new Rectangle(Point.Empty, redImage.Size);
                    g.FillRectangle(new SolidBrush(Color.FromArgb(100, 255, 0, 0)), rect);
                }
            }
        }
        public IHttpActionResult GetunitType(int id)
        {
            unitType unitType = db.unitType.Find(id);

            if (unitType == null)
            {
                return(NotFound());
            }

            return(Ok(unitType));
        }
Exemple #9
0
 public bool IsUClass(unitType uclass)
 {
     if (comboBox_UClass.Text == "Any")
     {
         return(true);
     }
     else
     {
         return(UnitType.Parse(comboBox_UClass.Text) == uclass);
     }
 }
        public IHttpActionResult PostunitType(unitType unitType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.unitType.Add(unitType);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = unitType.unitTypeID }, unitType));
        }
        public IHttpActionResult DeleteunitType(int id)
        {
            unitType unitType = db.unitType.Find(id);

            if (unitType == null)
            {
                return(NotFound());
            }

            db.unitType.Remove(unitType);
            db.SaveChanges();

            return(Ok(unitType));
        }
    public void InstantiateUnit(unitType type, string tileNumber, string controller)
    {
        string prefabPath = "Prefabs/";

        switch (type)
        {
        case unitType.bowman:
            prefabPath += "bowman";
            break;

        case unitType.horseman:
            prefabPath += "horseman";
            break;

        case unitType.infantryman:
            prefabPath += "infantryman";
            break;

        default: prefabPath = "";
            break;
        }

        if (prefabPath == "")
        {
            return;
        }

        if (controller == "redPlayer")
        {
            prefabPath += "_red";
        }
        else
        {
            prefabPath += "_blue";
        }

        Tile    targetedTile = Map.instance.FindTile(tileNumber);
        Vector3 position     = new Vector3();

        if (targetedTile.ReturnAvailablePositionForUnit(ref position))
        {
            object[] instanciationData = new object[1];
            instanciationData[0] = targetedTile.ReturnTileNumber();
            GameObject unitObj = Photon.Pun.PhotonNetwork.Instantiate(prefabPath, position, Quaternion.identity, 0, instanciationData);
            unitObj.GetComponent <Unit>().SetTileNumber(tileNumber);
        }
    }
Exemple #13
0
    void loadClasses()
    {
        Classes      = new unitType[10];
        healths      = new int[10];
        armors       = new int[10];
        mins         = new int[10];
        maxs         = new int[10];
        speeds       = new int[10];
        crits        = new int[10];
        classNames   = new string[10];
        spriteSheets = new string[10];
        attackID     = new int[10];
        Debug.Log(Classlist.text);
        string[] data = Classlist.text.Split(new char[] { '\n' });
        for (int i = 1; i < data.Length - 1; i++)
        {
            string[] ClassRow = data[i].Split(new char[] { ',' });
            classNames[i] = ClassRow[1];
            int.TryParse(ClassRow[2], out maxs[i]);
            int.TryParse(ClassRow[3], out mins[i]);
            int.TryParse(ClassRow[4], out crits[i]);
            int.TryParse(ClassRow[5], out healths[i]);
            int.TryParse(ClassRow[6], out armors[i]);
            spriteSheets[i] = ClassRow[7];
            int.TryParse(ClassRow[8], out attackID[i]);
            attacks = new attack[4];
            string[] attackRow = AttackSheet.text.Split(new char[] { '\n' });
            for (int p = 0; p < 4; p++)
            {
                string[] attackData = attackRow[p + 2 + 5 * attackID[i]].Split(new char[] { ',' });

                validTargets = new int[4];
                string attackName = attackData[1];
                int.TryParse(attackData[2], out type);
                int.TryParse(attackData[3], out damageMod);
                int.TryParse(attackData[4], out accuracy);
                int.TryParse(attackData[5], out stun);
                for (int o = 0; o < 4; o++)
                {
                    int.TryParse(attackData[6 + o], out validTargets[o]);
                }
                attacks[p] = new attack(attackName, type, damageMod, accuracy, stun, validTargets[0], validTargets[1], validTargets[2], validTargets[3]);
            }
            Classes[i - 1] = new unitType(classNames[i], mins[i], maxs[i], crits[i], healths[i], armors[i], spriteSheets[i], attacks[0], attacks[1], attacks[2], attacks[3]);
        }
    }
Exemple #14
0
 public void init(int owner, int type)
 {
     this.playerOwner = owner;
     this.life        = 10;
     this.wasMoved    = false;
     this.isDead      = false;
     if (type == 1)
     {
         this.currentType = unitType.ARCHER;
     }
     else if (type == 2)
     {
         this.currentType = unitType.KNIGHT;
     }
     else
     {
         this.currentType = unitType.SOLDIER;
     }
 }
Exemple #15
0
    public void getHitBy(CombatUnit attackingUnit)
    {
        unitType type = attackingUnit.currentType;

        if (currentType == unitType.KNIGHT && type == unitType.ARCHER ||
            currentType == unitType.ARCHER && type == unitType.SOLDIER ||
            currentType == unitType.SOLDIER && type == unitType.KNIGHT)
        {
            // extra damage
            this.life -= 4;
        }
        else
        {
            // normal damage
            this.life -= 20;
        }
        if (this.life < 1)
        {
            this.isDead = true;
            transform.Find("cross").gameObject.SetActive(true);
        }
    }
        /// END: Copied from http://cladosnippet.blogspot.com/2012/04/c-get-season-according-to-given-date.html
        public Weather()
        {
            // Position of Alexandria, VA on the map -- should be extensible to any "home" location of the application user
            longitude = 38.8047m; // 38.8047 degrees N (N is positive)
            latitude = -77.0472m; // 77.0472 degrees W (W is negative)
            weatherForecastProductType = productType.timeseries;
            startTime = DateTime.UtcNow; // Weather forecast begins at the current time
            endTime = DateTime.UtcNow.AddDays(1); // Weather forecast ends a day after the current time -- Daily weather forecast
            weatherUnit = unitType.m; // Weather forecast generated in metric (SI) units

            currentSeason = CurrentSeason(startTime);
            forecastParametersType = new weatherParametersType();
            forecastParametersType.maxt = true; // Maximum temperature
            forecastParametersType.mint = true; // Minimum temperature
            forecastParametersType.appt = true; // Apparent temperature
            forecastParametersType.maxrh = true; // Maximum relative humidity
            forecastParametersType.minrh = true; // Minimum relative humidity
            forecastParametersType.pop12 = true; // 12 hour probability of precipitation
            if (Equals(currentSeason, Seasons.Winter)) // Snowfall is almost certainly zero unless the query is made in the winter
            {
                forecastParametersType.snow = true; // Snowfall amount
            }
            forecastParametersType.wspd = true; // Wind speed
            forecastParametersType.wdir = true; // Wind direction

            weatherDictionary = new Dictionary<string, double>();
            weatherDictionary.Add("Maximum Temperature", 0.0);
            weatherDictionary.Add("Minimum Temperature", 0.0);
            weatherDictionary.Add("Apparent Temperature", 0.0);
            weatherDictionary.Add("12 Hour Probability of Precipitation", 0.0);
            weatherDictionary.Add("Wind Speed", 0.0);
            weatherDictionary.Add("Wind Direction", 0.0);
            weatherDictionary.Add("Maximum Relative Humidity", 0.0);
            weatherDictionary.Add("Minimum Relative Humidity", 0.0);
            weatherDictionary.Add("Snowfall Amount", 0.0); // Need to fix this for winter... will not work
        }
 public ScaleBar()
 {
     this.sizeField = new sizeType();
     this.outlineColorField = new rgbColorType();
     this.labelField = new Label();
     this.imageColorField = new rgbColorType();
     this.colorField = new rgbColorType();
     this.backgroundColorField = new rgbColorType();
     this.intervalsField = "4";
     this.positionField = positionEnum.LR;
     this.postLabelCacheField = booleanEnum.FALSE;
     this.unitsField = unitType.MILES;
     this.statusField = "OFF";
 }
Exemple #18
0
 public static UnitAttribute getAtribute(unitType t)
 {
     return((UnitAttribute)Attribute.GetCustomAttribute(
                typeof(unitType).GetField(Enum.GetName(typeof(unitType), t)),
                typeof(UnitAttribute)));
 }
Exemple #19
0
        //In: type of unit to be created, owner of created unit
        //Out: unit of specified details
        public Unit(unitType type, Player p)
        {
            hp    = 100;
            owner = p;
            t     = type;
            moved = true;
            acted = true;

            //switch to set stats based on given type
            switch (type)
            {
            //infantry
            case unitType.trooper:
                cost            = 100;
                movementSpeed   = 2;
                armor           = 0.3;
                armorT          = armorType.infantry;
                moveT           = moveType.foot;
                primaryAttack   = new Attack(Attack.Name.rifle);        //assault rifle
                secondaryAttack = new Attack(Attack.Name.flameThrower); //flame thrower
                break;

            case unitType.demolitionSquad:
                cost            = 200;
                movementSpeed   = 1;
                armor           = 0.35;
                armorT          = armorType.infantry;
                moveT           = moveType.foot;
                primaryAttack   = new Attack(Attack.Name.mortar);   //mortar
                secondaryAttack = new Attack(Attack.Name.bazooka);  //bazooka
                break;

            case unitType.samTrooper:
                cost            = 200;
                movementSpeed   = 1;
                armor           = 0.3;
                armorT          = armorType.infantry;
                moveT           = moveType.foot;
                primaryAttack   = new Attack(Attack.Name.samLauncher); //sam launcher
                secondaryAttack = new Attack(Attack.Name.rifle);       //rifle
                break;

            //Vehicles
            case unitType.halftrack:
                cost            = 400;
                movementSpeed   = 9;
                armor           = 0.4;
                armorT          = armorType.armor;
                moveT           = moveType.tread;
                primaryAttack   = new Attack(Attack.Name.hmg);     //Heavy Machine Gun
                secondaryAttack = new Attack(Attack.Name.hitNRun); //Hit and Run - no counter attack
                break;

            case unitType.flameTank:
                cost            = 500;
                movementSpeed   = 7;
                armor           = 0.45;
                armorT          = armorType.armor;
                moveT           = moveType.tread;
                primaryAttack   = new Attack(Attack.Name.flameThrower);   //flame launcher
                secondaryAttack = new Attack(Attack.Name.lightCannon);    //light cannon
                break;

            case unitType.heavyTank:
                cost            = 700;
                movementSpeed   = 6;
                armor           = 0.5;
                armorT          = armorType.armor;
                moveT           = moveType.tread;
                primaryAttack   = new Attack(Attack.Name.heavyCannon); //heavy cannon
                secondaryAttack = new Attack(Attack.Name.lmg);         //lmg
                break;

            case unitType.flakCannon:
                cost            = 600;
                movementSpeed   = 7;
                armor           = 0.4;
                armorT          = armorType.armor;
                moveT           = moveType.tread;
                primaryAttack   = new Attack(Attack.Name.flakCannon); //flak cannon
                secondaryAttack = new Attack(Attack.Name.lmg);        //lmg
                break;

            case unitType.artillery:
                cost            = 700;
                movementSpeed   = 6;
                armor           = 0.4;
                armorT          = armorType.armor;
                moveT           = moveType.tread;
                primaryAttack   = new Attack(Attack.Name.bombardment); //bombardment - AoE
                secondaryAttack = new Attack(Attack.Name.lmg);         //lmg
                break;

            //aircraft
            case unitType.helicopter:
                cost            = 700;
                movementSpeed   = 8;
                armor           = 0.4;
                armorT          = armorType.air;
                moveT           = moveType.air;
                primaryAttack   = new Attack(Attack.Name.RocketPods);  //Rocket Pods
                secondaryAttack = new Attack(Attack.Name.Minigun);     //minigun
                break;

            //demons
            case unitType.imp:
                cost            = 100;
                movementSpeed   = 7;
                armor           = 0.3;
                armorT          = armorType.demon;
                moveT           = moveType.foot;
                primaryAttack   = new Attack(Attack.Name.fireball);  //fireball
                secondaryAttack = new Attack(Attack.Name.claws);     //claws
                break;

            case unitType.harpy:
                cost            = 100;
                movementSpeed   = 7;
                armor           = 0.3;
                armorT          = armorType.air;
                moveT           = moveType.air;
                primaryAttack   = new Attack(Attack.Name.claws);   //claws
                secondaryAttack = new Attack(Attack.Name.skyDive); //sky dive - no counter attack
                break;

            case unitType.behemoth:
                cost            = 100;
                movementSpeed   = 6;
                armor           = 0.6;
                armorT          = armorType.demon;
                moveT           = moveType.foot;
                primaryAttack   = new Attack(Attack.Name.demonBlade);   //Demonic Blade
                secondaryAttack = new Attack(Attack.Name.darkPulse);    //Dark Pulse - AoE centered on unit
                break;

            case unitType.hellCannon:
                cost            = 100;
                movementSpeed   = 5;
                armor           = 0.4;
                armorT          = armorType.demon;
                moveT           = moveType.foot;
                primaryAttack   = new Attack(Attack.Name.siegeCannon);   //siege cannon - AoE
                secondaryAttack = new Attack(Attack.Name.exhaustVent);   //exhaust vent
                break;
            }

            movementPoints = movementSpeed;
        }
Exemple #20
0
 private void PumpThread(double diameter, unitType units, runMode mode, double volume, double rate)
 {
     switch (m_pump)
     {
         case pumpType.CHEMYX_FUSION:
             string cmd = "hexw2 " + ((int)units).ToString() + " " +
                                 ((int)mode).ToString() + " " +
                                 diameter.ToString("0.00000") + " " +
                                 volume.ToString("0.00000") + " " +
                                 rate.ToString("0.00000") + " 0 start\r\n";
             m_serialport.Write(cmd);
             Thread.Sleep(200);
             break;
         case pumpType.HARVARD_2000:
             m_serialport.ReadExisting();
             /*
             if (volume != m_volume)
             {
                 m_serialport.Write("TGT " + (volume / 1000.0).ToString("0.0000") + "\r");
                 m_serialport.ReadChar();
                 m_serialport.ReadExisting();
             }
             if (mode != m_mode)
             {
                 if (mode == runMode.REFILL) m_serialport.Write("DIR REF\r");
                 else m_serialport.Write("DIR INF\r");
                 m_serialport.ReadChar();
                 m_serialport.ReadExisting();
             }
             if (rate != m_rate)
             {
                 if (mode == runMode.REFILL) m_serialport.Write("RFR " + rate.ToString("0.0000") + " UM\r");
                 else m_serialport.Write("RAT " + rate.ToString("0.0000") + " UM\r");
                 m_serialport.ReadChar();
                 m_serialport.ReadExisting();
             }
              */
             m_serialport.Write("RUN\r");
             Thread.Sleep(200);
             break;
     }
 }
Exemple #21
0
    public void Init(unitType unitType, player owner, GameObject sector, Transform fightCanvas, GameObject gameMap) //used to initilize values of units
    {
        this.unitType = unitType;                                                                                   //set unit's unitType

        this.fightCanvas = fightCanvas;                                                                             //set a reference to the "fightCanvas" canvas Transform
        this.gameMap     = gameMap;                                                                                 //set a reference to the "gameMap" GameObject

        this.moveUnit(sector);                                                                                      //move this unit into the specified starting sector

        switch (unitType.ToString())                                                                                //set unit statistics depending on the unitType
        {
        case "basic":                                                                                               // Basic but cheap unit.
            this.maxHP    = 10;
            this.attack   = 4;
            this.defence  = 0;
            this.accuracy = 0.5;
            this.critical = 1.5;
            this.speed    = 1;
            break;

        case "dgirl":     // Accurate with some defence.
            this.maxHP    = 20;
            this.attack   = 4;
            this.defence  = 0;
            this.accuracy = 0.5;
            this.critical = 1.5;
            this.speed    = 1;
            break;

        case "jock":     // Strong but stupid.
            this.maxHP    = 25;
            this.attack   = 5;
            this.accuracy = 0.25;
            this.defence  = 0;
            this.critical = 1.75;
            this.speed    = 1;
            break;

        case "sonic":     // Fast unit.
            this.maxHP    = 20;
            this.attack   = 4;
            this.accuracy = 0.5;
            this.critical = 1.75;
            this.defence  = 0;
            this.speed    = 2;
            break;

        case "old":
            this.maxHP    = 20;
            this.attack   = 4;
            this.accuracy = 0.5;
            this.critical = 1.5;
            this.defence  = 1;
            this.speed    = 1;
            break;
        }

        this.currentSpeed = this.speed;                                         //at instantiation currentSpeed is set to speed

        this.owner = owner;                                                     //set unit's owner
        this.curHP = maxHP;                                                     //at instantiation set current health points to maximum health points
        this.gameObject.transform.SetParent(sector.gameObject.transform);       //set this unit's parent to the sector it is placed in

        this.gameObject.GetComponent <SpriteRenderer>().sprite = this.mapImage; //select appropriate sprite.

        this.gameObject.AddComponent <PolygonCollider2D>();                     //add a PolygonCollider2D to the unit, so that the unit can be clicked

        //this.gameObject.AddComponent<SpriteGlow.SpriteGlow>(); //add a SpriteGlow script to the unit, so that a border can be drawn around the unit when selected
        //this.gameObject.GetComponent<SpriteGlow.SpriteGlow>().OutlineWidth = 0; //do not draw border around unit when it is created
        //this.gameObject.GetComponent<SpriteGlow.SpriteGlow>().GlowBrightness = 5; //SpriteGlow settings used to ensure borders can be drawn correctly
        //this.gameObject.GetComponent<SpriteGlow.SpriteGlow>().AlphaThreshold = 0.5f; //SpriteGlow settings used to assure borders can be drawn correctly
    }
Exemple #22
0
 public void RunWithSettings(double diameter, unitType units, runMode mode, double volume, double rate)
 {
     Thread t = new Thread(delegate() { PumpThread(diameter, units, mode, volume, rate); });
     t.Start();
 }
Exemple #23
0
 public bool CheckType(unitType check)
 {
     myType [check];
 }
Exemple #24
0
    // Use this for initialization
    void Start()
    {
        float      x_start, y_start;
        orc_stats  newOrc;
        GameObject go1, temp;
        int        numOrcs, numArchers, i;
        float      spawnIntervalX;
        float      spawnIntervalY;
        Vector3    spawnPoint, actualSpawn;

        unitType[] armyArray = new unitType[MAX_UNITS];

        if (gameObject.tag == "brown")
        {
            // top team
            x_start        = X_START_TOP;
            y_start        = Y_START_TOP;
            spawnIntervalX = 0.14f;
            spawnIntervalY = -0.3f;
            spawnPoint     = new Vector3(x_start, y_start, 0);

            go1 = GameObject.Find("brown team");
        }
        else
        {
            // bottom team
            x_start        = X_START_BOTTOM;
            y_start        = Y_START_BOTTOM;
            spawnIntervalX = -0.14f;
            spawnIntervalY = 0.3f;
            spawnPoint     = new Vector3(x_start, y_start, 0);

            go1 = GameObject.Find("red team");
        }

        myTeam     = (orcTeam)go1.GetComponent(typeof(orcTeam));
        numOrcs    = myTeam.get_numOrcs();
        numArchers = myTeam.get_numArchers();

        dynamic_row_setup(armyArray, numOrcs, numArchers);

        // set these here in case row setup fudged the numbers
        numAlive = numOrcs + numArchers;
        updateNumAlive();

        for (i = 0; i < MAX_UNITS; i++, spawnPoint.x += spawnIntervalX)
        {
            if ((i % ROW_SIZE) == 0)
            {
                spawnPoint.y += spawnIntervalY;
                spawnPoint.x  = x_start;
            }

            if (armyArray[i] == unitType.none)
            {
                continue;
            }

            // add a small bit of randomness to the x position so the armies look more
            // natural as they charge at each other
            x_rand_pos     = Random.Range(-1.0f * X_RAND, X_RAND);
            actualSpawn    = spawnPoint;
            actualSpawn.x += x_rand_pos;

            if (armyArray[i] == unitType.archer)
            {
                temp = Instantiate(archerObj, actualSpawn, Quaternion.identity) as GameObject;
            }
            else
            {
                temp = Instantiate(orcObj, actualSpawn, Quaternion.identity) as GameObject;
            }

            newOrc          = temp.GetComponent <orc_stats>();
            newOrc.teamName = gameObject.tag;
            if (gameObject.tag == "brown")
            {
                newOrc.enemyTeam = "red";
            }
            else
            {
                newOrc.enemyTeam = "brown";
            }
        }
    }
Exemple #25
0
        /// <summary>
        /// Event called when some key is typed in textBoxEntrada.
        /// Also called by pasteClipBoard, to force refresh.
        /// Verifies the data in textBoxEntrada, call calculate to calculate the
        /// the result and print it on textBoxCalcOut.
        /// The ASCII translation is shown in the textBoxAscOut depending on the text entered.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void refreshOut(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 27)
            {
                textBoxEntrada.Text = "";
                textBoxCalcOut.Text = "";
                textBoxAscOut.Text = "";
                textBoxLabelOut.Text = "";
                useUnits(false);
            }
            else if (e.KeyValue == 189 && e.Modifiers == Keys.Shift)
            {
                textBoxEntrada.Text = textBoxEntrada.Text.Replace('_', '\n');
                useUnits(true);
            }
            else if (e.KeyValue >= 37 && e.KeyValue <= 40)
            {

            }
            else if (e.KeyValue == 84 && e.Modifiers == Keys.Control)
            {
                // Ctrl+T: enable or disable "Always on top"
                // Remembering that it only works while typing in the textBoxEntrada
                checkBoxAlwaysOnTop.Checked = !checkBoxAlwaysOnTop.Checked;
            }
            else if (e.KeyValue == 112)
            {
                // F1: open the About message.
                about();
            }
            else
            {
                try
                {
                    string textIn;
                    textIn = textBoxEntrada.Text;

                    double result;

                    if (!this.unit)
                        result = calculate(textIn);
                    else
                    {
                        this.unitIn = getUnitValue(textBoxUnitIn.Text);
                        this.unitOut = getUnitValue(textBoxUnitOut.Text);

                        if (unitIn.type == unitOut.type)
                            result = calculate(textIn) * unitIn.value / unitOut.value;
                        else if (unitIn.type * unitOut.type == 0)
                            result = calculate(textIn);
                        else
                            result = calculate("");
                    }

                    textBoxCalcOut.Text = Convert.ToString(result);
                }
                catch
                {
                    textBoxCalcOut.Text = "";
                }

                try
                {
                    ascOut = "";
                    entrAux = textBoxEntrada.Text;
                    int intChar;
                    if (entrAux != "")
                    {
                        chr = entrAux.Substring(0, 1).ToUpper().ToCharArray()[0];

                        // Checks if there are only numbers. If there are, calculates
                        // the ASCII^-1. Otherwise, calculates ASCII.

                        onlyNumbers = true;
                        for (int i = 0; i <= entrAux.Trim().Length - 1; i++)
                        {
                            chr = entrAux.Trim().Substring(i, 1).ToCharArray()[0];
                            if (chr < 48 || chr > 57) onlyNumbers = false;
                        }

                        if (onlyNumbers)
                        {
                            entrAux = entrAux.Trim();
                            if (entrAux.Length > 8) entrAux = entrAux.Substring(0, 8);
                            for (int i = 0; i <= entrAux.Length - 1; i++)
                            {
                                if (i % 2 == 0 && i + 1 <= entrAux.Length - 1)
                                {
                                    intChar = (entrAux.Substring(i, 1).ToCharArray()[0] - 48) * 10 +
                                              (entrAux.Substring(i + 1, 1).ToCharArray()[0] - 48);
                                    ascOut = ascOut + (char)intChar;
                                }
                            }
                            textBoxAscOut.Text = ascOut;
                            textBoxLabelOut.Text = "ASCII^-1 =";
                        }
                        else
                        {
                            if (entrAux.Length > 4) entrAux = entrAux.Substring(0, 4);
                            ascOut = "";
                            for (int i = 0; i <= entrAux.Length - 1; i++)
                            {
                                chr = entrAux.Substring(i, 1).ToUpper().ToCharArray()[0];
                                intChar = chr;
                                if (intChar > 32)
                                    ascOut = ascOut + intChar.ToString();
                            }
                            textBoxAscOut.Text = ascOut;
                            textBoxLabelOut.Text = "ASCII =";
                        }
                    }
                    else
                    {
                        textBoxAscOut.Text = "";
                        textBoxLabelOut.Text = "";
                    }
                }
                catch
                {
                    textBoxAscOut.Text = "";
                    textBoxLabelOut.Text = "";
                }

            }
        }
Exemple #26
0
        /// <summary>
        /// Receives a string, for example "kPa" and returns a struct with the value and
        /// type of the unit.
        /// All SI units have value 1.
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        private unitType getUnitValue(string str)
        {
            unitType u = new unitType();
            u.value = 1;
            u.type = 0;
            switch(str)
            {
                case "": u.value = 1; u.type = 0; break;

                case "m":  u.value = 1; u.type = 1; break;
                case "cm": u.value = 0.01; u.type = 1; break;
                case "mm": u.value = 0.001; u.type = 1; break;
                case "km": u.value = 1000; u.type = 1; break;
                case "ft": u.value = 0.3048; u.type = 1; break;
                case "in": u.value = 0.0254; u.type = 1; break;

                case "m3": u.value = 1; u.type = 2; break;
                case "ft3": u.value = 0.028316846592; u.type = 2; break;
                case "dm3":
                case "L": u.value = 0.001; u.type = 2; break;
                case "cm3":
                case "mL": u.value = 0.000001; u.type = 2; break;

                case "kg": u.value = 1; u.type = 3; break;
                case "g": u.value = 0.001; u.type = 3; break;
                case "mg": u.value = 0.000001; u.type = 3; break;
                case "lb": u.value = 0.4536; u.type = 3; break;

                case "s": u.value = 1; u.type = 4; break;
                case "min": u.value = 60; u.type = 4; break;
                case "h": u.value = 3600; u.type = 4; break;
                case "d": u.value = 86400; u.type = 4; break;

                case "Pa": u.value = 1; u.type = 5; break;
                case "kPa": u.value = 1e3; u.type = 5; break;
                case "MPa": u.value = 1e6; u.type = 5; break;
                case "bar": u.value = 1e5; u.type = 5; break;
                case "kgf/cm2": u.value = 98066.5; u.type = 5; break;
                case "atm": u.value = 101325; u.type = 5; break;
                case "mmHg": u.value = 133.3224; u.type = 5; break;
                case "psi": u.value = 6894.757; u.type = 5; break;

                case "K": u.value = 1; u.type = 6; break;
                case "°R": u.value = 1.0/1.8; u.type = 6; break;

                case "J": u.value = 1; u.type = 7; break;
                case "kJ": u.value = 1000; u.type = 7; break;
                case "cal": u.value = 4.1858; u.type = 7; break;
                case "kcal": u.value = 4185.8; u.type = 7; break;
                case "Btu": u.value = 1055.87; u.type = 7; break;

                case "kg/s": u.value = 1; u.type = 8; break;
                case "g/s": u.value = 0.001; u.type = 8; break;
                case "kg/h": u.value = 1.0/3600; u.type = 8; break;
                case "kg/d": u.value = 1.0/86400; u.type = 8; break;
                case "t/h": u.value = 1000.0/3600; u.type = 8; break;
                case "t/d": u.value = 1000.0/86400; u.type = 8; break;

                default: u.value=1; u.type=999; break;
            }
            return u;
        }