Пример #1
0
    public void SendMove(SC_MultiPlayer_TileLogic tile)
    {
        if (isMyTurn)
        {
            print("SendMove");
            Dictionary <string, object> _moveToSend = new Dictionary <string, object>();

            point _from = new point();
            point _to   = new point();
            _to.row   = tile.row;
            _to.col   = tile.col;
            _from.row = currentSelectedPiece.piece.currentTileRow;
            _from.col = currentSelectedPiece.piece.currentTileCol;
            _to.row   = tile.Row;
            _to.col   = tile.Col;

            SC_MultiPlayer_Globals.SoldierRank strength = currentSelectedPiece.piece.pieceStrengh;
            _moveToSend.Add("fromRow", _from.row);
            _moveToSend.Add("fromCol", _from.col);

            _moveToSend.Add("toRow", _to.row);
            _moveToSend.Add("toCol", _to.col);

            _moveToSend.Add("strength", strength);

            string _jsonToSend = MiniJSON.Json.Serialize(_moveToSend);
            Debug.Log(_jsonToSend);
            WarpClient.GetInstance().sendMove(_jsonToSend);
        }
    }
Пример #2
0
    public void SendMoveAfterRestarting(SC_MultiPlayer_TileLogic tile)
    {
        print("SendMove");
        Dictionary <string, object> _moveToSend = new Dictionary <string, object>();

        point _to = new point();

        _to.row = tile.Row;
        _to.col = tile.Col;

        SC_MultiPlayer_Globals.SoldierRank strength = currentSelectedPiece.piece.pieceStrengh;

        _moveToSend.Add("toRow", _to.row);
        _moveToSend.Add("toCol", _to.col);
        //_moveToSend.Add("number", currentSelectedPiece.name);

        _moveToSend.Add("strength", strength);
        if (currentSelectedPiece.piece != null)
        {
            int result = Int32.Parse(System.Text.RegularExpressions.Regex.Match(currentSelectedPiece.piece.name, @"\d+").Value);
            _moveToSend.Add("name", result);
        }

        string _jsonToSend = MiniJSON.Json.Serialize(_moveToSend);

        Debug.Log(_jsonToSend);
        WarpClient.GetInstance().sendMove(_jsonToSend);
    }
Пример #3
0
    public void UserPressedTile(SC_MultiPlayer_TileLogic tile)
    {
        print("currentTile is: " + gameBoard[tile.Row][tile.Col].tileStatus);
        if (currentSelectedPiece.piece != null)
        {
            if ((SC_MultiPlayer_Globals.GamePhase == SC_MultiPlayer_Globals.GameSituation.setPieces) && (tile.Row < 4))
            {
                if (gameBoard[tile.Row][tile.Col].tileStatus == SC_DefiendVariables.TileStatus.Empty)
                {
                    if (currentSelectedPiece.piece.currentTileRow != -1 && currentSelectedPiece.piece.currentTileCol != -1)
                    {
                        SC_MultiPlayer_Globals.instance.numOfDeployedBluePieces++;
                    }
                }
                MovePieceWhenEmpty(tile);
                if (SC_MultiPlayer_Globals.instance.numOfDeployedBluePieces == 40)
                {
                    SC_MultiPlayer_View.Instance.StartButton.SetActive(true);
                }
            }

            else if (SC_MultiPlayer_Globals.GamePhase == SC_MultiPlayer_Globals.GameSituation.Running)
            {
                if (currentTurn == SC_DefiendVariables.Turn.blueTurn)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        // print("[row]= " + validCoordinates[i].Row + " [Col]= " + validCoordinates[i].Col);

                        if (currentTurn == SC_DefiendVariables.Turn.blueTurn)
                        {
                            if ((validCoordinates[i].Row == tile.Row) && (validCoordinates[i].Col == tile.Col))
                            {
                                SendMove(tile);
                                //print("[Tile.row]= " + tile.Row + " [Tile.Col]= " + tile.Col);
                                pieceHasBeenSelected = true;
                                if (gameBoard[tile.Row][tile.Col].tileStatus == SC_DefiendVariables.TileStatus.Empty)
                                {
                                    MovePieceWhenEmpty(tile);
                                }
                                else if (gameBoard[tile.Row][tile.Col].tileStatus == SC_DefiendVariables.TileStatus.RedOccupied)
                                {
                                    fight(tile);
                                    ResetValidCoordinates();
                                }


                                //SC_MultiPlayer_View.Instance.movePieceToNewLocation(currentSelectedPiece.piece, tile);
                                ResetValidCoordinates();
                                //  SwitchTurn();
                            }
                        }
                    }
                }
            }
        }
    }
