/// <summary> /// 完成拼图 /// </summary> /// <param name="piece"></param> public void FinishPiece(PieceControl piece) { int i, j; piece.GetComponent <Renderer>().material.renderQueue = this.GetDrawPriorityFinishedPiece(); //将被点击的碎片从数组中剔除 for (i = 0; i < this.active_pieces.Length; i++) { if (this.active_pieces[i] == null) { continue; } if (this.active_pieces[i].name == piece.name) { //将位于被点击的碎片之后的碎片逐个往前移动 for (j = i; j < this.active_pieces.Length - 1; j++) { //直接把j后一位的数值赋值到j的位置,以此类推直到最后一位 this.active_pieces[j] = this.active_pieces[j + 1]; } //清空数组的末尾 this.active_pieces[this.active_pieces.Length - 1] = null; //得到正解的碎片数量+1 this.piece_finished_num++; break; } } this.Set_Height_Offset_To_Pieces(); }
// 将被点击的碎片移动到数组的头部,根据数组设置渲染优先级 public void PickPiece(PieceControl piece) { int i, j; for (i = 0; i < this.active_pieces.Length; i++) { if (this.active_pieces[i] == null) { continue; } if (this.active_pieces[i].name == piece.name) { for (j = i; j > 0; j--) { this.active_pieces[j] = this.active_pieces[j - 1]; } this.active_pieces[0] = piece; break; } } this.set_height_offset_to_pieces(); }
//开始拖动碎片时,把拖动中的碎片放在最上面 public void PickPiece(PieceControl _piece) { int i, j; //将被点击的碎片移动到数组的头部 //由于this.pieces[]按照显示的顺序排列,头部的元素将被显示在最上方 for (i = 0; i < this.active_pieces.Length; i++) { if (this.active_pieces[i] == null) { continue; } if (this.active_pieces[i].name == _piece.name) { //将位于“被点击碎片”之前的碎片,逐个向后移动 for (j = i; j > 0; j--) { this.active_pieces[j] = this.active_pieces[j - 1]; } //被点击的碎片回到数组头部 this.active_pieces[0] = _piece; break; } } //重新设置高度 this.Set_Height_Offset_To_Pieces(); }
// 碎片被放置到正解位置时的处理 public void FinishPiece(PieceControl piece) { int i, j; piece.GetComponent <Renderer>().material.renderQueue = this.GetDrawPriorityFinishedPiece(); for (i = 0; i < this.active_pieces.Length; i++) { if (this.active_pieces[i] == null) { continue; } if (this.active_pieces[i].name == piece.name) { for (j = i; j < this.active_pieces.Length - 1; j++) { this.active_pieces[j] = this.active_pieces[j + 1]; } this.active_pieces[this.active_pieces.Length - 1] = null; this.piece_finished_num++; break; } } }
public bool IsFit(int id, GameObject obj) { //Debug.Log("...........start"); PieceControl piece = obj.GetComponent <PieceControl>(); int count = piece.pieceLetterTypes.Count; Debug.Log(count); for (int i = 0; i < count; ++i) { int j = (id + i) % gearLetterList.Count; Debug.Log(gearLetterTypes[j] + " " + piece.pieceLetterTypes[count - i - 1]); if (isTaken[j] || piece.pieceLetterTypes[count - i - 1] != gearLetterTypes[j]) { return(false); } } //Debug.Log("...........end"); for (int i = 0; i < count; ++i) { int j = (id + i) % gearLetterList.Count; isTaken[j] = true; gearLetterList[j].GetComponentInChildren <GearSlotControl>().ShowPiece(); } return(true); }
public void FinishPiece(PieceControl piece) { piece.GetComponent <Renderer>().material.renderQueue = GetDrawPriorityFinishedPiece(); activePieces.Remove(piece); pieceFinishedNum++; SetHeightOffsetToPieces(); }
// 开始拖动碎片时的处理 public void PickPiece(PieceControl piece) { int i, j; // 将被点击的碎片移动到数组的头部 // // 由于this.pieces[] 按照显示的顺序排列,头部的元素将 // 被显示在最上方 for (i = 0; i < this.active_pieces.Length; i++) { if (this.active_pieces[i] == null) { continue; } if (this.active_pieces[i].name == piece.name) { // 将位于“被点击的碎片”之前的碎片,逐个向后移动 // for (j = i; j > 0; j--) { this.active_pieces[j] = this.active_pieces[j - 1]; } // 被点击的碎片回到数组头部 this.active_pieces[0] = piece; break; } } this.set_height_offset_to_pieces(); }
// ピースがドラッグ開始されたときの処理. public void PickPiece(PieceControl piece) { int i, j; // クリックされたピースを、配列の先頭に移動させる. // // this.pieces[] は表示される順に並んでいるので、先頭に持ってくると // 一番上に表示されるようになる. for (i = 0; i < this.active_pieces.Length; i++) { if (this.active_pieces[i] == null) { continue; } if (this.active_pieces[i].name == piece.name) { // 『クリックされたピース』より前にあるピースを、いっこづつ後ろにずらす. // for (j = i; j > 0; j--) { this.active_pieces[j] = this.active_pieces[j - 1]; } // クリックされたピースを先頭にもってくる. this.active_pieces[0] = piece; break; } } this.set_height_offset_to_pieces(); }
public Piece(Player team) { Team = team; Control = new PieceControl() { Style = team.PieceStyle }; }
void drop() { if (picked != null) { picked.release(); picked = null; force = force / carryForceMultiplier; } }
private void removePiece(PieceControl otherPiece) { if (otherPiece.color == PieceControl.Colour.Red) { redPieces.Remove(otherPiece); } else { blackPieces.Remove(otherPiece); } }
public void Reset() { if (piece == null) { piece = GetComponent <TilemapGridObject>(); } if (control == null) { control = GetComponent <PieceControl>(); } }
private void DrawHoldPiece() { if (Client == null) { return; } IBoard board = Client.Board; if (board == null) { return; } PieceControl.DrawPiece(Client.HoldPiece, board.Height); }
void pick() { RaycastHit hit; if (Physics.Raycast(transform.position, transform.right, out hit, maxPickUpDistance)) { PieceControl picking = hit.collider.gameObject.GetComponent <PieceControl>(); if (!picking.isHeld() && picking.pieceColor == pieceColor) { picking.hold(rb); picked = picking; force = force * carryForceMultiplier; } } }
//moving a piece, update the board private void movePiece(PieceControl piece, PositionOnBoard positionOnBoard) { //empty piece from old position emptyPosition(piece.position); //check the lists to see if there is a piece in new position if (theboard[positionOnBoard.Hpos, positionOnBoard.Vpos].pieceID != 0) { PieceControl otherPiece = theboard[positionOnBoard.Hpos, positionOnBoard.Vpos]; if (otherPiece.color != piece.color) { //remove removePiece(otherPiece); } } // move piece theboard[positionOnBoard.Hpos, positionOnBoard.Vpos] = piece; piece.position = positionOnBoard; }
// 碎片被放置到正解位置时的处理 public void FinishPiece(PieceControl piece) { int i, j; piece.GetComponent <Renderer>().material.renderQueue = this.GetDrawPriorityFinishedPiece(); // 将被点击的碎片从数组中剔除 for (i = 0; i < this.active_pieces.Length; i++) { if (this.active_pieces[i] == null) { continue; } if (this.active_pieces[i].name == piece.name) { // 将位于“被点击碎片”之后的碎片逐个往前移动 // for (j = i; j < this.active_pieces.Length - 1; j++) { this.active_pieces[j] = this.active_pieces[j + 1]; } // 清空数组的末尾 this.active_pieces[this.active_pieces.Length - 1] = null; // “已经得到正解的碎片”的数量 + 1 this.piece_finished_num++; break; } } this.set_height_offset_to_pieces(); }
// ピースが正解の位置におかれたときの処理. public void FinishPiece(PieceControl piece) { int i, j; piece.GetComponent <Renderer>().material.renderQueue = this.GetDrawPriorityFinishedPiece(); // クリックされたピースを配列から取り除く for (i = 0; i < this.active_pieces.Length; i++) { if (this.active_pieces[i] == null) { continue; } if (this.active_pieces[i].name == piece.name) { // 『クリックされたピース』より後ろにあるピースを、いっこづつ前にずらす. // for (j = i; j < this.active_pieces.Length - 1; j++) { this.active_pieces[j] = this.active_pieces[j + 1]; } // 配列の末尾を空にする. this.active_pieces[this.active_pieces.Length - 1] = null; // 『正解済みのピース』の数を+1する. this.piece_finished_num++; break; } } this.set_height_offset_to_pieces(); }
// 对碎片位置进行随机洗牌 private void shuffle_pieces() { #if true // 将碎片按照网格顺序排列 int[] piece_index = new int[this.shuffle_grid_num * this.shuffle_grid_num]; for (int i = 0; i < piece_index.Length; i++) { if (i < this.all_pieces.Length) { piece_index[i] = i; } else { piece_index[i] = -1; } } // 随机选取两个碎片,交换位置 for (int i = 0; i < piece_index.Length - 1; i++) { int j = Random.Range(i + 1, piece_index.Length); int temp = piece_index[j]; piece_index[j] = piece_index[i]; piece_index[i] = temp; } // 通过位置的索引变换为实际的坐标来进行配置 Vector3 pitch; pitch = this.shuffle_zone.size / (float)this.shuffle_grid_num; for (int i = 0; i < piece_index.Length; i++) { if (piece_index[i] < 0) { continue; } PieceControl piece = this.all_pieces[piece_index[i]]; Vector3 position = piece.finished_position; int ix = i % this.shuffle_grid_num; int iz = i / this.shuffle_grid_num; position.x = ix * pitch.x; position.z = iz * pitch.z; position.x += this.shuffle_zone.center.x - pitch.x * (this.shuffle_grid_num / 2.0f - 0.5f); position.z += this.shuffle_zone.center.z - pitch.z * (this.shuffle_grid_num / 2.0f - 0.5f); position.y = piece.finished_position.y; piece.start_position = position; } // 逐步(网格的格子内)随机移动位置 Vector3 offset_cycle = pitch / 2.0f; Vector3 offset_add = pitch / 5.0f; Vector3 offset = Vector3.zero; for (int i = 0; i < piece_index.Length; i++) { if (piece_index[i] < 0) { continue; } PieceControl piece = this.all_pieces[piece_index[i]]; Vector3 position = piece.start_position; position.x += offset.x; position.z += offset.z; piece.start_position = position; // offset.x += offset_add.x; if (offset.x > offset_cycle.x / 2.0f) { offset.x -= offset_cycle.x; } offset.z += offset_add.z; if (offset.z > offset_cycle.z / 2.0f) { offset.z -= offset_cycle.z; } } // 使全体旋转 foreach (PieceControl piece in this.all_pieces) { Vector3 position = piece.start_position; position -= this.shuffle_zone.center; position = Quaternion.AngleAxis(this.pazzle_rotation, Vector3.up) * position; position += this.shuffle_zone.center; piece.start_position = position; } this.pazzle_rotation += 90; #else // 简单地使用随机数来决定坐标时的情况 foreach (PieceControl piece in this.all_pieces) { Vector3 position; Bounds piece_bounds = piece.GetBounds(Vector3.zero); position.x = Random.Range(this.shuffle_zone.min.x - piece_bounds.min.x, this.shuffle_zone.max.x - piece_bounds.max.x); position.z = Random.Range(this.shuffle_zone.min.z - piece_bounds.min.z, this.shuffle_zone.max.z - piece_bounds.max.z); position.y = piece.finished_position.y; piece.start_position = position; } #endif }
internal PieceControl[,] boardFor(int[,] boardFromInts) { BoardAI newBoard = new BoardAI(numberofColumns, numberOfRows); PieceControl[,] placeHolder = new PieceControl[numberofColumns, numberOfRows]; for (int col = 0; col < numberofColumns; col++) { for (int row = 0; row < numberOfRows; row++) { switch (boardFromInts[col, row]) { case 0: placeHolder[col, row] = new BlankSpace(new PositionOnBoard(col, row)); break; case 1: placeHolder[col, row] = new King(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard); break; case 2: placeHolder[col, row] = new King(PieceControl.Colour.Red, new PositionOnBoard(col, row), newBoard); break; case 3: placeHolder[col, row] = new Guard(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard); break; case 4: placeHolder[col, row] = new Guard(PieceControl.Colour.Red, new PositionOnBoard(col, row), newBoard); break; case 5: placeHolder[col, row] = new Bishop(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard); break; case 6: placeHolder[col, row] = new Bishop(PieceControl.Colour.Red, new PositionOnBoard(col, row), newBoard); break; case 7: placeHolder[col, row] = new Knight(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard); break; case 8: placeHolder[col, row] = new Knight(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard); break; case 9: placeHolder[col, row] = new Rook(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard); break; case 10: placeHolder[col, row] = new Rook(PieceControl.Colour.Red, new PositionOnBoard(col, row), newBoard); break; case 11: placeHolder[col, row] = new Cannon(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard); break; case 12: placeHolder[col, row] = new Cannon(PieceControl.Colour.Red, new PositionOnBoard(col, row), newBoard); break; case 13: placeHolder[col, row] = new Pawn(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard); break; case 14: placeHolder[col, row] = new Pawn(PieceControl.Colour.Red, new PositionOnBoard(col, row), newBoard); break; } } } return(placeHolder); }
public void pickPiece(PieceControl _piece) { }
public void PickPiece(PieceControl piece) { activePieces.Remove(piece); activePieces.Insert(0, piece); SetHeightOffsetToPieces(); }
public void finishPiece(PieceControl _piece) { }
private void shufflePieces() { #if true int[] pieces_index = new int[this.shuffle_grid_num * this.shuffle_grid_num]; for (int i = 0; i < pieces_index.Length; i++) { if (i < this.pieces_all.Length) { pieces_index[i] = i; } else { pieces_index[i] = -1; } } for (int i = 0; i < pieces_index.Length - 1; i++) { int j = Random.Range(i + 1, pieces_index.Length); int temp = pieces_index[i]; pieces_index[i] = pieces_index[j]; pieces_index[j] = temp; } Vector3 pitch = this.shuffle_zone.size / (float)this.shuffle_grid_num; for (int i = 0; i < pieces_index.Length; i++) { if (pieces_index[i] < 0) { continue; } PieceControl _piece = this.pieces_all[pieces_index[i]]; int ix = i % this.shuffle_grid_num; int iz = i / this.shuffle_grid_num; Vector3 _position = new Vector3(ix * pitch.x, _piece.pos_finish.y, iz * pitch.z); _position.x += this.shuffle_zone.center.x - pitch.x * (this.shuffle_grid_num / 2.0f - 0.5f); _position.z += this.shuffle_zone.center.z - pitch.z * (this.shuffle_grid_num / 2.0f - 0.5f); _piece.pos_begin = _position; } for (int i = 0; i < pieces_index.Length; i++) { if (pieces_index[i] < 0) { continue; } Vector3 piece_offset = Vector3.zero; piece_offset.x = pitch.x * Random.Range(-0.4f, 0.4f); piece_offset.x = pitch.z * Random.Range(-0.4f, 0.4f); PieceControl _piece = this.pieces_all[pieces_index[i]]; _piece.pos_begin += piece_offset; } foreach (PieceControl _piece in this.pieces_all) { Vector3 _position = _piece.pos_begin; _position -= this.shuffle_zone.center; _position = Quaternion.AngleAxis(this.puzzle_rotation, Vector3.up) * _position; _position += this.shuffle_zone.center; _piece.pos_begin = _position; } this.puzzle_rotation += 90; #else foreach (PieceControl _piece in this.pieces_all) { Vector3 _position; Bounds piece_bounds = _piece.getBounds(Vector3.zero); _position.x = Random.Range(this.shuffle_zone.min.x - piece_bounds.min.x, this.shuffle_zone.max.x - piece_bounds.max.x); _position.z = Random.Range(this.shuffle_zone.min.z - piece_bounds.min.z, this.shuffle_zone.max.z - piece_bounds.max.z); _position.y = _piece.pos_begin.y; _piece.pos_begin = _position; } #endif }
private void shuffle_pieces() { #if true int[] piece_index = new int[this.shuffle_grid_num * this.shuffle_grid_num]; // 10个碎片会有 4*4 格子,空的格子标记 -1 for (int i = 0; i < piece_index.Length; i++) { if (i < this.all_pieces.Length) { piece_index[i] = i; } else { piece_index[i] = -1; } } // 随机交换两个格子位置 for (int i = 0; i < piece_index.Length - 1; i++) { int j = Random.Range(i + 1, piece_index.Length); int temp = piece_index[j]; piece_index[j] = piece_index[i]; piece_index[i] = temp; } // 标记数字的格子填充该数字对应的碎片 Vector3 pitch; pitch = this.shuffle_zone.size / (float)this.shuffle_grid_num; for (int i = 0; i < piece_index.Length; i++) { if (piece_index[i] < 0) { continue; } PieceControl piece = this.all_pieces[piece_index[i]]; // 根据格子在总格子的索引,结合中心点位置计算出格子坐标,把碎片坐标设置为那个格子坐标 Vector3 position = piece.finished_position; int ix = i % this.shuffle_grid_num; int iz = i / this.shuffle_grid_num; position.x = ix * pitch.x; position.z = iz * pitch.z; // 相对左上角第一个格子的【中心位置】计算,所以多了个 0.5 position.x += this.shuffle_zone.center.x - pitch.x * (this.shuffle_grid_num / 2.0f - 0.5f); position.z += this.shuffle_zone.center.z - pitch.z * (this.shuffle_grid_num / 2.0f - 0.5f); position.y = piece.finished_position.y; piece.start_position = position; } // 碎片在自己的小格内做小范围偏移 Vector3 offset_cycle = pitch / 2.0f; Vector3 offset_add = pitch / 5.0f; Vector3 offset = Vector3.zero; for (int i = 0; i < piece_index.Length; i++) { if (piece_index[i] < 0) { continue; } PieceControl piece = this.all_pieces[piece_index[i]]; Vector3 position = piece.start_position; position.x += offset.x; position.z += offset.z; piece.start_position = position; offset.x += offset_add.x; if (offset.x > offset_cycle.x / 2.0f) { offset.x -= offset_cycle.x; } offset.z += offset_add.z; if (offset.z > offset_cycle.z / 2.0f) { offset.z -= offset_cycle.z; } } // shuffle_zone 只是一个 bound 所以没办法旋转整个 shuffle_zone 来旋转所有碎片,而是每个碎片单独相对 shuffle_zone 的中心轴作旋转 foreach (PieceControl piece in this.all_pieces) { Vector3 position = piece.start_position; position -= this.shuffle_zone.center; position = Quaternion.AngleAxis(this.pazzle_rotation, Vector3.up) * position; position += this.shuffle_zone.center; piece.start_position = position; } // 这里作用是按重置按钮的时候,整体旋转角再变化 this.pazzle_rotation += 90; #else // 简单的使用随机数来决定坐标的情况 foreach (PieceControl piece in this.all_pieces) { Vector3 position; Bounds piece_bounds = piece.GetBounds(Vector3.zero); position.x = Random.Range(this.shuffle_zone.min.x - piece_bounds.min.x, this.shuffle_zone.max.x - piece_bounds.max.x); position.z = Random.Range(this.shuffle_zone.min.x - piece_bounds.min.z, this.shuffle_zone.max.z - piece_bounds.max.z); position.y = piece.finished_position.y; piece.start_position = position; } #endif }
// ピースの位置をシャッフルする. private void shuffle_pieces() { #if true // ピースをグリッドに順番に並べる. int[] piece_index = new int[this.shuffle_grid_num * this.shuffle_grid_num]; for (int i = 0; i < piece_index.Length; i++) { if (i < this.all_pieces.Length) { piece_index[i] = i; } else { piece_index[i] = -1; } } // ピース二つをランダムに選んで、位置を交換する. for (int i = 0; i < piece_index.Length - 1; i++) { int j = Random.Range(i + 1, piece_index.Length); int temp = piece_index[j]; piece_index[j] = piece_index[i]; piece_index[i] = temp; } // 場所のインデックスから実際の座標に変換して配置する. Vector3 pitch; pitch = this.shuffle_zone.size / (float)this.shuffle_grid_num; for (int i = 0; i < piece_index.Length; i++) { if (piece_index[i] < 0) { continue; } PieceControl piece = this.all_pieces[piece_index[i]]; Vector3 position = piece.finished_position; int ix = i % this.shuffle_grid_num; int iz = i / this.shuffle_grid_num; position.x = ix * pitch.x; position.z = iz * pitch.z; position.x += this.shuffle_zone.center.x - pitch.x * (this.shuffle_grid_num / 2.0f - 0.5f); position.z += this.shuffle_zone.center.z - pitch.z * (this.shuffle_grid_num / 2.0f - 0.5f); position.y = piece.finished_position.y; piece.start_position = position; } // 少しづつ(グリッドのマス目内で)ランダムに位置をずらす. Vector3 offset_cycle = pitch / 2.0f; Vector3 offset_add = pitch / 5.0f; Vector3 offset = Vector3.zero; for (int i = 0; i < piece_index.Length; i++) { if (piece_index[i] < 0) { continue; } PieceControl piece = this.all_pieces[piece_index[i]]; Vector3 position = piece.start_position; position.x += offset.x; position.z += offset.z; piece.start_position = position; // offset.x += offset_add.x; if (offset.x > offset_cycle.x / 2.0f) { offset.x -= offset_cycle.x; } offset.z += offset_add.z; if (offset.z > offset_cycle.z / 2.0f) { offset.z -= offset_cycle.z; } } // 全体を回転させる. foreach (PieceControl piece in this.all_pieces) { Vector3 position = piece.start_position; position -= this.shuffle_zone.center; position = Quaternion.AngleAxis(this.pazzle_rotation, Vector3.up) * position; position += this.shuffle_zone.center; piece.start_position = position; } this.pazzle_rotation += 90; #else // 単純に乱数で座標を決める場合. foreach (PieceControl piece in this.all_pieces) { Vector3 position; Bounds piece_bounds = piece.GetBounds(Vector3.zero); position.x = Random.Range(this.shuffle_zone.min.x - piece_bounds.min.x, this.shuffle_zone.max.x - piece_bounds.max.x); position.z = Random.Range(this.shuffle_zone.min.z - piece_bounds.min.z, this.shuffle_zone.max.z - piece_bounds.max.z); position.y = piece.finished_position.y; piece.start_position = position; } #endif }