public IEnumerable <CellPoint> GetSelectPoints(string input)
        {
            var cellVals = input.Split(" ");

            if (cellVals.Length % 2 != 0)
            {
                throw new SpreadSheetException("字符串的格式不正确,插入的值必须为2的备注");
            }
            var result      = new List <CellPoint>();
            var pointGroups = cellVals.CutArrayForAppointCount(2);

            foreach (var group in pointGroups)
            {
                if (!int.TryParse(group[0], out int x))
                {
                    throw new SpreadSheetException("cell的x坐标必须为整数");
                }

                if (!int.TryParse(group[1], out int y))
                {
                    throw new SpreadSheetException("cell的y坐标必须为整数");
                }
                var point = new CellPoint(x, y);
                result.Add(point);
            }
            return(result);
        }
Beispiel #2
0
        private CheckerMove[] SearchMoveAround(byte x, byte y, CellState[][] field, Team team)
        {
            var possibleMoves = new List <CheckerMove>();

            foreach (var i in _dx)
            {
                foreach (var j in _dy)
                {
                    if (CanMove(x, y, i, j, field, team))
                    {
                        var step = 1;

                        do
                        {
                            possibleMoves.Add(new CheckerMove
                            {
                                FromPoint = new CellPoint(x, y),
                                ToPoint   = new CellPoint((byte)(x + step * i), (byte)(y + step * j))
                            });

                            step++;
                        } while (IsQueen(field[y][x]) &&
                                 CellPoint.IsValidCellPoint(x + step * i, y + step * j) &&
                                 IsEmptyCell(field[y + step * j][x + step * i]));
                    }
                }
            }

            return(possibleMoves.ToArray());
        }
Beispiel #3
0
        public void ComparerTest()
        {
            var         cells    = maze.GetCells();
            List <Cell> allCells = new List <Cell>();

            foreach (var rows in cells)
            {
                allCells.AddRange(rows);
            }
            allCells = allCells.OrderBy(x => x.location, CellPoint.GetInstance()).ToList();

            Cell[][] sortedCells = new Cell[cells.Length][];
            for (int i = 0; i < sortedCells.Length; ++i)
            {
                sortedCells[i] = allCells.Skip(i * cells.Length).Take(cells.Length).ToArray();
            }

            for (int row = 0; row < cells.Length; ++row)
            {
                for (int col = 0; col < cells[0].Length; ++col)
                {
                    if (cells[row][col].location != sortedCells[row][col].location)
                    {
                        Assert.Fail();
                    }
                }
            }
        }
 private void MakeAliveOrDead(CellPoint item)
 {
     _current[item.Point.X, item.Point.Y] =
         item.CellState == CellState.SPAWNING ||
         item.CellState == CellState.ALIVE
                         ? CellState.ALIVE
                         : CellState.DEAD;
 }
Beispiel #5
0
 // c'tors
 public ViewCell()
 {
     this.Color = CellColor.LightGray;
     this.Point = new CellPoint()
     {
         X = 0, Y = 0
     };
 }
 private CellPoint desPoint;         //目标位置
 public FinishChargePacket(byte serialNum, ushort agvId, CellPoint desPoint)
 {
     this.Header    = 0xAA55;
     this.Len       = NeedLen();
     this.SerialNum = serialNum;
     this.Type      = (byte)PacketType.FinishCharge;
     this.AgvId     = agvId;
     this.desPoint  = desPoint;
 }
        public static Coordinate GetNewCoordinateByDegree(CellPoint centerCirclePoint, int xCoorFacotr, double radious, double degree)
        {
            Coordinate coor = new Coordinate();

            coor.X = Convert.ToInt32(Math.Round(centerCirclePoint.cellPointCoor.X + (Convert.ToDouble(radious * xCoorFacotr) * Math.Cos(CommonMethods.ConvertToRadians(degree)))));
            coor.Y = Convert.ToInt32(Math.Round(centerCirclePoint.cellPointCoor.Y + (Convert.ToDouble(radious * xCoorFacotr) * Math.Sin(CommonMethods.ConvertToRadians(degree)))));

            return(coor);
        }
