Esempio n. 1
0
 public void StartGame()
 {
     curPlayerIndex = 0;
     CurPlayer      = Players[curPlayerIndex];
     PieceController.UpdateMoves(CurPlayer);
     CurPlayer.TakeTurn();
 }
Esempio n. 2
0
        public override double Value()
        {
            double total = 1;

            if (Coord.Distance(Target, Oponent.GetCultCenter().Position) <
                Coord.Distance(AllyPos, Oponent.GetCultCenter().Position))
            {
                total += 2 * (1 + 1.0 / Coord.Distance(AllyPos, Oponent.GetCultCenter().Position));
            }

            ETerrain terrainAtTarget = Boards.TerrainAt(Target);

            foreach (ETerrain terrain in CurPlayer.GetPawnAt(AllyPos).PositiveTerrains)
            {
                if (terrainAtTarget == terrain)
                {
                    total += 1;
                    break;
                }
            }

            foreach (ABasicPawn enemy in Oponent.GetAttackers())
            {
                if (Coord.Distance(enemy.Position, CurPlayer.GetCultCenter().Position) < BoardConsts.MAX_COL / 2 &&
                    Coord.Distance(Target, enemy.Position) < Coord.Distance(AllyPos, enemy.Position))
                {
                    total += 3.0 * (1 + 1.0 / Coord.Distance(AllyPos, enemy.Position));
                }
            }

            return(total);
        }
Esempio n. 3
0
        public void Update()
        {
            Move move = CurPlayer.GetMove(GetValidMoves());

            if (IsValidMove(move))
            {
                MakeMove(move);
                UpdateView();
                CurPlayer = NextPlayer();

                if (CheckWin())
                {
                    CurPlayer = NextPlayer();
                    MessageBox.Show("Player:" + CurPlayer.PiecesColor + " wins!");
                    ResetGame();
                }
                else
                {
                    PieceController.UpdateMoves(CurPlayer);
                    CurPlayer.TakeTurn();
                }
            }
            else
            {
                MessageBox.Show("Invalid move!");
                ViewController.ClearSquares();
            }
        }
Esempio n. 4
0
        public override bool Execute(bool isSimualtion = false)
        {
            bool valid = false;

            if (Validate())
            {
                APawn        allyPawn  = CurPlayer.GetPawnAt(AllyPos);
                Dijkstra     didi      = new Dijkstra(Boards.GetBoard(), AllyPos, allyPawn.MovePoints);
                List <Coord> moveRange = didi.GetValidPaths(Command.MOVE);
                if (moveRange.Contains(Target))
                {
                    valid = true;
                    allyPawn.Erase(Boards);
                    allyPawn.Position = Target;
                    allyPawn.Place(Boards);
                    allyPawn.Adapt(Boards.TerrainAt(AllyPos), Boards.TerrainAt(Target));
                }
                else
                {
                    ErrorMsg = OUT_OF_RANGE;
                }
            }
            if (!ErrorMsg.Equals("") && !isSimualtion)
            {
                UserUtils.PrintError(ErrorMsg);
                Console.ReadLine();
            }

            return(valid);
        }
Esempio n. 5
0
        protected override bool Validate()
        {
            bool valid = true;

            if (!Coord.IsValid(AllyPos) || !Coord.IsValid(Target))
            {
                ErrorMsg = INVALID_POS;
                valid    = false;
            }
            else if (CurPlayer == null)
            {
                ErrorMsg = PLAYER;
                valid    = false;
            }
            else if (CurPlayer.GetPawnAt(AllyPos) == null)
            {
                ErrorMsg = NO_PAWN;
                valid    = false;
            }
            else if (!Boards.CellAt(Target).Equals(BoardConsts.EMPTY))
            {
                ErrorMsg = OCCUPIED_CELL;
                valid    = false;
            }
            return(valid);
        }
Esempio n. 6
0
 protected override void Draw(GameTime gameTime)
 {
     //Begin and End indicate when the sprite batch should start gather Textures and positions to be drawn to screen and when to push all the infomation it has to the screen
     spriteBatch.Begin();
     GraphicsDevice.Clear(Color.CornflowerBlue);
     foreach (Player CurPlayer in PlayerList)
     {
         CurPlayer.Draw(spriteBatch);
     }
     base.Draw(gameTime);
     spriteBatch.End();
 }
