Ejemplo n.º 1
0
 /// <summary>
 /// Update the tile if it is not locked, if it is lock, return the tile.
 /// </summary>
 /// <param name="tile"></param>
 /// <param name="color"></param>
 /// <returns></returns>
 public BoardTile UpdateTile(BoardTile tile, int color)
 {
     if (!IsTileLocked(tile))
     {
         return(Tiles.SingleOrDefault(t => t.X == tile.X && t.Y == tile.Y).SetColor(color));
     }
     else
     {
         return(GetTile(tile));
     }
 }
Ejemplo n.º 2
0
        public Player MovePlayer(BoardTile tile, BoardDirection direction)
        {
            var curPlayer = GetCurrentPlayer();
            var oldPos    = curPlayer.Position;
            // curPlayer.Position = tile;
            var othPlayer = PlayerList.GetAll().SingleOrDefault(plyr => plyr.Position.X == tile.X && plyr.Position.Y == tile.Y);

            if (othPlayer != null)
            {
                othPlayer.Position        = oldPos;
                othPlayer.FacingDirection = Utilities.Opposite(direction);
            }
            curPlayer.Position        = tile;
            curPlayer.FacingDirection = direction;
            curPlayer.MoveLeft       -= 1;
            return(curPlayer);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update the player position and update the Board
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        public Player MovePlayer(GameClient sender, BoardDirection direction, out bool success)
        {
            var player = PlayerManager.GetCurrentPlayer();

            success = false;
            if (IsCurrentPlayerCage())
            {
                return(player);
            }
            if (player.GetIdentifier() != sender.Character.Token)
            {
                return(null);
            }
            var       position = player.Position;
            BoardTile tile     = Utilities.ProcessDPad(position, direction, player.Effect);

            if (tile.X > 7 || tile.X < 0 || tile.Y > 7 || tile.Y < 0 || player.MoveLeft == 0)
            {
                player.Client.SendError("Invalid move");
                return(player);
            }
            // Get a copy
            if (Board.IsTileInaccessible(tile))
            {
                player.Client.SendError("Inaccessible tile");
                return(player);
            }
            // Update the Board Tile
            BoardTile boardTile = Board.UpdateTile(tile, player.PlayerColor);

            // Update player position
            player = PlayerManager.MovePlayer(boardTile, direction);
            Log.Debug("After: {0} {1}", player.Position.X, player.Position.Y);
            success = true;
            return(player);
        }
Ejemplo n.º 4
0
        public bool HandleUseItem(CmdTurnPlayerUseItem packet, out BoardTile tile)
        {
            tile = PlayerManager.GetCurrentPlayer().Position;
            if (!IsCurrentPlayerCage())
            {
                if (PlayerManager.GetCurrentPlayer().UseItem(packet.Item.Item))
                {
                    Player    curPlayer  = PlayerManager.GetCurrentPlayer();
                    BoardTile playerTile = curPlayer.Position;
                    Player    victim;
                    BoardTile targetTile = packet.Tile;
                    switch ((ItemType)packet.Item.Item)
                    {
                    case ItemType.Crown:
                        Board.Crown(curPlayer);
                        break;

                    case ItemType.Bed:
                        curPlayer.Position = Board.GetSpawn(curPlayer.PlayerColor);
                        break;

                    case ItemType.BoulderSpike:
                        victim          = PlayerManager.GetPlayers().SingleOrDefault(plyr => plyr.GetIdentifier() == packet.Victim);
                        victim.Position = Board.GetSpawn(victim.PlayerColor);
                        break;

                    case ItemType.Cage:
                        victim        = PlayerManager.GetPlayers().SingleOrDefault(plyr => plyr.GetIdentifier() == packet.Victim);
                        victim.Effect = ItemType.Cage;
                        break;

                    case ItemType.Coin:
                        curPlayer.MoveLeft += 2;
                        break;

                    case ItemType.Door:
                        curPlayer.Position = Board.UpdateTile(targetTile, curPlayer.PlayerColor);
                        tile = curPlayer.Position;
                        break;

                    case ItemType.Flag:
                        BoardTile flagTile = Board.UpdateTile(targetTile, curPlayer.PlayerColor);
                        tile = flagTile;
                        // Assign random tile
                        break;

                    case ItemType.GroundSpike:
                        BoardTile spikeTile = Board.SetInaccessible(targetTile);
                        tile = spikeTile;
                        break;

                    case ItemType.Lock:
                        Board.LockTile(curPlayer.PlayerColor);
                        break;

                    case ItemType.Pillar:
                        // Need debugging
                        Board.Pillar(curPlayer);
                        break;

                    case ItemType.SelfDestruct:
                        Board.SelfDestruct(curPlayer);
                        break;

                    case ItemType.WizardHat:
                        victim = PlayerManager.GetPlayers().SingleOrDefault(plyr => plyr.GetIdentifier() == packet.Victim);
                        BoardTile temp = victim.Position;
                        victim.Position    = curPlayer.Position;
                        curPlayer.Position = Board.UpdateTile(temp, curPlayer.PlayerColor);
                        tile = curPlayer.Position;
                        break;
                    }
                    return(true);
                }
                else
                {
                    PlayerManager.GetCurrentPlayer().Client.SendError("Item not found in inventory.");
                    return(false);
                }
            }
            else
            {
                PlayerManager.GetCurrentPlayer().Client.SendError("Unable to use item due to cage.");
                return(false);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Get the tile from the board given the tile x and y axis
 /// </summary>
 /// <seealso cref="GetTile(int, int)"/>
 /// <param name="tile"></param>
 /// <returns></returns>
 public BoardTile GetTile(BoardTile tile)
 {
     return(GetTile(tile.X, tile.Y));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Set the particular tile to be inaccessible
 /// </summary>
 /// <param name="tile"></param>
 /// <returns></returns>
 public BoardTile SetInaccessible(BoardTile tile)
 {
     return(Tiles.SingleOrDefault(t => t.X == tile.X && t.Y == tile.Y).SetInaccessible(true));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Check if a particular tile is inaccessible
 /// </summary>
 /// <param name="tile"></param>
 /// <returns></returns>
 public bool IsTileInaccessible(BoardTile tile)
 {
     return(GetTile(tile).IsInaccessible());
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Check if a particular tile is locked
        /// </summary>
        /// <param name="tile"></param>
        /// <returns></returns>
        public bool IsTileLocked(BoardTile tile)
        {
            var tileSelected = GetTile(tile);

            return(Tiles.Where(selectTile => selectTile.Color == tileSelected.Color).Where(selectTile => selectTile.IsLocked() == true).Count() > 0);
        }