void AddItem(HexItemType type, HexCell cell)
    {
        HexItem item = Instantiate <HexItem>(HexItem.itemPrefab);

        item.itemType = type;
        grid.AddItem(item, cell);
    }
Exemplo n.º 2
0
    public void RemoveItem(int cellIndex)
    {
        HexItem item = cells[cellIndex].Item;

        items.Remove(item);
        item.RemoveFromMap();
    }
Exemplo n.º 3
0
	public bool IsAdjacent(HexItem item)
	{
		bool bResult = false;
		
		if( m_nColumn == item.m_nColumn)
		{
			bResult = Mathf.Abs(m_nRow - item.m_nRow) == 1;
		}
		if( m_nRow == item.m_nRow)
		{
			bResult = Mathf.Abs(m_nColumn - item.m_nColumn) == 1;
		}
		
//		int nDeltaCol = Mathf.Abs(m_nColumn - item.m_nColumn);
//		
//		if( nDeltaCol == 1)
//		{
//			if( IsEven(m_nColumn) && m_nRow - 1 == item.m_nRow)
//				bResult = true;
//			if( IsEven(m_nColumn) == false && m_nRow + 1 == item.m_nRow)
//				bResult = true;
//		}
		
		int nDeltaRow = Mathf.Abs(m_nRow - item.m_nRow);
		if( nDeltaRow == 1)
		{
			if( IsEven(m_nRow) && m_nColumn + 1 == item.m_nColumn)
				bResult = true;
			if( IsEven(m_nRow) == false && m_nColumn - 1 == item.m_nColumn)
				bResult = true;
		}
		
		return bResult;
	}
Exemplo n.º 4
0
    public void AddItem(HexItem item, HexCell location)
    {
        items.Add(item);
        item.Grid = this;
        item.transform.SetParent(transform, false);
        item.Location = location;
        item.InstantiateItem();

        if (item.itemType == HexItemType.Treasure)
        {
            Log.Dev(GetType(), "treasure at " + location.coordinates.ToString());
        }
    }
    void AddItems()
    {
        if (!isServer)
        {
            for (int i = 0; i < StartInfo.ItemTypes.Length; i++)
            {
                itemTypes.Add(StartInfo.ItemTypes[i]);
                itemCellIndex.Add(StartInfo.ItemCellIndex[i]);
            }
        }

        for (int i = 0; i < itemTypes.Count; i++)
        {
            HexItem item = Instantiate <HexItem>(HexItem.itemPrefab);
            item.itemType = (HexItemType)itemTypes[i];
            grid.AddItem(item, grid.GetCell(itemCellIndex[i]));
        }
    }
Exemplo n.º 6
0
    /*
     *                          2    3
     *                      1             4
     *                          6     5
     *
     *
     * x-2
     * x-1 y+2
     * x+1 y+2
     * x+2
     * x+1 y-2
     * x-1 y-2
     */
    public List <HexItem> createItems()
    {
        List <HexItem> Items = new List <HexItem>();
        HexItem        item1 = new HexItem(index, centerX - 2, centerY);
        HexItem        item2 = new HexItem(index, centerX - 1, centerY + 2);
        HexItem        item3 = new HexItem(index, centerX + 1, centerY + 2);
        HexItem        item4 = new HexItem(index, centerX + 2, centerY);
        HexItem        item5 = new HexItem(index, centerX + 1, centerY - 2);
        HexItem        item6 = new HexItem(index, centerX - 1, centerY - 2);

        Items.Add(item1);
        Items.Add(item2);
        Items.Add(item3);
        Items.Add(item4);
        Items.Add(item5);
        Items.Add(item6);

        return(Items);
    }
Exemplo n.º 7
0
        public IActionResult PostFromHex([FromBody] HexItem value)
        {
            if (value == null || !ModelState.IsValid)
            {
                return(BadRequest("empty request"));
            }
            HexString hs;

            try {
                hs = new HexString(value.hex);
            } catch (InvalidOperationException e) {
                return(BadRequest("invalid hex string"));
            }

            if (!hs.isValid())
            {
                return(BadRequest("invalid hex string"));
            }
            return(Ok(hs.asBase64()));
        }
        public void FromHexPost_ReturnsBadResult(string hex, string errorMessage)
        {
            // Arrange
            var controller = new Base64Controller();

            // Act
            HexItem hi = new HexItem();

            hi.hex = hex;
            IActionResult actionResult = controller.PostFromHex(hi);

            // Assert
            Assert.NotNull(actionResult);

            BadRequestObjectResult result = actionResult as BadRequestObjectResult;

            Assert.NotNull(result);

            string message = result.Value as string;

            Assert.Equal(errorMessage, message);
        }
