void GameEngine::Run()
{
    Init();
    m_renderer->Draw(m_world);
    Render();
    while(m_running)
    {
        std::string command;
        std::getline(std::cin, command);
        UserInput(command);
        Render();
    }
    CleanUp();
}
예제 #2
0
UserInput apply_strategy( const Ceil& pattern, char history_deep )
{
/*    UserInput newui;
    if ( history.size() == 0 ) 
    {
        newui = "0123";
        return newui;
    }

    std::set<int>  free_set;
    std::set<int>  prev_set;
    prev_set.insert( history.back()[0] );
    prev_set.insert( history.back()[1] );
    prev_set.insert( history.back()[2] );
    prev_set.insert( history.back()[3] );

    for( CeilsT::iterator It = invariants.begin(); It != invariants.end(); ++It )
    {
        Ceil& c = *It;
        for (char i = 0; i < 4; i++ )
            if ( prev_set.end() == prev_set.find(c[i]) )
                free_set.insert( c[i] );
    }

    for (char i = 0; i < 4; i++ )
    {
        if ( pattern[i] == 0 ) 
        {
            if ( free_set.size() == 0 )
                return UserInput();
            newui = *free_set.begin();
            free_set.erase( free_set.begin() );
        }
        else 
        {
            if( pattern[i] == 1 )
                newui.at(i) = history.back()[0];
            else if( pattern[i] == 2 )
                newui.at(i) = history.back()[1];
            else if( pattern[i] == 3 )
                newui.at(i) = history.back()[2];
            else if( pattern[i] == 4 )
                newui.at(i) = history.back()[3];
        }
    }
    return newui;*/
    return UserInput();
}
예제 #3
0
// This is my primary Event Loop. This is where most of the fun stuff happens ;)
void Megamaniac() {
    // WTF does this do? Something to do with my Data Structure I assume...
    Game game;

	while (true) {
	    // Let's run our initial setup to get everything for the game ready.
	    SetupGame(&game);

	    // Do we need to change the level? Not really but we should probably start at Level 1.
	    ChangeLevel(&game);

		// This is where the Event Loop actually starts. This will run repeatedly until our game is over.
	    while (!game.game_over) {
		    clear_screen();
		    GameStats(&game);
			int userInput = UserInput(&game);
		    MovementPlayer(&game, userInput);
			MovementMissiles(&game, userInput);
		    MovementAliens(&game);
			MovementBombs(&game);
			MovementBonuses(&game);

			CollisionMissiles(&game);
			CollisionAliens(&game);
		    CollisionBombs(&game);
			CollisionBonuses(&game);

			UpdateScreen(&game);
		    show_screen();
		    timer_pause(25);
	    }

		GameOver(&game);

		int userInput = wait_char();
		while (userInput != 'r' && userInput >= 0) {
			if (userInput == 'q') {
				exit(0);
			}
			if (userInput == 'r') {
				Megamaniac();
			}
			userInput = wait_char();
		}
	}
}
예제 #4
0
파일: GraphView.cpp 프로젝트: ke2ny/MoBu
//! input callback.
void GraphView::ViewInput(int pMouseX,int pMouseY,FBInputType pAction,int pButtonKey,int pModifier)
{
	switch(pAction)
	{
	case kFBKeyPress:
		{
			UserInput(pMouseX, pMouseY, pButtonKey, pModifier);
		}
		break;

	case kFBButtonPress:
		{
		// register mouse down in viewport
		mDown = true;
		mLastX = pMouseX;
		mLastY = pMouseY;

		if (pModifier == kFBKeyAlt)
			if (pButtonKey == 2)	// middle button click
				SetManipulator( MANIPULATOR_GRAPH_PAN );
			else if (pButtonKey == 3)	// right button click
				SetManipulator( MANIPULATOR_GRAPH_ZOOM );


		// do some action below
		MouseDown(pMouseX, pMouseY, pModifier);
		} break;
	case kFBButtonRelease:
		// do some action below
		MouseUp(pMouseX, pMouseY, pModifier);
		// release button
		mDown = false;

		ClearManipulator();
		break;
	case kFBMotionNotify:
		// do some action
		MouseMove(pMouseX, pMouseY, pModifier);
		
		// lastx, lasty
		mLastX = pMouseX;
		mLastY = pMouseY;
		break;
	}
}
예제 #5
0
파일: main.c 프로젝트: bmxrt/CC3100
/*
 * Application's entry point
 */
