Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("starting");
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                GridObj g1 = new GridObj(new Vector3(i * 10f, .5f, j * 10f));
                if (i > 0)
                {
                    g1.connected.Add(grid[i - 1, j]);
                    grid[i - 1, j].connected.Add(g1);
                }

                if (j > 0)
                {
                    g1.connected.Add(grid[i, j - 1]);
                    grid[i, j - 1].connected.Add(g1);
                }
                grid[i, j] = g1;
            }
        }

        Debug.Log(aStar(grid[0, 0]));
    }
Example #2
0
    public ChessObj addChess(GridObj go)
    {
        if (!_Manager.ifThisPlayerLocal())
        {
            return(null);
        }

        if (!_IsStarted || (_RoundState != DisplayState.HAS_NOT_PLACE_CHESS &&
                            _RoundState != DisplayState.HAS_PLACE_CHESS &&
                            _RoundState != DisplayState.PLACE_CHESS_WRONG &&
                            _RoundState != DisplayState.DO_NOTHING))
        {
            //Debug.Log("回合状态不对");
            return(null);
        }

        if (_Manager.isThisGridEmpty(go.x, go.y))
        {
            ChessObj co = generateChess(go.x, go.y, go, _Manager._PlayerNow);
            if (_TempChess != null)
            {
                Destroy(_TempChess.gameObject);
            }
            _TempChess = co;
            changeDgree(0);
            return(co);
        }

        Debug.Log("底层认为格子不空");
        return(null);
    }
Example #3
0
        private void button7_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "Grid List File(*.grdl)|*.grdl";
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            for (; gridList1.Count > 0;)
            {
                gridList1.Remove(0);
            }
            FileStream fs    = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read);
            int        count = fs.ReadByte();

            for (int i = 0; i < count; i++)
            {
                gridList1.Add(GridObj.LoadFromStream(fs));
            }
            if (count > 0)
            {
                gridList1_SelectionMade(0);
            }
            fs.Close();
        }
Example #4
0
    private void GenerateCube(GridObj gridObj)
    {
        GameObject   obj        = new GameObject("Cube");
        MeshRenderer meshRender = obj.AddComponent <MeshRenderer>();
        MeshFilter   filter     = obj.AddComponent <MeshFilter>();

        filter.name = "cube";

        Mesh mesh = new Mesh();

        mesh.Clear();

        mesh.vertices  = vertices;
        mesh.triangles = triangles;
        mesh.normals   = normals;
        mesh.uv        = uvs;

        filter.mesh = mesh;

        Material cubeMaterial = new Material(Shader.Find("Custom / Floor"));

        cubeMaterial.color = transColor(gridObj.type);
        cubeMaterial.SetTexture("_MainTex", floor);
        meshRender.material = cubeMaterial;

        // Translate
        obj.transform.position = transPos(gridObj.x, gridObj.y);
        gridObj._cube          = obj;
    }
Example #5
0
    public ChessObj set(int xx, int yy, int dir, GridObj go, int ownner)
    {
        _Ownner              = ownner;
        _Direction           = dir;
        _ChessIdentityNumber = -1;
        _GridOccupy          = go;

        x = go.x;
        y = go.y;

        Debug.Log(ownner);

        _DisRenderer.sprite = _DirsSprite[ownner];

        _Health = 0;
        _Absorb = 0;
        _Attack = 0;

        this.transform.name = "(" + go.x + ", " + go.y + ")--棋子";

        _CanMove = false;

        _IsAlive           = true;
        _Temp_ForwardChess = null;

        return(this);
    }
Example #6
0
    GridObj SpawnObj(GridObj obj, int row, int col, bool CanDrag, Objcolor color = Objcolor.NONE)
    {
        if (panellist[row, col].Wall)
        {
            Debug.Log("Panel has Wall in: " + row + " " + col);
            return(null);
        }
        Vector3 newobjpos = panellist[row, col].transform.position;

        newobjpos.y += .5f;
        GridObj newobj = Instantiate(obj, newobjpos, Quaternion.identity, newLevel.transform);

        if (newobj.objtype == ObjType.TARGET)
        {
            targets.Add(newobj);
            if (color != Objcolor.NONE)
            {
                newobj.ChangeColor(color);
            }
        }
        newobj.CanDrag      = CanDrag;
        newobj.GridPosition = new Vector2(row, col);
        panellist[row, col].SetItem(newobj);
        return(newobj);
    }
