public static void UpdateBlockType(this CellDto cell, BlockType newType)
 {
     cell.BlockType = newType;
     cell.Type      = newType == BlockType.Empty ?
                      cell.CellType.ToString().ToLower() :
                      cell.BlockType.ToString().ToLower();
     if (cell.CellType == CellType.Target && cell.BlockType == BlockType.Box)
     {
         cell.Type = "boxOnTarget";
     }
 }
Beispiel #2
0
        public GameDto GetDto()
        {
            var cells = new CellDto[SizeX * SizeY];
            int index = 0;

            for (var i = 0; i < SizeX; i++)
            {
                for (var j = 0; j < SizeY; j++)
                {
                    cells[index++] = new CellDto(
                        index.ToString(),
                        new Vec(i, j),
                        Palette[Content[i, j]],
                        "",
                        0);
                }
            }
            return(new GameDto(cells,
                               true,
                               true, SizeX,
                               SizeY, id,
                               false,
                               Score));
        }
        public static void MovePlayer(this GameDto game, Vec movement)
        {
            CellDto fromCell = game.GetPlayer();

            if (fromCell != null)
            {
                Vec     newPosition = fromCell.Pos + movement;
                CellDto toCell      = game.GetCellByPosition(newPosition);
                if (toCell != null)
                {
                    switch (toCell.BlockType)
                    {
                    case BlockType.Empty:
                        toCell.UpdateBlockType(BlockType.Player);
                        fromCell.UpdateBlockType(BlockType.Empty);
                        toCell.Id   = fromCell.Id;
                        fromCell.Id = (next++).ToString();
                        break;

                    case BlockType.Box:
                        Vec     nextPosition = newPosition + movement;
                        CellDto nextCell     = game.GetCellByPosition(nextPosition);
                        if (nextCell != null && nextCell.BlockType == BlockType.Empty)
                        {
                            nextCell.UpdateBlockType(BlockType.Box);
                            toCell.UpdateBlockType(BlockType.Player);
                            fromCell.UpdateBlockType(BlockType.Empty);
                            nextCell.Id = toCell.Id;
                            toCell.Id   = fromCell.Id;
                            fromCell.Id = (next++).ToString();
                        }
                        break;
                    }
                }
            }
        }