예제 #1
0
int main(void) {
	
	struct Node *head = NULL;

	addEnd(&head, 15);
	addEnd(&head, 25);
	addBegin(&head, 14);
	addAt(&head, 22, 1);
	addAt(&head, 30, 4);
	addAt(&head, 30,4);

	struct Node *itr = head;
	while (itr != NULL) {
		printf("%d\n", itr->data);
		itr = itr->next;
	}
	puts("");

	deleteAt(&head, 6);
	
	itr = head;
	while (itr != NULL) {
		printf("%d\n", itr->data);
		itr = itr->next;
	}

	return 0;
}
예제 #2
0
파일: FotoEntity.cpp 프로젝트: som/FED
bool CFotoEntity::addLine(int nY, int& nL, int& nR){
	if (!addAt(nL, nY)) return false;

	for(nL--; addAt(nL, nY); nL--);
	nL++;

	for(nR = nL+1; addAt(nR, nY); nR++);
	nR--;

	return true;
}
예제 #3
0
int main(){

	struct node *root = (struct node *) malloc(sizeof(struct node));
	struct node *first = (struct node *) malloc(sizeof(struct node));
	
	root->next = first;
	
	first->next = NULL;
	first->data = 10;
	printf("First List\n");
	printList(root->next);
	
	struct node *second = (struct node *) malloc(sizeof(struct node));
	second->data = 5;
	addToFront(second, root);
	printf("Second List\n");
	printList(root->next);
	
	struct node *third = (struct node *) malloc(sizeof(struct node));
	third->data = 15;
	addToLast(third, root);
	printf("Third List\n");
	printList(root->next);
	
	struct node *mid = (struct node *) malloc(sizeof(struct node));
	mid->data = 12;
	addAt(mid, first);
	printf("Fourth List\n");
	printList(root->next);
	
	struct node *mid2 = (struct node *) malloc(sizeof(struct node));
	mid2->data = 14;
	addAt(mid2, mid);
	printf("Fifth List\n");
	printList(root->next);
	
	deleteNode(mid2, root);
	printf("Sixth List\n");
	printList(root->next);
	
	return 0;
}
예제 #4
0
파일: StopSign.c 프로젝트: cs50/spl
int main() {
   GWindow gw;
   GPolygon stopSign;
   double edge;
   int i;

   printf("This program draws a red octagon.\n");
   gw = newGWindow(600, 400);
   edge = 75;
   stopSign = newGPolygon();
   addVertex(stopSign, -edge / 2, edge / 2 + edge / sqrt(2.0));
   for (i = 0; i < 8; i++) {
      addPolarEdge(stopSign, edge, 45 * i);
   }
   setFilled(stopSign, true);
   setColor(stopSign, "RED");
   addAt(gw, stopSign, getWidth(gw) / 2, getHeight(gw) / 2);

   return 0;
}
예제 #5
0
파일: array.cpp 프로젝트: barak/raidutils
uSHORT  baseArray_C::moveTo(uSHORT objOffset,uSHORT newOffset)
{

    uSHORT retVal = 0;

    // If both offsets are within range...
    if ((objOffset < objCount) && (newOffset < objCount)) {
        retVal = 1;
        if (objOffset!=newOffset) {
            // Copy the object to the swap space
            memcpy(buff_P+totalObjs*objSize,buff_P+objOffset*objSize,objSize);
            // Remove the object from its current location
            remAt(objOffset);
            // Add the object to the new location
            addAt(buff_P+totalObjs*objSize,newOffset);
        }
    }

    return (retVal);

}
예제 #6
0
  // Add the specified pointer in front of the current object
 uSHORT      add(void *obj_P)
     {
         return (addAt((void *) &obj_P,curIndex));
     }
