Esempio n. 1
0
 //成り決定用ガイド
 public static void CreateGuidePromote(int board_x, int board_y, PieceBase piece)
 {
     for (int i = 0; i < 2; i++)
     {
         GameObject clone = CreateGuideInstant(board_x, board_y, GuideKind.PROMOTE);
         Guide      comp  = clone.GetComponent <Guide> ();
         //スケール2倍
         clone.transform.localScale = new Vector3(2, 2, 1);
         //位置設定
         comp.SetPos(board_x, board_y);
         float x = BoardManager.GetPieceXFromBoardPosX(board_x);
         float y = BoardManager.GetPieceYFromBoardPosY(board_y);
         //選択用
         if (i == 0)
         {
             comp.promote = true;                         //成る
             x           -= define.chip_size_x_local * 2; //位置を左にずらす
         }
         else if (i == 1)
         {
             comp.promote = false;
             x           += define.chip_size_x_local * 2;      //位置を右にずらす
         }
         Vector3 pos = new Vector3(x, y, 0);
         clone.transform.localPosition = pos;            //ローカル位置を設定
         //画像設定
         Sprite sprite = PieceManager.GetInstance().GetSprite(piece.kind, piece.enemy_flag, comp.promote);
         UnityEngine.UI.Image image;
         image        = clone.gameObject.GetComponent <UnityEngine.UI.Image> ();
         image.sprite = sprite;
         image.color  = new Color(1.0f, 1.0f, 1.0f, 1.0f);        //透明度をリセットする
     }
 }
Esempio n. 2
0
    //WWWManagerで接続成功後のデータを受け取る関数
    //ゲーム状態(ターン数など)の取得
    void ReceiveGameState(Dictionary <string, object> jsonData)
    {
        int turn_count = System.Convert.ToInt32(jsonData ["turn_count"]);

        if (last_turn != turn_count)
        {
            //ターンが変化した
            Debug.Log("ターンの変化を受信");
            last_turn      = turn_count;       //ターン数を保存
            turn_player_id = System.Convert.ToInt32(jsonData ["turn_player"]);
            //盤の情報を更新
            PieceManager.GetInstance().ReceivePiecesDate();
            if (end_flag == false)              //ゲームが終了していない
            {
                if (turn_player_id == loginDataManager.user_id)
                {
                    SetIsTurnPlayerMe(true);
                }
                else
                {
                    SetIsTurnPlayerMe(false);
                }
                //UI更新
                turn_text.text = "ターン " + turn_count.ToString();
            }
        }
    }
Esempio n. 3
0
    //クリックされた時
    public void ClickPiece()
    {
        //自分のターンか確認
        if (GameManager.GetInstance().GetIsTurnPlayerMe() == false)
        {
            return;
        }
        if (enemy_flag == true)
        {
            return;
        }
        //ピースマネージャーに選択されたことを伝える
        PieceManager pieceManager = PieceManager.GetInstance();

        pieceManager.SetSelectPiece(this.gameObject);
        //ガイドリセット
        Guide.AllGuideDelete();
        if (have_flag == true)
        {
            //持ち駒なら配置可能判定
            Guide.CreateGuideForHavePiece(kind);
        }
        else
        {
            //自分の移動可能な場所にガイドを設置
            move.CreateMoveGuide(board_pos_x, board_pos_y);
        }
    }
Esempio n. 4
0
 //種類を設定し画像を設定する
 public void SetKind(int k)
 {
     kind = k;
     UnityEngine.UI.Image image;
     image        = gameObject.GetComponent <UnityEngine.UI.Image> ();
     image.sprite = PieceManager.GetInstance().GetSprite(k, enemy_flag, promote);
     //移動設定
     SetMove();
 }
Esempio n. 5
0
    //クリックされたとき
    public void ClickGuide()
    {
        if (kind == GuideKind.LAST_MOVER)
        {
            return;
        }
        //ピースマネージャーに移動命令を出させる
        PieceManager pieceManager = PieceManager.GetInstance();

        pieceManager.MoveSelectPiece(this);
    }