Beispiel #8
0
 public CellPoint(CellPoint poUInt32)
 {
     if (poUInt32 == null)
     {
         return;
     }
     this.x = poUInt32.x;
     this.y = poUInt32.y;
 }
Beispiel #9
0
        public override bool Equals(object obj)
        {
            if ((obj == null) || !GetType().Equals(obj.GetType()))
            {
                return(false);
            }
            CellPoint p = (CellPoint)obj;

            return((X == p.X) && (Y == p.Y));
        }
Beispiel #10
0
 private void button1_Click_1(object sender, EventArgs e)
 {
     while (selectedCells.Count > 0)
     {
         CellPoint a = selectedCells[0];
         if (dataGridView1.Rows[a.rowPosition].Cells[a.colPosition].Selected)
         {
             dataGridView1.Rows[a.rowPosition].Cells[a.colPosition].Selected = false;
             selectedCells.Remove(a);
         }
     }
 }
Beispiel #11
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            CellPoint selectedCell = new CellPoint(dataGridView1.CurrentCell.RowIndex, dataGridView1.CurrentCell.ColumnIndex);

            if (!selectedCells.Contains(selectedCell))
            {
                selectedCells.Add(selectedCell);
            }
            foreach (CellPoint a in selectedCells)
            {
                if (!dataGridView1.Rows[a.rowPosition].Cells[a.colPosition].Selected)
                {
                    dataGridView1.Rows[a.rowPosition].Cells[a.colPosition].Selected = true;
                }
            }
        }
Beispiel #12
0
        public void SearchAttackMoves(byte x, byte y, CellState[][] field, Team team, CheckerMoveTreeNode parent)
        {
            parent.ChildMoves = new List <CheckerMoveTreeNode>();

            foreach (var i in _dx)
            {
                foreach (var j in _dy)
                {
                    var c = 1;
                    if (IsQueen(field[y][x]))
                    {
                        while (CellPoint.IsValidCellPoint(x + c * i, y + c * j) && IsEmptyCell(field[y + c * j][x + c * i]))
                        {
                            c++;
                        }
                    }

                    if (CheckAttackMove(x, y, i, j, c, field, team))
                    {
                        var step = 1;
                        do
                        {
                            var node = new CheckerMoveTreeNode
                            {
                                Move = new CheckerMove
                                {
                                    FromPoint = new CellPoint(x, y),
                                    ToPoint   = new CellPoint((byte)(x + (c + step) * i), (byte)(y + (c + step) * j))
                                }
                            };

                            SearchAttackMoves(
                                node.Move.ToPoint.X,
                                node.Move.ToPoint.Y,
                                RefreshedField(field, x, y, i, j, c, step),
                                team,
                                node);

                            parent.ChildMoves.Add(node);
                            step++;
                        } while (IsQueen(field[y][x]) &&
                                 CellPoint.IsValidCellPoint(x + (c + 1 * step) * i, y + (c + 1 * step) * j) &&
                                 IsEmptyCell(field[y + (c + 1 * step) * j][x + (c + 1 * step) * i]));
                    }
                }
            }
        }
Beispiel #13
0
 public void flush_src_infos()
 {
     foreach (var data in m_src_infos)
     {
         CellPoint     p        = data.Key;
         List <object> src_info = data.Value;
         StringBuilder sb       = new StringBuilder();
         for (int i = 0; i < src_info.Count; i++)
         {
             if (i > 0)
             {
                 sb.Append(',');
             }
             sb.Append(src_info[i]);
         }
         m_sheet.Cells[p.row, p.col].Value = sb.ToString();
     }
 }