Esempio n. 7
0
        public override bool IsValid()
        {
            bool valid = Validate();

            if (valid)
            {
                ABasicPawn   allyPawn = (ABasicPawn)CurPlayer.GetPawnAt(AllyPos);
                Dijkstra     didi     = new Dijkstra(Boards.GetBoard(), AllyPos, allyPawn.AtkRange);
                List <Coord> atkRange = didi.GetValidPaths(Command.ATTACK);
                valid = PosValidate(atkRange);
            }
            return(valid);
        }
Esempio n. 8
0
        protected override bool Validate()
        {
            bool valid = true;

            if (!Coord.IsValid(AllyPos) || !Coord.IsValid(Target))
            {
                ErrorMsg = INVALID_POS;
                valid    = false;
            }
            else if (Oponent == null)
            {
                ErrorMsg = NO_OPONENT;
                valid    = false;
            }
            else if (CurPlayer == null)
            {
                ErrorMsg = PLAYER;
                valid    = false;
            }
            else if (Boards == null)
            {
                ErrorMsg = NO_BOARDS;
                valid    = false;
            }
            else
            {
                APawn allyPawn = CurPlayer.GetPawnAt(AllyPos);
                if (allyPawn is ABasicPawn)
                {
                    ABasicPawn allyAttackerPawn = CurPlayer.GetPawnAt(AllyPos) as ABasicPawn;
                    if (allyPawn == null)
                    {
                        ErrorMsg = NO_PAWN;
                        valid    = false;
                    }
                    else if (Oponent.GetUnitAt(Target) == null)
                    {
                        ErrorMsg = NO_PAWN;
                        valid    = false;
                    }
                }
                else
                {
                    valid = false;
                }
            }
            return(valid);
        }
Esempio n. 9
0
    public void init(JsonObject opts, MapData mapdata)
    {
        Debug.Log("<color=#00ff00> >>>>>>>>>>>>>>>>>>>> Area Init Start >>>>>>>>>>>>>>>>>>>>></color>");
        //根据设备分辨率,修改对应的aoi范围
        initColorBox();
        //创建背景地图
        map = new Map(mapdata, this.scene, Vector2.zero);
        Debug.Log("<color=#00ff00> [[[ Map Init end ]]]</color>");
        //添加当前玩家
        addEntity(DataManager.Inst.playerdata);
        //添加其他对象:玩家,npc,mob
        //Debug.Log("add other entities:"+opts["entities"].ToString());
        JsonObject entities = (JsonObject)opts["entities"];

        addOtherEntity(entities);

        //设置坐标
        var pos = this.getCurPlayer().getSprite().getPosition();

        this.map.centerTo(pos);
        //重新修正AOI灯塔范围
        var        width  = Utils.ScreenWidth;
        var        height = Utils.ScreenHeight;
        JsonObject msg    = new JsonObject();

        msg["width"]  = width;
        msg["height"] = height;

        //根据屏幕的大小,重新修改角色的可视范围大小
        //PomeloSocket.Inst.Notify("area.playerHandler.changeView", msg);
        PomeloSocket.Inst.Request("area.playerHandler.changeView", msg, (_data) =>
        {
            Debug.LogFormat("<color=#00ff00> >>>> screewidth: {0},screenheight: {1},changeViewData: {2} <<<< </color>", Utils.ScreenWidth, Utils.ScreenHeight, _data);
            if (_data.ContainsKey("range"))
            {
                DataManager.Inst.playerdata.range = Convert.ToInt32(_data["range"]);
                CurPlayer e = (CurPlayer)this.getCurPlayer();
                e.range     = DataManager.Inst.playerdata.range;
            }
        });
        //添加当前玩家点击移动组件
        this.componentAdder.addComponent();

        Debug.Log("<color=#00ff00><<<<<<<<<<<<<<<<<<<< Area Init End  <<<<<<<<<<<<<<<<<<<< </color>");
    }
Esempio n. 10
0
        public override string ToString()
        {
            string msg  = base.ToString();
            string cult = "";

            if (CurPlayer.GetCulture() == ECultures.DALRIONS)
            {
                cult = "D";
            }
            else
            {
                cult = "R";
            }
            msg += String.Format("Culture: {0}\n", cult);
            msg += String.Format("Ally: {0}\n", AllyPos);
            msg += "Move: ATK\n";
            return(msg);
        }
