Example #1
0
void GameState::loop()
{
	Ogre::Real elapse = UtilityFunc::getElapseLastFrame();
	if (elapse > 0.1f) 
		elapse = 0.1f;

	AIManager::getSingleton()->run();

	cheat(car, vai1, 0);
	cheat(car2, vai2, 1);
	cheat(car3, vai3, 2);
	cheat(car4, vai4, 3, false);

	car->updata(elapse);
	car2->updata(elapse);
	car3->updata(elapse);
	car4->updata(elapse);

	raceLogic(car, vai1, 0);
	raceLogic(car2, vai2, 1);
	raceLogic(car3, vai3, 2);
	raceLogic(car4, vai4, 3);

	UtilityFunc::showFPS(mWindow);

	if (!mIsPause)
	{
		mPhysicScene->simulate(1.0f/6.0f);
		mPhysicScene->flushStream();
		mPhysicScene->fetchResults(NX_RIGID_BODY_FINISHED, true);
	}
}
Example #2
0
int		my_put_nbr(int nb)
{
  unsigned char	len;
  int		copy;
  int		diz;

  if (nb == -2147483648)
    {
      cheat();
      return (0);
    }
  nb = is_negative(nb);
  copy = nb;
  len = 1;
  while (copy > 9)
    {
      copy = copy / 10;
      len = len + 1;
    }
  while (len != 0)
    {
      diz = nb / my_pow(len-1);
      my_putchar(diz + 48);
      nb = nb - diz * my_pow(len-1);
      len = len - 1;
    }
}
Example #3
0
uint8_t handle_fire(){
    static uint16_t timer = 0; // for holdoff
    static uint16_t counter = 0; // for power
    uint16_t a;

    a=ADC_read();
    if (a > config.fire_cheating){
        cheat();
    }
    if (a > config.fire_threshold && a < config.fire_cheating)
    {
        while(!my_random_number){
            my_random_number = TMR0;
        }
        if(timer < config.fire_holdoff)
        {
            timer ++;
        }
        else
        {
            if(!config.power || counter <= config.power)
            {
                if(!counter)
                {
                    green_led_on();
                    play_song((uint16_t*)fire_song,sizeof(fire_song)/sizeof(uint16_t),3000,!(config.power));
                }
                Send_Byte(config.id);
                counter++;
            }
            else
            {
                led_off();
            }
        }
    }
    else
    {
        led_off();
        if(!config.power && counter) stop_song();
        timer = 0;
        counter = 0;
        return 0;
    }
    return 1;
}
Example #4
0
int play(uint32_t goal)
{
    while (!reach_goal(goal)) {
        print_board();
        if (!SPACE)
            return 0;

        switch (get_move()) {
            case 'W':
            case 'w':
                up();
                new_item();
                break;
            case 'S':
            case 's':
                down();
                new_item();
                break;
            case 'A':
            case 'a':
                left();
                new_item();
                break;
            case 'D':
            case 'd':
                right();
                new_item();
                break;
            case 'C':
            case 'c':
                if (CHEAT)
                    cheat();
                break;
            case 'G':
            case 'g':
                if (CHEAT)
                    return 0;
                break;
        }
    }

    return 1;
}
Example #5
0
void options()
{
    int choix = 0;
    

    FctVideEcran();
    
    do
    {
        // Affichage de "OPTIONS" en ASCII //
        
        printf("                        _   _\n             ___  _ __ | |_(_) ___  _ __  ___\n            / _ \\| '_ \\| __| |/ _ \\| '_ \\/ __|\n           | (_) | |_) | |_| | (_) | | | \\__ \\\n            \\___/| .__/ \\__|_|\\___/|_| |_|___/\n                 |_|\n\n");
    
        printf("\tFaites votre choix :\n\n\n");
        printf("\t1 - High Score\n");
        printf("\t2 - Credits\n");
        printf("\t3 - Cheat Codes\n");
        printf("\t4 - Retour\n\n");
        printf("\t Veuillez entrez votre choix : ");
    
        scanf("%i",&choix);
    
    
        switch(choix)
        {
            case 1: menu_highscore(); break;
            case 2: credits(); break;
            case 3: cheat(); break;
            case 4: break;
            default:
                FctVideEcran();
                viderBuffer();
                printf("Erreur: votre choix doit ĂȘtre compris entre 1 et 4\n");
                char tempo = get_one_char();
                FctVideEcran();
                break;
        }
    
        FctVideEcran();
    }while(choix != 4);
}
Example #6
0
void Send_Byte(uint8_t data)
{
    data ^= 0b10101010; 
    delay_1_ms();
    RCSTAbits.CREN = 0; // Disable receiver
    //if (!PORTAbits.RA1){cheat();} // IR receiver isn't in place
    for(uint16_t i=0; i<100; i++){
        if(PORTAbits.RA1){break;} // You aren't cheating if RA1 is high
        delay_1_ms();
        if(i==99){cheat();}
    }

    Modulate_Serial();
    TXREG = data;
    while(!TXSTAbits.TRMT); // Wait for USART to send all data
    Disable_Modulation();
    RCSTAbits.CREN = 1; // Enable receiver
    RCREG;
    delay_1_ms();
    delay_1_ms();
}
Example #7
0
/*scanning input from user*/
char scan(char input[length],int i, char color[length])
{

	printf("Guess %i\t%c ", i+1, 175);
	fflush(stdin);
	scanf("%c", &input[i]);
	input[i] = toupper(input[i]);
	if(input[i] == 'Q')
	{
		return 'Q';
	}
	else if(input[i] == 'I')
	{
		Info();
		return 'I';
	}
	else if(input[i] == '*')
	{
		cheat(color);
		return 'I';
	}
}
/** initialization process
 **/