Beispiel #14
0
        private static bool CanMove(byte x, byte y, int dirrectionX, int dirrectionY, CellState[][] field, Team team)
        {
            var targetX = x + dirrectionX;
            var targetY = y + dirrectionY;

            if (!CellPoint.IsValidCellPoint(targetX, targetY) || !IsEmptyCell(field[targetY][targetX]))
            {
                return(false);
            }

            if (IsQueen(field[y][x]))
            {
                return(true);
            }

            return(team == Team.White && targetY < y ||
                   team == Team.Black && targetY > y);
        }
Beispiel #15
0
        private bool CheckAttackMove(byte x, byte y, int dirrectionX, int dirrectionY, int cofficient, CellState[][] field, Team team)
        {
            int victomCellX = x + cofficient * dirrectionX;
            int victomCellY = y + cofficient * dirrectionY;

            int nextCellX = victomCellX + 1 * dirrectionX;
            int nextCellY = victomCellY + 1 * dirrectionY;

            if (CellPoint.IsValidCellPoint(victomCellX, victomCellY) &&
                CellPoint.IsValidCellPoint(nextCellX, nextCellY))
            {
                if (IsEnemyChecker(field[victomCellY][victomCellX], team) &&
                    IsEmptyCell(field[nextCellY][nextCellX]))
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #16
0
    public void Add_val_by_pmid(string v_pmkey, string v_col_name, object v_val)
    {
        int col = m_header.get_col(v_col_name);

        if (col < 0)
        {
            ZFDebug.Error(string.Format("{0}中没找到名为{1}的列", m_sheet_name, v_col_name));
            return;
        }
        if (!pm_index.ContainsKey(v_pmkey))
        {
            ZFDebug.Error(string.Format("{0}中没找到名为{1}的主键", m_sheet_name, v_pmkey));
            return;
        }
        int       row = pm_index[v_pmkey];
        CellPoint cp  = new CellPoint(row, col);

        if (!m_src_infos.ContainsKey(cp))
        {
            m_src_infos.Add(cp, new List <object>());
        }
        m_src_infos[cp].Add(v_val);
    }
Beispiel #17
0
        private void LoadBuffer()
        {
            for (uint i = 0; i < SizeY; i++)
            {
                for (uint j = 0; j < SizeX; j++)
                {
                    Cell cell = cells[i, j];
                    if (cell == null)
                    {
                        continue;
                    }

                    cell.y = i;
                    cell.x = j;
                    field[i * SizeX + j] = new CellPoint {
                        x = j, y = i, color = cell.Color, textureLayer = cell.TextureLayer
                    };
                }
            }

            fixed(void *pointer = field)
            {
                GL.BindBuffer(GL.ARRAY_BUFFER, vbo);
                GL.BindTexture(GL.TEXTURE_2D_ARRAY, textureId);
                GL.TexImage3D(GL.TEXTURE_2D_ARRAY, 0, GL.RGBA8, 16, 16, CellTextureManager.Textures.Count, 0, GL.BGRA, GL.UNSIGNED_BYTE, IntPtr.Zero);
                for (int i = 0; i < CellTextureManager.Textures.Count; i++)
                {
                    CellTexture texture = CellTextureManager.Textures[i];
                    GL.TexSubImage3D(GL.TEXTURE_2D_ARRAY, 0, 0, 0, i, texture.Width, texture.Height, 1, GL.BGRA, GL.UNSIGNED_BYTE, texture.DataPointer);
                }
                GL.GenerateMipmap(GL.TEXTURE_2D_ARRAY);
                GL.BindTexture(GL.TEXTURE_2D_ARRAY, 0);
                GL.BufferData(GL.ARRAY_BUFFER, sizeof(CellPoint) * field.Length, pointer, GL.DYNAMIC_DRAW);
                GL.BindBuffer(GL.ARRAY_BUFFER, 0);
            }
        }
Beispiel #18
0
    private void setUpMap()
    {
        pixels = boardMap.GetPixels();
        int indexPixels = -1;

        cells = new Dictionary <string, Cell> ();

        float xOffset = (baseSize * boardMap.width) / 2;
        float yOffset = (baseSize * boardMap.height) / 2;

        for (int y = 0; y < boardMap.height; y++)
        {
            for (int x = 0; x < boardMap.width; x++)
            {
                indexPixels++;

                if (pixels [indexPixels] == Color.white)
                {
                    continue;
                }

                CellPoint up       = new CellPoint(x, y + 1);
                string    upKey    = up.x + ":" + up.y;
                CellPoint down     = new CellPoint(x, y - 1);
                string    downKey  = down.x + ":" + down.y;
                CellPoint left     = new CellPoint(x - 1, y);
                string    leftKey  = left.x + ":" + left.y;
                CellPoint right    = new CellPoint(x + 1, y);
                string    rightKey = right.x + ":" + right.y;

                int type = 0;

                if (cells.ContainsKey(upKey))
                {
                    type += 1;
                }
                if (cells.ContainsKey(downKey))
                {
                    type += 2;
                }
                if (cells.ContainsKey(leftKey))
                {
                    type += 4;
                }
                if (cells.ContainsKey(rightKey))
                {
                    type += 8;
                }

                //0: ALL, 1: RDL, 2: LUR, 3: RL, 4: URD, 5: RD, 6: UR, 7: R, 8: DLU,
                //9: DL, 10: UL, 11: L, 12: UD, 13: D, 14: U, 15: NONE

                string key  = x + ":" + y;
                Cell   cell = getCellByType((CellType)type);
                cell.transform.SetParent(transform);

                cell.transform.localPosition = new Vector3((x * baseSize), (y * baseSize), 0);

                cells.Add(key, cell);
            }
        }
    }
Beispiel #19
0
        /// <summary>
        /// 获取空网格集合
        /// </summary>
        private List<CellPoint> GetEmptyCells()
        {
            List<CellPoint> result = new List<CellPoint>();

            List<CellPoint> aroundHeadCells = new List<CellPoint>();
            CellPoint headPoint = this.snakeBodyList.First().Value;
            for (int i = -5; i < 5; i++)
            {
                for (int j = -5; j < 5; j++)
                {
                    CellPoint point = new CellPoint(headPoint.X + i, headPoint.Y + j);
                    point = AdjustCellPoint(point);

                    aroundHeadCells.Add(point);
                }
            }

            // skin 的占位情况因为确定了就不变了,所以在 AddSkin() 处计算
            // 为了以下 LINQ 的可用,需要重写 CellPoint 的 public override bool Equals(object obj)
            result = this.emptyCells.Where(p => !this.snakeBodyList.Select(x => x.Value).Contains(p)).ToList();
            result = result.Where(p => !this.snakeBodyList.Select(x => x.Value).Contains(p)).ToList();
            result = result.Where(p => !aroundHeadCells.Contains(p)).ToList();

            return result;
        }
Beispiel #20
0
    void ImportRoom(SnapshotImporter importer, bool hasSpecialGraphics)
    {
        //throw new NotImplementedException();

        RoomData data = new RoomData();

        /*
         * for(int y=0; y<16; y++)
         * {
         *  for(int x=0; x<32; x++)
         *  {
         *      data.SetAttr(x, y, importer.Read());
         *  }
         * }
         */

        byte[] buf = importer.ReadBytes(512);
        int    ii  = 0;

        for (int y = 0; y < 16; y++)
        {
            for (int x = 0; x < 32; x++)
            {
                //data.SetAttr(x, y, buf[i]);
                data.Attributes[ii] = buf[ii];
                ii++;
            }
        }

        data.RoomName = importer.ReadString(32);

        for (int i = 0; i < 8; i++)
        {
            byte attr = importer.Read();

            ////SpriteTexture tex = new SpriteTexture(8, 8, Vector2.zero);
            //SpriteTexture tex = new SpriteTexture(8, 8, new Vector2(0,1));
            //tex.Clear(new Color(0,0,0,0));
            //for(int y=0; y<8; y++)
            //{
            //    tex.SetLine(y, importer.Read());
            //}

            //data.Blocks[attr] = tex.Apply();

            byte[] blockData = importer.ReadBytes(8);
            data.Blocks[attr] = new BlockData(blockData, (BlockType)i);

            // for debug only

            /*
             * GameObject go = new GameObject();
             * go.transform.position = new Vector3(i*8, _rooms.Count*8, 0);
             * var sr = go.AddComponent<SpriteRenderer>();
             * sr.sprite = data.Blocks[attr];
             */
            // /for debug only
        }

        importer.Read(); // y-offset
        importer.Read(); // starts at
        importer.Read(); // direction facing
        importer.Read(); // always 0

        // start position
        short     startPos = importer.ReadShort();
        CellPoint pos      = new CellPoint(startPos.GetX(), startPos.GetY());

        data.StartPoint = pos;

        importer.Read(); // always 0 ???

        //importer.ReadBytes(4); // (623-626) conveyor belt
        data.ConveyorDirection = (ConveyorDirection)importer.Read();
        importer.ReadBytes(3);

        data.BorderColour = importer.Read(); // border color

        // positions of the items (keys)
        bool addKey = true;

        for (int j = 0; j < 5; j++)
        {
            addKey = true; // reset value (set default)

            byte attr = importer.Read();
            //if (attr == 255) continue;
            //if (attr == 0) continue;
            //if (attr == 255) addKey = false;
            //if (attr == 0) addKey = false;

            byte      secondGfxBuf = importer.Read();
            short     keyPosRaw    = importer.ReadShort();
            CellPoint keyPos       = new CellPoint(keyPosRaw.GetX(), keyPosRaw.GetY());

            importer.Read(); // dummy byte

            if (addKey)
            {
                data.RoomKeys.Add(new RoomKey(attr, keyPos));
            }
        }

        importer.Read(); // dummy
        importer.Read(); // dummy always =255

        // PORTAL
        byte portalColour = importer.Read();               // 655

        byte[] portalShape       = importer.ReadBytes(32); // 656-687 (=687-656+1)
        short  portalPositionRaw = importer.ReadShort();   // 688-691

        importer.ReadShort();                              // skip short
        data.AddPortal(portalColour, portalShape, portalPositionRaw.GetX(), portalPositionRaw.GetY());
        // /PORTAL

        data.KeyShape = importer.ReadBytes(8); // ITEMS (keys) shape

        byte airFirst = importer.Read();
        byte airSize  = (byte)(airFirst - 32 - 4);
        byte airPixel = importer.Read();

        data.AirSupply = new AirSupply()
        {
            Length = airSize, Tip = airPixel
        };

        // GUARDIANS
        // horizontal guardians(offset 702-732)
        for (int i = 0; i < 4; i++)
        {
            // todo: check black square in room 1
            GuardianHorizontal gh = new GuardianHorizontal();
            gh.Attribute = importer.Read();
            var pos_tmp = importer.ReadShort();
            gh.StartX = pos_tmp.GetX();
            gh.StartY = pos_tmp.GetY();
            //gh.StartPoint = new CellPoint(pos_tmp.GetX(), pos_tmp.GetY());
            importer.Read(); // ignore
            gh.StartFrame = importer.Read();
            gh.Left       = importer.Read() & 0x1f;
            gh.Right      = importer.Read() & 0x1f;

            if (gh.Attribute != 255)
            {
                data.HorizontalGuardians.Add(gh);
            }
        }

        importer.ReadBytes(3); // offset 730 - 255, 731-0, 732-0

        if (hasSpecialGraphics)
        {
            importer.ReadBytes(3); // ignore offset 733, 734, 735

            // SPECIAL GRAPHICS (offset 736-767)
            byte[] specialGraphic = importer.ReadBytes(32);
            data.SpecialGraphics.Add(specialGraphic);
            // /SPECIAL GRAPHICS
        }
        else
        {
            // vertical guardians(offset 702-732)
            for (int i = 0; i < 4; i++)
            {
                GuardianHorizontal gh = new GuardianHorizontal();
                gh.Attribute = importer.Read();
                var pos_tmp = importer.ReadShort();
                gh.StartX = pos_tmp.GetX();
                gh.StartY = pos_tmp.GetY();
                //gh.StartPoint = new CellPoint(pos_tmp.GetX(), pos_tmp.GetY());
                importer.Read(); // ignore
                gh.StartFrame = importer.Read();
                gh.Left       = importer.Read() & 0x1f;
                gh.Right      = importer.Read() & 0x1f;

                if (gh.Attribute != 255)
                {
                    //data.VerticalGuardians.Add(gh);
                }
            }
        }
        // /GUARDIANS

        // GUARDIAN GRAPHICS (offset 768-1023)
        for (int i = 0; i < 8; i++)
        {
            byte[] shape = importer.ReadBytes(32);
            data.GuardianGraphics.Add(shape);
        }
        // /GUARDIAN GRAPHICS


        _rooms.Add(data);
    }
Beispiel #21
0
 public SpreadSheetCell(CellPoint point, string val)
 {
     _x   = point.X;
     _y   = point.Y;
     _val = val;
 }
Beispiel #22
0
	public SCellValue GetSCellValue(CellPoint point)
	{
		if(point.x<Grid.GetLength(0) && point.y<Grid.GetLength(1))
			return Grid[point.x,point.y];
		else
		{
			throw new Exception("Index is out of grid");
		}
	}
Beispiel #23
0
        private CellPoint AdjustCellPoint(CellPoint point)
        {
            if (this.allowCrossBorder)
            {
                if (point.X > this.colCount - 1)
                    point.X = this.colCount - point.X;
                else if (point.X < 0)
                    point.X = point.X + this.colCount;

                if (point.Y > this.rowCount - 1)
                    point.Y = this.rowCount - point.Y;
                else if (point.Y < 0)
                    point.Y = point.Y + this.rowCount;
            }
            return point;
        }
Beispiel #24
0
 public RoomKey(int attr, CellPoint pt)
 {
     Attr     = attr;
     Position = pt;
 }
Beispiel #25
0
 public ViewCell(CellColor color, CellPoint point)
 {
     this.Color = color;
     this.Point = point;
 }
Beispiel #26
0
	public void MarkGridCell(CellPoint point, SCellValue.ECellContainValues value)
	{
		
		if(Grid == null)
			Grid = DeserializeGridData(GridAssetData);
		InitComponents();

		int i = point.x;
		int j = point.y;

		Color result = EmptyColor;
		
		switch(value)
		{
		case SCellValue.ECellContainValues.Empty: result = EmptyColor;  break;
		case SCellValue.ECellContainValues.Obstracle: result = ObstracleColor; break;
		case SCellValue.ECellContainValues.Enemy: result = EnemyColor; break;
		case SCellValue.ECellContainValues.Player: result = PlayerColor; break;
		}
		Grid[i,j].CellContainValue= value;
		
		Color[] cl = GridMesh.colors;
		for(int q=0; q<Grid[i,j].ConerListVertexIndexes.Length; q++)
		{
			cl[Grid[i,j].ConerListVertexIndexes[q]] = result;
		}
		GridMesh.colors = cl;
		
		filter.mesh = GridMesh;
		
	}
Beispiel #27
0
	public bool isContainsCell(CellPoint point)
	{
		return point.x<Grid.GetLength(0) && point.y<Grid.GetLength(1);
	}
 public static Vector3 ToVector3(this CellPoint pt)
 {
     return(new Vector3(pt.X, pt.Y));
 }
Beispiel #29
0
	public Vector3 GetCellPosition(CellPoint point)
	{
		if(point.x<Grid.GetLength(0) && point.y<Grid.GetLength(1))
		{
			Vector3 result = new Vector3();

			// local position of cell
			result.x = GridWorldStep*point.x+GridWorldStep*0.5F;
			result.z = GridWorldStep*point.y+GridWorldStep*0.5F;

			result += CachedTransform.position; // offset from local to world

			return result;
		}
		else
		{
			throw new Exception("Index is out of grid");
		}
	}
Beispiel #30
0
    void ImportRoom(SnapshotImporter importer, bool hasSpecialGraphic)
    {
        RoomData data = new RoomData();

        // Read in the screen attributes
        byte[] buf = importer.ReadBytes(512);
        int    i   = 0;

        //string s = "";

        for (int y = 0; y < 16; y++)
        {
            for (int x = 0; x < 32; x++)
            {
                //s += " " + buf[i];
                data.Attributes[i] = buf[i];
                i++;
            }
            //s += "\r\n";
        }

        //print(s);

        // Read in the room name
        data.RoomName = importer.ReadString(32);

        // Read in the block graphics
        for (i = 0; i < 8; i++)
        {
            // Read in the first byte that represents the attribute
            byte   attr      = importer.Read();
            byte[] blockData = importer.ReadBytes(8);
            data.Blocks[attr] = new BlockData(blockData, (BlockType)i);
        }

        // Read Miner Willy's start position

        // TODO: Read 1 byte for y-offset
        importer.Read();
        // TODO: Read 1 byte for sprite willy starts at
        importer.Read();
        // TODO: Read 1 byte for direction facing
        importer.Read();
        // TODO: Read 1 byte, should always be 0
        importer.Read();

        short     rawMWPos = importer.ReadShort();
        CellPoint startPos = new CellPoint(rawMWPos.GetX(), rawMWPos.GetY());

        data.MinerWillyStart = startPos;
        importer.Read(); // Should always be zero??

        // TODO: Conveyor belt (4 bytes for the conveyor belt)
        data.ConveyorDirection = (ConveyorDirection)importer.Read();
        importer.ReadBytes(3);

        data.BorderColour = importer.Read();

        bool addKey = true;

        for (var j = 0; j < 5; j++)
        {
            byte attr = importer.Read();
            //if (attr == 255) addKey = false;
            //if (attr == 0) addKey = false;

            byte      secondGfxBuf = importer.Read();
            short     keyPosRaw    = importer.ReadShort();
            CellPoint keyPos       = new CellPoint(keyPosRaw.GetX(), keyPosRaw.GetY());

            // read dummy byte
            int dummy = importer.Read();

            if (addKey)
            {
                data.RoomKeys.Add(new RoomKey(attr, keyPos));
            }

            addKey = true;
        }

        /*
         * Offset 628 is set at 0 in all Manic Miner rooms. Its counterpart in the runtime work area
         * (see Appendix F) "is used to decide whether or not all the items have yet been collected;
         * just before the items are displayed it is set to zero, then when an uncollected item is
         * displayed, it is changed to the attribute of that item. Thus, after printing items, if
         * this byte is still zero then all items must have been collected." [Garry Lancaster]
         *
         *  Offset 654 is always set at 255.
         */
        byte d1 = importer.Read();
        byte d2 = importer.Read();

        // PORTAL
        byte portalColour = importer.Read();

        byte[] portalShape = importer.ReadBytes(32);

        short portalPosRaw = importer.ReadShort();

        importer.ReadShort(); // Bit of a fudge, because we're gonna ignore the SECOND short...

        data.AddPortal(portalColour, portalShape, portalPosRaw.GetX(), portalPosRaw.GetY());

        data.KeyShape = importer.ReadBytes(8);

        byte airFirst  = importer.Read();
        byte airSize   = (byte)((airFirst - 32) - 4);
        byte airPixels = importer.Read();

        data.AirSupply = new AirSupply()
        {
            Length = airSize, Tip = airPixels
        };

        // Horizontal guardians
        for (int h = 0; h < 4; h++)
        {
            // TODO: Check this logic because we are getting black areas top left

            HorizontalGuardian hg = new HorizontalGuardian();
            hg.Attribute = importer.Read();
            var pos = importer.ReadShort();
            hg.StartX = pos.GetX();
            hg.StartY = pos.GetY();
            importer.Read(); // ignore this byte
            hg.StartFrame = importer.Read();
            hg.Left       = importer.Read() & 0x1f;
            hg.Right      = importer.Read() & 0x1f;

            if (hg.Attribute != 255)
            {
                data.HorizontalGuardians.Add(hg);
            }
        }

        importer.ReadBytes(3); // Always 255, and 0 and 0 Offset 730 is a terminator which is always set at 255, and Offsets 731 and 732 are 0 for all Manic Miner rooms.

        if (hasSpecialGraphic)
        {
            importer.ReadBytes(3); // ignore offsets 733, 734 and 736

            byte[] specialGraphic = importer.ReadBytes(32);
            data.SpecialGraphics.Add(specialGraphic);
        }
        else
        {
            // TODO: Vertical guardians
            for (int h = 0; h < 4; h++)
            {
                HorizontalGuardian hg = new HorizontalGuardian();
                hg.Attribute = importer.Read();
                var pos = importer.ReadShort();
                hg.StartX = pos.GetX();
                hg.StartY = pos.GetY();
                importer.Read(); // ignore this byte
                hg.StartFrame = importer.Read();
                hg.Left       = importer.Read() & 0x1f;
                hg.Right      = importer.Read() & 0x1f;

                if (hg.Attribute != 0)
                {
                    // TODO: NEED TO ADD TO VERTICAL GUARDIANS
                    //data.HorizontalGuardians.Add(hg);
                }
            }
        }

        for (int sp = 0; sp < 8; sp++)
        {
            byte[] shape = importer.ReadBytes(32);
            data.GuardianGraphics.Add(shape);
        }

        _rooms.Add(data);
    }
Beispiel #31
0
        /// <summary>
        /// 增加一个尾巴
        /// </summary>
        private void AddTail()
        {
            var prevBody = this.snakeBodyList.Last().Key;
            var prevBodyPoint = this.snakeBodyList.Last().Value;

            SnakeTail tail = new SnakeTail();
            tail.MoveDirection = prevBody.MoveDirection;
            CellPoint tailPoint = new CellPoint(prevBodyPoint.X, prevBodyPoint.Y);

            switch (prevBody.MoveDirection)
            {
                case Direction.Up:
                    tail.SetValue(Canvas.LeftProperty, (double)prevBody.GetValue(Canvas.LeftProperty));
                    tail.SetValue(Canvas.TopProperty, (double)prevBody.GetValue(Canvas.TopProperty) + this.cellSize);
                    tailPoint.Y++;
                    break;
                case Direction.Down:
                    tail.SetValue(Canvas.LeftProperty, (double)prevBody.GetValue(Canvas.LeftProperty));
                    tail.SetValue(Canvas.TopProperty, (double)prevBody.GetValue(Canvas.TopProperty) - this.cellSize);
                    tailPoint.Y--;
                    break;
                case Direction.Left:
                    tail.SetValue(Canvas.LeftProperty, (double)prevBody.GetValue(Canvas.LeftProperty) + this.cellSize);
                    tail.SetValue(Canvas.TopProperty, (double)prevBody.GetValue(Canvas.TopProperty));
                    tailPoint.X++;
                    break;
                case Direction.Right:
                    tail.SetValue(Canvas.LeftProperty, (double)prevBody.GetValue(Canvas.LeftProperty) - this.cellSize);
                    tail.SetValue(Canvas.TopProperty, (double)prevBody.GetValue(Canvas.TopProperty));
                    tailPoint.X--;
                    break;
            }

            tailPoint = AdjustCellPoint(tailPoint);

            this.snakeBodyList.Add(tail, tailPoint);
            canvasSnake.Children.Add(tail);
        }