Пример #1
0
UnitPosition Snake::RemoveTail() {
	//if (tail == NULL)
	//	return;
	LinkNode* p = tail;
	tail = p->last;
	if (tail != NULL)
	{
		tail->next = NULL;
	}
	Length -= 1;
	return UnitPosition(p->Data.ColIndex, p->Data.RowIndex);
}
Пример #2
0
	//生成一个确定头的位置、运行方向以及节段长度的贪食蛇
Snake::Snake(UnitPosition headunit, Orientation movedirection, int length) {
	head =new LinkNode(headunit);
	tail = head;
	Length = 1;
	moveDirection = movedirection;
	if (length < 1)
		length = 1;		//至少有一个头
	for (int i = 1; i < length; i++) {
		UnitPosition bodypos = UnitPosition(headunit.ColIndex,headunit.RowIndex);
		bodypos.Move(movedirection, -1 * i);
		AddToTail(bodypos);
	}		
}
Пример #3
0
void Spawn(Unit *U, PathList *PL)
{
    Path *tempPath;
    tempPath = PathPeek(UnitPosition(U),PL);
    
    attron(COLOR_PAIR(UnitID(U)-96));
    if (UnitSpeed(U))
    {

        mvprintw(STARTY+PathY(tempPath),STARTX+PathX(tempPath)*MAPSCALE+2,"%d",UnitHealth(U));
    }
    else
    {
        mvprintw(STARTY+PathY(tempPath),STARTX+PathX(tempPath)*MAPSCALE,"%d",UnitHealth(U));
    }
    attroff(COLOR_PAIR(UnitID(U)-96));
}
Пример #4
0
//蛇移动一次,返回舍弃的尾部数据
UnitPosition Snake::Move() {
	UnitPosition pos = UnitPosition(head->Data.ColIndex, head->Data.RowIndex);
	pos.Move(moveDirection);
	InsertAsHead(pos);
	return RemoveTail();
}
Пример #5
0
void TowerTargetting(UnitList *UL, UnitList *PDUL, TowerList *TL, PathList *PL, FunctionQueue *FQ, int loopCounter)
{
    for (int i = 0; i < TowerSize(TL); i++)
    {
        // Declare and initiage of variables needed per loop
        int j;
        Tower *T;
        Path *P;
        Unit *U;
        int targetFlag;
        targetFlag = false;

        // Get the tower
        T = TowerPeek(i, TL);

        if (loopCounter % TowerRate(T) == 0)
        {
            // Iterate through the unit list
            for (j = 0; j < UnitSize(UL); j++)
            {
                if (TowerEffect(T) != EFFECT_AOE)
                {
                    if (targetFlag == false)
                    {
                        // Get unit & position data
                        U = UnitPeek(j, UL);
                        P = PathPeek(UnitPosition(U), PL);

                        // check range
                        if (TowerPosX(T) + TowerRange(T) >= PathX(P) && TowerPosX(T) - TowerRange(T) <= PathX(P))
                        {
                            if (TowerPosY(T) + TowerRange(T) >= PathY(P) && TowerPosY(T) - TowerRange(T) <= PathY(P))
                            {
                                targetFlag = true;
                                if (UnitSpeed(U) == SPEED_SLOW)
                                {
                                    // Exit the unit loop, we have our target
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        Unit *target;
                        // Get unit & position data
                        target = UnitPeek(j, UL);
                        P = PathPeek(UnitPosition(target), PL);

                        // Check unit speed for aggro. Less calls than range checking to eliminate cases
                        if (UnitSpeed(target) == SPEED_SLOW)
                        {
                            // Check if the unit is within tower range
                            if (TowerPosX(T) + TowerRange(T) >= PathX(P) && TowerPosX(T) - TowerRange(T) <= PathX(P))
                            {
                                if (TowerPosY(T) + TowerRange(T) >= PathY(P) && TowerPosY(T) - TowerRange(T) <= PathY(P))
                                {
                                    // exit the unit loop, we have our target
                                    U = target;
                                    break;
                                }
                            }
                        }
                    }
                }
                // AoE damage
                else
                {
                    // Get unit & position data
                    U = UnitPeek(j, UL);
                    P = PathPeek(UnitPosition(U), PL);

                    // check range
                    if (TowerPosX(T) + TowerRange(T) >= PathX(P) && TowerPosX(T) - TowerRange(T) <= PathX(P))
                    {
                        if (TowerPosY(T) + TowerRange(T) >= PathY(P) && TowerPosY(T) - TowerRange(T) <= PathY(P))
                        {
                            // Deal the damage to the unit in range.
                            DamageHandler(U, T, PDUL);
                            CreateSPAWN(FQ,U);
                        }
                    }
                }
            }
             // Deal damage to target

            if (targetFlag == true)
            {
                DamageHandler(U, T, PDUL);
                CreateSPAWN(FQ,U);
            }
        }
    }
}