Beispiel #1
0
void PrintSmileyDemo(void)
{
    int type   = 0;
    int health = 0;
    printf("%12s|%s|%s\n", "Type", "Healthy", "Sick");
    
    // For each type of Smiley
    for (type = INDIFFERENT; type <= GERM; type++)
    {
        switch (type)
        {
            case INDIFFERENT:
                printf("%12s", "INDIFFERENT");
                break;
            case SHINY_HAPPY:
                printf("%12s", "SHINY_HAPPY");
                break;
            case GRUMPY:
                printf("%12s", "GRUMPY");
                break;
            case DOCTOR:
                printf("%12s", "DOCTOR");
                break;
            case LEADER:
                printf("%12s", "LEADER");
                break;
            case GERM:
                printf("%12s", "GERM");
                break;
            default:
                printf("%12s", " ");
                break;
        }
        
        printf("|   ");
        PrintSmileyStateSymbol(CreateSmiley((SmileyType) type, HEALTHY));
        printf("   | ");
        PrintSmileyStateSymbol(CreateSmiley((SmileyType) type, SICK));
        printf("\n");
    }
}
Beispiel #2
0
HRESULT STDAPICALLTYPE HookCoCreateInstance(
    __in     REFCLSID rclsid,
    __in_opt LPUNKNOWN pUnkOuter,
    __in     DWORD dwClsContext, 
    __in     REFIID riid, 
    __deref_out LPVOID FAR* ppv)
{
    if(rclsid == CLSID_SSmileyCtrl)
    {
        return CreateSmiley(riid,ppv);
    }
    return TrueCoCreateInstance(rclsid,pUnkOuter,dwClsContext,riid,ppv);
}
Beispiel #3
0
int main(void)
{
    int     input             = -1;
    int     smileyTypeInput   = -1;
    int     smileyHealthInput = -1;
    int     xCoordinateInput  = -1;
    int     yCoordinateInput  = -1;
    int     turns             = 0;
    Smiley* board[BOARD_SIZE][BOARD_SIZE];
    
    // Set up board
    InitializeSmileyBoard(board);
    
    srand(time(0));
    
    PrintSmileyDemo();
    
    // Main loop; continues until user exits program
    while (input != 0)
    {
        PrintBoard(board);
        
        // Prompt for initial user input
        printf("Please choose from the following:\n");
        printf("1: Add a smiley to the board\n");
        printf("2: Do nothing this turn\n");
        printf("0: Exit\n");
        
        input = GetIntegerInput();
        
        switch (input)
        {
                // Add smiley to the board
            case 1:
                // Smiley type
                smileyTypeInput = GetSmileyType();
                
                // If type is -1, then cancel operation
                if (smileyTypeInput == -1)
                {
                    break;
                }
                
                // Smiley health
                smileyHealthInput = GetSmileyHealth();
                
                // If health is -1, then cancel operation
                if (smileyHealthInput == -1)
                {
                    break;
                }
                
                // Coordinates
                GetCoordinate(&xCoordinateInput, 'x');
                GetCoordinate(&yCoordinateInput, 'y');
                
                // If the given coordinates are empty and valid, then place the Smiley there
                if ((IsValidCoordinatePair(xCoordinateInput, yCoordinateInput)) &&
                    (board[yCoordinateInput][xCoordinateInput] == NULL))
                {
                    board[yCoordinateInput][xCoordinateInput] = CreateSmiley((SmileyType) smileyTypeInput, 
                                                                             (SmileyHealth) smileyHealthInput);
                }
                
                // Else display error message and cancel operation
                else
                {
                    printf("There is already a Smiley at (%d, %d).\n", xCoordinateInput, yCoordinateInput);
                }
                
                break;
            case 2:
                printf("You wait.\n");
                break;
            case 0:
                continue;
            default:
                break;
        }
        
        IterateBoard(board);
        turns++;
    }
    
    FreeSmileysOnBoard(board);
    printf("Press ENTER to continue");
    getchar();
    exit(0);
}