private void ApplyRotateRestriction() { if (RotationType.STATIC != rotationType) { if (RotationType.TWO_DIMENSION == rotationType) { if (angle == 0) { desiredAngle = +90; } else { rotateBack = true; desiredAngle = 0; } } else if (RotationType.FREE_ROTATE == rotationType) { desiredAngle -= 90; } SetFigureTrigger(true); state = FigureState.Rotation; deltaH = gameObject.transform.position.y; ScriptManager.SoundController.PlaySound(SoundController.SoundAction.Rotate); } }
private async void MoveY() { while (_state == FigureState.Mooving) { await Task.Delay(_field.GetDelay() * 100); try { foreach (var mini in _miniCubes) { if (_field.GetCubes()[new Vector2Int(mini.GetPosition().x, mini.GetPosition().y - 1)] != null) { State = FigureState.Idle; break; } } } catch (KeyNotFoundException k) { } if (_state == FigureState.Idle) { break; } foreach (var mini in _miniCubes) { mini.transform.position += Vector3.down; mini.SetNewPosition(new Vector2Int((int)mini.transform.position.x, (int)mini.transform.position.y)); } } }
public FieldController(int _fieldWidth, int _fieldHeight, Transform _container) { fieldWidth = _fieldWidth; fieldHeight = _fieldHeight; container = _container; storedCubes = new List <Cube>(); State = new FigureState(); }
public Wawka(sbyte team, Point position, bool damka) { this.position = position; state = FigureState.usuall; if (damka) { state = FigureState.damka; } this.team = team; }
public FigureState GetState() { FigureState fs = new FigureState() { color = this.color, field = this.field, moveCount = this.moveCount, type = this.type }; return fs; }
protected void CheckFalled() { if (ScriptManager.BoardController.CanNotMoveDown(gameObject)) { state = FigureState.Stopped; ResetFigureTags(); Destroy(this); ScriptManager.SoundController.PlaySound(SoundController.SoundAction.Falling); ScriptManager.GameController.Respawn(); } }
/// <summary> /// 改變人物指定狀態的類別,傳回原先狀態 /// (沒輸入則直接回傳目前狀態不改變原先狀態) /// 數字溢位則回傳Null /// </summary> /// <param name="_newState"></param> public FigureState ChangeState(FigureState _newState, int _type) { if (_newState == null) { return(myStateList[_type]); } if (_type > myStateList.Length) { return(null); } return(myStateList[_type]); }
void SaveGame() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/GameInfo.dat"); SaveInfo saveData = new SaveInfo(); if (gameEnd || figures == null) { saveData.saved = false; bf.Serialize(file, saveData); file.Close(); } for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (figures[i, j] != null) { AddToListSaveFigures(figures[i, j], saveData); } } } for (int i = 0; i < defeatedBlackFigures.Count; i++) { AddToListSaveFigures(defeatedBlackFigures[i], saveData); } for (int i = 0; i < defeatedWhiteFigures.Count; i++) { AddToListSaveFigures(defeatedWhiteFigures[i], saveData); } if (becomeKingFigure != null) { saveData.idBecomeKingFigure = becomeKingFigure.id; } else { saveData.idBecomeKingFigure = -1; } saveData.presentTeam = presentTeam; saveData.saved = true; saveData.states.Clear(); while (stateManager.HaveElementInStack()) { FigureState temp = stateManager.GetState(); saveData.states.Add(temp); } bf.Serialize(file, saveData); file.Close(); }
private void FullEmptySpace(FigureState state, Figure figure) { if (state == FigureState.Idle) { foreach (var mini in figure.MiniCubes) { _model.Cubes[new Vector2Int(mini.GetPosition().x, mini.GetPosition().y)] = mini.gameObject; } } CheckForFull(); CreateFigure(); }
private void handle_figure_state_changed(InteractiveFigure figure, FigureState state) { if (state == FigureState.Closed) { int index = this.FiguresTyped.FindIndex((x) => figure == x); if (index >= 0) { this.FiguresTyped.RemoveAt(index); if (this.ActiveFigureIndex >= index) { this.ActiveFigureIndex = Math.Max(this.ActiveFigureIndex - 1, this.FiguresTyped.Count - 1); } figure.StateChange -= handle_figure_state_changed; } } }
void PerformMoveRight() { Vector2 position = gameObject.transform.position; if (position.x < desiredPosX) { position.x += DELTA_X; gameObject.transform.position = position; } else { position.x = desiredPosX; gameObject.transform.position = position; state = FigureState.Idle; } }
void StopRotation() { SetFigureTrigger(false); state = FigureState.Idle; //BoardGizmos.ClearLog (); float delta = deltaH - gameObject.transform.position.y; if (delta > maxDeltaH) { maxDeltaH = delta; } if (delta < minDeltaH) { minDeltaH = delta; } //Debug.Log ("max=" + maxDeltaH + " min=" + minDeltaH); }
/// <summary> /// 抽換指定的狀態 /// </summary> /// <param name="_stateIndex"></param> public void ChangeState(FigureStateEnum _stateEnum) { //狀態枚舉 int stateIndex = (int)_stateEnum; //過濾不合理情況 if (myStateList.Length < (int)_stateEnum) { return; } if (myStateList[stateIndex] == null) { return; } //如前後一樣也無視 if (currentStateEnum == _stateEnum) { return; } //新的狀態 FigureStateEnum newEnum = _stateEnum; FigureState newState = myStateList[(int)_stateEnum]; //替換掉舊的監聽者 if (currentState != null) { currentState.Exit(); RemoveActionListener = currentState; RemoveCombatListener = currentState; RemoveValueListener = currentState; } //更換成新的 currentState = newState; currentStateEnum = newEnum; currentState.Start(); AddActionListener = currentState; AddValueListener = currentState; AddCombatListener = currentState; }
/// <summary> /// 初始化狀態 /// </summary> protected virtual void InitialState() { int index = 0; FigureStateEnum[] figureStateEnum = Enum.GetValues(typeof(FigureStateEnum)) as FigureStateEnum[]; myStateList = new FigureState[figureStateEnum.Length]; foreach (FigureStateEnum _states in figureStateEnum) { var stateString = _states.ToString(); Type stateType = Type.GetType(stateString); var stateObject = Activator.CreateInstance(stateType) as FigureState; stateObject.Figure = this; if (stateObject == null) { MyLog.Log(" state : " + stateString + " is null"); break; } myStateList[index++] = stateObject; } //initial state is normal state ChangeState((int)FigureStateEnum.NormalState); }
IEnumerator BackToTheStart() { speed = 1f; while (stateManager.HaveElementInStack()) { FigureState tempState = stateManager.GetState(); ChessFigure tempFigure = FindFigure(tempState.id); bool destroy = tempState.numberTurn == 0 && tempState.beforeFigure; tempFigure.AnimateTurn(new Vector3(tempState.positionX, tempState.positionY, tempState.positionZ), speed, TypeAnimation.Back, destroy); //Debug.Log("coroutine" + Time.time); yield return(new WaitForSeconds(speed)); if (speed >= .1f) { speed *= .9f; } } ReInitGame(); //есть лишнее }
void Update() { if (FigureState.Stopped == state) { return; } // Level menu invokation if (Input.GetKeyDown(KeyCode.Escape)) { ScriptManager.GameController.PauseResume(); } if (isPause) { return; } if (FigureState.MoveDownFast == state) { CheckFalled(); PerformTransformation(); return; } if (FigureState.Idle == state || FigureState.MoveDown == state) { CheckFalled(); if (Input.GetKey(KeyCode.LeftArrow)) { if (ScriptManager.BoardController.CanMoveLeft(gameObject)) { Vector2 pos = gameObject.transform.position; desiredPosX = pos.x - BoardController.BRICK_SIZE; state = FigureState.MoveLeft; } } else if (Input.GetKey(KeyCode.RightArrow)) { if (ScriptManager.BoardController.CanMoveRight(gameObject)) { Vector2 pos = gameObject.transform.position; desiredPosX = pos.x + BoardController.BRICK_SIZE; state = FigureState.MoveRight; } } else if (Input.GetKey(KeyCode.UpArrow)) { if (FigureState.Idle == state && ScriptManager.BoardController.CanRotate(gameObject)) { ApplyRotateRestriction(); } } else if (Input.GetKey(KeyCode.DownArrow)) { if (ScriptManager.BoardController.CanMoveDown(gameObject)) { state = FigureState.MoveDown; } } else if (Input.GetKeyUp(KeyCode.DownArrow)) { if (FigureState.MoveDown == state) { state = FigureState.Idle; } } else if (Input.GetKeyDown(KeyCode.Space)) { if (ScriptManager.BoardController.CanMoveDown(gameObject)) { state = FigureState.MoveDownFast; } } } PerformTransformation(); }
public Wawka(sbyte team, Point position) { this.position = position; state = FigureState.usuall; this.team = team; }
public Wawka(sbyte team) { position = new Point(0, 0); state = FigureState.usuall; this.team = team; }
public Wawka() { position = new Point(0, 0); state = FigureState.usuall; team = 0; }
public void AddState(FigureState figure) { states.Push(figure); //Debug.Log(figure.type.ToString() + " " + states.Peek().position + " " + states.Peek().numberTurn); }
void BaseImperativeFigure_StateChanged(InteractiveFigure arg1, FigureState arg2) { this.State = arg2; }