Exemplo n.º 9
0
        public override void Deserialize(Stream stream)
        {
            var reader     = new StreamReader(stream);
            var list       = new List <HexItem>();
            var lineNumber = 0;

            while (!reader.EndOfStream)
            {
                lineNumber++;
                var line = reader.ReadLine();
                if (!line.StartsWith(":"))
                {
                    Locator.Resolve <IUserMessage>()
                    .Error("Intel HEX loader\n\nInvalid Intel HEX file at line" + lineNumber.ToString());
                }
                line = line.Substring(1).Trim().Replace(" ", "");
                if ((line.Length & 1) != 0)
                {
                    Locator.Resolve <IUserMessage>()
                    .Error("Intel HEX loader\n\nIncorrect data at line" + lineNumber.ToString());
                }
                var data = new byte[line.Length / 2];
                for (var i = 0; i < data.Length; i++)
                {
                    var hex = line.Substring(i * 2, 2).ToLowerInvariant();
                    if (!hex.All(arg => char.IsDigit(arg) || (arg >= 'a' && arg <= 'f')))
                    {
                        Locator.Resolve <IUserMessage>()
                        .Error("Intel HEX loader\n\nIncorrect data at line" + lineNumber.ToString() +
                               ", position " + (i * 2 + 1).ToString());
                    }
                    data[i] = Convert.ToByte(hex, 16);
                }
                var leng = data[0];
                if (data.Length != leng + 4 + 1)
                {
                    Locator.Resolve <IUserMessage>()
                    .Error("Intel HEX loader\n\nInvalid data length at line" + lineNumber.ToString());
                }
                byte checkSum = 0;
                for (var i = 0; i < data.Length - 1; i++)
                {
                    checkSum += data[i];
                }
                checkSum = (byte)(~checkSum + 1); // get two's complement
                if (checkSum != data[data.Length - 1])
                {
                    Locator.Resolve <IUserMessage>()
                    .Error("Intel HEX loader\n\nChecksum error at line" + lineNumber.ToString());
                }
                var item = new HexItem();
                item.Addr = (ushort)((data[1] << 8) | data[2]);
                item.Type = data[3];
                item.Data = new byte[leng];
                Array.Copy(data, 4, item.Data, 0, leng);
                if (item.Type == 1)
                {
                    break;                 // End Of File
                }
                list.Add(item);
            }
            var memory = _spec.BusManager.FindDevice <IMemoryDevice>();

            foreach (var item in list)
            {
                if (item.Type != 0)
                {
                    Logger.Warn("IntelHex: skip type: {0}, addr: {1}, data: {2}",
                                item.Type, item.Addr,
                                string.Join("", item.Data.Select(arg => string.Format(CultureInfo.InvariantCulture, "{0:x02}")).ToArray()));
                    continue;
                }
                if (item.Addr < 0x4000)
                {
                    Logger.Warn("IntelHex: skip rom addr: {1}",
                                item.Type, item.Addr,
                                string.Join("", item.Data.Select(arg => string.Format(CultureInfo.InvariantCulture, "{0:x02}")).ToArray()));
                    continue;
                }
                for (var i = 0; i < item.Data.Length; i++)
                {
                    ushort locAddr = (ushort)(item.Addr + i);
                    var    page    = locAddr >> 14;
                    if (page == 0)
                    {
                        continue;
                    }
                    memory.WRMEM_DBG(locAddr, item.Data[i]);
                }
            }
            UpdateState();
        }
Exemplo n.º 10
0
	public void HandleDrag(HexItem pFirst, HexItem pSecond)
	{
		if( pFirst.Child == null || pFirst.Child.GetImpType() != Impermanent.eImpType.Patient )
			return;
		
		if( pSecond.IsAdjacent(pFirst) )
		{
			if( pSecond.Child != null )
			{
				if( pSecond.Child.GetImpType() == Impermanent.eImpType.Teleporter )
				{
					pFirst.Child.OnTeleport();
				}
				else
				{
					
				}
			}
			else 
			{
				pSecond.Child = pFirst.Child;
				pFirst.Child = null;
			}
		}
		else
		{
			
		}
	}
Exemplo n.º 11
0
	public void HandlePress(HexItem pItem, bool bUp)
	{
		if( bUp == false)
			m_pCurrentItem = null;
		else
			m_pCurrentItem = pItem.Child;
	}
Exemplo n.º 12
0
    public void SendRemoveItem(HexItem item)
    {
        photonView.RPC("GetRemoveItem", RpcTarget.Others, item.Location.Index);

        RemoveItem(item.Location.Index);
    }