int irrigation_controller::init(OBJECT *parent){
	OBJECT *hdr = OBJECTHDR(this);
	char tname[32];
	parent2=parent;
	insync=0;
	

	initial_zipload_power=gl_get_double_by_name(parent,"base_power");

	char *namestr = (hdr->name ? hdr->name : tname);

	sprintf(tname, "irrigation_controller:%i", hdr->id);
	first=0;
	cheat();

	if(parent == NULL){
		gl_error("%s: irrigation_controller has no parent, therefore nothing to control", namestr);
		return 0;
	}

	if(pMarket == NULL){
		gl_error("%s: irrigation_controller has no market, therefore no price signals", namestr);
		return 0;
	}

	if(gl_object_isa(pMarket, "auction")){
		gl_set_dependent(hdr, pMarket);
		market = OBJECTDATA(pMarket, auction);
	} else {
		gl_error("irrigation_controllers only work when attached to an 'auction' object");
		return 0;
	}

	if(dPeriod == 0.0){
		if((pMarket->flags & OF_INIT) != OF_INIT){
			char objname[256];
			gl_verbose("irrigation_controller::init(): deferring initialization on %s", gl_name(pMarket, objname, 255));
			return 2; // defer
		}
		period = market->period;
	} else {
		period = (TIMESTAMP)floor(dPeriod + 0.5);
	}

	if(bid_delay < 0){
		bid_delay = -bid_delay;
	}
	if(bid_delay > period){
		gl_warning("Bid delay is greater than the irrigation_controller period. Resetting bid delay to 0.");
		bid_delay = 0;
	}

	if(target[0] == 0){
		GL_THROW("irrigation_controller: %i, target property not specified", hdr->id);
	}
	if(setpoint[0] == 0 && control_mode == CN_RAMP){
		GL_THROW("irrigation_controller: %i, setpoint property not specified", hdr->id);;
	}
	if(demand[0] == 0 && control_mode == CN_RAMP){
		GL_THROW("irrigation_controller: %i, demand property not specified", hdr->id);
	}
	if(deadband[0] == 0 && use_predictive_bidding == TRUE && control_mode == CN_RAMP){
		GL_THROW("irrigation_controller: %i, deadband property not specified", hdr->id);
	}
	if(total[0] == 0){
		GL_THROW("irrigation_controller: %i, total property not specified", hdr->id);
	}
	if(load[0] == 0){
		GL_THROW("irrigation_controller: %i, load property not specified", hdr->id);
	}

	
	fetch(&pMonitor, target, parent); // auto tha einai to soil hmidit tha to pairnei apo to soil_SENSOR
	if(control_mode == CN_RAMP){
		fetch(&pSetpoint, setpoint, parent);
		fetch(&pDemand, demand, parent);
		fetch(&pTotal, total, parent);
		fetch(&pLoad, load, parent);
		if(use_predictive_bidding == TRUE){
			fetch(&pDeadband, deadband.get_string(), parent);
		}
	} 
	fetch(&pAvg, avg_target.get_string(), pMarket);
	fetch(&pStd, std_target.get_string(), pMarket);


	if(dir == 0){
		double high = ramp_high * range_high;
		double low = ramp_low * range_low;
			//printf("high:%f, low:%f, rh:%f, rl:%f,gh:%f,gl:%f\n\n\n\n",high,low,ramp_high,ramp_low,range_high,range_low);
		if(high > low){
			dir = 1;
		} else if(high < low){
			dir = -1;
		} else if((high == low) && (fabs(ramp_high) > 0.001 || fabs(ramp_low) > 0.001)){
			dir = 0;
			if(ramp_high > 0){
				direction = 1;
			} else {
				direction = -1;
			}
			gl_warning("%s: irrigation_controller has no price ramp", namestr);
			/* occurs given no price variation, or no control width (use a normal thermostat?) */
		}
		if(ramp_low * ramp_high < 0){
			gl_warning("%s: irrigation_controller price curve is not injective and may behave strangely");
			/* TROUBLESHOOT
				The price curve 'changes directions' at the setpoint, which may create odd
				conditions in a number of circumstances.
			 */
		}
	}
	if(setpoint0==0)
		setpoint0 = -1; // key to check first thing

//	double period = market->period;
//	next_run = gl_globalclock + (TIMESTAMP)(period - fmod(gl_globalclock+period,period));
	next_run = gl_globalclock;// + (market->period - gl_globalclock%market->period);
	init_time = gl_globalclock;
	time_off = TS_NEVER;
	if(sliding_time_delay < 0 )
		dtime_delay = 21600; // default sliding_time_delay of 6 hours
	else
		dtime_delay = (int64)sliding_time_delay;

	if(state[0] != 0){
		// grab state pointer
		pState = gl_get_enum_by_name(parent, state);
		last_pState = 0;
		if(pState == 0){
			gl_error("state property name \'%s\' is not published by parent class", state);
			return 0;
		}
	}

	
	// get override, if set
	if(re_override[0] != 0){
		pOverride = gl_get_enum_by_name(parent, re_override);
	}
	if((pOverride == 0) && (use_override == OU_ON)){
		gl_error("use_override is ON but no valid override property name is given");
		return 0;
	}

	if(control_mode == CN_RAMP){
		if(slider_setting < -0.001){
			gl_warning("slider_setting is negative, reseting to 0.0");
			slider_setting = 0.0;
		}
		if(slider_setting > 1.0){
			gl_warning("slider_setting is greater than 1.0, reseting to 1.0");
			slider_setting = 1.0;
		}
	}
	
	last_p = market->init_price;

	/////////////////search for virtual_battery///////////////////////
	/*
				 static FINDLIST *xt1=NULL;
				 xt1=gl_find_objects(FL_NEW,FT_CLASS,SAME,"virtual_battery",FT_END);
				 OBJECT *firstt1= gl_find_next(xt1,NULL);
				 OBJECT *it1;
				 for(it1=firstt1;it1!=NULL;it1=it1->next)
				 {
				
					 if(gl_object_isa(it1,"virtual_battery"))
				     {

						
						 virtual_battery_object=it1;
						
					 }
					 else
					 {
					 
					// virtual_battery_object=NULL;
					 
					 }


				 }

	*/
	//////////////////////////////////////////////////////////////////
	return 1;
}
Example #9
0
void runner_update(LandRunner * self) {
    All * a = global_a;
#line 234
    update();
#line 236
    if (land_closebutton()) {
        save_level(0);
        land_quit();
    }
    if (land_switched_out()) {
        save_level(0);
    }
    if (land_was_halted()) {
#line 243
        ;
    }
#line 246
    if (! land_keybuffer_empty()) {
        int k, u;
        land_keybuffer_next(& k, & u);
        cheat(u);
#line 251
        if (k == LandKeyEscape) {
            save_level(0);
            land_quit();
        }
#line 254
        else if (k == LandKeyFunction + 1) {
            a->show_fps = ! a->show_fps;
        }
#line 255
        else {
#line 257
            if (a->text_input) {
                if (u == '|') {
                    u = '\n';
                }
#line 260
                if (u == 13) {
                    u = 0;
                }
#line 262
                if (a->text_input == 1) {
                    game->title [a->cursor++] = u;
                }
#line 264
                else if (a->text_input == 2) {
                    game->hint [a->cursor++] = u;
                }
#line 266
                if (u == 0) {
                    a->text_input = 0;
                }
            }
#line 268
            else if (! a->title) {
                if (a->editor_enabled) {
                    game_key(game, k);
                }
            }
        }
    }
}
Example #10
0
/** initialization process
 **/
