Ejemplo n.º 1
0
    // Spawn something with a certain Team identifier
    private void spawn(int team = -1, int x = -1, int z = -1)
    {
        if (team == -1)
        {
            for (int i = 0; i < 4; i++)
            {
                this.spawn(i, (int)(i % 2) * (gameBoardSize - 1), (int)(i / 2) * (gameBoardSize - 1));
            }
        }
        else if (team < 0 || team > 4)
        {
            Debug.LogError("Team Number not correct!");
        }
        else
        {
            Vector3 pos = new Vector3(
                (x) * 1.25f - ((gameBoardSize - 1) / 2.0f) * 1.25f,
                0.0f,
                (z) * 1.25f - ((gameBoardSize - 1) / 2.0f) * 1.25f
                );

            GameObject spawned = Instantiate(piecePrefab, pos, Quaternion.identity) as GameObject;
            spawned.tag  = "team" + (team).ToString();
            spawned.name = "team" + (team).ToString();

            switch (team)
            {
            case 0:
                spawned.GetComponentInChildren <MeshRenderer>().material = Blue;
                break;

            case 1:
                spawned.GetComponentInChildren <MeshRenderer>().material = Red;
                break;

            case 2:
                spawned.GetComponentInChildren <MeshRenderer>().material = Green;
                break;

            case 3:
                spawned.GetComponentInChildren <MeshRenderer>().material = Yellow;
                break;
            }

            pieceController pc = spawned.GetComponent <pieceController>();
            pc.x          = x;
            pc.z          = z;
            pc.controller = this;

            // if( pc.x != -1 && pc.y != -1 )
            store.Add(new Vector2(pc.x, pc.z).ToString(), pc);
            // else {
            //  store.Add()
            // }
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Finish this teams turn
    /// </summary>
    public void endTurn(pieceController piece)
    {
        finishedPieces++;
        piece.finishMove();

        if (finishedPieces == totalPieces)
        {
            game.finishedTurn(team);
        }
    }
Ejemplo n.º 3
0
    public void turn()
    {
        finishedPieces = 0;
        int  dir = -1;        // which direction should a team go
        bool b;

        // pieceControllers of the pieces to be moved
        pieceController[] pieces = null;

        foreach (GameObject obj in GameObject.FindGameObjectsWithTag("team" + team.ToString()))
        {
            pieceController pc = obj.GetComponent <pieceController>();
            if (dir == -1)
            {
                int   count = 0;
                int[] temp  = new int[] { -1, -1, -1, -1 };

                if (pc.x != 0)
                {
                    temp[count] = 3;
                    count++;
                }
                if (pc.x != game.gameBoardSize - 1)
                {
                    temp[count] = 1;
                    count++;
                }
                if (pc.z != 0)
                {
                    temp[count] = 2;
                    count++;
                }
                if (pc.z != game.gameBoardSize - 1)
                {
                    temp[count] = 0;
                    count++;
                }

                dir = temp[Random.Range(0, count)];

                b = pc.move(dir, ref pieces);
            }
            else
            {
                b = pc.move(dir, ref pieces);
            }
        }

        if (pieces != null)
        {
            totalPieces = pieces.Length;

            foreach (pieceController piece in pieces)
            {
                iTween.MoveTo(piece.gameObject, iTween.Hash(
                                  "position", piece.getMoveTo(),
                                  "time", 1.0,
                                  "oncompletetarget", this.gameObject,
                                  "oncomplete", "endTurn",
                                  "oncompleteparams", piece
                                  ));
            }
        }
    }
Ejemplo n.º 4
0
    //     mmmmmmm    mmmmmmm      ooooooooooo vvvvvvv           vvvvvvv eeeeeeeeeeee
    //   mm:::::::m  m:::::::mm  oo:::::::::::oov:::::v         v:::::vee::::::::::::ee
    //  m::::::::::mm::::::::::mo:::::::::::::::ov:::::v       v:::::ve::::::eeeee:::::ee
    //  m::::::::::::::::::::::mo:::::ooooo:::::o v:::::v     v:::::ve::::::e     e:::::e
    //  m:::::mmm::::::mmm:::::mo::::o     o::::o  v:::::v   v:::::v e:::::::eeeee::::::e
    //  m::::m   m::::m   m::::mo::::o     o::::o   v:::::v v:::::v  e:::::::::::::::::e
    //  m::::m   m::::m   m::::mo::::o     o::::o    v:::::v:::::v   e::::::eeeeeeeeeee
    //  m::::m   m::::m   m::::mo::::o     o::::o     v:::::::::v    e:::::::e
    //  m::::m   m::::m   m::::mo:::::ooooo:::::o      v:::::::v     e::::::::e
    //  m::::m   m::::m   m::::mo:::::::::::::::o       v:::::v       e::::::::eeeeeeee
    //  m::::m   m::::m   m::::m oo:::::::::::oo         v:::v         ee:::::::::::::e
    //  mmmmmm   mmmmmm   mmmmmm   ooooooooooo            vvv            eeeeeeeeeeeeee
    /** Move this piece based on the dir, 0 = Positive Y, 1 = Postive X, ...etc */
    /// <summary>
    /// Move this piece a certain direction
    /// </summary>
    /// <param name="dir">the direction to move the piece, 0 = Positive Z, 1 = Positive X, 2 = Negative Z, 3 = Negative X</param>
    /// <returns>boolean if it was able to move</returns>
    public bool move(int dir, ref pieceController[] pieces)
    {
        pieceController[] piece_array = (pieces != null? pieces : new pieceController[] {});

        if (lastTurn == gc.currentTurn)            // I already took a turn
        {
            pieces = piece_array;
            return(false);
        }
        else
        {
            lastTurn = gc.currentTurn;
        }

        moveToLocation = this.gameObject.transform.position;         // Moved here because it was causing a bug where it was before

        int x = this.x;
        int z = this.z;

        // set how the piece is gonna move
        if (dir == 0)
        {
            z += 1;
        }
        else if (dir == 1)
        {
            x += 1;
        }
        else if (dir == 2)
        {
            z -= 1;
        }
        else
        {
            x -= 1;
        }

        pieceController temp = null;

        if (gc.store.TryGetValue(new Vector2(x, z).ToString(), out temp) && !(x < 0 || z < 0 || x >= gc.gameBoardSize || z >= gc.gameBoardSize))
        {
            // team 4 are the white structures that can't move
            // also move the other object first see if it can
            if (temp.gameObject.tag == "team4" || !temp.move(dir, ref piece_array))
            {
                pieces = piece_array;
                return(false);
            }
        }

        if (dir == 0)
        {
            moveToLocation += (new Vector3(0.0f, 0.0f, 1.25f));
        }
        else if (dir == 1)
        {
            moveToLocation += (new Vector3(1.25f, 0.0f, 0.0f));
        }
        else if (dir == 2)
        {
            moveToLocation += (-new Vector3(0.0f, 0.0f, 1.25f));
        }
        else
        {
            moveToLocation += (-new Vector3(1.25f, 0.0f, 0.0f));
        }

        gc.store.Remove(new Vector2(this.x, this.z).ToString()); // remove this entry from the array

        this.x = x;                                              // update with new locations
        this.z = z;

        if (this.x < 0 || this.z < 0 || this.x >= gc.gameBoardSize || this.z >= gc.gameBoardSize)            // the object was pushed out of bounds and needs to die
        {
            int teamTemp = -1;
            if (int.TryParse(this.gameObject.tag.Split('m')[1], out teamTemp))
            {
                gc.reduceLives(teamTemp);
            }
            // Destroy(this.gameObject);
            mustDie = true;
        }
        else
        {
            gc.store.Add(new Vector2(this.x, this.z).ToString(), this);
        }

        // add this pieceController to the pieceController array so that we can move all the pieces in unison
        Array.Resize <pieceController>(ref piece_array, piece_array.Length + 1);
        piece_array[piece_array.Length - 1] = this;
        pieces = piece_array;
        return(true);
    }