Example #7
0
    void CreatePressure(int Row, int Col, PressureObj[] objects)
    {
        if (panellist[Row, Col].Wall)
        {
            Debug.Log("Panel has Wall in: " + Row + " " + Col);
            return;
        }
        Vector3 newobjpos = panellist[Row, Col].transform.position;

        newobjpos.y += .05f;
        Pressure newobj = Instantiate(Pressure, newobjpos, Quaternion.identity, newLevel.transform);

        for (int i = 0; i < objects.Length; i++)
        {
            GridObj newPobj = SpawnObj(objects[i].obj, objects[i].Row, objects[i].Col, false);
            newPobj.gameObject.SetActive(objects[i].DefActive);
            objects[i].obj = newPobj;
            newobj.Objects.Add(objects[i]);
            getPanel(objects[i].Row, objects[i].Col).CanDragOver = false;
        }
        newobj.GridPosition = new Vector2(Row, Col);
        newobj.curpanel     = panellist[Row, Col];

        panellist[Row, Col].HasPressure = true;
        LevelPressure = newobj;
    }
Example #8
0
 public void RemoveAttatch()
 {
     Attatched    = false;
     AttDirection = Direction.INVALID;
     AttatchedObj.AttachtoGrid();
     AttatchedObj = null;
 }
Example #9
0
    private void generateChessBoardGameObjs(int level)
    {
        _GridList  = new List <GridObj>();
        _ChessList = new List <ChessObj>();

        for (int i = 0; i < 2 * level - 1; i++)
        {
            if (i < level)
            {
                for (int j = 0; j < level + i; j++)
                {
                    GridObj gb = generateSingleGird(i - level + 1, j - level + 1);
                    _GridList.Add(gb);
                }
            }
            else
            {
                for (int j = i - level + 1; j < 2 * level - 1; j++)
                {
                    GridObj gb = generateSingleGird(i - level + 1, j - level + 1);
                    _GridList.Add(gb);
                }
            }
        }
    }
Example #10
0
 public void aiMove(Vector3 np, ChessObj tar)
 {
     transform.DOMove(np, 0.35f);
     _GridOccupy         = tar._GridOccupy;
     x                   = tar.x;
     y                   = tar.y;
     this.transform.name = "(" + x + ", " + y + ")--棋子";
 }
Example #11
0
 public PressureObj(GridObj obj, int Row, int Col, bool DefActive)
 {
     this.obj       = obj;
     this.Row       = Row;
     this.Col       = Col;
     objtype        = obj.objtype;
     this.DefActive = DefActive;
 }
Example #12
0
 public Node(GridObj go)
 {
     this.go = go;
     g       = 0;
     h       = 0;
     cost    = 0;
     prev    = null;
 }
Example #13
0
 /// <summary>
 /// Inserts a new row in the grid at the specified index
 /// </summary>
 /// <param name="index"></param>
 /// <param name="row"></param>
 public void InsertRow(int index, Row row)
 {
     if (index < 0 || index >= RowCount)
     {
         throw new ArgumentOutOfRangeException("Invalid Index value: must be greater than or equal to zero and less than Row count");
     }
     GridObj.Insert(index, row);
 }
Example #14
0
 public Node(GridObj go, Vector3 goal, Node prev)
 {
     this.go   = go;
     g         = (go.position - prev.go.position).magnitude + prev.g + go.height;
     h         = (go.position - goal).magnitude;
     cost      = h + g;
     this.prev = prev;
 }
Example #15
0
 //移动到老地方
 public void moveToOld()
 {
     transform.DOMove(_OldTrans, 0.35f);
     _GridOccupy         = _GridOccupyOld;
     x                   = oldx;
     y                   = oldy;
     this.transform.name = "(" + x + ", " + y + ")--棋子";
     _HasMove            = false;
 }
