//桂馬特有の移動 public override void CreateMoveGuide(int pos_x, int pos_y) { int y_mul = 2; if (GameManager.GetInstance().first_player_flag == false) { y_mul = -2; //後手ならy方向を逆にする } Guide.CreateGuide(pos_x - 1, pos_y - y_mul, GuideKind.MOVE); Guide.CreateGuide(pos_x + 1, pos_y - y_mul, GuideKind.MOVE); }
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; //ほかの駒があれば終了 } } } } } }
//GET //駒の状態を取得 IEnumerator DownloadPiecesData() { string url = define.URL; if (loginDataManager.login_flag == false) { url = (define.URL + "get_pieces.json"); //test用 } else { url += "plays/" + loginDataManager.play_id.ToString() + "/pieces"; } WWW www = new WWW(url); //接続待ち yield return(www); if (www.error != null) { Debug.Log("Error!"); } else { //接続成功 Debug.Log("DOWNLOAD Piece Success"); Debug.Log(www.text); Debug.Log(www.url); //JSON //1~40 駒のID var jsonAllPieceData = MiniJSON.Json.Deserialize(www.text) as Dictionary <string, object>; //初期化 InitBoardPosArray(); HavePiecesList.Clear(); HavePiecesListEnemy.Clear(); Guide.AllDeleteFromTag(define.LastMoverTag); //最後に移動した駒表示ガイドを削除 bool create_flag = false; //各駒の情報 for (int i = 0; i < define.PieceNum; i++) { var jsonOnePieceData = (Dictionary <string, object>)jsonAllPieceData[(i + 1).ToString()]; if (PiecesArrayID[i] == null) //初めて呼ばれた時は作成する { GameObject piece = CreatePiece(); PiecesArrayID[i] = piece; create_flag = true; } //コンポーネントの取得 PieceBase comp = PiecesArrayID[i].GetComponent <PieceBase> (); //ID設定 comp.SetID(i + 1); //位置設定 int pos_x = System.Convert.ToInt32(jsonOnePieceData["posx"]); int pos_y = System.Convert.ToInt32(jsonOnePieceData["posy"]); if (create_flag == false) //初期化時ではない { //このターン移動した駒を判定 if (comp.board_pos_x != pos_x || comp.board_pos_y != pos_y) { comp.last_move_flag = true; } if (comp.last_move_flag == true) { Guide.CreateGuide(pos_x, pos_y, GuideKind.LAST_MOVER); comp.SetBoardPos(pos_x, pos_y); //駒をアニメーション移動 //持ち駒ではなく盤面にあるかチェック if (BoardManager.CheckOutRangeBoardPointXY(pos_x, pos_y) == false) { comp.SetMoveTargetPos(pos_x, pos_y); SetPieceMoveAnimStart(PiecesArrayID[i]); } } } else { comp.SetLocalPos(pos_x, pos_y); } comp.last_move_flag = false; int user_id = loginDataManager.user_id; if (loginDataManager.login_flag == false) { //test用 user_id = 5; } if (loginDataManager.watcher_flag == true) { //観戦者なら先手視点 user_id = UserNameManager.GetInst().first_player_user_ID; } int owner_ID = System.Convert.ToInt32(jsonOnePieceData["owner"]); comp.owner_ID = owner_ID; if (owner_ID == user_id) { //自軍 comp.SetEnemyFlag(false); } else { //敵 comp.SetEnemyFlag(true); } //成り bool promote_flag = System.Convert.ToBoolean(jsonOnePieceData["promote"]); comp.SetPromote(promote_flag); //駒の名前と敵判定と成りの情報から種類を決定 int kind = PieceKind.ChangeKindStringToint((string)jsonOnePieceData["name"]); comp.SetKind(kind); //盤面配列に記録 if (BoardManager.CheckOutRangeBoardPointXY(pos_x, pos_y) == false) //盤面上の駒なら 取った駒は座標0,0 { int tx = pos_x - 1; int ty = pos_y - 1; BoardPosArray[ty, tx] = PiecesArrayID[i]; comp.SetHaveFlag(false); //持ち駒ではなくす } else { //盤面に無い駒は持ち駒とする comp.SetHaveFlag(true); if (comp.enemy_flag == true) { HavePiecesList.Add(PiecesArrayID[i]); } else { HavePiecesListEnemy.Add(PiecesArrayID[i]); } } } //王手判定 CheckOhte(); Guide.AllGuideDelete(); //ガイド削除 //持ち駒を並べる if (create_flag == true) { //最初はアニメーション移動あり 観戦者用 UpdateHavePiece(true); } else { UpdateHavePiece(false); } //盤 if (GameManager.GetInstance().first_player_flag == false) { //後手なら盤を180度回転させる board.transform.localEulerAngles = new Vector3(0, 0, 180.0f); } else { board.transform.localEulerAngles = new Vector3(0, 0, 0.0f); } } }