Пример #4
0
 private void SearchTile(SC_MultiPlayer_TileLogic tile)
 {
     for (int i = 0; i < 10; i++)
     {
         for (int j = 0; j < 10; j++)
         {
             if (gameBoard[i][j].tile == tile)
             {
                 gameBoard[i][j].tileStatus = SC_DefiendVariables.TileStatus.Empty;
             }
         }
     }
 }
Пример #5
0
    public void CheckIfUserWantsToFight(SC_MultiPlayer_PieceLogic redPiece, SC_MultiPlayer_TileLogic tile)
    {
        print("redPiece= " + redPiece.name + " maybe blue= " + currentSelectedPiece.piece.name);

        if (currentSelectedPiece.piece != null)
        {
            if ((Math.Abs(currentSelectedPiece.piece.currentTileRow - redPiece.currentTileRow) == 0) && (Math.Abs(currentSelectedPiece.piece.currentTileCol - redPiece.currentTileCol) == 1) ||
                (Math.Abs(currentSelectedPiece.piece.currentTileRow - redPiece.currentTileRow) == 1) && (Math.Abs(currentSelectedPiece.piece.currentTileCol - redPiece.currentTileCol) == 0))
            {
                fight(tile);
            }
            SwitchTurn();
        }
    }
Пример #6
0
 private void KillPiece(SC_MultiPlayer_PieceLogic defender, SC_MultiPlayer_TileLogic tile)
 {
     gameBoard[defender.currentTileRow][defender.currentTileCol].tileStatus = SC_DefiendVariables.TileStatus.Empty;
     gameBoard[defender.currentTileRow][defender.currentTileCol].piece      = null;
     gameBoard[tile.Row][tile.Col].tileStatus = SC_DefiendVariables.TileStatus.Empty;
     gameBoard[tile.Row][tile.Col].piece      = null;
     defender.currentTileRow = -1;
     defender.currentTileCol = -1;
     SC_MultiPlayer_View.Instance.KillPiece(defender);
     if (defender.whoAmI == SC_DefiendVariables.whoAmI.Red)
     {
         enemyArray.Remove(defender);
         //enemyArrayCount--;
     }
 }
Пример #7
0
    public void MovePieceWhenEmpty(SC_MultiPlayer_TileLogic tile)
    {
        gameBoard[tile.Row][tile.Col].tileStatus = SC_DefiendVariables.TileStatus.BlueOccupied;
        gameBoard[tile.Row][tile.Col].piece      = currentSelectedPiece.piece;
        SC_MultiPlayer_View.Instance.movePieceToNewLocation(currentSelectedPiece.piece, tile);
        if (currentSelectedPiece.piece.currentTileRow != -1)
        {
            gameBoard[currentSelectedPiece.piece.currentTileRow][currentSelectedPiece.piece.currentTileCol].piece      = null;
            gameBoard[currentSelectedPiece.piece.currentTileRow][currentSelectedPiece.piece.currentTileCol].tileStatus = SC_DefiendVariables.TileStatus.Empty;
        }
        currentSelectedPiece.piece.currentTileRow = tile.Row;
        currentSelectedPiece.piece.currentTileCol = tile.Col;

        //gameBoard[currentSelectedPiece.piece.currentTileRow =
        currentSelectedPiece.piece = null;
        currentSelectedPiece.tile  = null;

        SC_MultiPlayer_View.Instance.HideValidPlacements();
    }