Example #16
0
 //移动到新地方
 public void moveToTemp()
 {
     transform.DOMove(_TenpTrans, 0.35f);
     _GridOccupy         = _Temp_ForwardChess._GridOccupy;
     x                   = _Temp_ForwardChess.x;
     y                   = _Temp_ForwardChess.y;
     this.transform.name = "(" + x + ", " + y + ")--棋子";
     _HasMove            = true;
 }
Example #17
0
    private GridObj generateSingleGird(int xx, int yy)
    {
        GridObj go = Instantiate(_GridPrefab, new Vector3(0, 0, 0), Quaternion.identity);

        go.set(xx, yy);
        go._Father = this;
        go.transform.SetParent(_GridRoot);
        return(go);
    }
Example #18
0
    void Start()
    {
        myGridObj     = this.transform.GetComponentInChildren <GridObj>();
        myParticleObj = this.transform.GetComponentInChildren <ParticleObj>();

        detA.SetRow(0, new Vector4(1f, -0.3f, 0, 0));
        detA.SetRow(1, new Vector4(-0.7f, 0.6f, 0, 0));
        detA.SetRow(2, new Vector4(0, 0, 1, 0));
        detA.SetRow(3, new Vector4(0, 0, 0, 1));
    }
Example #19
0
    public GridObj Clone()
    {
        GridObj temp = new GridObj();

        temp.grid          = (int[, ]) this.grid.Clone();
        temp.flow          = (int[, ]) this.flow.Clone();
        temp.goalLocation  = goalLocation;
        temp.agentLocation = agentLocation;
        temp.m_size        = m_size;
        return(temp);
    }
Example #20
0
    private ChessObj generateChess(int xx, int yy, GridObj go, int ownner)
    {
        ChessObj co = Instantiate(_ChessPrefab, new Vector3(0, 0, 0), Quaternion.identity);

        co.set(xx, yy, 0, go, ownner);
        co._Father = this;
        co.recalculatorTransform();
        co.transform.SetParent(_ChessRoot);
        //Debug.Log(pos.ToString());
        return(co);
    }
Example #21
0
 public void SetItem(GridObj Item)
 {
     if (Item.objtype != ObjType.PRESSURE)
     {
         HasItem = true;
     }
     if (Item.objtype == ObjType.WALL)
     {
         Wall = true;
     }
     item = Item;
 }
Example #22
0
    public static GridObj LoadData(string FileName)
    {
        FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);

        byte[] array = new byte[4];
        fs.Read(array, 0, 4);
        int size = BitConverter.ToInt32(array, 0);

        int[,] grid = new int[size, size];
        int[,] flow = new int[size, size];
        for (int i = 0; i < grid.GetLength(0); i++)
        {
            for (int j = 0; j < grid.GetLength(1); j++)
            {
                fs.Read(array, 0, 4);
                grid[i, j] = BitConverter.ToInt32(array, 0);
            }
        }

        for (int i = 0; i < grid.GetLength(0); i++)
        {
            for (int j = 0; j < grid.GetLength(1); j++)
            {
                fs.Read(array, 0, 4);
                flow[i, j] = BitConverter.ToInt32(array, 0);
            }
        }
        fs.Read(array, 0, 4);
        int x = BitConverter.ToInt32(array, 0);

        fs.Read(array, 0, 4);
        int   y             = BitConverter.ToInt32(array, 0);
        Point agentLocation = new Point(x, y);

        fs.Read(array, 0, 4);
        x = BitConverter.ToInt32(array, 0);
        fs.Read(array, 0, 4);
        y = BitConverter.ToInt32(array, 0);
        Point goalLocation = new Point(size - 1, size - 1);

        // -- doğrusu bu -- Point goalLocation = new Point(x, y);

        fs.Close();
        GridObj obj = new GridObj();

        obj.m_size        = size;
        obj.grid          = grid;
        obj.flow          = flow;
        obj.goalLocation  = goalLocation;
        obj.agentLocation = agentLocation;

        return(obj);
    }
