public void Turn(Game.direction_type direction) { if (IsOppositeDirection(direction)) { return; } this.direction = direction; }
//初始 public void Init() { body.Clear(); //加入預設的節點 Node node; for (int i = 0; i < 5; i++) { node = new Node(); node.row = 5; node.col = 3 + i; AddNode(node); } direction = Game.direction_type.RIGHT; }
// 玩家輸入 void PlayerInput() { if (Input.GetKeyUp(KeyCode.DownArrow)) { key_direction = Game.direction_type.DOWN; } if (Input.GetKeyUp(KeyCode.UpArrow)) { key_direction = Game.direction_type.UP; } if (Input.GetKeyUp(KeyCode.RightArrow)) { key_direction = Game.direction_type.RIGHT; } if (Input.GetKeyUp(KeyCode.LeftArrow)) { key_direction = Game.direction_type.LEFT; } }
private bool IsOppositeDirection(Game.direction_type another) { return(direction + 2 == another || direction == another + 2); }