Пример #8
0
    private void MovePieceWhenDefeatEnemy(SC_MultiPlayer_PieceLogic attack, SC_MultiPlayer_TileLogic tile)
    {
        gameBoard[attack.currentTileRow][attack.currentTileCol].piece = null;
        gameBoard[tile.Row][tile.Col].tileStatus = gameBoard[attack.currentTileRow][attack.currentTileCol].tileStatus;
        gameBoard[attack.currentTileRow][attack.currentTileCol].tileStatus = SC_DefiendVariables.TileStatus.Empty;
        attack.currentTileRow = tile.Row;
        attack.currentTileCol = tile.Col;
        gameBoard[tile.Row][tile.Col].piece = attack;


        if (attack.whoAmI == SC_DefiendVariables.whoAmI.Red)
        {
            SC_MultiPlayer_View.Instance.movePieceToNewLocation(attack, tile);
            //if(attack.whoAmI == SC_DefiendVariables.whoAmI.Red)
            //StartCoroutine(ShowRedPieceStrengh(attack));
            redWinnerPiece = attack;
            ShowRedPieceStrength();
        }
    }
Пример #9
0
 public void UserPressedTile(SC_MultiPlayer_TileLogic SC_MultiPlayer_TileLogic)
 {
     SC_MultiPlayer_Logic.Instance.UserPressedTile(SC_MultiPlayer_TileLogic);
 }
Пример #10
0
 private void GameOver(SC_MultiPlayer_TileLogic tile)
 {
     //print(v);
 }
Пример #11
0
    public void fight(SC_MultiPlayer_TileLogic tile)
    {
        SC_MultiPlayer_PieceLogic attack   = currentSelectedPiece.piece;
        SC_MultiPlayer_PieceLogic defender = gameBoard[tile.Row][tile.Col].piece;

        print("currentAttacker= " + currentTurn + "[" + attack.currentTileRow + "][" + attack.currentTileCol + "].strengh = " + attack.pieceStrengh);
        print("currentAttacker= " + currentTurn + "[" + defender.currentTileRow + "][" + defender.currentTileCol + "].strengh = " + defender.pieceStrengh);
        if ((attack.pieceStrengh == SC_MultiPlayer_Globals.SoldierRank.spy) && (defender.pieceStrengh == SC_MultiPlayer_Globals.SoldierRank.ten))
        {
            //spy captured your marshell
            KillPiece(defender, tile);
            MovePieceWhenDefeatEnemy(attack, tile);
        }
        else if ((defender.pieceStrengh == SC_MultiPlayer_Globals.SoldierRank.bomb) && (attack.pieceStrengh == SC_MultiPlayer_Globals.SoldierRank.three))
        {
            //defuse the bomb!
            KillPiece(defender, tile);
            MovePieceWhenDefeatEnemy(attack, tile);
        }

        else if (defender.pieceStrengh == SC_MultiPlayer_Globals.SoldierRank.flag)
        {
            print("GAMEOVER");
            SC_MultiPlayer_Globals.GamePhase = SC_MultiPlayer_Globals.GameSituation.Finished;
            SC_MultiPlayer_View.Instance.EndGamePanel.SetActive(true);
            if (defender.whoAmI == SC_DefiendVariables.whoAmI.Blue)
            {
                SC_MultiPlayer_View.Instance.EndGameText.GetComponent <Text>().text = "Winner: Red"; //Red won!
            }
            SC_MultiPlayer_View.Instance.EndGameText.GetComponent <Text>().text = "Winner: Blue";    //blue won!
        }

        else if (defender.pieceStrengh == SC_MultiPlayer_Globals.SoldierRank.bomb)
        {
            //red steps on your bomb! he need to die!
            KillPiece(defender, tile);
            KillPiece(attack, tile);
        }
        else if (defender.pieceStrengh == attack.pieceStrengh)
        {
            //same strength! they r both need to die
            KillPiece(defender, tile);
            KillPiece(attack, tile);
        }
        else
        {
            if (attack.pieceStrengh > defender.pieceStrengh)
            {
                KillPiece(defender, tile);
                MovePieceWhenDefeatEnemy(attack, tile);
            }
            else
            {
                KillPiece(attack, tile);
                MovePieceWhenDefeatEnemy(defender, tile);
            }
        }

        SwitchTurn();
        currentSelectedPiece.piece = null;
        SC_MultiPlayer_View.Instance.HideValidPlacements();
    }
Пример #12
0
 public void movePieceToNewLocation(SC_MultiPlayer_PieceLogic piece, SC_MultiPlayer_TileLogic tile)
 {
     //Vector3.MoveTowards(tile.transform.position, piece.transform.position,50f);
     //piece.transform.position = Vector2.MoveTowards(piece.transform.position, tile.transform.position, 50f);
     piece.transform.position = tile.transform.position;
 }