Esempio n. 11
0
        //Update and Draw are called once every tick up to 60Hz (60 times per second)
        protected override void Update(GameTime gameTime)
        {
            //The Keyboard is the input and output device the state is which keys are pressed at any given time.
            CurKeyState = Keyboard.GetState();
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            else
            {
                foreach (Player CurPlayer in PlayerList)
                {
                    CurPlayer.Update(CurKeyState);
                }
            }

            base.Update(gameTime);
        }
Esempio n. 12
0
        public override double Value()
        {
            double total = 10;

            if (Oponent.GetUnitAt(Target) is CulturalCenter)
            {
                total += 1.0;
            }
            double remainingHealth = Oponent.GetUnitAt(Target).CurrLife / Oponent.GetUnitAt(Target).TotalLife;

            if (remainingHealth < 0.5)
            {
                total += 3.0;
            }
            if (Coord.Distance(Target, CurPlayer.GetCultCenter().Position) < BoardConsts.MAX_COL / 2)
            {
                total += 1 + 100 / Coord.Distance(Target, CurPlayer.GetCultCenter().Position);
            }
            return(total);
        }
Esempio n. 13
0
        public override bool Execute(bool isSimulation = false)
        {
            bool valid = false;

            if (Validate())
            {
                ABasicPawn   allyPawn = (ABasicPawn)CurPlayer.GetPawnAt(AllyPos);
                Dijkstra     didi     = new Dijkstra(Boards.GetBoard(), AllyPos, allyPawn.AtkRange);
                List <Coord> atkRange = didi.GetValidPaths(Command.ATTACK);
                if (PosValidate(atkRange))
                {
                    valid = true;
                    Unit enemyUnit = Oponent.GetUnitAt(Target);
                    int  damage    = allyPawn.Atk - enemyUnit.Def;
                    if (damage > 0)
                    {
                        HitMsg             = String.Format("{0} HAVE DEALT {1} DAMAGE!", allyPawn.Culture, damage);
                        enemyUnit.CurrLife = enemyUnit.CurrLife - damage;
                        if (enemyUnit.CurrLife <= 0)
                        {
                            Oponent.RemoveUnitAt(Target, Boards);
                            HitMsg += " ENEMY KILLED!!";
                        }
                    }
                    else
                    {
                        HitMsg = BLOCK;
                    }
                }
            }
            //if (!isSimulation) {
            //    UserUtils.PrintSucess((valid) ? (HitMsg) : (ErrorMsg));
            //    Console.ReadLine();
            //}
            return(valid);
        }
Esempio n. 14
0
    public bool addEntity(EntityData entity)
    {
        if (entity == null || entity.entityId <= 0)
        {
            return(false);
        }
        Entity e = null;

        switch (entity.type)
        {
        case "player":
        {
            Debug.Log("add id:" + entity.id + ",curplayer id:" + DataManager.Inst.pomelodata.playerId);
            if (entity.id == DataManager.Inst.pomelodata.playerId)        //当前玩家
            {
                var player = DataManager.Inst.playerdata;
                e = new CurPlayer(player, this.scene, map) as CurPlayer;
                this.players.Add(player.id, e.entityId);
            }
            else
            {         //其它玩家
                var entitydata = (PlayerData)entity;
                e = new Player(entitydata, this.scene, map);
                Debug.Log("AddEntity ~ playerId :" + entitydata.id + ", teamId =" + entitydata.teamId);
                if (!this.players.ContainsKey(entity.id))
                {
                    this.players.Add(entity.id, e.entityId);
                }
            }

            break;
        }

        case "npc":
        {
            e = new Npc(entity, this.scene, map);
            break;
        }

        case "mob":
        {
            var entitydata = (PlayerData)entity;
            e = new Mob(entitydata, this.scene, map);
            break;
        }

        case "item":
        {
            var entitydata = (ItemData)entity;
            e = new Item(entitydata, this.scene, map);
            break;
        }

        case "equipment":
        {
            break;
        }

        default: return(false);
        }

        var eNode = e.getSprite().curNode.transform;

        if (eNode.parent == null)
        {
            Debug.Log("this entity curNode de father is null");
            eNode.parent = this.map.node.transform;
        }
        if (!this.entities.ContainsKey(entity.entityId))
        {
            this.entities.Add(entity.entityId, e);
        }
        this.componentAdder.addComponentTo(e);

        return(true);
    }