Example #23
0
 //可以移动
 public void setForward(Vector3 np, ChessObj tar, int ti)
 {
     _OldTrans  = new Vector3(transform.position.x, transform.position.y, transform.position.z);
     _TenpTrans = new Vector3(np.x, np.y, np.z);
     _ForwardTarget.DOScale(new Vector3(1, 1, 1), 0.25f);
     _Temp_ForwardChess = tar;
     _CanMove           = true;
     _HasMove           = false;
     _GridOccupyOld     = _GridOccupy;
     oldx       = x;
     oldy       = y;
     _TargetInt = ti;
 }
Example #24
0
    //A* Algorithm
    public Node aStar(GridObj star)
    {
        Node begin = new Node(star);

        frontier.Add(begin);


        while (frontier.Count != 0)
        {
            Node current = frontier[0];
            frontier.RemoveAt(0);



            if (current.go.position == grid[0, 8].position)
            {
                show(current);
                return(current);
            }
            else
            {
                explored.Add(current);
            }

            foreach (GridObj conn in current.go.connected)
            {
                Node con = new Node(conn, goal, current);

                if (inList(frontier, con) == null && inList(explored, con) == null)
                {
                    frontier.Add(con);
                    frontier.Sort();
                }

                else if (inList(frontier, con) != null)
                {
                    Node exists = inList(frontier, con);



                    if (con.cost < exists.cost)
                    {
                        frontier.Remove(exists);
                        frontier.Add(con);
                        frontier.Sort();
                    }
                }
            }
        }
        return(null);
    }
Example #25
0
    public void placeChessUnsafeAI(int xx, int yy, int dir, int ownner)
    {
        GridObj  go  = findGridObj(xx, yy);
        ChessObj co  = generateChess(go.x, go.y, go, ownner);
        int      idm = _Manager.makeNewChessUnSafe(xx, yy, dir, ownner);

        co._ChessIdentityNumber = idm;
        _ChessList.Add(co);
        go._Chess = co;
        co.rotate(dir);
        GameManager._Main.updateChessBoard();
        updateBoard();
        Debug.Log("生成了一颗棋子");
    }
Example #26
0
        public static void Log(GridObj go)
        {
            string str = "棋格" + go.transform.name + ":\n";

            if (go._CanChange)
            {
                str += "可以下棋\n";
            }
            if (go._Chess != null)
            {
                str += "里面有棋子\n";
            }

            Debug.Log(str);
        }
Example #27
0
    public void makeChess(int xx, int yy, int dir, int oo)
    {
        GridObj  go  = findGridObj(xx, yy);
        ChessObj co  = generateChess(go.x, go.y, go, oo);
        int      idm = _Manager.makeNewChessUnSafe(xx, yy, dir, oo);

        co._ChessIdentityNumber = idm;
        _ChessList.Add(co);
        go._Chess = co;
        co.rotate(dir);

        Debug.Log("生成了一颗棋子");

        return;
    }
Example #28
0
 public void SwitchActions()
 {
     if (m_gridlist.SelectedIndex + 1 >= m_gridlist.Count)
     {
         m_gridlist.SelectedIndex = 0;
     }
     else
     {
         m_gridlist.SelectedIndex++;
     }
     GridObject = m_gridlist.Get(m_gridlist.SelectedIndex);
     //int[] temp = actionDirections;
     //actionDirections = actionDirections2;
     //actionDirections2 = temp;
 }
Example #29
0
    public void GenerateMap(int[] mapData)
    {
        for (int i = 0; i < mapData.Length; i++)
        {
            int x = Convert.ToInt32(i % gridsWidth);
            int y = Convert.ToInt32(i / gridsWidth);

            GridObj gridObj = new GridObj();
            gridObj.type = mapData[i];
            gridObj.x    = x;
            gridObj.y    = y;

            GenerateCube(gridObj);
            gridObjs.Add(gridObj);
        }
    }
Example #30
0
    public bool ShrinkAfterReachingSqaure(Direction nextDirection, float amount, out float amountShrunk)
    {
        var size = Rect.Size(nextDirection);

        if (size >= amount)
        {
            DoShrink(nextDirection, amount);
            amountShrunk = amount;
            return(true);
        }
        else
        {
            amountShrunk = size;
            GridObj.OnRemovedFromGrid();
            return(false);
        }
    }