int controller::init(OBJECT *parent){
	OBJECT *hdr = OBJECTHDR(this);
	char tname[32];
	char *namestr = (hdr->name ? hdr->name : tname);
//	double high, low;

	sprintf(tname, "controller:%i", hdr->id);

	cheat();

	if(parent == NULL){
		gl_error("%s: controller has no parent, therefore nothing to control", namestr);
		return 0;
	}

	if(pMarket == NULL){
		gl_error("%s: controller has no market, therefore no price signals", namestr);
		return 0;
	}

	if(gl_object_isa(pMarket, "auction")){
		gl_set_dependent(hdr, pMarket);
		market = OBJECTDATA(pMarket, auction);
	} else {
		gl_error("controllers only work when attached to an 'auction' object");
		return 0;
	}

	if(dPeriod == 0.0){
		period = market->period;
	} else {
		period = (TIMESTAMP)floor(dPeriod + 0.5);
	}

	if(bid_delay < 0){
		bid_delay = -bid_delay;
	}
	if(bid_delay > period){
		gl_warning("Bid delay is greater than the controller period. Resetting bid delay to 0.");
		bid_delay = 0;
	}

	if(target[0] == 0){
		GL_THROW("controller: %i, target property not specified", hdr->id);
	}
	if(setpoint[0] == 0 && control_mode == CN_RAMP){
		GL_THROW("controller: %i, setpoint property not specified", hdr->id);;
	}
	if(demand[0] == 0 && control_mode == CN_RAMP){
		GL_THROW("controller: %i, demand property not specified", hdr->id);
	}
	if(total[0] == 0){
		GL_THROW("controller: %i, total property not specified", hdr->id);
	}
	if(load[0] == 0){
		GL_THROW("controller: %i, load property not specified", hdr->id);
	}

	if(heating_setpoint[0] == 0 && control_mode == CN_DOUBLE_RAMP){
		GL_THROW("controller: %i, heating_setpoint property not specified", hdr->id);;
	}
	if(heating_demand[0] == 0 && control_mode == CN_DOUBLE_RAMP){
		GL_THROW("controller: %i, heating_demand property not specified", hdr->id);
	}

	if(cooling_setpoint[0] == 0 && control_mode == CN_DOUBLE_RAMP){
		GL_THROW("controller: %i, cooling_setpoint property not specified", hdr->id);;
	}
	if(cooling_demand[0] == 0 && control_mode == CN_DOUBLE_RAMP){
		GL_THROW("controller: %i, cooling_demand property not specified", hdr->id);
	}

	if(deadband[0] == 0 && control_mode == CN_DOUBLE_RAMP){
		GL_THROW("controller: %i, deadband property not specified", hdr->id);
	}

	fetch(&pMonitor, target, parent);
	if(control_mode == CN_RAMP){
		fetch(&pSetpoint, setpoint, parent);
		fetch(&pDemand, demand, parent);
		fetch(&pTotal, total, parent);
		fetch(&pLoad, load, parent);
	} else if(control_mode == CN_DOUBLE_RAMP){
		sprintf(aux_state, "is_AUX_on");
		sprintf(heat_state, "is_HEAT_on");
		sprintf(cool_state, "is_COOL_on");
		fetch(&pHeatingSetpoint, heating_setpoint, parent);
		fetch(&pHeatingDemand, heating_demand, parent);
		fetch(&pHeatingTotal, total, parent);
		fetch(&pHeatingLoad, total, parent);
		fetch(&pCoolingSetpoint, cooling_setpoint, parent);
		fetch(&pCoolingDemand, cooling_demand, parent);
		fetch(&pCoolingTotal, total, parent);
		fetch(&pCoolingLoad, load, parent);
		fetch(&pDeadband, deadband, parent);
		fetch(&pAuxState, aux_state, parent);
		fetch(&pHeatState, heat_state, parent);
		fetch(&pCoolState, cool_state, parent);
	}
	fetch(&pAvg, avg_target, pMarket);
	fetch(&pStd, std_target, pMarket);


	if(dir == 0){
		double high = ramp_high * range_high;
		double low = ramp_low * range_low;
		if(high > low){
			dir = 1;
		} else if(high < low){
			dir = -1;
		} else if((high == low) && (fabs(ramp_high) > 0.001 || fabs(ramp_low) > 0.001)){
			dir = 0;
			gl_warning("%s: controller has no price ramp", namestr);
			/* occurs given no price variation, or no control width (use a normal thermostat?) */
		}
		if(ramp_low * ramp_high < 0){
			gl_warning("%s: controller price curve is not injective and may behave strangely");
			/* TROUBLESHOOTING
				The price curve 'changes directions' at the setpoint, which may create odd
				conditions in a number of circumstances.
			 */
		}
	}
	if(setpoint0==0)
		setpoint0 = -1; // key to check first thing

	if(heating_setpoint0==0)
		heating_setpoint0 = -1;

	if(cooling_setpoint0==0)
		cooling_setpoint0 = -1;

//	double period = market->period;
//	next_run = gl_globalclock + (TIMESTAMP)(period - fmod(gl_globalclock+period,period));
	next_run = gl_globalclock;// + (market->period - gl_globalclock%market->period);
	time_off = TS_NEVER;
	if(sliding_time_delay < 0 )
		dtime_delay = 21600; // default sliding_time_delay of 6 hours
	else
		dtime_delay = (int64)sliding_time_delay;

	if(state[0] != 0){
		// grab state pointer
		pState = gl_get_enum_by_name(parent, state);
		last_pState = 0;
		if(pState == 0){
			gl_error("state property name \'%s\' is not published by parent class", state);
			return 0;
		}
	}

	if(heating_state[0] != 0){
		// grab state pointer
		pHeatingState = gl_get_enum_by_name(parent, heating_state);
		if(pHeatingState == 0){
			gl_error("heating_state property name \'%s\' is not published by parent class", heating_state);
			return 0;
		}
	}

	if(cooling_state[0] != 0){
		// grab state pointer
		pCoolingState = gl_get_enum_by_name(parent, cooling_state);
		if(pCoolingState == 0){
			gl_error("cooling_state property name \'%s\' is not published by parent class", cooling_state);
			return 0;
		}
	}
	// get override, if set
	if(re_override[0] != 0){
		pOverride = gl_get_enum_by_name(parent, re_override);
	}
	if((pOverride == 0) && (use_override == OU_ON)){
		gl_error("use_override is ON but no valid override property name is given");
		return 0;
	}

	if(control_mode == CN_RAMP){
		if(slider_setting < 0.0){
			gl_warning("slider_setting is negative, reseting to 0.0");
			slider_setting = 0.0;
		}
		if(slider_setting > 1.0){
			gl_warning("slider_setting is greater than 1.0, reseting to 1.0");
			slider_setting = 1.0;
		}
	}
	if(control_mode == CN_DOUBLE_RAMP){
		if(slider_setting_heat < 0.0){
			gl_warning("slider_setting_heat is negative, reseting to 0.0");
			slider_setting_heat = 0.0;
		}
		if(slider_setting_cool < 0.0){
			gl_warning("slider_setting_cool is negative, reseting to 0.0");
			slider_setting_cool = 0.0;
		}
		if(slider_setting_heat > 1.0){
			gl_warning("slider_setting_heat is greater than 1.0, reseting to 1.0");
			slider_setting_heat = 1.0;
		}
		if(slider_setting_cool > 1.0){
			gl_warning("slider_setting_cool is greater than 1.0, reseting to 1.0");
			slider_setting_cool = 1.0;
		}
		// get override, if set
	}
	last_p = market->init_price;
	return 1;
}
Example #11
0
static void read_config(void)
{
  FILE *fp;
  char file[MAX_PATH + 1];
  char line[MAX_LINE];
  char *key, *val, *p;
  long n;
  int story_matches = 1;

  zterp_os_rcfile(file, sizeof file);

  fp = fopen(file, "r");
  if(fp == NULL) return;

  while(fgets(line, sizeof line, fp) != NULL)
  {
    line[strcspn(line, "#\n")] = 0;
    if(line[0] == 0) continue;

    if(line[0] == '[')
    {
      p = strrchr(line, ']');
      if(p != NULL && p[1] == 0)
      {
        *p = 0;

        story_matches = 0;
        for(p = strtok(line + 1, " ,"); p != NULL; p = strtok(NULL, " ,"))
        {
          if(is_story(p)) story_matches = 1;
        }
      }

      continue;
    }

    if(!story_matches) continue;

    key = strtok(line, " \t=");
    if(key == NULL) continue;
    val = strtok(NULL, "=");
    if(val == NULL) continue;

    /* Trim whitespace. */
    while(isspace((unsigned char)*val)) val++;
    if(*val == 0) continue;
    p = val + strlen(val) - 1;
    while(isspace((unsigned char)*p)) *p-- = 0;

    n = strtol(val, NULL, 10);

#define BOOL(name)	else if(strcmp(key, #name) == 0) options.name = (n != 0)
#define NUMBER(name)	else if(strcmp(key, #name) == 0) options.name = n
#define STRING(name)	else if(strcmp(key, #name) == 0) do { free(options.name); options.name = xstrdup(val); } while(0)
#define CHAR(name)	else if(strcmp(key, #name) == 0) options.name = val[0]
#ifdef GARGLK
#define COLOR(name, num)else if(strcmp(key, "color_" #name) == 0) update_color(num, strtol(val, NULL, 16))
#else
#define COLOR(name, num)else if(0)
#endif

    if(0);

    NUMBER(eval_stack_size);
    NUMBER(call_stack_size);
    BOOL  (disable_color);
    BOOL  (disable_timed);
    BOOL  (disable_sound);
    BOOL  (enable_escape);
    STRING(escape_string);
    BOOL  (disable_fixed);
    BOOL  (assume_fixed);
    BOOL  (disable_graphics_font);
    BOOL  (enable_alt_graphics);
    BOOL  (disable_term_keys);
    BOOL  (disable_utf8);
    BOOL  (force_utf8);
    BOOL  (disable_meta_commands);
    NUMBER(max_saves);
    BOOL  (disable_undo_compression);
    NUMBER(int_number);
    CHAR  (int_version);
    BOOL  (replay_on);
    STRING(replay_name);
    BOOL  (record_on);
    STRING(record_name);
    BOOL  (transcript_on);
    STRING(transcript_name);
    BOOL  (disable_abbreviations);
    BOOL  (enable_censorship);
    BOOL  (overwrite_transcript);
    NUMBER(random_seed);
    STRING(random_device);

    COLOR(black,   2);
    COLOR(red,     3);
    COLOR(green,   4);
    COLOR(yellow,  5);
    COLOR(blue,    6);
    COLOR(magenta, 7);
    COLOR(cyan,    8);
    COLOR(white,   9);

#ifndef ZTERP_NO_CHEAT
    else if(strcmp(key, "cheat") == 0) cheat(val);
#endif

#undef BOOL
#undef NUMBER
#undef STRING
#undef CHAR
#undef COLOR
  }
Example #12
0
void grid::Grid::update()
{

	if( egn::Keyboard::isActive( "return" ) )
	{
		GameState::set( Gamestate::MENU_PAUSE );
		egn::Keyboard::setActive("return",false);
	}

	if( egn::Keyboard::isActive( "space" ) )
	{
		cheat( 1024 );
		egn::Keyboard::setActive( "space", false );
	}


	if( m_InMove == false )
	{
		
		if( egn::Keyboard::isActive("up") )
		{
			move(Direction::UP);
			egn::Keyboard::setActive("up",false);
			egn::AudioManager::get()->playSound("data/audio/theme1.ogg");
		}
		else if( egn::Keyboard::isActive("down") )
		{
			move(Direction::DOWN);
			egn::Keyboard::setActive("down",false);
			egn::AudioManager::get()->playSound("data/audio/theme1.ogg");
		}
		else if( egn::Keyboard::isActive("left") )
		{
			move(Direction::LEFT);
			egn::Keyboard::setActive("left",false);
			egn::AudioManager::get()->playSound("data/audio/theme1.ogg");
		}
		else if( egn::Keyboard::isActive("right") )
		{
			move(Direction::RIGHT);
			egn::Keyboard::setActive("right",false);
			egn::AudioManager::get()->playSound("data/audio/theme1.ogg");
		}
	}

	for( int i = 0; i < m_MoveNumber.size(); i++ )
	{
		m_MoveNumber[i].update();
		if( m_MoveNumber[i].inMove() == false )
		{
			ref ref_tmp = m_MoveNumber[i].getRef();
			m_Grid[ref_tmp.i][ref_tmp.j].setDraw( true );
			if( m_Grid[ref_tmp.i][ref_tmp.j].get() == 2048 && m_Continue == false && !m_Challenge )
			{
				m_Continue = true;
				GameState::set(Gamestate::MENU_CONTINUE);
				m_InMove = false;
			}
		}
	}

	for( int i = 0; i < m_MoveNumber.size(); i++ )
	{
		if( m_MoveNumber[i].inMove() == false )
		{
			m_MoveNumber.erase( m_MoveNumber.begin() + i );

		}
	}

	if( m_MoveNumber.size() <= 0 && m_InMove == true )
	{
		if( !moveIsPossible( m_Direction ) )
		{
			m_InMove = false;
			if( !isFull() ) 
			{
				popNumber( 1 );
			}	
		}
		else 
		{
			move( m_Direction );
		}
	}

	m_PlayerInfo.update();
}
Example #13
0
// ----------------------- MAINWINDOW() -----------------------
MainWindow::MainWindow() {
	// Set initial gameplay states
	shouldDelete = false;
	heuristic = NONE;
	tileMoving = false;
	
	// Change app style
	defaultStyle = new QPlastiqueStyle;
	QApplication::setStyle(defaultStyle);
	
	// Create Main Layout
	mainLayout = new QGridLayout();
	
	// Board Visualization
	puzzleScene = new QGraphicsScene(-WINDOW_MAX_X/2, -WINDOW_MAX_X/2, WINDOW_MAX_X, WINDOW_MAX_Y);
	puzzleScene->setBackgroundBrush(Qt::white);
	viewStyle = new QProxyStyle;
	puzzleView = new QGraphicsView(puzzleScene);
	puzzleView->setStyle(viewStyle);
	puzzleView->setFixedSize(WINDOW_MAX_X + 20, WINDOW_MAX_Y + 20);
	mainLayout->addWidget(puzzleView, 2, 1, 4, 1);
	
	// Error Box
	errorText = new QTextEdit();
	errorText->setReadOnly(true);
	errorBox = new QGroupBox("Console");
	errorBoxLayout = new QVBoxLayout;
	errorBoxLayout->addWidget(errorText);
	errorBox->setLayout(errorBoxLayout);
	mainLayout->addWidget(errorBox, 6, 1);
	
	// Title Label
	titleLabel = new QLabel();
	titleLabel->setAlignment(Qt::AlignCenter);
	titleLabel->setTextFormat(Qt::RichText);
	titleLabel->setText("<b>Game Time!</font></b>");
	mainLayout->addWidget(titleLabel, 1, 0);
	
	// Exit Button
	exitButton = new QPushButton("&Quit");
	connect(exitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
	mainLayout->addWidget(exitButton, 6, 0);
	
	// A* Button
	cheatButton = new QPushButton("&Cheat");
	connect(cheatButton, SIGNAL(clicked()), this, SLOT(cheat()));
	
	// A* Results
	cheatResults = new QListWidget();
	
	// Radio Button Label
	heuristicLabel = new QLabel("Choose a Heuristic:");
	
	// Radio Buttons
	outOfPlaceRadio = new QRadioButton("&Out of Place");
	connect(outOfPlaceRadio, SIGNAL(clicked()), this, SLOT(handleRadios()));
	manhattanRadio = new QRadioButton("&Manhattan");
	connect(manhattanRadio, SIGNAL(clicked()), this, SLOT(handleRadios()));
	
	// Cheaters GroupBox
	cheatersBox = new QGroupBox("For Cheaters");
	cheatersBoxLayout = new QVBoxLayout;
	cheatersBoxLayout->addWidget(heuristicLabel);
	cheatersBoxLayout->addWidget(manhattanRadio);
	cheatersBoxLayout->addWidget(outOfPlaceRadio);
	cheatersBoxLayout->addWidget(cheatButton);
	cheatersBoxLayout->addWidget(cheatResults);
	cheatersBox->setLayout(cheatersBoxLayout);
	mainLayout->addWidget(cheatersBox, 5, 0);
	
	// Start Game Button
	startButton = new QPushButton("&Start Game");
	connect(startButton, SIGNAL(clicked()), this, SLOT(start()));
	
	// Input Labels
	sizeLabel = new QLabel("Board Size:");
	sizeLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
	movesLabel = new QLabel("Initial Moves:");
	movesLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
	seedLabel = new QLabel("Seed:");
	seedLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
	
	// Input Text Boxes
	sizeText = new QLineEdit();
	movesText = new QLineEdit();
	seedText = new QLineEdit();
	
	// Input GroupBox
	initialStuffBox = new QGroupBox("Initial Values");
	formLayout = new QFormLayout;
	formLayout->setLabelAlignment(Qt::AlignRight);
	formLayout->addRow(sizeLabel, sizeText);
	formLayout->addRow(movesLabel, movesText);
	formLayout->addRow(seedLabel, seedText);
	formLayout->addRow(startButton);
	initialStuffBox->setLayout(formLayout);
	mainLayout->addWidget(initialStuffBox, 2, 0);
	
	// Set Layout Settings
	setWindowTitle("Game Time!");
	setLayout(mainLayout);
}
Example #14
0
void
process_keystrokes (int key)
{

#if defined (commentout)	/* KBR 10/14/2002 - Cleanup MSVC warning */
    int retval;
#endif

    switch (key)
    {
    case 0: printf("dead!"); return;
    case ' ':   /* Space */
    case 10:    /* Linefeed/Return */
    case 13:    /* Enter */
    case 127:   /* Backspace */
	if (key == 127) {
	    cs_mouse_handler (LC_MOUSE_RIGHTBUTTON | LC_MOUSE_PRESS,
			      0, 0);
	    cs_mouse_handler (LC_MOUSE_RIGHTBUTTON | LC_MOUSE_RELEASE,
			      0, 0);
	} else {
	    cs_mouse_handler (LC_MOUSE_LEFTBUTTON | LC_MOUSE_PRESS,
			      0, 0);
	    cs_mouse_handler (LC_MOUSE_LEFTBUTTON | LC_MOUSE_RELEASE,
			      0, 0);
	}
	if (help_flag) {
	    draw_help_page ("return-2");
	}
	if (prefs_flag) {
	    close_prefs_screen ();
	    refresh_main_screen ();
	}
	break;

#if defined (SVGALIB)
    case 91:
	{
	    int w = vga_getkey ();
	    switch (w)
	    {
	    case ('A'):
		cs_mouse_handler (0, 0, -kmouse_val);
		break;
	    case ('B'):
		cs_mouse_handler (0, 0, kmouse_val);
		break;
	    case ('C'):
		cs_mouse_handler (0, kmouse_val, 0);
		break;
	    case ('D'):
		cs_mouse_handler (0, -kmouse_val, 0);
		break;
	    }
	}
	break;
#endif

#if defined (WIN32) || defined (LC_X11)
    case 1:
	/* Scroll left */
	if (x_key_shifted) {
	    adjust_main_origin (main_screen_originx - RIGHT_MOUSE_MOVE_VAL,
				main_screen_originy,
				TRUE);
	} else {
	    adjust_main_origin (main_screen_originx - 1,
				main_screen_originy,
				TRUE);
	}
	break;

    case 2:
	/* Scroll down */
	if (x_key_shifted) {
	    adjust_main_origin (main_screen_originx,
				main_screen_originy + RIGHT_MOUSE_MOVE_VAL,
				TRUE);
	} else {
	    adjust_main_origin (main_screen_originx,
				main_screen_originy + 1,
				TRUE);
	}
	break;

    case 3:
	/* Scroll up */
	if (x_key_shifted) {
	    adjust_main_origin (main_screen_originx,
				main_screen_originy - RIGHT_MOUSE_MOVE_VAL,
				TRUE);
	} else {
	    adjust_main_origin (main_screen_originx,
				main_screen_originy - 1,
				TRUE);
	}
	break;

    case 4:
	/* Scroll right */
	if (x_key_shifted) {
	    adjust_main_origin (main_screen_originx + RIGHT_MOUSE_MOVE_VAL,
				main_screen_originy,
				TRUE);
	} else {
	    adjust_main_origin (main_screen_originx + 1,
				main_screen_originy,
				TRUE);
	}
	break;
#endif

    case 'P':
    case 'p':
	select_pause ();
	break;

#ifdef DEBUG_KEYS
    case 'e':
	if (cheat () != 0)
	    people_pool += 100;
	break;

    case 'd':
	if (cheat () != 0)
	    dump_screen ();
	break;
	  
    case 'D':
	/*	dump_tcore (); */
	break;

    case 't':
	if (cheat () != 0)
	    tech_level += 1000;
	break;

    case 'T':
	if (cheat () != 0)
	    tech_level += 10000;
	break;

    case 'm':
	if (cheat () != 0) 
	    adjust_money(1000000);
	break;
#endif

    case 'f':
	do_random_fire (-1, -1, 1);
	break;

    case 'L':
    case 'l':
	load_flag = 1;
	break;

    case 'H':
    case 'h':
	activate_help ("index.hlp");
	break;

	/* Escape Key */
#ifdef LC_X11
    case 27:
#else
    case 5:
#endif
	if (help_flag) {
	    /* exit help */
	    draw_help_page("return-2"); 
	} else if (prefs_flag) {
	    close_prefs_screen();
	    refresh_main_screen ();
	} else {
	    activate_help ("menu.hlp");
	}
	break;

    case 'S':
    case 's':
	save_flag = 1;
	break;

    case 'v':
    case 'V':
	/* Toggle overlay */
	rotate_main_screen();
	break;

    case 'o':
    case 'O':
	prefs_flag = 1;
	break;

    case 'r':
        window_results();
	break;

    case 'q':
    case 'Q':
	quit_flag = 1;
	break;

    } /* end switch on keystroke */
}