int main()
{
    _u8 input[MAX_BUF_SIZE] = {0};
    UserIn User = {0};
    _i32 flag = 1;
    _i32 first = 0;
    _i32 retVal=-1;
    _i8 *pConfig = NULL;

    retVal = initializeAppVariables();
    ASSERT_ON_ERROR(retVal);

#ifdef SL_IF_TYPE_UART
    params.BaudRate = 115200;
    params.FlowControlEnable = 1;
    params.CommPort = COMM_PORT_NUM;

    pConfig = (_i8 *)&params;
#endif /* SL_IF_TYPE_UART */

    /* This line is for Eclipse CDT only due to a known bug in console buffering
     * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=173732 */
    setvbuf(stdout, NULL, _IONBF, 0);

    displayBanner();

    /*
     * Following function configures the device to default state by cleaning
     * the persistent settings stored in NVMEM (viz. connection profiles &
     * policies, power policy etc)
     *
     * Applications may choose to skip this step if the developer is sure
     * that the device is in its default state at start of application
     *
     * Note that all profiles and persistent settings that were done on the
     * device will be lost
     */
    retVal = configureSimpleLinkToDefaultState(pConfig);
    if(retVal < 0)
    {
        printf(" Failed to configure the device in its default state, Error code: %ld\r\n",retVal);
        LOOP_FOREVER();
    }

    printf("Device is configured in default state \r\n");

    /*
     * Asumption is that the device is configured in station mode already
     * and it is in its default state
     */
    retVal = sl_Start(0, pConfig, 0);
    if ((retVal < 0) ||
            (ROLE_STA != retVal) )
    {
        printf(" Failed to start the device, Error code: %ld\r\n",retVal);
        LOOP_FOREVER();
    }

    printf("Device started as STATION \r\n");

    while(flag)
    {
        User = UserInput();
        switch(User.choice)
        {
        case 1:
            retVal = TxContinues(User.channel, RATE_11M, User.packets, 100);
            if(retVal < 0)
            {
                printf("Failed to send the packet over phy, Error code: %ld",retVal);
                LOOP_FOREVER();
            }
            break;
        case 2:
            retVal = RxStatisticsCollect(User.channel);
            if(retVal < 0)
            {
                printf("Failed to collect statics, Error code: %ld",retVal);
                LOOP_FOREVER();
            }
            break;
        }

        printf("\nEnter \"1\" to restart or \"0\" to quit: \n");
        fgets((char *)input, sizeof(input), stdin);
        printf("\n");
        flag = atoi((const char *)input);

        first = 1;
    }

    return SUCCESS;
}
예제 #6
0
파일: main.c 프로젝트: gale320/cc3200
//****************************************************************************
//                            MAIN FUNCTION
//****************************************************************************
void main()
{
    long lRetVal = -1;

    //
    // Board Initialization
    //
    BoardInit();

    //
    // uDMA Initialization
    //
    UDMAInit();

    //
    // Configure the pinmux settings for the peripherals exercised
    //
    PinMuxConfig();

    //
    // Configuring UART
    //
    InitTerm();

    //
    // Display banner
    //
    DisplayBanner(APPLICATION_NAME);

    InitializeAppVariables();

    //
    // Following function configure the device to default state by cleaning
    // the persistent settings stored in NVMEM (viz. connection profiles &
    // policies, power policy etc)
    //
    // Applications may choose to skip this step if the developer is sure
    // that the device is in its desired state at start of applicaton
    //
    // Note that all profiles and persistent settings that were done on the
    // device will be lost
    //
    lRetVal = ConfigureSimpleLinkToDefaultState();

    if(lRetVal < 0)
    {
        if (DEVICE_NOT_IN_STATION_MODE == lRetVal)
          UART_PRINT("Failed to configure the device in its default state \n\r");

        LOOP_FOREVER();
    }

    UART_PRINT("Device is configured in default state \n\r");

    //
    // Asumption is that the device is configured in station mode already
    // and it is in its default state
    //
    lRetVal = sl_Start(0, 0, 0);
    if (lRetVal < 0 || lRetVal != ROLE_STA)
    {
        UART_PRINT("Failed to start the device \n\r");
        LOOP_FOREVER();
    }

    UART_PRINT("Device started as STATION \n\r");

    UART_PRINT("Connecting to AP: %s ...\r\n",SSID_NAME);

    //
    //Connecting to WLAN AP
    //
    lRetVal = WlanConnect();
    if(lRetVal < 0)
    {
        UART_PRINT("Failed to establish connection w/ an AP \n\r");
        LOOP_FOREVER();
    }

    UART_PRINT("Connected to AP: %s \n\r",SSID_NAME);

    UART_PRINT("Device IP: %d.%d.%d.%d\n\r\n\r",
                SL_IPV4_BYTE(g_ulIpAddr,3),
                SL_IPV4_BYTE(g_ulIpAddr,2),
                SL_IPV4_BYTE(g_ulIpAddr,1),
                SL_IPV4_BYTE(g_ulIpAddr,0));

#ifdef USER_INPUT_ENABLE
    lRetVal = UserInput();
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }

#else
    lRetVal = BsdUdpClient(PORT_NUM);
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }

    lRetVal = BsdUdpServer(PORT_NUM);
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }
#endif

    UART_PRINT("Exiting Application ...\n\r");

    //
    // power off the network processor
    //
    lRetVal = sl_Stop(SL_STOP_TIMEOUT);

    while (1)
    {
     _SlNonOsMainLoopTask();
    }
}
예제 #7
0
int main()
{
    UserIn User;
    int iFlag = 1;
    long lRetVal = -1;
    char cChar;
    unsigned char policyVal;
    
    //
    // Initialize Board configuration
    //
    BoardInit();
    
    //
    //
    //Pin muxing
    //
    PinMuxConfig();
    
    // Configuring UART
    //
    InitTerm();
    DisplayBanner(APPLICATION_NAME);

    InitializeAppVariables();

    //
    // Following function configure the device to default state by cleaning
    // the persistent settings stored in NVMEM (viz. connection profiles &
    // policies, power policy etc)
    //
    // Applications may choose to skip this step if the developer is sure
    // that the device is in its default state at start of applicaton
    //
    // Note that all profiles and persistent settings that were done on the
    // device will be lost
    //
    lRetVal = ConfigureSimpleLinkToDefaultState();
    if(lRetVal < 0)
    {
        if (DEVICE_NOT_IN_STATION_MODE == lRetVal)
          UART_PRINT("Failed to configure the device in its default state \n\r");
          LOOP_FOREVER();
    }

    UART_PRINT("Device is configured in default state \n\r");

    CLR_STATUS_BIT_ALL(g_ulStatus);

    //
    // Assumption is that the device is configured in station mode already
    // and it is in its default state
    //
    lRetVal = sl_Start(0, 0, 0);
    if (lRetVal < 0 || ROLE_STA != lRetVal)
    {
        UART_PRINT("Failed to start the device \n\r");
        LOOP_FOREVER();
    }

    UART_PRINT("Device started as STATION \n\r");

    //
    // reset all network policies
    //
    lRetVal = sl_WlanPolicySet(  SL_POLICY_CONNECTION,
                  SL_CONNECTION_POLICY(0,0,0,0,0),
                  &policyVal,
                  1 /*PolicyValLen*/);
    if (lRetVal < 0)
    {
        UART_PRINT("Failed to set policy \n\r");
        LOOP_FOREVER();
    }

    while (iFlag)
    { 
    User = UserInput();

    switch(User.choice)
    {
    case(1):

        /*******An example of Tx continuous on user selected channel, rate 11,
        * user selected number of packets, minimal delay between packets*******/
        lRetVal = Tx_continuous(User.channel,User.rate,User.packets, \
                             User.Txpower,0);
        if(lRetVal < 0)
        {
            UART_PRINT("Error during transmission of raw data\n\r");
            LOOP_FOREVER();
        }
        break;
    case(2):

        /******An example of Rx statistics using user selected channel *******/
        lRetVal = RxStatisticsCollect();
        if(lRetVal < 0)
        {
            UART_PRINT("Error while collecting statistics data\n\r");
            LOOP_FOREVER();
        }
        break;
    }

    UART_PRINT("\n\rEnter \"1\" to restart or \"0\" to quit: ");
    //
    // Wait to receive a character over UART
    //
    cChar = MAP_UARTCharGet(CONSOLE);
    //
    // Echo the received character
    //
    MAP_UARTCharPut(CONSOLE, cChar);
    UART_PRINT("\n\r");
    iFlag = atoi(&cChar);
    }
    UART_PRINT("\r\nEnding the application....");
    //
    // power off network processor
    //
    lRetVal = sl_Stop(SL_STOP_TIMEOUT);

    LOOP_FOREVER();

}
예제 #8
0
void Storage::Load()
{
    FILE* f = 0; 
    fopen_s( &f, FileName.c_str(), "rb" );
    if ( f == 0 )
        return;

    // Number of probes what we have
    int num_probes = 0;
    fread( &num_probes, 4, 1, f );

    while( num_probes ) 
    {
        // probe hints
        int record_guess = -1;
        fread( &record_guess, 4, 1, f );
        int record_inplace = -1;
        fread( &record_inplace, 4, 1, f );

        UserInput ui(record_guess, record_inplace);

        // number of history records
        int num_records = 0;
        fread( &num_records, 4, 1, f );

        while( num_records )
        {
            // history record value
            int record_value = -1111;
            fread( &record_value, 4, 1, f );
            // history record hints
            record_guess = -1;
            fread( &record_guess, 4, 1, f );
            record_inplace = -1;
            fread( &record_inplace, 4, 1, f );

            ui.history.push_back( UserInput( record_value, record_guess, record_inplace ) );
            num_records--;
        }

        // number of digits with minimal invariance
        int min_size = 0;
        fread( &min_size, 4, 1, f );

        // invariance value
        int min_value = 0;
        fread( &min_value, 4, 1, f );

        // read digits
        int *buf = new int[min_size];
        unsigned int page = (unsigned int)min_size;
        unsigned int readed = 0;
        while( page ) 
        {
            readed = _fread_nolock( buf + readed, 4, page, f);
            page -= readed;
        }

        for( int i = 0; i < min_size; i++ )
            ui.min_variants.insert( MinimalsT::value_type( buf[i], min_value ) );
        delete[] buf;

        if ( !ui.empty() )
            probes.insert( ui );
        num_probes--;
    }

    fclose(f);
}
예제 #9
0
파일: menu.c 프로젝트: chenlongchoo/EM6300
/*====	2012-04-30 Liz: Control 3 Buttons: UP, DOWN, ENTER to let user key in password/CT_rating 	=====*/
BYTE user_input_control(BYTE number_of_digits)
{
	BYTE i = 0;
	
	// Display cursor to let user know to start key in value
	//if(current_pw_digit == 0 && is_cursor_on==0)
	if(is_cursor_on==0)
	{
		if(getMenuCurrentState() == MENU_PASSWORD_STATE)	LCD_PrintStringPGM("PASSWORD?    1/1", LCD_ROW0);
		UserInput();
		is_cursor_on = 1;
	}

	// If BUTTON_DOWN is pressed, decrease digit value (from 0-9)
	if (digit > 48)
	{
		if (BUTTON_DOWN == 0) button_down_old_state = 1;
		if ((BUTTON_DOWN == 1) && (button_down_old_state == 1))
		{
			digit--;
			UserInput();
			button_down_old_state = 0;
			#ifdef APP_USE_BUZZER
			sound();
			#endif
			return 1;
		}
	}
	
	// If BUTTON_UP is pressed, increase digit value (from 0-9)	
	if (digit < 57)
	{
		if (BUTTON_UP == 0) button_up_old_state = 1;
		if ((BUTTON_UP == 1) && (button_up_old_state == 1))
		{
			digit++;
			UserInput();
			button_up_old_state = 0;
			#ifdef APP_USE_BUZZER
			sound();
			#endif
			return 2;
		}
	}
	// If BUTTON_ENTER is pressed, move to next digit or submit user input
	if (BUTTON_ENTER == 0) button_enter_old_state = 1;
	if ((BUTTON_ENTER == 1) && (button_enter_old_state == 1))
	{
		button_enter_old_state = 0;
		if(current_pw_digit < number_of_digits - 1)
		{
			UserInput();
			current_pw_digit++; 
			digit = 48;
			is_cursor_on = 0;
		}
		else
		{
			// User already key in 4-digit pw, checking if pw is correct
			if(getMenuCurrentState() == MENU_PASSWORD_STATE)
			{
				if(char_menu_pw[0]==AppConfig.Password[0] && char_menu_pw[1]==AppConfig.Password[1]
			 	  && char_menu_pw[2]==AppConfig.Password[2] && char_menu_pw[3]==AppConfig.Password[3])
				{
					LCD_ClearScreen();
					setMenuCurrentState(MENU_SETTINGS_STATE);
					set_current_menu(0);
					gotoMenuSettingState();
				}
				else
				{
					LCD_PrintStringPGM("Wrong Password", LCD_ROW1);
					Delay10KTCYx(0);
					Delay10KTCYx(0);
					LCD_ClearScreen();
					is_cursor_on = 0;
					//LCD_PrintStringPGM("Settings     2/3", LCD_ROW0);
				}
			}
			else if(getMenuCurrentState() == SUBMENU_SETTINGS_STATE && get_current_menu() == 0)	// Get CT_Rating input
			{
				CALIBRATION_VALUES stCalib;
				
				// Get Calib value first
				if( !MCURequestToBOTTOMBoard(MMT_GET_CALIBRATION_DATA, &stCalib, sizeof(CALIBRATION_VALUES), TRUE, TRUE) )
				{
					LCD_PrintStringPGM("Try Again...", LCD_ROW1);
				}
				else
				{
					// Update CT value
					stCalib.CT_RANGE = atoi(char_menu_pw);

					// There are changes... save it!
					MCURequestToBOTTOMBoard(MMT_SET_CALIBRATION_DATA_NEW, &stCalib, sizeof(CALIBRATION_VALUES), TRUE, TRUE);
			
					if( ((BYTE*)&stCalib)[0] != 'O' && ((BYTE*)&stCalib)[1] != 'K' )
						LCD_PrintStringPGM("Try Again...", LCD_ROW1);
					else
					{
						LCD_PrintStringPGM("OK-PLS RESET ENR", LCD_ROW1);
						setMenuCurrentState(MENU_SETTINGS_STATE);
						resetUserInput();
					}
				}
			
				Delay10KTCYx(0);
				Delay10KTCYx(0);
				LCD_ClearScreen();
				LCD_PrintStringPGM("Set CT_Range 1/3", LCD_ROW0);
			}
			else if(getMenuCurrentState() == SUBMENU_SETTINGS_STATE && get_current_menu() == 2)	// Get IPAddr input
			{
				char s[16] = "192.168.1.";

				s[10] = 0;
				strcat(s, char_menu_pw);			

				if(!StringToIPAddress((BYTE*)s, &AppConfig.MyIPAddr))
					LCD_PrintStringPGM("Try Again...", LCD_ROW1);
				else
				{
					LCD_PrintString(s, LCD_ROW1, 0);
					setMenuCurrentState(MENU_SETTINGS_STATE);
					resetUserInput();

					SaveAppConfig();
					Reset();
				}
				Delay10KTCYx(0);
				Delay10KTCYx(0);
				LCD_ClearScreen();
				LCD_PrintStringPGM("Set IP addr  3/3", LCD_ROW0);	
			}
			
			resetUserInput();
		}
		#ifdef APP_USE_BUZZER
			sound();
		#endif	
		return 3;
	}
}