예제 #7
0
파일: tic.c 프로젝트: zafar11235/TicTacToe
void play(int mode, GWindow window)
{	
	/* Initialize the Game */
	
	//create the game-board
	G3DRect board = newG3DRect(BOARD_X, BOARD_Y, 3*BOX, 3*BOX, true);
	setColor(board, "LIGHT_GRAY");
    setFilled(board, true);
    add(window, board);
    
    //creates the array of small rects
    GRect rect[9];
    int k = 0;
    for(int i = 0; i < 3; i++)
    {
    	for (int j = 0; j < 3; j++)
    	{
    		rect[k] = newGRect(BOX*j + BOARD_X, BOX*i + BOARD_Y, BOX, BOX);
    		setColor(rect[k], "#0000FF");
        	add(window, rect[k]);
        	k++;
    	}  	
    }
    
    GLabel status = newGLabel("Player 1");
    setFont(status, "SansSerif-26");
    setLabel(status, "Player 1");
    add(window, status);
    double x = WIDTH/2 - getWidth(status)/2;
    double y = HEIGHT/2 + 200;
    setLocation(status, x, y);
    
	A[0][0] = -1; A[0][0] = -1; A[0][0] = -1;
	A[0][0] = -1; A[0][0] = -1; A[0][0] = -1;
	A[0][0] = -1; A[0][0] = -1; A[0][0] = -1;
	
	int i = 0, player = 0, flag = -1;
	// if 2 player is seleceted	          
	if (mode == 2)
	{
		while( i <= 8)
		{
			player = i%2;
			
			if (player == 0)
			{
				setLabel(status, "Player 1");
				double x = WIDTH/2 - getWidth(status)/2;
    			double y = HEIGHT/2 + 200;
    			setLocation(status, x, y);
			}
			else
			{
				setLabel(status, "Player 2");
				double x = WIDTH/2 - getWidth(status)/2;
    			double y = HEIGHT/2 + 200;
    			setLocation(status, x, y);
			}
			
			printf("Player %d move....\n", player + 1);
			
			
			
			// wait for click
			while (true)
    		{	
        		GEvent event = getNextEvent(MOUSE_EVENT);		// check for mouse event		
        		if (event != NULL)								// if we heard one
        		{	
           			if (getEventType(event) == MOUSE_CLICKED)	// if the event was movement
            		{
                		GObject object = getGObjectAt(window, getX(event), getY(event));
                		if(object != NULL)
                		{
                			int j;
                			int rightClick = 0;
                			for(j = 0; j < 9; j++)
                			{
                				if (object == rect[j])
                				{
                					//remove the rect and add appropriate image
                					int x = getX(object);
                					int y = getY(object);
                					printf("Rect[%d] clicked by player %d\n", j, player);
                					removeGWindow(window, object);
                					updateArray(player, j);	
        							if(player == 0)
        							{
        								GImage cross = newGImage("cross.png");
        								addAt(window, cross, x, y);
        							}
        							else
        							{
        								GImage circle = newGImage("circle.png");
        								addAt(window, circle, x, y);
        							}
        							rightClick = 1;
                				}
                			}
                			if(rightClick == 1)
                				break;             	               	
                		}
            		}
        		}
    		}// end of a click operation
    		
    		// check Status
    		if (checkStatus())
    		{
    			printf("Player %d won\n", player);
    			flag = player;
    			break;
    		}
    		
    		i++;
		}// end of i = 0 to 8 loop
	}// if mode == 2
	
	else // if mode == 1
	{
		while( i <= 8)
		{
			player = i%2;
			
			if (player == 0)
			{
				setLabel(status, "Player 1");
				double x = WIDTH/2 - getWidth(status)/2;
    			double y = HEIGHT/2 + 200;
    			setLocation(status, x, y);
			}
			else
			{
				setLabel(status, "Player 2");
				double x = WIDTH/2 - getWidth(status)/2;
    			double y = HEIGHT/2 + 200;
    			setLocation(status, x, y);
			}
			
			printf("Player %d move....\n", player + 1);
			
			//showPlayer(player, mode);
			
			if (player == 0)  // aka human being
			{
				// wait for click
				while (true)
    			{	
        			GEvent event = getNextEvent(MOUSE_EVENT);		// check for mouse event		
        			if (event != NULL)								// if we heard one
        			{	
           				if (getEventType(event) == MOUSE_CLICKED)	// if the event was movement
            			{
                			GObject object = getGObjectAt(window, getX(event), getY(event));
                			if(object != NULL)
                			{
                				int j;
                				int rightClick = 0;
                				for(j = 0; j < 9; j++)
                				{
                					if (object == rect[j])
                					{
                						//remove the rect and add appropriate image
                						int x = getX(object);
                						int y = getY(object);
                						printf("Rect[%d] clicked by player %d\n", j, player);
                						removeGWindow(window, object);
                						updateArray(player, j);	
        								GImage cross = newGImage("cross.png");
        								addAt(window, cross, x, y);
        								rightClick = 1;
                					}
                				}
                				if(rightClick == 1)
                					break;             	               	
                				}
            				}
        				}
    			}// end of a click operation
			}// end if player == 0 aka human being
			
			else // if player is computer
			{
				pause(750);
				
				// find the position
				int pos;
				if(check(59) >= 0)
					pos = check(59);
				else if (check(5) >= 0)
					pos = check(5);
				else
					pos = any();
					
				updateArray(player, pos);
				
				//remove the rect and add appropriate image
                int x = getX(rect[pos]);
                int y = getY(rect[pos]);
                printf("Rect[%d] clicked by player %d\n", pos, player);
                removeGWindow(window, rect[pos]);
        		GImage circle = newGImage("circle.png");
        		addAt(window, circle, x, y);		
				
			}// end if player is computer
			
    		// check Status
    		if (checkStatus())
    		{
    			printf("Player %d won\n", player);
    			flag = player;
    			break;
    		}
    		
    		i++;
		}// end of i = 0 to 8 loop
	}// end if mode == 1
    
    if (flag == 0 && mode == 2)
	{
		setLabel(status, "Player 1 Wins!!!");
		double x = WIDTH/2 - getWidth(status)/2;
    	double y = HEIGHT/2 + 200;
    	setLocation(status, x, y);
	}
	else if (flag == 1 && mode == 2)
	{
		setLabel(status, "Player 2 Wins!!!");
		double x = WIDTH/2 - getWidth(status)/2;
    	double y = HEIGHT/2 + 200;
    	setLocation(status, x, y);
	}
	else if (flag == 0 && mode == 1)
	{
		setLabel(status, "You Win !!!");
		double x = WIDTH/2 - getWidth(status)/2;
    	double y = HEIGHT/2 + 200;
    	setLocation(status, x, y);
	}
	else if (flag == 1 && mode == 1)
	{
		setLabel(status, "You Lose !!!");
		double x = WIDTH/2 - getWidth(status)/2;
    	double y = HEIGHT/2 + 200;
    	setLocation(status, x, y);
	}
	else if (flag == -1)
	{
		setLabel(status, "Game Draws !!!");
		double x = WIDTH/2 - getWidth(status)/2;
    	double y = HEIGHT/2 + 200;
    	setLocation(status, x, y);
	}
	
	printf("flag = %d\n", flag);
	
	waitForClick();
}