Esempio n. 6
0
    public bool CanPromote = true;    //成ることが出来る駒か
    //移動可能な場所にガイド配置を配置
    public virtual void CreateMoveGuide(int pos_x, int pos_y)
    {
        //自分の移動可能な場所にガイドを設置
        int y_mul = 1;        //後手ならy方向を逆にする

        if (GameManager.GetInstance().first_player_flag == false)
        {
            y_mul = -1;
        }
        for (int y = 0; y < 3; y++)
        {
            for (int x = 0; x < 3; x++)
            {
                int move_x     = x - 1;              //-1 ~ 1に変換
                int move_y     = y - 1;
                int move_power = CanMoveArray[y, x]; //移動力
                if (move_power == 1)                 //1マス移動
                {
                    int tx = pos_x + move_x;
                    int ty = pos_y + move_y * y_mul;
                    Guide.CreateGuide(tx, ty, GuideKind.MOVE);
                }
                else if (move_power > 1)               //複数マス進める
                {
                    for (int i = 1; i < move_power; i++)
                    {
                        int tx = pos_x + move_x * i;
                        int ty = pos_y + move_y * y_mul * i;
                        if (Guide.CreateGuide(tx, ty, GuideKind.MOVE) == false)
                        {
                            //移動不可能になれば終了
                            break;
                        }
                        GameObject obj = PieceManager.GetInstance().BoardPosArray [ty - 1, tx - 1];                        //移動先にいる別の駒
                        if (obj != null)
                        {
                            break;                            //ほかの駒があれば終了
                        }
                    }
                }
            }
        }
    }
Esempio n. 7
0
 //持ち駒用ガイド配置
 public static void CreateGuideForHavePiece(int kind)
 {
     //全マスをループ
     for (int x = 0; x < define.BoardSizeX; x++)
     {
         if (kind == PieceKind.FU)           //歩なら二歩にならないか調べる
         {
             bool continue_flag = false;
             //列に歩がいないか探す
             for (int y = 0; y < define.BoardSizeY; y++)
             {
                 GameObject obj = PieceManager.GetInstance().BoardPosArray [y, x];                    //移動先にいる別の駒
                 if (obj != null)
                 {
                     PieceBase Piece = obj.GetComponent <PieceBase>();
                     if (Piece.kind == PieceKind.FU && Piece.promote == false && Piece.enemy_flag == false)                       //味方の成っていない歩があれば
                     {
                         //二歩なのでこの列に置けない
                         continue_flag = true;
                         break;
                     }
                 }
             }
             if (continue_flag == true)
             {
                 continue;
             }
         }
         for (int y = 0; y < define.BoardSizeY; y++)
         {
             GameObject obj = PieceManager.GetInstance().BoardPosArray [y, x];                //移動先にいる別の駒
             if (obj == null)
             {
                 //駒のない場所なら
                 if (PieceManager.GetInstance().CheckMovePos(kind, y + 1) == true)                  //移動先があるか
                 {
                     CreateGuide(x + 1, y + 1, GuideKind.MOVE);
                 }
             }
         }
     }
 }
Esempio n. 8
0
    //移動可能な場所設定
    public static bool CreateGuide(int board_x, int board_y, int guide_kind)
    {
        if (guide_kind == GuideKind.PROMOTE)
        {
            Debug.LogError("CreateGuideError");
            return(false);
        }
        if (BoardManager.CheckOutRangeBoardPointXY(board_x, board_y) == true)
        {
            return(false);                                                                        //範囲外
        }
        if (ohte_check_flag == false)                                                             //王手チェックではない
        {
            GameObject obj = PieceManager.GetInstance().BoardPosArray [board_y - 1, board_x - 1]; //移動先にいる別の駒
            if (obj != null)
            {
                PieceBase piece = obj.GetComponent <PieceBase> ();
                if (piece.enemy_flag == false)
                {
                    return(false);                   //味方の駒がある
                }
            }
        }
        GameObject clone = CreateGuideInstant(board_x, board_y, guide_kind);

        if (guide_kind == GuideKind.LAST_MOVER)
        {
            clone.tag = define.LastMoverTag;
            //画像設定
            Sprite sprite = last_mover_sprite;
            UnityEngine.UI.Image image;
            image        = clone.gameObject.GetComponent <UnityEngine.UI.Image> ();
            image.sprite = sprite;
        }
        return(true);
    }
Esempio n. 9
0
 //何もないところがクリックされた時
 public void Click()
 {
     //駒選択リセット
     PieceManager.GetInstance().SetSelectPiece(null);
     Guide.AllGuideDelete();
 }