示例#1
0
        public override void NextTurn()
        {
            MapObject o = Game.game.Map[x, y, 2];

            if (o != null && o is Unit)
            {
                Unit u = o as Unit;
                if (u.owner != owner)
                {
                    Game.game.Map[x, y, z] = null;
                    u.owner.resources     += 4;
                    if (u.owner == Game.game.players[0])
                    {
                        Achievement.recruitTentsDestroyed++;
                        Achievement.Check();
                    }
                }
                else
                {
                    u.hp++;
                    if (u.hp > u.maxhp)
                    {
                        u.hp = u.maxhp;
                    }
                }
            }
        }
示例#2
0
        public bool Rebuild()
        {
            if (canRebuild())
            {
                owner = cityOwner.owner;
                cityOwner.owner.resources -= cost;
                ready              = true;
                texture            = readyTexture;
                cityOwner.Currpop += firstTurn_productionBoost;

                if (destroyAfterDone)
                {
                    Game.game.Map[x, y, 1] = null;
                }

                if (owner == Game.game.players[0])
                {
                    Achievement.resourcesRebuilt++;
                    Achievement.Check();
                }

                return(true);
            }
            return(false);
        }
示例#3
0
 public void OnPlayerTurnBegin(Player player)
 {
     if (state == States.InProgress)
     {
         turnsRemaining--;
         if (turnsRemaining <= 0)
         {
             state = States.Researched;
             player.currentlyResearching = null;
             App.Announce($"{name} research completed! Go to research tab and choose another research.");
             if (player == Game.game.players[0])
             {
                 if (name == rssrch[(int)researches.Ironsmithing].name)
                 {
                     Achievement.achievements[(int)Achievement.eAchievs.Ironman].isSpecial = false;
                 }
                 if (name == rssrch[(int)researches.Gunpowder].name)
                 {
                     Achievement.achievements[(int)Achievement.eAchievs.PowerOfGunpowder].isSpecial = false;
                 }
                 Achievement.researchesResearched++;
                 Achievement.Check();
             }
         }
     }
 }
示例#4
0
文件: City.cs 项目: SoptikHa2/kingdom
        public bool Capture()
        {
            if (CanCapture())
            {
                owner = (Game.game.Map[x, y, 2] as Unit).owner;

                switch (owner.color)
                {
                case 0:
                    texture = App.Textures.city_blue;
                    break;

                case 1:
                    texture = App.Textures.city_red;
                    break;

                case 2:
                    texture = App.Textures.city_green;
                    break;

                case 3:
                    texture = App.Textures.city_yellow;
                    break;
                }

                readyToCapture = false;
                (Game.game.Map[x, y, 2] as Unit).turns     = 0;
                (Game.game.Map[x, y, 2] as Unit).canAttack = false;

                owner.revealTilesNear(x, y, 4);

                if (App.debug)
                {
                    Bridge.Script.Call("console.log", "A city was captured");
                }

                App.DisplayPlayerInfo();

                if (owner == Game.game.players[0])
                {
                    Achievement.citiesCaptured++;
                    Achievement.Check();
                }

                return(true);
            }
            return(false);
        }
示例#5
0
        public static RecruitTent Build(Player p, int x, int y)
        {
            if (p.resources >= price && (Game.game.Map[x, y, 0] as Terrain).type == (int)Terrain.Types.Land && Game.game.Map[x, y, 1] == null && Game.game.Map[x, y, 2] != null && (Game.game.Map[x, y, 2] as Unit).owner == p)
            {
                p.resources -= price;
                App.Textures t = App.Textures.border;
                switch (p.color)
                {
                case 0:
                    t = App.Textures.city_recruitTent_blue;
                    break;

                case 1:
                    t = App.Textures.city_recruitTent_red;
                    break;

                case 2:
                    t = App.Textures.city_recruitTent_green;
                    break;

                case 3:
                    t = App.Textures.city_recruitTent_yellow;
                    break;
                }

                if (p == Game.game.players[0])
                {
                    Achievement.recruitTentsBuilt++;
                    Achievement.Check();
                }

                return(new RecruitTent(p, t, x, y));
            }

            return(null);
        }
