void ReInitGame() { presentTeam = TypeTeam.white; gameEnd = false; ChessFigure[,] newFigures = new ChessFigure[height, width]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (figures[i, j] != null) { BackUpFigure(figures[i, j], newFigures); } } } for (int i = 0; i < defeatedWhiteFigures.Count; i++) { BackUpFigure(defeatedWhiteFigures[i], newFigures); } defeatedWhiteFigures.Clear(); for (int i = 0; i < defeatedBlackFigures.Count; i++) { BackUpFigure(defeatedBlackFigures[i], newFigures); } defeatedBlackFigures.Clear(); figures = newFigures; }
public void Init(Vector2Int _pos, TypeTeam _team, bool _before) { startPos = pos = _pos; team = _team; turnCounter = 0; enable = true; beforeFigure = _before; id = idCounter++; }
bool LoadGame() { if (!File.Exists(Application.persistentDataPath + "/GameInfo.dat")) { return(false); } BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/GameInfo.dat", FileMode.Open); SaveInfo saveData = (SaveInfo)bf.Deserialize(file); file.Close(); figures = new ChessFigure[height, width]; figuresParent = new GameObject("Figures"); defeatedWhiteFiguresParent = new GameObject("Defeated white figures"); float x = ((width + 1) / 2f) * startSize * scale / 100f; float y = ((height - 1) / 2f) * startSize * scale / 100f; defeatedWhiteFiguresParent.transform.position = new Vector3(x, y, 0); defeatedBlackFiguresParent = new GameObject("Defeated black figures"); x = ((-width - 1) / 2f) * startSize * scale / 100f; y = ((height - 1) / 2f) * startSize * scale / 100f; defeatedBlackFiguresParent.transform.position = new Vector3(x, y, 0); for (int i = 0; i < saveData.figures.Count; i++) { SaveFigure temp = saveData.figures[i]; if (temp.enable) { figures[temp.posX, temp.posY] = GetFromListSaveFifures(temp, figuresParent.transform); } else if (temp.team == TypeTeam.white) { defeatedWhiteFigures.Add(GetFromListSaveFifures(temp, defeatedWhiteFiguresParent.transform)); } else { defeatedBlackFigures.Add(GetFromListSaveFifures(temp, defeatedBlackFiguresParent.transform)); } } presentTeam = saveData.presentTeam; becomeKingFigure = FindFigure(saveData.idBecomeKingFigure); for (int i = saveData.states.Count - 1; i >= 0; i--) { stateManager.AddState(saveData.states[i]); } return(true); }
void CreateOneTeamChess(GameObject[] chessType, Transform parent, TypeTeam team) { //Init powns for (int i = 0; i < width; i++) { CreateFigure(chessType[0], team == TypeTeam.white ? height - 2 : 1, i, parent, team); } //Init other all for (int i = 0; i < width; i++) { CreateFigure(chessType[i < 5 ? i + 1 : 8 - i], team == TypeTeam.white ? height - 1 : 0, i, parent, team); } }
void TurnOn(Vector2Int turnPos, ChessFigure chessFigure = null) { //Debug.Log("Turn"); TypeFigures defeatedType = TypeFigures.Pawn; if (chessFigure != null) { defeatedType = chessFigure.type; PullToRetreat(chessFigure); } stateManager.AddState(activeFigure); if (activeFigure.type == TypeFigures.Pawn && defeatedType != TypeFigures.King) { if ((activeFigure.team == TypeTeam.white && turnPos.x == 0) || (activeFigure.team == TypeTeam.black && turnPos.x == height - 1)) { pawnReadyBecomeKing = true; becomeKingFigure = activeFigure; uiManager.ActiveChooseUI(becomeKingFigure.team, ExchangeFigure); activeUI = true; } } Vector2Int beforePos = activeFigure.pos; Vector3 position = boardsTile[turnPos.x, turnPos.y].transform.position; position.z = 0; //activeFigure.transform.position = position; activeFigure.AnimateTurn(position, speedAnimation, chessFigure != null ? TypeAnimation.Hit : TypeAnimation.Step); activeFigure.pos = new Vector2Int(turnPos.x, turnPos.y); activeFigure.turnCounter++; figures[turnPos.x, turnPos.y] = activeFigure; figures[beforePos.x, beforePos.y] = null; activeFigure.DischooseFigure(); activeFigure = null; DischoosingTile(); if (defeatedType == TypeFigures.King) { gameEnd = true; uiManager.EnableGameOver(); } presentTeam = presentTeam == TypeTeam.black ? TypeTeam.white : TypeTeam.black; //FlipBoard(); }
void CreateFigure(GameObject chessType, int posY, int posX, Transform parent, TypeTeam team, bool _before = false) { GameObject figure = Instantiate(chessType, parent); Vector3 position = boardsTile[posY, posX].transform.position; position.z = 0; figure.transform.position = position; figure.transform.localScale = new Vector3(scale * .8f, scale * .8f, 1); ChessFigure tempChess = figure.GetComponent <ChessFigure>(); tempChess.Init(new Vector2Int(posY, posX), team, _before); tempChess.OnClick += ChooseTurn; figures[posY, posX] = tempChess; }
public void ActiveChooseUI(TypeTeam team, EventExchangeFigure exchangeMethod) { panelForChoose.SetActive(true); for (int i = 0; i < buttons.Length; i++) { imageButtons[i].sprite = team == TypeTeam.white ? whiteFigureSprites[i] : blackFigureSprites[i]; SpriteState sprites = new SpriteState(); sprites.highlightedSprite = sprites.pressedSprite = team == TypeTeam.white ? whiteChooseFigureSprites[i] : blackChooseFigureSprites[i]; buttons[i].spriteState = sprites; method = exchangeMethod; //buttons[i].onClick.AddListener(delegate { BecomeKing(i); }); } }
public void SetBackground(TypeTeam team) { Color color = team == TypeTeam.white ? blueTeamColor : greenTeamColor; iTween.ColorTo(background, iTween.Hash("color", color, "time", 1.5f, "includechildren", true, "easetype", iTween.EaseType.easeInOutSine)); /*for (int i = 0; i < height * 2; i++) * { * for (int j = 0; j < width * 2; j++) * { * Color color = team == TypeTeam.white ? blueTeamColor : greenTeamColor; * iTween.ColorTo(tiles[i, j].gameObject, iTween.Hash("color", color, "time", 1.5f, "easetype", iTween.EaseType.easeInOutSine)); * } * }*/ }