public void UpdateShopDisplay(List <GameObject> shop) { localPlayerShop = shop; ClearShopDisplay(); RectTransform templateRect = templateItem.GetComponent <RectTransform> (); float itemWidth = templateRect.sizeDelta.x; float fullWidth = shopItemsParent.transform.parent.GetComponent <RectTransform> ().sizeDelta.x; Vector3 startPos = templateRect.localPosition; float edgeWidth = ((fullWidth - itemWidth * shop.Count) / (shop.Count + 1)); startPos.x = edgeWidth - (fullWidth / 2) + itemWidth / 2; for (int i = 0; i < shop.Count; i++) { GameObject item = shop[i]; ChessController chess = item.GetComponent <ChessController> (); GameObject newItem = GameObject.Instantiate(templateItem, shopItemsParent.transform); // Debug.Log ("Width" + itemWidth + "," + fullWidth); RectTransform rect = newItem.transform.GetComponent <RectTransform> (); rect.localScale = Vector3.one; rect.localPosition = startPos + new Vector3(i * (itemWidth + edgeWidth), 0, 0); int j = i; newItem.GetComponent <Button> ().onClick.AddListener(() => BuyItem(j)); newItem.SetActive(true); Transform label = newItem.transform.Find("Item Label"); Text text = label.GetComponent <Text> (); text.text = chess.name + " ☆" + chess.price; itemsGameObj.Add(newItem); } }
private void PopulateBoard() { controller = new ChessController("../../../ChessTest/test_data/start.txt"); gridBoard.Columns = 8; gridBoard.Rows = 8; // Set-up events for when pieces are moved or placed. controller.game.ChessBoard.OnPieceMoved += ChessBoard_OnPieceMoved; controller.game.ChessBoard.OnPiecePlaced += ChessBoard_OnPiecePlaced; controller.game.OnMoveFailure += Game_OnMoveFailure; controller.game.OnCheckMate += Game_OnCheckMate; // Bind player's move to label. lblTurn.DataContext = controller.game; Binding binding = new Binding("WhiteToMove"); binding.Converter = new BoolToMessageConverter(); lblTurn.SetBinding(Label.ContentProperty, binding); // Populate grid with tiles for (int i = 7; i >= 0; i--) { for (int j = 0; j < 8; j++) { Color color = (i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1) ? darkSlate : softWhite; Tuple <int, int> position = new Tuple <int, int>(i, j); Tile tile = new Tile(color); tiles.Add(position, tile); gridBoard.Children.Add(tile.Grid); } } controller.PlayFromFile(); }
public void StopBattle() { List <ChessController> newChess = new List <ChessController> (); //添加备份棋子 foreach (GameObject chessObj in chessesBackup) { chessObj.SetActive(true); ChessController chess = chessObj.GetComponent <ChessController> (); chess.Init(this); newChess.Add(chess); } //添加未战斗棋子,删除战斗棋子 foreach (ChessController chess in chesses) { if (chess == null) { continue; } if (chess.gameObject && chess.state == MyUtil.CommonUtil.ChessState.MANAGE) { newChess.Add(chess); } else { chess.DestroySelf(); } } Debug.Log(chesses.Count + "," + newChess.Count); chesses = newChess; }
public override List <string> GetAvailableMoves() { List <string> availibleMoves = new List <string>(); for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { int movementReturn = Move(new int[] { x, y }, false); if (movementReturn == 0 || movementReturn == 6) { availibleMoves.Add($"{ Convert.ToString(Convert.ToChar(x + 97)) }{ Math.Abs(y - 8) }"); } } } bool inCheck = ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1; if (inCheck) { List <string> remove = new List <string>(); int xPos = XPosition; int yPos = YPosition; foreach (string move in availibleMoves) { Piece tempPiece = ChessController.Board.GetPieceAt(move); Piece currentPieceClone = new Knight((char.IsLower(GetSymbol()) ? "White" : "Black"), xPos, yPos); //BUG: Pawn promotes if can block or take to last row XPosition = xPos; YPosition = yPos; Move(ChessController.ConvertToXY(move), true); if (ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1) { remove.Add(move); } ChessController.Board.gameSpace[xPos, yPos] = currentPieceClone; ChessController.Board.gameSpace[ChessController.ConvertToXY(move)[0], ChessController.ConvertToXY(move)[1]] = tempPiece; } foreach (string move in remove) { availibleMoves.Remove(move); } XPosition = xPos; YPosition = yPos; } if (!availibleMoves.Contains($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }")) { availibleMoves.Add($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }"); } return(availibleMoves); }
// Use this for initialization void Start() { float xSize = GetComponent <Renderer>().bounds.size.x;; Camera.main.orthographicSize = xSize * Screen.height / Screen.width * 0.5f; InitChessBoard(); int[,] mInitValue = ChessBoard.GameBoardOrigin; float unit = xSize / 9f; float xStart = -4f * unit; float yStart = -4.5f * unit; for (int i = 0; i < 9; i++) { for (int j = 0; j < 10; j++) { XY newPoint = new XY { mX = i, mY = j, mXWorld = xStart + unit * i, mYWorld = yStart + unit * j }; XYValues.Add(newPoint); } } for (int i = 0; i < mInitValue.GetLength(0); i++) { for (int j = 0; j < mInitValue.GetLength(1); j++) { int index = i * 10 + j; XY point = (XY)XYValues[index]; if (mInitValue[i, j] != Chess.EMPTY) { Transform newChess = Instantiate(chess, new Vector3(point.mXWorld, point.mYWorld, -1), Quaternion.identity); ChessController controller = newChess.GetComponent <ChessController>(); controller.SetValue(mInitValue[i, j], i, j); controller.SetOnShowPosCanMoveListener(this); if (mInitValue[i, j] == Chess.VUA_1) { KingRed = controller.GetChess(); } if (mInitValue[i, j] == Chess.VUA_2) { KingBlue = controller.GetChess(); } AllChessList.Add(controller); } } } }
//这里是使用Ray射线来控制物体移动。 private void RayMove() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Input.GetMouseButton(0)) { if (!oldHitObj) { if (mouseState == MOUSE_STATE.NORMAL) { if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) { GameObject hitObj = hit.transform.gameObject; ChessController chess = hitObj.GetComponent <ChessController> (); CommonUtil.ChessState state = chess.GetState(); int chessTeam = chess.team; if (state == CommonUtil.ChessState.MANAGE && chessTeam == team) { mouseState = MOUSE_STATE.DRAGING; oldHitObj = hitObj; } } if (mouseState != MOUSE_STATE.DRAGING) { mouseState = MOUSE_STATE.DRAG_NOTHING; } } else { //is drag nothing } // Vector3 offset = Input.mousePosition; // hit.transform.position = new Vector3(hit.point.x, hit.point.y, hit.transform.position.z); // Debug.DrawLine(ray.origin, hit.point); } else { float enter; bool banana = BOARD_CHESS_PLAIN.Raycast(ray, out enter); Vector3 point = ray.GetPoint(enter); oldHitObj.transform.position = point; } // oldMouse = hit.point; } else { if (oldHitObj) { ChessController chess = oldHitObj.GetComponent <ChessController> (); chess.NearBySitDown(); oldHitObj = null; } mouseState = MOUSE_STATE.NORMAL; } }
void Start() { chessController = FindObjectOfType <ChessController>(); showMoveScript = FindObjectOfType <ShowMoves>(); gridSize = chessController.ReturnGridSize(); gridOrigin = chessController.ReturnOrigin(); rectTransform = GetComponent <RectTransform>(); audioSource = GetComponent <AudioSource>(); GetComponent <Button>().onClick.AddListener(() => { ShowMoves(); audioSource.Play(); }); }
void Start() { chessController = FindObjectOfType <ChessController>(); gridSize = chessController.gridSize; gridOrigin = chessController.gridOrigin; rectTransform = GetComponent <RectTransform>(); GetComponent <Button>().onClick.AddListener(() => ShowMoves()); thisInformation = GetComponent <PieceInformation>(); thisInformation.gridCoordinate = gridCoordinate; thisInformation.isWhite = isWhite; thisInformation.isKing = false; }
void Start() { chessController = FindObjectOfType <ChessController>(); chessSetUp = FindObjectOfType <ChessBoardSetUp>(); beginButton.onClick.AddListener(() => BeginGame()); resetButton.onClick.AddListener(() => ResetOptions()); choosePieceButtons[0].onClick.AddListener(() => ChangeCapturePiece(1)); choosePieceButtons[1].onClick.AddListener(() => ChangeCapturePiece(-1)); pointLimitText.text = infinity; turnLimitText.text = infinity; ToggleWinCondition(); }
public void OnShow(ChessController chess, ArrayList posCanMove) { ClearDotOnBoard(); foreach (int pos in posCanMove) { XY point = (XY)XYValues[pos]; Transform newDot = Instantiate(dot, new Vector3(point.mXWorld, point.mYWorld, -1), Quaternion.identity); DotController controller = newDot.GetComponent <DotController>(); controller.SetIndex(pos); controller.SetOnMoveClickListener(this); mDots.Add(newDot); } mCurrentChess = chess; }
public void PutNewChess(GameObject prefab) { Vector2Int pos = FindNearestEmptyPosition((xMax + xMin) / 2, (yMax + yMin) / 2, FindPositionType.OUT_BOARD); GameObject newChessObj = Instantiate <GameObject> (prefab); newChessObj.transform.parent = GameObject.Find("Chesses").transform; ChessController chess = newChessObj.GetComponent <ChessController> (); chess.state = MyUtil.CommonUtil.ChessState.READY; chess.x = pos.x; chess.y = pos.y; chess.state = ChessState.MANAGE; chess.team = ownerTeam; chess.enemyTeam = enemyTeam; newChessObj.SetActive(true); chess.BoardReady(this); chesses.Add(chess); }
void Start() { chessController = FindObjectOfType <ChessController>(); beginButton.onClick.AddListener(() => BeginGame()); pointLimitButtons[0].onClick.AddListener(() => ChangePointLimit(-1)); pointLimitButtons[1].onClick.AddListener(() => ChangePointLimit(1)); turnLimitButtons[0].onClick.AddListener(() => ChangeTurnLimit(-1)); turnLimitButtons[1].onClick.AddListener(() => ChangeTurnLimit(1)); choosePieceButtons[0].onClick.AddListener(() => ChangeCapturePiece(1)); choosePieceButtons[1].onClick.AddListener(() => ChangeCapturePiece(-1)); pointLimitText.text = infinity; turnLimitText.text = infinity; UpdateRuleText(); CheckInteractive(); }
public void ChessDie(ChessController chessCtrl) { Debug.Log("ChessDie" + chessCtrl.team); if (chessCtrl.team == ownerTeam) { weCount--; if (weCount <= 0) { BattleOver(false); } } else { enemyCount--; if (enemyCount <= 0) { BattleOver(true); } } }
private void UpdateValueOnBoard(int index) { ChessBoard.PositionChess[mCurrentChess.index] = Chess.EMPTY; ChessBoard.PositionChess[index] = mCurrentChess.value; mCurrentChess.UpdateXY(index); foreach (ChessController mChess in AllChessList) { if (mChess.index == index && mChess.value != mCurrentChess.value) { mChess.Lose(); break; } } CheckCheckMate(); //finaly mCurrentChess = null; IsRedTurn = !IsRedTurn; }
void Start() { chessController = FindObjectOfType <ChessController>(); }
// Use this for initialization void Awake() { chessController = Singleton <ChessController> .Instance; }
void Start() { master = gameObject.transform.root.GetComponent <ChessController>(); piece = gameObject.transform.parent.GetComponent <Piece>(); }
void Awake() { instance = this; }
static void Main(string[] args) { ChessController chess = new ChessController(args[0]); chess.PlayFromFile(); }
void Start() { chessController = GetComponent <ChessController>(); gridSpace = chessController.ReturnGridSize(); gridOrigin = chessController.ReturnOrigin().x; }
public List <string> GetAvailableMoves(bool isQueen) { List <string> availibleMoves = new List <string>(); //int xIter = 0; //int yIter = 0; //for (int x = XPosition; x < 8; x++) //{ // xIter++; // for (int y = YPosition; y < 8; y++) // { // yIter++; // if (xIter == yIter) // { // if () // { // availibleMoves.Add($"{ Convert.ToString(Convert.ToChar(x + 97)) }{ y + 1}"); // } // } // } //} //xIter = 0; //yIter = 0; //for (int x = XPosition; x < 8; x++) //{ // xIter++; // for (int y = YPosition; y >= 0; y--) // { // yIter++; // if (xIter == yIter) // { // } // } //} //xIter = 0; //yIter = 0; //for (int x = XPosition; x >= 0; x--) //{ // xIter++; // for (int y = YPosition; y < 8; y++) // { // yIter++; // if (xIter == yIter) // { // } // } //} //xIter = 0; //yIter = 0; //for (int x = XPosition; x >= 0; x--) //{ // xIter++; // for (int y = YPosition; y >= 0; y--) // { // yIter++; // if (xIter == yIter) // { // } // } //} for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { if (Math.Abs(x - XPosition) == Math.Abs(y - YPosition)) { int checkMovement = Move(new int[] { x, y }, false); if (checkMovement == 0 || checkMovement == 6) { availibleMoves.Add($"{ Convert.ToString(Convert.ToChar(x + 97)) }{ Math.Abs(y - 8) }"); } } } } bool inCheck = ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1; if (inCheck && !isQueen) { List <string> remove = new List <string>(); int xPos = XPosition; int yPos = YPosition; foreach (string move in availibleMoves) { Piece tempPiece = ChessController.Board.GetPieceAt(move); Piece currentPieceClone = new Bishop((char.IsLower(GetSymbol()) ? "White" : "Black"), xPos, yPos); //BUG: Pawn promotes if can block or take to last row XPosition = xPos; YPosition = yPos; Move(ChessController.ConvertToXY(move), true); if (ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1) { remove.Add(move); } ChessController.Board.gameSpace[xPos, yPos] = currentPieceClone; ChessController.Board.gameSpace[ChessController.ConvertToXY(move)[0], ChessController.ConvertToXY(move)[1]] = tempPiece; } foreach (string move in remove) { availibleMoves.Remove(move); } XPosition = xPos; YPosition = yPos; } if (!availibleMoves.Contains($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }")) { availibleMoves.Add($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }"); } return(availibleMoves); }
public Piece GetPieceAt(string move) { int[] pos = ChessController.ConvertToXY(move); return(gameSpace[pos[0], pos[1]]); }
public void ShowHiddenChess(ChessController chess, string newName) { Dictionary<string, Sprite> lsImageSource; if (chess.color == (int)ChessColor.BLUEHIDDEN) { lsImageSource = lsImageBlue; } else{ lsImageSource = lsImageRed; } chess.GetComponent<Image> ().sprite = lsImageSource [newName]; chess._name = newName; chess.color = chess.color % 10; }
static void Main(string[] args) { ChessController.Run(); }
public override List <string> GetAvailableMoves() { Rook tempRook = new Rook(char.IsLower(GetSymbol()) ? "White" : "Black", XPosition, YPosition); List <string> rookMoves = tempRook.GetAvailableMoves(true); Bishop tempBishop = new Bishop(char.IsLower(GetSymbol()) ? "White" : "Black", XPosition, YPosition); List <string> bishopMoves = tempBishop.GetAvailableMoves(true); List <string> moves = new List <string>(); foreach (string move in rookMoves) { moves.Add(move); } foreach (string move in bishopMoves) { if (!moves.Contains(move)) { moves.Add(move); } } bool inCheck = ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1; if (inCheck) { List <string> remove = new List <string>(); int xPos = XPosition; int yPos = YPosition; foreach (string move in moves) { Piece tempPiece = ChessController.Board.GetPieceAt(move); Piece currentPieceClone = new Queen((char.IsLower(GetSymbol()) ? "White" : "Black"), xPos, yPos); //BUG: Pawn promotes if can block or take to last row XPosition = xPos; YPosition = yPos; Move(ChessController.ConvertToXY(move), true); int[] isKingInCheck = ChessController.Board.IsKingInCheck(ChessController.IsWhite); if (isKingInCheck[2] == 1) { remove.Add(move); } ChessController.Board.gameSpace[xPos, yPos] = currentPieceClone; ChessController.Board.gameSpace[ChessController.ConvertToXY(move)[0], ChessController.ConvertToXY(move)[1]] = tempPiece; } foreach (string move in remove) { moves.Remove(move); } XPosition = xPos; YPosition = yPos; } if (!moves.Contains($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }")) { moves.Add($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }"); } return(moves); }
public List <string> GetAvailableMoves(bool isQueen) { List <string> movablePositions = new List <string>(); for (int i = 0; i < 8; i++) { if (i != XPosition) { int[] pos = new int[2] { i, YPosition }; if (Move(pos, false) == 0 || Move(pos, false) == 6) { movablePositions.Add($"{ Convert.ToString(Convert.ToChar(pos[0] + 97)) }{ Math.Abs(pos[1] - 8) }"); } } else { for (int j = 0; j < 8; j++) { int[] pos = new int[2] { XPosition, j }; if (Move(pos, false) == 0 || Move(pos, false) == 6) { movablePositions.Add($"{ Convert.ToString(Convert.ToChar(pos[0] + 97)) }{ Math.Abs(pos[1] - 8) }"); } } } } bool inCheck = ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1; if (inCheck && !isQueen) { List <string> remove = new List <string>(); int xPos = XPosition; int yPos = YPosition; foreach (string move in movablePositions) { Piece tempPiece = ChessController.Board.GetPieceAt(move); Piece currentPieceClone = new Rook((char.IsLower(GetSymbol()) ? "White" : "Black"), xPos, yPos); //BUG: Pawn promotes if can block or take to last row XPosition = xPos; YPosition = yPos; Move(ChessController.ConvertToXY(move), true); if (ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1) { remove.Add(move); } ChessController.Board.gameSpace[xPos, yPos] = currentPieceClone; ChessController.Board.gameSpace[ChessController.ConvertToXY(move)[0], ChessController.ConvertToXY(move)[1]] = tempPiece; } foreach (string move in remove) { movablePositions.Remove(move); } XPosition = xPos; YPosition = yPos; } if (!movablePositions.Contains($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }")) { movablePositions.Add($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }"); } return(movablePositions); }
void Start() { chessController = GetComponent <ChessController>(); gridSpace = chessController.gridSize; gridOrigin = chessController.gridOrigin.x; }
IEnumerator AddInfo(ChessController chessController) { yield return(new WaitForSeconds(0.2f)); chessController.AddToPieceInfo(); }
static void Main(string[] args) { ChessController chess = new ChessController(); chess.play(); }