示例#6
0
        public Pong()
        {
            canvas = Document.GetElementById("pong") as HTMLCanvasElement;
            ctx    = canvas.GetContext("2d").As <CanvasRenderingContext2D>();

            gameInfo = Document.GetElementById("gameInfo") as HTMLParagraphElement;

            try
            {
                highscore = ulong.Parse(Window.LocalStorage["highscore"].ToString());
            }
            catch { }

            pong = this;

            canvas.OnClick = (ev) => { if (!ingame)
                                       {
                                           Achievement.achievements[(int)Achievement.eAchievs.Upgrade].isSpecial = false; Achievement.Check(); pWidth = 200; pX = ev.ClientX - 250; ingame = true; score = 0; ball = new Ball {
                                               x = canvas.OffsetWidth / 2, y = canvas.OffsetHeight / 2, vx = new double[] { -0.5, -0.4, -0.3, -0.2, -0.1, 0.1, 0.2, 0.3, 0.4, 0.5 }[new Random().Next(10)], vy = 5
                                           }; ball.Move();
                                       }
            };
            Document.Body.OnMouseMove = (ev) =>
            {
                pX = ev.ClientX - 90 - canvas.OffsetLeft;
                if (pX < 0)
                {
                    pX = 0;
                }
                if (pX + pWidth > canvas.OffsetWidth)
                {
                    pX = canvas.OffsetWidth - pWidth;
                }
            };
            // Mobile devices

            /*
             * canvas.OnTouchMove = (ev) =>
             * {
             *  pX = ev.PageX - 250;
             *  Console.WriteLine(ev.PageX - 250);
             *  if (pX < 0)
             *      pX = 0;
             *  if (pX + pWidth > canvas.OffsetWidth)
             *      pX = canvas.OffsetWidth - pWidth;
             * };*/

            gameInfo.InnerHTML = $"Score: {score}<br />Highscore: {highscore}";
        }
示例#7
0
        public void Attack(Unit target)
        {
            bool debug_attBack = false;
            int  debug_att1    = 0;
            int  debug_att2    = 0;

            if (canAttack && target.owner != owner && (!App.useFog || !(Game.game.Map[target.x, target.y, 0] as Terrain).isFogForPlayers[Game.game.playerState]))
            {
                //App.Anim(x, y, (x + target.x) / 2, (y + target.y) / 2, this, () => { App.Anim((x + target.x) / 2, (y + target.y) / 2, x, y, this, () => { }); });

                canAttack = false;
                if (!ability.HasFlag(Ability.Dash))
                {
                    turns = 0;
                }

                int attackStrength = attack * 2;

                /*if (hp < ((double)maxhp / 100) * 40)
                 *  attackStrength = attack;*/
                attackStrength -= target.defense;

                // If defending unit stands in city with walls, substract another one attack point
                if (Game.game.Map[target.x, target.y, 1] is City && (Game.game.Map[target.x, target.y, 1] as City).buildings[(int)Building.EBuildings.Walls].state == Building.States.Builded)
                {
                    attackStrength--;
                }

                // If attacking unit is in water, substract another attack point
                if ((Game.game.Map[x, y, 0] as Terrain).type == (int)Terrain.Types.Sea)
                {
                    attackStrength--;
                }
                // If defeding unit is in water, add one attack point
                if ((Game.game.Map[target.x, target.y, 0] as Terrain).type == (int)Terrain.Types.Sea)
                {
                    attackStrength++;
                }

                if (attackStrength < 1)
                {
                    attackStrength = 1;
                }

                debug_att1 = attackStrength;

                target.hp -= attackStrength;

                if (target.hp <= 0)
                {
                    target.alive = false;
                    Game.game.Map[target.x, target.y, target.z] = null;
                    if (ability.HasFlag(Ability.Combo))
                    {
                        canAttack = true;
                        turns     = maxturns;
                    }
                    if (owner == Game.game.players[0])
                    {
                        Achievement.enemiesKilled++;
                        Achievement.Check();
                    }
                    else if (target.owner == Game.game.players[0])
                    {
                        Achievement.unitsLost++;
                        Achievement.Check();
                    }
                }
                // If enemy is alive AND (you attack melee OR you both attack ranged), attack back
                else if (!ability.HasFlag(Ability.RangedAttack) || (ability.HasFlag(Ability.RangedAttack) && target.ability.HasFlag(Ability.RangedAttack)))
                {
                    debug_attBack = true;

                    attackStrength = target.attack * 2;

                    /*if (target.hp < ((double)target.maxhp / 100) * 80)
                     *  attackStrength = target.attack;*/
                    attackStrength -= defense;
                    if (attackStrength < 1)
                    {
                        attackStrength = 1;
                    }

                    debug_att2 = attackStrength;

                    hp -= attackStrength;

                    if (hp <= 0)
                    {
                        alive = false;
                        Game.game.Map[x, y, z] = null;
                        if (target.owner == Game.game.players[0])
                        {
                            Achievement.enemiesKilled++;
                            App.KilledInDefense++;
                        }
                        else if (owner == Game.game.players[0])
                        {
                            Achievement.unitsLost++;
                            Achievement.Check();
                        }
                    }
                }
            }

            if (App.debug)
            {
                Bridge.Script.Call("console.log", $"Unit {name} (player: {owner.color}) attacked {target.name} (player: {target.owner.color}). Attack back: {debug_attBack}. Attack 1: {debug_att1}. Attack 2: {debug_att2}");
            }
        }