protected BlockTextureGenerator.BlockType PIECE_TYPE_to_BlockType(PIECE_TYPE t) { switch (t) { case PIECE_TYPE.T: return(BlockTextureGenerator.BlockType.WHITE); case PIECE_TYPE.J: return(BlockTextureGenerator.BlockType.PRIMARY); case PIECE_TYPE.Z: return(BlockTextureGenerator.BlockType.SECONDARY); case PIECE_TYPE.O: return(BlockTextureGenerator.BlockType.WHITE); case PIECE_TYPE.S: return(BlockTextureGenerator.BlockType.PRIMARY); case PIECE_TYPE.L: return(BlockTextureGenerator.BlockType.SECONDARY); case PIECE_TYPE.I: return(BlockTextureGenerator.BlockType.WHITE); default: return(BlockTextureGenerator.BlockType.WHITE); } }
private static string PIECE_TYPE_toString(PIECE_TYPE p) { switch (p) { case PIECE_TYPE.T: return("T"); case PIECE_TYPE.J: return("J"); case PIECE_TYPE.Z: return("Z"); case PIECE_TYPE.O: return("O"); case PIECE_TYPE.S: return("S"); case PIECE_TYPE.L: return("L"); case PIECE_TYPE.I: return("I"); default: return("None"); } }
private bool checkIfPieceExist(int position, PIECE_TYPE pieceType) { var existingPiece = _chessBoard.Pieces.FirstOrDefault(x => x.SetType == pieceType && x.Position == position); if (existingPiece != null) { return(false); } return(true); }
public void DisplayBoard(PIECE_TYPE currentSet) { // var pieces = _chessBoard.Pieces.Where(x => x.SetType == currentSet).ToList(); Console.WriteLine("Your Available pieces are"); foreach (var piece in pieces) { Console.WriteLine($"Id:{piece.Id}, Name: {piece.Name} "); } }
// Use this for initialization void Start() { for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(1); j++) { board[i, j] = PIECE_TYPE.EMPTY; } } pieceType = PIECE_TYPE.WHITE; putPiece(new Vector2(3, 4)); pieceType = PIECE_TYPE.BLACK; putPiece(new Vector2(3, 3)); pieceType = PIECE_TYPE.BLACK; putPiece(new Vector2(4, 4)); pieceType = PIECE_TYPE.WHITE; putPiece(new Vector2(4, 3)); TimeLimit = menu.getLimitTime(); }
public CheckerPiece(PIECE_COLOR color, string textureName) { Color = color; PieceType = PIECE_TYPE.PAWN; this.textureName = textureName; }
// 駒を盤に置く/ void putPiece(Vector2 key) { if (key.x < 0 || key.y < 0 || key.x > 7 || key.y > 7) { return; } if (board[(int)key.x, (int)key.y] != PIECE_TYPE.EMPTY) { return; } if (gamestatus != GAME_STATUS.PLAY) { return; } board[(int)key.x, (int)key.y] = pieceType; bool changeFlag = updateBoard(key, true); // initial position var initialFlag = false; if (key == new Vector2(3, 3) || key == new Vector2(3, 4) || key == new Vector2(4, 3) || key == new Vector2(4, 4)) { initialFlag = true; } if (changeFlag || initialFlag) { calcStatus(); var rotation = transform.rotation; var position = new Vector3(key.x - 4.0f + 0.5f, 0.25f, key.y - 4.0f + 0.5f); //if (pieceType == 1) { // rotation = Quaternion.AngleAxis(180, new Vector3(1, 0, 0)); //} else { // rotation = Quaternion.AngleAxis(0, new Vector3(1, 0, 0)); //} pieceList[(int)key.x, (int)key.y] = (GameObject)Instantiate(piecePrefab, position, rotation); for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(1); j++) { if (board[i, j] == PIECE_TYPE.BLACK) { pieceList[i, j].renderer.material.color = new Color(0, 0, 0, 255); } else if (board[i, j] == PIECE_TYPE.WHITE) { pieceList[i, j].renderer.material.color = new Color(255, 255, 255, 255); } } } pieceType = pieceType == PIECE_TYPE.BLACK ? PIECE_TYPE.WHITE : PIECE_TYPE.BLACK; // 置くところが無いかチェック/ foreach (Object obj in markerList) { Object.Destroy(obj); } ArrayList enablePutList = new ArrayList(); if (!checkEnablePut(ref enablePutList) && !initialFlag) { pieceType = pieceType == PIECE_TYPE.BLACK ? PIECE_TYPE.WHITE : PIECE_TYPE.BLACK; // 攻守交代2回してどこも置けなかったらそのゲームは終了/ if (!checkEnablePut(ref enablePutList) && !initialFlag) { StartCoroutine("GameOver"); } } startTime = Time.time; if (menu.getGuideEnable()) { foreach (Vector2 v in enablePutList) { position = new Vector3(v.x - 4.0f + 0.5f, 0.201f, v.y - 4.0f + 0.5f); markerList.Add(Instantiate(markerPrefab, position, Quaternion.identity)); } } enablePutList.Clear(); } else { Debug.Log("cannot put here"); board[(int)key.x, (int)key.y] = PIECE_TYPE.EMPTY; } // for debug string _s = ""; for (int i = 0; i < board.GetLength(0); i++) { _s = _s + '\n'; for (int j = 0; j < board.GetLength(1); j++) { if (board[i, j] == PIECE_TYPE.BLACK) { _s = _s + 'B'; } else if (board[i, j] == PIECE_TYPE.WHITE) { _s = _s + 'W'; } else { _s = _s + 'E'; } } } Debug.Log(_s); }
///<summary> ///ブロックを二位元配列にコピー /// </summary>> /// <param name="a">The alpha component.</param> void PutPiece(int item) { int cx, cy; for(int i=0; i<BLOCK_COUNT;i++) { cx = pieceX + x1[i]; cy = pieceY + y1[i]; //ブロックの位置がステージ内に収まっている? if(cx >= 0 && cx < STAGE_WIDTH && cy >= 0 && cy < STAGE_HEIGHT) { StageData[cx,cy]=item; } } ///<summary> ///ピースの新規作成 ///<summary> void StageData NewPiece(){ //ピースの形状データ。 int[,,] pieceData = new int[,,] { { {0,-1},{0,0},{0,1},{0,2} },//I. { {0,-1},{0,0},{0,1},{0,2} },//T. { {0,-1},{0,0},{0,1},{0,2} },//O. { {0,-1},{0,0},{0,1},{0,2} },//S. { {0,-1},{0,0},{0,1},{0,2} },//Z. { {0,-1},{0,0},{0,1},{0,2} },//J. { {0,-1},{0,0},{0,1},{0,2} },//L. }; pieceX = 6; pieceY = 1; pieceType = (PIECE_TYPE)Random.Range(0, 7);//抽選 for (int i=0; i< BLOCK_COUNT;i++) { x1[i] = pieceData[(int)pieceType, i, 0]; y1[i] = pieceData[(int)pieceType, i, 1]; } if (hitCheck()) { Debug.Log("ゲームオーバ-"); ClearStage(); } PutPiece((int)ITEM_TYPE.ACTIVE); } ///<summary> ///ブロックを描画 ///</summary> void DrawStage(){ for (int i = 0; i < STAGE_HEIGHT;i++) { for (int j = 0; j < STAGE_HEIGHT; j++) { MeshRenderer mr = ViewBlocks[i, j].GetComponent<MeshRenderer>(); Material m = viewBlocks[i,j]GetComponent<Renderer>().material; mr.enabled = true; switch (StageData[i, j]) { case (int)ITEM_TYPE.BLANK: mr.enabled = false; break; case (int)ITEM_TYPE.WALL: m.color = Color.black; break; case (int)ITEM_TYPE.ACTIVE: m.color = PieceColors[(int)pieceType]; break; case (int)ITEM_TYPE.AFTER: m.color = Color.gray; break; default: break; } } } } ///<summary> ///ピースを回転 ///</summary> ///<param name="r">回転方向.</param>> void turnPiece(int r){ int temp; //回転する位置が正常? if (r==1||r==-1) { for (int i = 0; i<BLOCK_COUNT;i++) { temp = x1[i] * r; x1[i] = -y1[i] * r; y1[i] = temp; } } } ///<summary> ///入力によるピースの回転 ///</summary>> void RotatePiece(){ //回転方向. int r = 0; PutPiece((int)ITEM_TYPE.BLANK); if(Input.GetKeyDown(KeyCode.Z)) { r = -1; } PutPiece((int)ITEM_TYPE.BLANK); if (Input.GetKeyDown(KeyCode.X)) { r = 1; } if (r != 0) { turnPiece(-r);//回転取り消し } } PutPiece((int)ITEM_TYPE.ACTIVE); ///<summary> ///入力によるピースの移動 ///</summary>> void MovePiece(){ int oldx = pieceX; int oldy = pieceY; PutPiece((int)ITEM_TYPE.BLANK); { pieceX--; } if (Input.GetKey(KeyCode.LeftArrow)) { pieceX++; } if (Input.GetKey(KeyCode.LeftArrow)) { pieceY++; } //移動できない場合は移動を取り消す if (hitCheck()) { pieceX = oldx; pieceY = oldy; } PutPiece((int)ITEM_TYPE.ACTIVE); } ///<summary> ///ブロックを下に動かす ///</summary>> void EraseDown(int downCount){ int currentLine = STAGE_HEIGHT - 2; bool checkCountinue = ture; while (checkCountinue) { bool empty = true; int x; //枠を除く横一列分回す for (x = 1; x < STAGE_WIDTH-1; x++) { //空以外のブロックがある? if (stageData[currentLine,x] !=(int)ITEM_TYPE.BLANK ){ empty = false; } } //全て空? if(empty) { for (int y = currentLine; y >=1; y--) { for (x=1; x<STAGE_WIDTH - 1; x++) { stageData[y, x] = StageData[y - 1, }
static void Main(string[] args) { init(); Console.WriteLine("Type \"help\" to see all supported commands."); bool exit = false; while (!exit) { Console.Write("$ "); string input = Console.ReadLine(); string cmdPattern = "^([a-zA-Z]+)"; Match m = Regex.Match(input, cmdPattern, RegexOptions.IgnoreCase); if (m.Success) { string cmd = m.Value.ToLower(); Console.WriteLine(cmd); switch (cmd) { case "help": Console.WriteLine("place command"); Console.WriteLine(" structure: place type name color row column"); Console.WriteLine(" example: place knight w_knig_1 white 1 2"); Console.WriteLine("move command"); Console.WriteLine(" structure: move current_row current_column target_row target column"); Console.WriteLine(" example: move 1 2 2 5"); Console.WriteLine("show command"); Console.WriteLine(" structure: show"); Console.WriteLine("exit command"); Console.WriteLine(" structure: exit"); Console.WriteLine("help command"); Console.WriteLine(" structure: help"); break; case "exit": exit = true; break; case "move": // move source.r source.c target.r target.c string movePattern = @"(\d+)"; int[] num = { 0, 0, 0, 0 }; Regex.Matches(input, movePattern); int i = 0; foreach (Match match in Regex.Matches(input, movePattern, RegexOptions.IgnoreCase)) { num[i] = Int32.Parse(match.Value); i++; } Console.WriteLine($"Move {board.ChessBoard[num[0], num[1]].Name} [{num[0]}, {num[1]}] -> [{num[2]}, {num[3]}]"); bool result = board.MoveAPiece(new Position { Row = num[0], Column = num[1] }, new Position { Row = num[2], Column = num[3] }); Console.WriteLine(result); break; case "show": board.PrintBoard(); break; case "place": // place type name color position.r position.c string placePattern = @"place\s+([a-zA-Z]+)\s+(\w+)\s+([a-zA-Z]+)\s+([0-9]+)\s+([0-9]+)"; m = Regex.Match(input, placePattern, RegexOptions.IgnoreCase); if (m.Success) { Console.WriteLine($"{m.Groups[0]}, {m.Groups[1]}, {m.Groups[2]}, {m.Groups[3]}, {m.Groups[4]}, {m.Groups[5]}"); string typeName = m.Groups[1].ToString().ToLower(); PIECE_TYPE type = PIECE_TYPE.Invalid; try { type = (PIECE_TYPE)Enum.Parse(typeof(PIECE_TYPE), typeName, true); } catch (ArgumentException) { } string name = m.Groups[2].ToString().ToLower(); string colorName = m.Groups[3].ToString().ToLower(); PIECE_COLOR color = PIECE_COLOR.Invalid; try { color = (PIECE_COLOR)Enum.Parse(typeof(PIECE_COLOR), colorName, true); } catch (ArgumentException) {} Position position = new Position { Row = Int32.Parse(m.Groups[4].ToString()), Column = Int32.Parse(m.Groups[5].ToString()) }; if (type != PIECE_TYPE.Invalid && color != PIECE_COLOR.Invalid) { Console.WriteLine($"place {type.ToString()} {name} to [{position.Row}, {position.Column}]"); switch (type) { case PIECE_TYPE.King: board.PlaceAPiece(new King { Color = color, Name = name }, position); break; case PIECE_TYPE.Queen: board.PlaceAPiece(new Queen { Color = color, Name = name }, position); break; case PIECE_TYPE.Rook: board.PlaceAPiece(new Rook { Color = color, Name = name }, position); break; case PIECE_TYPE.Bishop: board.PlaceAPiece(new Bishop { Color = color, Name = name }, position); break; case PIECE_TYPE.Knight: board.PlaceAPiece(new Knight { Color = color, Name = name }, position); break; case PIECE_TYPE.Pawn: board.PlaceAPiece(new Pawn(1) { Color = color, Name = name }, position); break; default: break; } } } break; default: break; } } } }
public void SetPieceType(PIECE_TYPE t, int level) { switch (t) { case PIECE_TYPE.T: blocks[0].transform.localPosition = new Vector2(-1f, 0.5f) * pieceWidth; blocks[1].transform.localPosition = new Vector2(0f, 0.5f) * pieceWidth; blocks[2].transform.localPosition = new Vector2(+1f, 0.5f) * pieceWidth; blocks[3].transform.localPosition = new Vector2(0f, -0.5f) * pieceWidth; break; case PIECE_TYPE.J: blocks[0].transform.localPosition = new Vector2(-1f, 0.5f) * pieceWidth; blocks[1].transform.localPosition = new Vector2(0f, 0.5f) * pieceWidth; blocks[2].transform.localPosition = new Vector2(+1f, 0.5f) * pieceWidth; blocks[3].transform.localPosition = new Vector2(+1f, -0.5f) * pieceWidth; break; case PIECE_TYPE.Z: blocks[0].transform.localPosition = new Vector2(-1f, 0.5f) * pieceWidth; blocks[1].transform.localPosition = new Vector2(0f, 0.5f) * pieceWidth; blocks[2].transform.localPosition = new Vector2(0f, -0.5f) * pieceWidth; blocks[3].transform.localPosition = new Vector2(1f, -0.5f) * pieceWidth; break; case PIECE_TYPE.O: blocks[0].transform.localPosition = new Vector2(-0.5f, -0.5f) * pieceWidth; blocks[1].transform.localPosition = new Vector2(-0.5f, 0.5f) * pieceWidth; blocks[2].transform.localPosition = new Vector2(0.5f, -0.5f) * pieceWidth; blocks[3].transform.localPosition = new Vector2(0.5f, 0.5f) * pieceWidth; break; case PIECE_TYPE.S: blocks[0].transform.localPosition = new Vector2(-1f, -0.5f) * pieceWidth; blocks[1].transform.localPosition = new Vector2(0f, -0.5f) * pieceWidth; blocks[2].transform.localPosition = new Vector2(0f, 0.5f) * pieceWidth; blocks[3].transform.localPosition = new Vector2(1f, 0.5f) * pieceWidth; break; case PIECE_TYPE.L: blocks[0].transform.localPosition = new Vector2(-1f, -0.5f) * pieceWidth; blocks[1].transform.localPosition = new Vector2(-1f, 0.5f) * pieceWidth; blocks[2].transform.localPosition = new Vector2(+0f, 0.5f) * pieceWidth; blocks[3].transform.localPosition = new Vector2(+1f, 0.5f) * pieceWidth; break; case PIECE_TYPE.I: blocks[0].transform.localPosition = new Vector2(-1.5f, 0f) * pieceWidth; blocks[1].transform.localPosition = new Vector2(-0.5f, 0f) * pieceWidth; blocks[2].transform.localPosition = new Vector2(+0.5f, 0f) * pieceWidth; blocks[3].transform.localPosition = new Vector2(+1.5f, 0f) * pieceWidth; break; case PIECE_TYPE.NONE: default: break; } for (int i = 0; i < 4; i++) { blocks[i].SetImage(BlockTextureGenerator.Instance.getLevelSprite(level, BlockTextureGenerator.Border.ORIGINAL, PIECE_TYPE_to_BlockType(t))); } }