private BattleData() { mapTotalGrid = mapRow * mapColumn; mapWidth = mapColumn * gridLenth; mapHeigh = mapRow * gridLenth; curOperationID = 1; selfOperation = new PlayerOperation(); selfOperation.move = 121; ResetRightOperation(); dic_speed = new Dictionary <int, GameVector2> (); //初始化速度表 GlobalData.Instance().GetFileStringFromStreamingAssets("Desktopspeed.txt", _fileStr => { InitSpeedInfo(_fileStr); }); curFramID = 0; maxFrameID = 0; maxSendNum = 5; lackFrame = new List <int> (); dic_rightOperationID = new Dictionary <int, int> (); dic_frameDate = new Dictionary <int, AllPlayerOperation> (); }
void CheckTriggerForPlayer(Collider other, PlayerOperation operation) { Player player = other.GetComponent <Player>(); bool contains = players.Contains(player); if (player) { switch (operation) { case PlayerOperation.addPlayer: if (!contains) { players.Add(player); } break; case PlayerOperation.removePlayer: if (contains) { players.Remove(player); } break; } } }
private BattleData() { curOperationID = 1; SelfOperation = new PlayerOperation(); curFrameID = 0; maxFrameID = 0; maxSendNum = 5; lackFrame = new List <int>(); dic_frameData = new Dictionary <int, AllPlayerOperation>(); }
public PlayerOperation ClonePlayerOperation() { PlayerOperation _operation = new PlayerOperation(); _operation.battleID = BattleData.Instance.selfOperation.battleID; _operation.move = BattleData.Instance.selfOperation.move; _operation.operationID = BattleData.Instance.selfOperation.operationID; _operation.rightOperation = BattleData.Instance.selfOperation.rightOperation; _operation.operationValue1 = BattleData.Instance.selfOperation.operationValue1; _operation.operationValue2 = BattleData.Instance.selfOperation.operationValue2; return(_operation); }
public void UpdatePlayerOperation(PlayerOperation _op, int _msgNum) { int _index = _op.BattleID; if (_msgNum > playerMsgNum[_index]) // 如果消息ID小于客户端,则服务器丢帧,赋值补足 { frameOperation[_index] = _op; playerMsgNum[_index] = _msgNum; } else { // 早期的包就不记录了 } }
public void UpdatePlayerOperation(PlayerOperation _operation, int _mesNum) { int _index = _operation.battleID - 1; // LogManage.Instance.AddLog ("收到玩家操作:" + _index + "," + _mesNum + "," + playerMesNum [_index]); if (_mesNum > playerMesNum [_index]) { frameOperation [_index] = _operation; playerMesNum [_index] = _mesNum; } else { //早期的包就不记录了 } }
void Logic_HandleInput(RoleBase role, PlayerOperation op) { switch (op.Keyinput) { case "A": role.Logic_MoveLeft(); break; case "W": role.Logic_MoveUp(); break; case "D": role.Logic_MoveRight(); break; case "S": role.Logic_MoveDown(); break; default: break; } }
/// <summary> /// Operate the move according to Operation o and dynamic info. /// </summary> /// <param name="o">Movement</param> /// <param name="info">Dynamic info</param> /// <returns>Whether the operation is available.</returns> public bool PlayerOperate(PlayerOperation o, BoardInfo info) { // Prepare variables. int rowNum = RowNum; int columnNum = ColumnNum; int playerX = info.Player.X; int playerY = info.Player.Y; int nxtY = -1; int nxtX = -1; int altY = -1; int altX = -1; bool hasAlternateGrid = false; switch (o) { case PlayerOperation.Up: { if (playerY == 0) { return(false); } nxtY = playerY - 1; nxtX = playerX; altY = playerY - 2; altX = playerX; hasAlternateGrid = (playerY > 1); break; } case PlayerOperation.Down: { if (playerY == rowNum - 1) { return(false); } nxtY = playerY + 1; nxtX = playerX; altY = playerY + 2; altX = playerX; hasAlternateGrid = (playerY < rowNum - 2); break; } case PlayerOperation.Left: { if (playerX == 0) { return(false); } nxtY = playerY; nxtX = playerX - 1; altY = playerY; altX = playerX - 2; hasAlternateGrid = (playerX > 1); break; } case PlayerOperation.Right: { if (playerX == columnNum - 1) { return(false); } nxtY = playerY; nxtX = playerX + 1; altY = playerY; altX = playerX + 2; hasAlternateGrid = (playerX < columnNum - 2); break; } } // Logic Judgement. // next is brick if (GridMatrix[nxtY, nxtX] == GridType.Brick) { return(false); } // next is not brick else if (GridMatrix[nxtY, nxtX] == GridType.Ground || GridMatrix[nxtY, nxtX] == GridType.Target) { if (!hasAlternateGrid) { throw new Exception("Map data invalid error."); } if (GridMatrix[altY, altX] == GridType.OutSide) { throw new Exception("Map data invalid error."); } // Search if there is a box to move. foreach (var box in info.Boxes) { if (nxtY == box.Y && nxtX == box.X) { // alternate grid is brick if (GridMatrix[altY, altX] == GridType.Brick) { return(false); } else { // if alternate grid has a box, cannot move. foreach (var boxB in info.Boxes) { if (boxB.Y == altY && boxB.X == altX) { return(false); } } // now the box could be moved. box.Y = altY; box.X = altX; break; } } } ; // Move the player. info.Player.Y = nxtY; info.Player.X = nxtX; return(true); } // wrong GameState else { throw new Exception("Map Data damaged."); } }
public UdpUpPlayerOperation(int _mid, PlayerOperation _op) : base() { MsgID = _mid; PlayerOperation = _op; }