Exemplo n.º 1
0
        public void PlayerThread()
        {
            while (true)
            {
                try
                {
                    byte[] buffer = new byte[1024];
                    int    length = clientScoket.Receive(buffer);
                    if (length > 0)
                    {
                        string   data = Encoding.UTF8.GetString(buffer);
                        string[] msgs = data.Split(';');
                        foreach (string msg in msgs)
                        {
                            string[] cmdTokens = msg.Split(' ');
                            switch (cmdTokens[0])
                            {
                            case "USRNAME":
                                name = cmdTokens[1];
                                Console.WriteLine(string.Format("[LOG]: {0} join the server.", name));
                                break;

                            case "MSG":
                                Console.WriteLine(string.Format("[LOG]: {0}: " + cmdTokens[1], name));
                                break;
                            }
                        }
                    }
                }
                catch
                {
                    PlayerExit?.Invoke(id);
                }
            }
        }
 public void OpenExit()
 {
     for (int i = 0; i < Level.MazeExits.Count; i++)
     {
         PlayerExit exit = Level.MazeExits[i];
         exit.OpenExit();
     }
 }
    // Loading a player exit for a tile, not creating a new one. We already have the connection score
    public void PlacePlayerExit(ObstacleType obstacleType, TileConnectionScoreInfo obstacleConnectionScoreInfo)
    {
        PlayerExit playerExit = (PlayerExit)InstantiateTileAttributeGO <PlayerExit>();

        playerExit.WithObstacleType(obstacleType);
        playerExit.WithConnectionScoreInfo(obstacleConnectionScoreInfo);

        Tile.SetWalkable(false);
        Tile.TryMakeMarkable(false);
        Tile.AddAttribute(playerExit);
    }
    public void RemovePlayerExit(PlayerExit playerExit = null)
    {
        if (playerExit == null)
        {
            playerExit = (PlayerExit)_tile.GetAttributes().FirstOrDefault(attribute => attribute is PlayerExit);
        }

        if (playerExit == null)
        {
            return;
        }

        _tile.SetWalkable(true);

        ObstacleType obstacleType = playerExit.ObstacleType;

        _tile.RemoveAttribute(playerExit);
        playerExit.Remove();

        UpdateNeighboursForRemovedObstacle(obstacleType);
    }
Exemplo n.º 5
0
 public void InvokePlayerExit(PlayerExit exit)
 {
     OnPlayerExit.Invoke(exit);
 }
Exemplo n.º 6
0
    private ISerialisableTileAttribute CreateSerialisableTileAttribute(Tile tile, ITileAttribute tileAttribute)
    {
        if (tileAttribute.GetType() == typeof(TileObstacle))
        {
            TileObstacle tileObstacle = tileAttribute as TileObstacle;
            SerialisableTileObstacleAttribute serialisableTileObstacleAttribute =
                new SerialisableTileObstacleAttribute(
                    new TileConnectionScoreInfo(tileObstacle.ConnectionScore, tileObstacle.SpriteNumber));
            return(serialisableTileObstacleAttribute);
        }
        else if (tileAttribute.GetType() == typeof(PlayerExit))
        {
            PlayerExit playerExit = tileAttribute as PlayerExit;

            SerialisablePlayerExitAttribute serialisablePlayerExitAttribute = new SerialisablePlayerExitAttribute(
                new TileConnectionScoreInfo(playerExit.ConnectionScore, playerExit.SpriteNumber));
            return(serialisablePlayerExitAttribute);
        }
        else if (tileAttribute.GetType() == typeof(PlayerOnly))
        {
            SerialisablePlayerOnlyAttribute serialisablePlayerOnlyAttribute = new SerialisablePlayerOnlyAttribute();
            return(serialisablePlayerOnlyAttribute);
        }
        else if (tileAttribute.GetType() == typeof(PlayerSpawnpoint))
        {
            SerialisablePlayerSpawnpointAttribute serialisablePlayerSpawnpointAttribute = new SerialisablePlayerSpawnpointAttribute();
            return(serialisablePlayerSpawnpointAttribute);
        }
        else if (tileAttribute.GetType() == typeof(EnemySpawnpoint))
        {
            EnemySpawnpoint enemySpawnpoint = tileAttribute as EnemySpawnpoint;
            SerialisableEnemySpawnpointAttribute serialisableEnemySpawnpointAttribute = new SerialisableEnemySpawnpointAttribute(enemySpawnpoint.TileAreas);
            return(serialisableEnemySpawnpointAttribute);
        }
        else if (tileAttribute.GetType() == typeof(MazeLevelEntry))
        {
            MazeLevelEntry mazeLevelEntry = tileAttribute as MazeLevelEntry;
            SerialisableMazeLevelEntryAttribute serialisableMazeLevelEntryAttribute = new SerialisableMazeLevelEntryAttribute(mazeLevelEntry.MazeLevelName);
            return(serialisableMazeLevelEntryAttribute);
        }
        else if (tileAttribute.GetType() == typeof(BridgePiece))
        {
            BridgePiece          bridgePiece          = tileAttribute as BridgePiece;
            BridgePieceDirection bridgePieceDirection = bridgePiece.BridgePieceDirection;

            SerialisableBridgePieceAttribute serialisableBridgePieceAttribute = new SerialisableBridgePieceAttribute(bridgePieceDirection);
            return(serialisableBridgePieceAttribute);
        }
        else if (tileAttribute.GetType() == typeof(BridgeEdge))
        {
            BridgeEdge bridgeEdge = tileAttribute as BridgeEdge;

            SerialisableBridgeEdgeAttribute serialisableBridgeEdgeAttribute = new SerialisableBridgeEdgeAttribute(bridgeEdge.EdgeSide);
            return(serialisableBridgeEdgeAttribute);
        }
        else if (tileAttribute.GetType() == typeof(MusicInstrumentCase))
        {
            SerialisableMusicInstrumentCaseAttribute serialisableMusicInstrumentCaseAttribute = new SerialisableMusicInstrumentCaseAttribute();
            return(serialisableMusicInstrumentCaseAttribute);
        }
        else
        {
            Logger.Error($"Could not serialise the tile attribute {tileAttribute.GetType()}");
            return(null);
        }
    }