Example #1
0
    // decide the logic
    //
    void CalculateGameLogic()
    {
        //if(BoardClass == null) return;

        /// first: get all the tile and data nearby (max totally 6 )

            // 1. get the tile i stand now.
            Tile TileStand = BoardClass._game.AllTiles.Single(o => o.X == Piece.Location.X && o.Y == Piece.Location.Y); // get the tile

            // First , find if the Animal Stand on the same place
            GameObject AnimalOnTile = BoardClass._gamePieces_Animals.Find( o => ( (AnimalBehaviour)o.GetComponent("AnimalBehaviour")).Piece.X == TileStand.X  && ( (AnimalBehaviour)o.GetComponent("AnimalBehaviour")).Piece.Y == TileStand.Y );
            // the same place ... Battle !
            if(AnimalOnTile)
            {
                //TileStand.Tile_StandStatus = TILE_STAND_STATUS.TILE_STAND_STATUS_BOTH;
                TileStand.IsBattleField = true;

                    if( UnityEngine.Random.Range( 0 , 2) ==0  )
                        m_bDistroy = true;
                    else
                        ((AnimalBehaviour)AnimalOnTile.GetComponent("AnimalBehaviour")).m_bDistroy = true;

                // stay at the same place
                    m_HumanPiece_Behaviour_Prev = m_HumanPiece_Behaviour ;
                    m_HumanPiece_Behaviour = HUMAN_BEHAVIOUR.HUMAN_BEHAVIOUR_FIGHT;
                    Position_Destination =BoardBehavior.GetWorldCoordinates(TileStand.Location.X, TileStand.Location.Y, 0f);

                    // to decide who win / lose

                    return;
            }

            // or just do normal process
            TileStand.CanPass = true; // release this tile
            TileStand.Tile_StandStatus = TILE_STAND_STATUS.TILE_STAND_STATUS_NONE;

            // 2.get all the neighbours
            int nNewX = Piece.X;
            int nNewY = Piece.Y;
            List <Tile>AvailableTiles =  TileStand.Neighbours.ToList();
            // 2. include self  , calculate all it's attribute , apply to probability
            AvailableTiles.Add(TileStand);

            //3.  decide which tile will be taken
            int nRandomChoose =  UnityEngine.Random.Range(0 , AvailableTiles.Count);
            Debug.Log( "CalculateGameLogic:"+ Piece.X + ","+Piece.Y +"neib # "+AvailableTiles.Count+",choose:"+ nRandomChoose );

            nNewX = AvailableTiles[nRandomChoose].X;
            nNewY = AvailableTiles[nRandomChoose].Y;
            //Piece_Destination = new GamePiece( nNewX , nNewY);

            // 4.
            AvailableTiles[nRandomChoose].CanPass = false; // occupy now
            AvailableTiles[nRandomChoose].Tile_StandStatus =TILE_STAND_STATUS.TILE_STAND_STATUS_HUMAN; /// hey now i stand on this tile

            // 5. decide the action depends on probability
            m_HumanPiece_Behaviour_Prev = m_HumanPiece_Behaviour ;

            if(AvailableTiles[nRandomChoose].TileStatus  == TILE_STATUS.TILE_STATUS_TERRIAN)
            {
                if (AvailableTiles[nRandomChoose].TerrianType == TERRIAN_STATUS.MINE)
                {
                    m_HumanPiece_Behaviour = HUMAN_BEHAVIOUR.HUMAN_BEHAVIOUR_GETRESOURCE;
                }
                else // if no mine =>
                {
                    AvailableTiles[nRandomChoose].TileStatus = TILE_STATUS.TILE_STATUS_BUILDING;  // set this tile as
                // decide the behavior by probability //m_Human
                    m_HumanPiece_Behaviour = HUMAN_BEHAVIOUR.HUMAN_BEHAVIOUR_BUILD; // hey  , now we are make building
                }
            }
            else
            if(AvailableTiles[nRandomChoose].TileStatus  == TILE_STATUS.TILE_STATUS_BUILDING)
            {
            // the same
            //AvailableTiles[nRandomChoose].TileStatus = TILE_STATUS.TILE_STATUS_BUILDING;  //
            // Use It to Generate Point
                m_HumanPiece_Behaviour = HUMAN_BEHAVIOUR.HUMAN_BEHAVIOUR_BUILD_USE; // hey  , now we are make building
            }
            else
            if(AvailableTiles[nRandomChoose].TileStatus  == TILE_STATUS.TILE_STATUS_TERRIAN && AvailableTiles[nRandomChoose].TerrianType == TERRIAN_STATUS.MINE)
            {
                m_HumanPiece_Behaviour = HUMAN_BEHAVIOUR.HUMAN_BEHAVIOUR_GETRESOURCE;
            }

            /// To process the AI activity
            Piece = new GamePiece(new Point(nNewX, nNewY));
            //transform.position =  BoardBehavior.GetWorldCoordinates(Piece.X, Piece.Y, 0f);
            Position_Destination =BoardBehavior.GetWorldCoordinates(Piece.X, Piece.Y, 0f);

        // also to resigted this tile , means it's occupy by user now
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        m_HumanType = HUMAN_TYPE.HUMAN_TYPE_NORMAL;
        //		Piece.m_StrongValue=2;  //
        CoreGame = GameObject.Find("coreGame");
        BoardClass =    CoreGame.GetComponent("BoardBehavior") as  BoardBehavior;

        /// Init the TextUI
        GameObject go  = new GameObject("Text_"+ this.name);
        UI_StatusText = (GUIText)go.AddComponent( typeof(GUIText) );
        UI_StatusText.transform.parent = transform;

        Font BroadwayFont = (Font)Resources.Load("Fonts/Arial");
        UI_StatusText.font = BroadwayFont;
        UI_StatusText.text = "Init";
        UI_StatusText.fontSize=16;
        // GText.material.color = Color.Green;
        UI_StatusText.transform.position=new Vector3(0,0,0);
        TextCoords = new Vector3(0,0,0);

        /// Status control init
        m_HumanPiece_Behaviour =m_HumanPiece_Behaviour_Prev =  HUMAN_BEHAVIOUR.HUMAN_BEHAVIOUR_IDLE;
        m_HumanStatus = HUMAN_STATUS.HUMAN_STATUS_INIT;
        m_nCurrentFrame = 0 ;

        m_bDistroy = false;

        UI_StatusText.enabled = ( CoreGame.GetComponent("MainGameWorld") as MainGameWorld).bDebugShowMsg_Creature;
    }