Example #1
0
// Updating function to change highlighting of difficulty options
void update(int selection) {
  // Replace the old selection, so that it is not highlighted.
  // Need to set the cursor to the line old selection.
  // Since every line has 8 pixels, we skip 8 pixels for every line
  if (selection == 1) {
    tft.setTextColor(WHITE);
    easy(RED);
    tft.setTextColor(RED);
    medium(WHITE);
    hard(WHITE);
  }
  
  else if (selection == 2) {
    tft.setTextColor(WHITE);
    medium(RED);
    tft.setTextColor(RED);
    easy(WHITE);
    hard(WHITE);
  }
  
  else if (selection == 3) {
    tft.setTextColor(WHITE);
    hard(RED);
    tft.setTextColor(RED);
    easy(WHITE);
    medium(WHITE);
  }
}
Example #2
0
void cMenu::handleButton( pClient ps, cClientPacket* pkg  )
{
	
	cPacketMenuSelection* p = (cPacketMenuSelection*)pkg;

	pChar pc = ps->currChar();
	if ( ! pc ) return;

	uint32_t button = p->buttonId.get();

	this->switchs = &p->switchs;
	this->textResp = &p->text_entries;
	
	uint32_t buttonReturnCode;
	if( button!=MENU_CLOSE ) { 

		buttonReturnCode = getButton( button );

		map< uint32_t, FUNCIDX >::iterator iter( buttonCallbacks.find( button ) );
		if( iter!=buttonCallbacks.end() ) {

			AmxFunction func( iter->second );
			func.Call( serial, pc->getSerial(), buttonReturnCode );
			return;

		}
	}
	else {
		buttonReturnCode = 0;
	}

	//set property if there are

	if( ( buttonReturnCode!=MENU_CLOSE ) && ( buttonReturnCode==buffer[3] ) ) { 
		map< uint32_t, int32_t >::iterator propIter( editProps.begin() ), lastProp( editProps.end() );
		for( ; propIter!=lastProp; ++propIter ) {

			int32_t props = propIter->first;
			int prop, prop2, prop3;
			getPropsFromInt( props, prop, prop2, prop3 );  

			if( getPropertyType( prop )!=T_BOOL ) {
				unistring* data = getText( propIter->second, true );
				if( data!=NULL )
					setPropertyField( buffer[0], buffer[1], prop, prop2, prop3, *data );
			}
			else {
				setPropertyField( buffer[0], buffer[1], prop, prop2, prop3, getCheckBox( propIter->second, true ) );
			}
		}
	}
	
	if( callback!=NULL )
		callback->Call( serial, pc->getSerial(), buttonReturnCode );
	else
		hard( this, ps, buttonReturnCode );
}
Example #3
0
int generate(int x){
	time_t l;
	int p = 0, q = 0, i, j;
	srand((unsigned)time(&l));
	int k = rand() % 100;
	if(k % 2 == 1){
		answer1();
	}
	else
		answer2();
	switch(x){
		case 1:
			p = easy();
			break;
		case 2:
			p = medium();
			break;
		case 3:
			p = hard();
			break;
	}
	for(i = 1; i < 10; i++){
		for(j = 1; j < 10; j++){
			sudoko.b[i][j] = 0;
		}
	}
	while(q < p){
		sudoko.b[a[q]][b[q]] = sudoko.c[a[q]][b[q]];
		q++;
	}
	for(i = 1; i < 10; i++){
		for(j = 1; j < 10; j++){
			t[i][j] = sudoko.a[i][j] = 0;
		}
	}
	for(i = 1; i < 10; i++){
		for(j = 1; j < 10; j++){
			t[i][j] = sudoko.a[i][j] = sudoko.b[i][j];
		}
	}
	return 0;
}
Example #4
0
static unsigned parse_opt(std::istream& in, bool is_wcnf) {
    ast_manager m;
    reg_decl_plugins(m);
    opt::context opt(m);
    g_opt = &opt;
    params_ref p = gparams::get_module("opt");
    opt.updt_params(p);
    if (is_wcnf) {
        parse_wcnf(opt, in, g_handles);
    }
    else {
        parse_opb(opt, in, g_handles);
    }
    try {
        lbool r = opt.optimize();
        switch (r) {
        case l_true:  std::cout << "sat\n"; break;
        case l_false: std::cout << "unsat\n"; break;
        case l_undef: std::cout << "unknown\n"; break;
        }
        DEBUG_CODE(
            if (false && r == l_true) {
                model_ref mdl;
                opt.get_model(mdl);
                expr_ref_vector hard(m);
                opt.get_hard_constraints(hard);
                for (unsigned i = 0; i < hard.size(); ++i) {
                    std::cout << "validate: " << i << "\n";
                    expr_ref tmp(m);
                    VERIFY(mdl->eval(hard[i].get(), tmp));
                    if (!m.is_true(tmp)) {
                        std::cout << tmp << "\n";
                    }
                }
            });
    }
Example #5
0
int main ( int argc, char** argv )
{

    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "Unable to init SDL: %s\n", SDL_GetError() );
        return 1;
    }

     atexit(SDL_Quit);

     screen = SDL_SetVideoMode(SCREENW, SCREENH, 32,
                                           SDL_HWSURFACE|SDL_DOUBLEBUF);
    if ( !screen )
    {
        printf("Unable to set 800x600 video: %s\n", SDL_GetError());
        return 1;
    }
	SDL_WM_SetCaption("Szit the Game", NULL);
	if( TTF_Init() == -1 )
    {
		printf("Unable to initialize font");
        return 1;
    }

    font=TTF_OpenFont("tahoma.ttf", 28);
    if(font){printf("Success");}

    // centre the bitmap on screen

	CGameManager manager;

    bool done = false;
    CBlock blockT(0, -1, 0, 0, 0, 1, 0, 0, -1, 100, 100, 100); //t
    blockT.TryTurn();
    blockT.Turn();
    blockT.TryTurn();
    blockT.Turn();

    CBlock blockZ(0, -1,-1,0,-1,0,0,1,0, 198,255,126); //z
    CBlock blockS(0, -1,0,0,0,0,-1,1,-1, 126,196,255); //s
    CBlock blockO(1, 0,0,1,0,0,1,1,1, 100, 100, 0); //o
    CBlock blockI(0, 0,-1,0,0,0,1,0,2, 255,159,126); //i
    CBlock blockJ(0, -1,1,0,1,0,0,0,-1, 139,77,156); //j
    CBlock blockL(0, 0,-1,0,0,0,1,1,1, 255,229,126); //l

    CBlock GameBlock(0, -1, 0, 0, 0, 1, 0, 0, -1, 179,206,221); //creating t
    CBlock NextBlock(0, -1, 0, 0, 0, 1, 0, 0, -1, 179,206,221); //t
    //CBlock GameBlock(0, -1,0,0,0,0,-1,1,-1); //s
    //CBlock GameBlock(0, 0,-1,0,0,0,1,0,2); //i


	CButton start(300, 350, 200, 50, 100, 100, 100, 150, 150, 150, 1, "Start");
	CButton help(300, 425, 200, 50, 100, 100, 100, 150, 150, 150, 0, "Help");
	CButton exit(300, 500, 200, 50, 100, 100, 100, 150, 150, 150, 0, "Exit");
	CButton easy(100, 350, 200, 50, 200, 200, 200, 255, 255, 255, 0, "Easy");
	CButton medium(300, 350, 200, 50, 200, 200, 200, 255, 255, 255, 1, "Medium");
	CButton hard(500, 350, 200, 50, 200, 200, 200, 255, 255, 255, 0, "Hard");
	manager.Refresh(&GameBlock, &NextBlock);
	manager.Refresh(&GameBlock, &NextBlock);


	srand(time(NULL));
			switch(rand()%7){
					case 0: GameBlock.Set(0, -1, 0, 0, 0, 1, 0, 0, -1,179,206,221);break; //t
					case 1: GameBlock.Set(0, -1,-1,0,-1,0,0,1,0, 198,255,126);break; //z
					case 2: GameBlock.Set(0, -1,0,0,0,0,-1,1,-1, 126,196,255);break; //s
					case 3: GameBlock.Set(1, 0,0,1,0,0,1,1,1, 100, 100, 0);break; //o
					case 4: GameBlock.Set(0, 0,-1,0,0,0,1,0,2, 255,159,126);break; //i
					case 5: GameBlock.Set(0, -1,1,0,1,0,0,0,-1, 139,77,156);break; //j
					case 6: GameBlock.Set(0, 0,-1,0,0,0,1,1,1, 255,229,126);break; //l
			}

	srand(time(NULL)+SDL_GetTicks());
			switch(rand()%7){
					case 0: NextBlock.Set(0, -1, 0, 0, 0, 1, 0, 0, -1,179,206,221);break; //t
					case 1: NextBlock.Set(0, -1,-1,0,-1,0,0,1,0, 198,255,126);break; //z
					case 2: NextBlock.Set(0, -1,0,0,0,0,-1,1,-1, 126,196,255);break; //s
					case 3: NextBlock.Set(1, 0,0,1,0,0,1,1,1, 100, 100, 0);break; //o
					case 4: NextBlock.Set(0, 0,-1,0,0,0,1,0,2, 255,159,126);break; //i
					case 5: NextBlock.Set(0, -1,1,0,1,0,0,0,-1, 139,77,156);break; //j
					case 6: NextBlock.Set(0, 0,-1,0,0,0,1,1,1, 255,229,126);break; //l
			}

    // program main loop
    while (!done)
    {
        // message processing loop
        SDL_Event event;
        ++frame;
		SetFPS();
		LastFrame=SDL_GetTicks();

		if(gamestatus==1){manager.Refresh(&GameBlock, &NextBlock);
		}

        while (SDL_PollEvent(&event))
        {
            // check for messages
            switch (event.type)
            {
                // exit if the window is closed
            case SDL_QUIT:
                done = true;
                break;

                // check for keypresses
            case SDL_KEYDOWN:
                {
                    // exit if ESCAPE is pressed
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                        {done = true;}

					if(!gamestatus)
					{
						if(event.key.keysym.sym == SDLK_DOWN){
							if(start.Active()){start.ChangeActivity(); help.ChangeActivity();}else
							if(help.Active()){help.ChangeActivity(); exit.ChangeActivity();}else
							if(exit.Active()){exit.ChangeActivity(); start.ChangeActivity();}
							}
						else if(event.key.keysym.sym == SDLK_UP){
							if(start.Active()){start.ChangeActivity(); exit.ChangeActivity();}else
							if(help.Active()){help.ChangeActivity(); start.ChangeActivity();}else
							if(exit.Active()){exit.ChangeActivity(); help.ChangeActivity();}
						}
						if(event.key.keysym.sym == SDLK_RETURN){
							if(start.Active()){gamestatus=3;}
							else if(help.Active()){gamestatus=5;}
							else if(exit.Active()){done=1;}
						}
					}else
					if(gamestatus==1){
						if(event.key.keysym.sym == SDLK_DOWN){
								manager.MoveBlockDown(&GameBlock, 1);
						}
						if(event.key.keysym.sym == SDLK_SPACE){
								manager.TurnGameBlock(&GameBlock);
						}
						if(event.key.keysym.sym == SDLK_LEFT){
								manager.MoveBlockLeft(&GameBlock);
						}
						if(event.key.keysym.sym == SDLK_RIGHT){
								manager.MoveBlockRight(&GameBlock);
						}
						if(event.key.keysym.sym == SDLK_w){
								manager.SpeedUp();
						}
						if(event.key.keysym.sym ==SDLK_p){
							gamestatus=2;
						}
					}else
					if(gamestatus==2){
						if(event.key.keysym.sym ==SDLK_p){
							gamestatus=1;
						}
					}else
					if(gamestatus==3){
						if(event.key.keysym.sym == SDLK_RETURN){
							if(easy.Active()){manager.SetLevel(1);}else
							if(medium.Active()){manager.SetLevel(2);}else
							if(hard.Active()){manager.SetLevel(3);}
							gamestatus=1;
						}else
						if(event.key.keysym.sym == SDLK_RIGHT){
							if(easy.Active()){easy.ChangeActivity(); medium.ChangeActivity();}else
							if(medium.Active()){medium.ChangeActivity(); hard.ChangeActivity();}else
							if(hard.Active()){hard.ChangeActivity(); easy.ChangeActivity();}
						}else
						if(event.key.keysym.sym == SDLK_LEFT){
							if(easy.Active()){easy.ChangeActivity(); hard.ChangeActivity();}else
							if(medium.Active()){medium.ChangeActivity(); easy.ChangeActivity();}else
							if(hard.Active()){hard.ChangeActivity(); medium.ChangeActivity();}
						}
					}else
					if(gamestatus==4){
							if(event.key.keysym.sym){
									SDL_Delay(1000);
									gamestatus=0;
									manager.ClearGame();
							}
					}else
					if(gamestatus==5){
							if(event.key.keysym.sym){
									gamestatus=0;
							}
					}
                    break;
                }
            } // end switch
         }// end of message processing

        // DRAWING STARTS HERE


        // clear screen
        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));

        // draw bitmap




		if(gamestatus==0){
			int a=SDL_GetTicks();

			RBC_DrawRect(0, 0, screen->w, screen->h, 0, 0, 50);

			RBC_DrawRect((0+frame/2)%screen->w, 0, screen->w/5, screen->h, 105,210,231);
			if(((0+frame/2)%screen->w+screen->w/5)>screen->w){RBC_DrawRect(0, 0, ((0+frame/2)%screen->w+screen->w/5)-screen->w, screen->h, 105,210,231);}

			RBC_DrawRect((screen->w/5+frame/2)%screen->w, 0, screen->w/5, screen->h, 167,219,216);
			if(((screen->w/5+frame/2)%screen->w+screen->w/5)>screen->w){RBC_DrawRect(0, 0, ((screen->w/5+frame/2)%screen->w+screen->w/5)-screen->w, screen->h, 167,219,216);}

			RBC_DrawRect((screen->w/5*2+frame/2)%screen->w, 0, screen->w/5, screen->h, 224,228,204);
			if(((screen->w/5*2+frame/2)%screen->w+screen->w/5)>screen->w){RBC_DrawRect(0, 0, ((screen->w/5*2+frame/2)%screen->w+screen->w/5)-screen->w, screen->h, 224,228,204);}

			RBC_DrawRect((screen->w/5*3+frame/2)%screen->w, 0, screen->w/5, screen->h, 243,134,48);
			if(((screen->w/5*3+frame/2)%screen->w+screen->w/5)>screen->w){RBC_DrawRect(0, 0, ((screen->w/5*3+frame/2)%screen->w+screen->w/5)-screen->w, screen->h, 243,134,48);}

			RBC_DrawRect((screen->w/5*4+frame/2)%screen->w, 0, screen->w/5, screen->h, 250,105,0);
			if(((screen->w/5*4+frame/2)%screen->w+screen->w/5)>screen->w){RBC_DrawRect(0, 0, ((screen->w/5*4+frame/2)%screen->w+screen->w/5)-screen->w, screen->h, 250,105,0);}


			blockS.Draw(-100, 90+sin(a/100)*50);
			blockZ.Draw(50, 90+sin(a/100+10)*50);
			blockI.Draw(200, 90+sin(a/100+20)*50);
			blockT.Draw(350, 90+sin(a/100+30)*50);

			start.Draw();
			help.Draw();
			exit.Draw();

		}else
		if(gamestatus==1){
			switch(manager.ReturnSpeed()){
					case 2:RBC_DrawRect(0, 0, screen->w, screen->h, 105,210,231);break;
					case 4:RBC_DrawRect(0, 0, screen->w, screen->h, 167,219,216);break;
					case 6:RBC_DrawRect(0, 0, screen->w, screen->h, 224,228,204);break;
					case 8:RBC_DrawRect(0, 0, screen->w, screen->h, 243,134,48);break;
					case 10:RBC_DrawRect(0, 0, screen->w, screen->h, 250,105,0);break;
					case 12:RBC_DrawRect(0, 0, screen->w, screen->h, 250,70,0);break;
					case 14:RBC_DrawRect(0, 0, screen->w, screen->h, 250,35,0);break;
					case 16:RBC_DrawRect(0, 0, screen->w, screen->h, 250,10,0);break;
					case 18:RBC_DrawRect(0, 0, screen->w, screen->h, 250,0,0);break;

			}
			RBC_DrawRect(245, 0, 310, 600, 0,0,0);
			RBC_DrawRect(250, 0, 300, 600, 85,98,112);
			RBC_DrawRect(570, 70, 210, 210, 0,0,0);
			RBC_DrawRect(575, 75, 200, 200, 200, 200, 200);
			GameBlock.Draw(manager.GetGameBlockX()*30, manager.GetGameBlockY()*30);
			NextBlock.Draw(375, 150);
			manager.DrawTable();
			RBC_Write(575, 300, "Speed:", screen);
			RBC_Write(675, 300, manager.ReturnSpeed(), screen);
			RBC_Write(575, 330, "Lines:", screen);
			RBC_Write(675, 330, manager.ReturnDone(), screen);
			RBC_Write(575, 360, "Score:", screen);
			RBC_Write(675, 360, manager.ReturnScore(), screen);

		}else
		if(gamestatus==2){
			switch(manager.ReturnSpeed()){
					case 2:RBC_DrawRect(0, 0, screen->w, screen->h, 105,210,231);break;
					case 4:RBC_DrawRect(0, 0, screen->w, screen->h, 167,219,216);break;
					case 6:RBC_DrawRect(0, 0, screen->w, screen->h, 224,228,204);break;
					case 8:RBC_DrawRect(0, 0, screen->w, screen->h, 243,134,48);break;
					case 10:RBC_DrawRect(0, 0, screen->w, screen->h, 250,105,0);break;
					case 12:RBC_DrawRect(0, 0, screen->w, screen->h, 250,70,0);break;
					case 14:RBC_DrawRect(0, 0, screen->w, screen->h, 250,35,0);break;
					case 16:RBC_DrawRect(0, 0, screen->w, screen->h, 250,10,0);break;
					case 18:RBC_DrawRect(0, 0, screen->w, screen->h, 250,0,0);break;

			}
			RBC_DrawRect(245, 0, 310, 600, 0,0,0);
			RBC_DrawRect(250, 0, 300, 600, 85,98,112);
			RBC_Write(360, 250, "Pause", screen);
		}else
		if(gamestatus==3){
			RBC_DrawRect((0+frame/2)%screen->w, 0, screen->w/5, screen->h, 105,210,231);
			if(((0+frame/2)%screen->w+screen->w/5)>screen->w){RBC_DrawRect(0, 0, ((0+frame/2)%screen->w+screen->w/5)-screen->w, screen->h, 105,210,231);}

			RBC_DrawRect((screen->w/5+frame/2)%screen->w, 0, screen->w/5, screen->h, 167,219,216);
			if(((screen->w/5+frame/2)%screen->w+screen->w/5)>screen->w){RBC_DrawRect(0, 0, ((screen->w/5+frame/2)%screen->w+screen->w/5)-screen->w, screen->h, 167,219,216);}

			RBC_DrawRect((screen->w/5*2+frame/2)%screen->w, 0, screen->w/5, screen->h, 224,228,204);
			if(((screen->w/5*2+frame/2)%screen->w+screen->w/5)>screen->w){RBC_DrawRect(0, 0, ((screen->w/5*2+frame/2)%screen->w+screen->w/5)-screen->w, screen->h, 224,228,204);}

			RBC_DrawRect((screen->w/5*3+frame/2)%screen->w, 0, screen->w/5, screen->h, 243,134,48);
			if(((screen->w/5*3+frame/2)%screen->w+screen->w/5)>screen->w){RBC_DrawRect(0, 0, ((screen->w/5*3+frame/2)%screen->w+screen->w/5)-screen->w, screen->h, 243,134,48);}

			RBC_DrawRect((screen->w/5*4+frame/2)%screen->w, 0, screen->w/5, screen->h, 250,105,0);
			if(((screen->w/5*4+frame/2)%screen->w+screen->w/5)>screen->w){RBC_DrawRect(0, 0, ((screen->w/5*4+frame/2)%screen->w+screen->w/5)-screen->w, screen->h, 250,105,0);}


					easy.Draw();
					medium.Draw();
					hard.Draw();
		}else
		if(gamestatus==4){
			switch(manager.ReturnSpeed()){
					case 2:RBC_DrawRect(0, 0, screen->w, screen->h, 105,210,231);break;
					case 4:RBC_DrawRect(0, 0, screen->w, screen->h, 167,219,216);break;
					case 6:RBC_DrawRect(0, 0, screen->w, screen->h, 224,228,204);break;
					case 8:RBC_DrawRect(0, 0, screen->w, screen->h, 243,134,48);break;
					case 10:RBC_DrawRect(0, 0, screen->w, screen->h, 250,105,0);break;
					case 12:RBC_DrawRect(0, 0, screen->w, screen->h, 250,70,0);break;
					case 14:RBC_DrawRect(0, 0, screen->w, screen->h, 250,35,0);break;
					case 16:RBC_DrawRect(0, 0, screen->w, screen->h, 250,10,0);break;
					case 18:RBC_DrawRect(0, 0, screen->w, screen->h, 250,0,0);break;

			}
			RBC_DrawRect(245, 0, 310, 600, 0,0,0);
			RBC_DrawRect(250, 0, 300, 600, 85,98,112);
			RBC_DrawRect(570, 70, 210, 210, 0,0,0);
			RBC_DrawRect(575, 75, 200, 200, 200, 200, 200);
			GameBlock.Draw(manager.GetGameBlockX()*30, manager.GetGameBlockY()*30);
			NextBlock.Draw(375, 150);
			manager.DrawTable();
			RBC_Write(575, 300, "Speed:", screen);
			RBC_Write(675, 300, manager.ReturnSpeed(), screen);
			RBC_Write(575, 330, "Lines:", screen);
			RBC_Write(675, 330, manager.ReturnDone(), screen);
			RBC_Write(575, 360, "Score:", screen);
			RBC_Write(675, 360, manager.ReturnScore(), screen);

			for(int i=0; i<screen->w/2; i++){
					for(int j=0; j<screen->h/2; j++){
							RBC_DrawRect(i*2, j*2, 1,1, 0,0,0);
					}
			}


				RBC_Write(300, 300, "Game Over", screen);
				RBC_Write(300, 350, manager.ReturnScore(), screen);

		}else
		if(gamestatus==5){
			RBC_DrawRect((0+frame/2)%screen->w, 0, screen->w/5, screen->h, 105,210,231);
			if(((0+frame/2)%screen->w+screen->w/5)>screen->w){RBC_DrawRect(0, 0, ((0+frame/2)%screen->w+screen->w/5)-screen->w, screen->h, 105,210,231);}

			RBC_DrawRect((screen->w/5+frame/2)%screen->w, 0, screen->w/5, screen->h, 167,219,216);
			if(((screen->w/5+frame/2)%screen->w+screen->w/5)>screen->w){RBC_DrawRect(0, 0, ((screen->w/5+frame/2)%screen->w+screen->w/5)-screen->w, screen->h, 167,219,216);}

			RBC_DrawRect((screen->w/5*2+frame/2)%screen->w, 0, screen->w/5, screen->h, 224,228,204);
			if(((screen->w/5*2+frame/2)%screen->w+screen->w/5)>screen->w){RBC_DrawRect(0, 0, ((screen->w/5*2+frame/2)%screen->w+screen->w/5)-screen->w, screen->h, 224,228,204);}

			RBC_DrawRect((screen->w/5*3+frame/2)%screen->w, 0, screen->w/5, screen->h, 243,134,48);
			if(((screen->w/5*3+frame/2)%screen->w+screen->w/5)>screen->w){RBC_DrawRect(0, 0, ((screen->w/5*3+frame/2)%screen->w+screen->w/5)-screen->w, screen->h, 243,134,48);}

			RBC_DrawRect((screen->w/5*4+frame/2)%screen->w, 0, screen->w/5, screen->h, 250,105,0);
			if(((screen->w/5*4+frame/2)%screen->w+screen->w/5)>screen->w){RBC_DrawRect(0, 0, ((screen->w/5*4+frame/2)%screen->w+screen->w/5)-screen->w, screen->h, 250,105,0);}

			RBC_Write(20, 300, "Use left and right arrow to move block sideways", screen);
			RBC_Write(20, 350, "Use down arrow to move block down faster for extra points", screen);
			RBC_Write(20, 400, "Use space to turn falling tetramino", screen);
			RBC_Write(20, 450, "Hit 'P' to pause game", screen);
		}

        RBC_Write(10, 20, "FPS: ", screen);RBC_Write(70, 20, GetFPS(), screen);

        // DRAWING ENDS HERE

        // finally, update the screen :)
        SDL_Flip(screen);
    } // end main loop

    // free loaded bitmap
	TTF_CloseFont(font);
	TTF_Quit();
    // all is well ;)
    printf("Exited cleanly\n");
    return 0;
}
Example #6
0
void MainWindow::createMenus()
{
    openAct = new QAction(tr("读取地图(&M)"), this);
    saveAct = new QAction(tr("存档(&S)"), this);
    loadAct = new QAction(tr("读档(&R)"), this);
    rechargeAct = new QAction(tr("充值(&C)"), this);
    exitAct = new QAction(tr("退出(&E)"), this);

    restartAct = new QAction(tr("重新开始(&L)"), this);
    hardAct = new QAction(tr("困难"), this);
    mediumAct = new QAction(tr("中等"), this);
    easyAct = new QAction(tr("简单"), this);
    foresoundAct = new QAction(tr("音效开关(&O)"), this);

    manualAct = new QAction(tr("用户手册(&U)"), this);
    aboutAct = new QAction(tr("关于(&A)"), this);

    fileMenu = menuBar()->addMenu(tr("文件(&F)"));
    settingMenu = menuBar()->addMenu(tr("游戏设置(&G)"));
    helpMenu = menuBar()->addMenu(tr("帮助(&H)"));

    fileMenu->addAction(openAct);
    openAct->setShortcut(QKeySequence("Ctrl+m"));
    fileMenu->addSeparator();
    fileMenu->addAction(saveAct);
    saveAct->setShortcut(QKeySequence("Ctrl+s"));
    fileMenu->addAction(loadAct);
    loadAct->setShortcut(QKeySequence("Ctrl+r"));
    fileMenu->addSeparator();
    fileMenu->addAction(rechargeAct);
    rechargeAct->setShortcut(QKeySequence("Ctrl+c"));
    fileMenu->addSeparator();
    fileMenu->addAction(exitAct);
    exitAct->setShortcut(QKeySequence("Ctrl+e"));

    settingMenu->addAction(restartAct);
    restartAct->setShortcut(QKeySequence("Ctrl+l"));
    settingMenu->addSeparator();
    difficultyMenu = settingMenu->addMenu(tr("选择难度(&D)"));
    settingMenu->addSeparator();
    settingMenu->addAction(foresoundAct);
    foresoundAct->setCheckable(true);
    foresoundAct->setChecked(true);
    foresoundAct->setShortcut(QKeySequence("Ctrl+o"));

    difficultyMenu->addAction(hardAct);
    hardAct->setCheckable(true);
    hardAct->setChecked(false);
    difficultyMenu->addAction(mediumAct);
    mediumAct->setCheckable(true);
    mediumAct->setChecked(true);
    difficultyMenu->addAction(easyAct);
    easyAct->setCheckable(true);
    easyAct->setChecked(false);

    helpMenu->addAction(manualAct);
    manualAct->setShortcut(QKeySequence("Ctrl+u"));
    helpMenu->addAction(aboutAct);
    aboutAct->setShortcut(QKeySequence("Ctrl+a"));

    connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
    connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
    connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
    connect(loadAct, SIGNAL(triggered()), this, SLOT(load()));
    connect(rechargeAct, SIGNAL(triggered()),this, SLOT(recharge()));

    connect(restartAct, SIGNAL(triggered()), this, SLOT(restart()));
    connect(hardAct, SIGNAL(triggered()), this, SLOT(hard()));
    connect(mediumAct, SIGNAL(triggered()), this, SLOT(medium()));
    connect(easyAct, SIGNAL(triggered()), this, SLOT(easy()));
    connect(foresoundAct, SIGNAL(triggered()), this, SLOT(foresound()));

    connect(manualAct, SIGNAL(triggered()), this, SLOT(manual()));
    connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
}
Example #7
0
int main() {
  // SETUP
  init();
  Serial.begin(9600);
  tft.initR(INITR_BLACKTAB);  // initialize screen
  
  // Setting the joystick button and LEDs
  pinMode(JOYSTICK_BUTTON, INPUT);
  digitalWrite(JOYSTICK_BUTTON, HIGH);
  
  // Initialize the SD card
  Serial.print("Initializing SD card...");
  if (!SD.begin(SD_CS)) {
    Serial.println("failed!");
    while(true) {} // something is wrong
  } 
  else {Serial.println("OK!");}
  
  // More initialization
  Serial.print("Initializing Raw SD card...");
  if (!card.init(SPI_HALF_SPEED, SD_CS)) {
    Serial.println("failed!");
    while(true) {} // something is wrong
  } 
  else {Serial.println("OK!");}
  
  // Create states for different modes
  // C1 for Mode 1 - MENU screen
  // C2 for Mode 2 - Snake Game
  // C3 for Mode 3 - GAME OVER screen
  // C4 for Mode 4 - Choose level
  // C5 for Mode 5 - PAUSE screen
  typedef enum {C1 = 1, C2, C3, C4, C5, ERR} State;
  State state = C1;
  int select, snakelength;
  
  while (state!=ERR) {
    if  (state == C1) {
      /// ====== MODE 1 - MENU ====== ///
      Serial.println("Currently in Mode 1");
      snakelength = 1;
      init_vert = analogRead(JOYSTICK_VERT); 
      init_horiz = analogRead(JOYSTICK_HORIZ);
      
      // preparations for the game - to not overlap with the pause menu
      q = q_create(720);
      i = 64; // x component
      j = 80; // y component
      q_add(q,i,j); // load into the queue
      random_x = food_x(); // load x coordinate of food piece
      random_y = food_y(); // load y coordinate of food piece
      pausedirection = 0; // set paused direction to 0
      // reset grid to 0
      for (int a = 0; a < 24; a++) {
        for (int b = 0; b < 30; b++) {
        grid[a][b] = 0;
        }
      }
      
      // display main menu
      snake();
      tft.setTextSize(2);
      
      while(true) {
        // alternate highlighting of START
        unsigned long time = millis()%1000;
        int a = time%1000;
        if ((a<17)) {
        tft.setCursor(34, 83);
        tft.fillRoundRect(30,80,65,20,5,WHITE);
        tft.setTextColor(RED);
        tft.print("START");
        }
        else if ((a>500) && (a<520)) {
        tft.setCursor(34, 83);
        tft.fillRoundRect(30,80,65,20,5,RED);
        tft.setTextColor(WHITE);
        tft.print("START");
        }
        // Read the Joystick - HIGH if not pressed, LOW otherwise
        select = digitalRead(JOYSTICK_BUTTON);     
        if (select == LOW) {
          break;
        }
      }
      state = C4; 
    }
    
    else if (state == C2) {
      /// ====== MODE 2 - SNAKE GAME ====== ///
      Serial.println("Currently in Mode 2");
      delay(50);
      soundsetup(); //setting up sound pin
      // print the background
      tft.fillScreen(DARKRED);
      tft.fillRect(4,5,120,150,DARKGRN);
      
      // print the snake
      int x,y;
      x = q_frontx(q);
      y = q_fronty(q);
      tft.fillRect(x,y,5,5, WHITE);
      
      //Bringing the food in, outside while loop first.
      tft.fillRect(random_x, random_y, 5, 5, YELLOW);
      
      // do auto calibration
      int px, py;
      int lastmove;
      
      // read beginning direction chosen by user
      if (pausedirection == 0) {
        direction = read_direction();
      }
      else {
        direction = pausedirection;
      }
      lastmove = direction;
      
      while (true) {
        
        // to direct movement 
        // (without going in reverse direction of previous movement)
        
        // up
        if (direction == 1) {
          if (lastmove == 2) {
            direction = 2;
            j = j-5;
          }
          else {
            j = j+5;
        }
        q_add(q,i,j);
        }
        // down
        else if (direction == 2) {
          if (lastmove == 1) {
            direction = 1;
            j = j+5;
          }
          else {
            j = j-5;
          }
        q_add(q,i,j);
        }
        // right
        else if (direction == 3) {
          if (lastmove == 4) {
            direction = 4;
            i = i-5;
          }
          else {
            i = i+5;
          }
        q_add(q,i,j);
        }
        // left
        else if (direction == 4) {
          if (lastmove == 3) {
            direction = 3;
            i = i+5;
          }
          else {
            i = i-5;
          }
        q_add(q,i,j);
        }
        
        // if the direction is changed, store the new direction & last move
        int new_direc = read_direction();
        if ((new_direc != direction) && (new_direc != 0)) {
          lastmove = direction;
          direction = new_direc;
        }
        
        // if the snake hits a piece of food, the food vanishes and gets replaced 
        if ((i == random_x) && (j == random_y)) {
          // snake grows by 4 squares, except for the first time
          // this allows for it to end up as a max of 720 in the queue
          if (snakelength == 1) {
            q_add(q,i,j);
            q_add(q,i,j);
            q_add(q,i,j);
            snakelength += 3;
          }
          else {
            q_add(q,i,j);
            q_add(q,i,j);
            q_add(q,i,j);
            q_add(q,i,j);
            snakelength += 4;
          }
      if (snakelength < 720) {
        random_x = food_x();
        random_y = food_y();
      
        // if the snake is already there, find a new spot for the food
        while (grid[random_x/5][random_y/5-1] == 1) {
          random_x = food_x();
          random_y = food_y();
        }
        // print the new food
        tft.fillRect(random_x, random_y, 5, 5, YELLOW);
          }
        }
        
        // if the snake runs over itself
        if ((snakelength > 1) && (grid[i/5][j/5-1] == 1)) {
          delay(450); // pause when snake runs into itself
          int m = 0;
          soundLoop();
          while(m < 6000) {
            int rand_x = dissolve_x();
            int rand_y = dissolve_y();
            tft.fillRect(rand_x, rand_y, 5, 5, BLACK);
            m++;
          }
          state = C3;
          break;
        }
        
        px = q_frontx(q);
        py = q_fronty(q);
        // reprint the snake if there is movement
        if ((i != px) || (j != py)) {
          tft.fillRect(i,j,5,5, WHITE);
          grid[i/5][j/5-1] = 1;          // snake body is in grid
          tft.fillRect(px,py,5,5,DARKGRN);
          grid[px/5][py/5-1] = 0;        // snake body is no longer in grid
          q_remove(q);                   // take away from the queue
          delay(speed);                  // controls the speed of the snake
        }
       
        // if any of the borders are hit
        if ((i < 4)||(j < 5)||(i > 119)||(j > 150)) {
          delay(450); // pause when border is hit
          // dissolve the screen
          int m = 0;
          soundLoop();
          while(m < 6000) {
            int rand_x = dissolve_x();
            int rand_y = dissolve_y();
            tft.fillRect(rand_x, rand_y, 5, 5, BLACK);
            m++;
          }
          //~ delay(250);
          state = C3; 
          break;
        }
        
        // Read the Joystick - HIGH if not pressed, LOW otherwise
        select = digitalRead(JOYSTICK_BUTTON);     
        if (select == LOW) {
          state = C5;
          break;
        }
      }
    }
    
    else if (state == C3) {
      /// ====== MODE 3 - GAME OVER ====== ///
      Serial.println("Currently in Mode 3");
      q_destroy(q); // clear the queue
      tft.fillScreen(BLACK);
      tft.fillRoundRect(5,20,118,25,5,RED);
      tft.setCursor(10, 25); 
      tft.setTextColor(BLACK);
      tft.setTextSize(2);
      tft.setTextWrap(true);
      tft.print("GAME OVER");
      tft.print("\n"); 
      
      tft.setCursor(10, 55);
      tft.setTextColor(RED);
      tft.setTextSize(1.5);
      if (snakelength >= 720) {
        snakelength = 720;
        tft.print("YOU WON! CONGRATZ");
      }
      else {
        tft.print("      Oh no!         You hit something!");
      }
      
      tft.setCursor(10, 80);
      tft.setTextColor(WHITE);
      tft.setTextSize(1);
      tft.print("Length of Snake:");
      tft.print(snakelength);
      tft.setCursor(10, 100);
      tft.print("Press the joystick   to return to main    menu");
      
      // Read the Joystick - HIGH if not pressed, LOW otherwise
      while (true) {
        select = digitalRead(JOYSTICK_BUTTON);     
        if (select == LOW) {
          break;
        }
      }
      state = C1;
    }
    
    else if (state == C4) {
      /// ====== MODE 4 - CHOOSE LEVEL ====== ///
      Serial.println("Currently in Mode 4");
      // printing
      // snake display
      snake();
      // difficulty levels
      tft.setTextSize(2);  
      tft.setTextColor(WHITE);
      easy(RED);
      tft.setTextColor(RED);
      medium(WHITE);
      hard(WHITE);
      
      int selection = 1;
      int oldselection;
      while(true) {
        // read direction from the user for updating selection
        oldselection = selection;
        vertical = analogRead(JOYSTICK_VERT);      // will be 0-1023
        delay(100);
        
        // scroll down
        if (vertical > init_vert + 200) {
        selection++;
          if (selection > 3) {
            selection = 0;
          }
        } 
        // scroll up
        else if (vertical < init_vert - 200) {
          selection--;
          if (selection < 0) {
            selection = 3;
          }
        }
        
        if (selection != oldselection) {
          update(selection);
        }
        
        // Read the Joystick - HIGH if not pressed, LOW otherwise
        select = digitalRead(JOYSTICK_BUTTON);     
        if (select == LOW) {
          Serial.print("made selection: ");
          Serial.println(selection);
          if (selection == 1) {speed = 225;}
          else if (selection == 2) {speed = 150;}
          else if (selection == 3) {speed = 75;}
          break;
        }
      }
      state = C2;
    }
    
    else if (state == C5) {
      /// ====== MODE 5 - PAUSE MENU ====== ///
      Serial.println("Currently in Mode 5");
      pausedirection = direction;
      
      // printing snake and pause
      snake();
      tft.setTextSize(2);
      tft.setCursor(34, 73); 
      tft.fillRoundRect(30,70,65,20,5,WHITE);
      tft.setTextColor(RED);
      tft.print("Pause");
      
      while(true) {
        // Read the Joystick - HIGH if not pressed, LOW otherwise
        select = digitalRead(JOYSTICK_BUTTON);     
        if (select == LOW) {
          break;
        }
      }
      // reset grid to 0
      for (int a = 0; a < 24; a++) {
        for (int b = 0; b < 30; b++) {
        grid[a][b] = 0;
        }
      }
      state = C2; 
    }
    //if not any of this:
    else { 
      Serial.println("There has been an error");
      state = ERR; 
    }
  }
    
  Serial.end();
  return 0;
}
Example #8
0
int main()
{
	easy();
	hard();
}
Example #9
0
/* this is called when there is no processes left */
void initng_main_when_out(void)
{

	int failing = 0;
	active_db_h *current = NULL;

	while_active_db(current) {
		if (GET_STATE(current) == IS_FAILED) {
			failing++;
			printf("\n [%i] service \"%s\" marked \"%s\"\n",
			       failing, current->name,
			       current->current_state->name);
		}
	}

	if (failing > 0) {
		printf("\n\n All %i services listed above, are marked with a "
		       "failure.\n"
		       " Will sleep for 15 seconds before reboot/halt so you "
		       "can see them.\n\n", failing);
		sleep(15);
	}

	if (getpid() != 1) {
		F_("I AM NOT INIT, THIS CANT BE HAPPENING!\n");
		sleep(3);
		return;
	}

	/* always good to do */
	sync();

	/* none of these calls should return, so the su_login on the end will be a fallback */
	switch (g.when_out) {
	case THEN_QUIT:
		P_(" ** Now Quiting **\n");
		initng_main_exit(0);
		break;

	case THEN_SULOGIN:
		P_(" ** Now SuLogin\n");
		/* break here leads to su_login below */
		break;

	case THEN_RESTART:
		P_(" ** Now restarting\n");
		initng_main_restart();
		break;

	case THEN_NEW_INIT:
		P_(" ** Launching new init\n");
		initng_main_new_init();
		break;

	case THEN_REBOOT:
	case THEN_HALT:
	case THEN_POWEROFF:
		hard(g.when_out);
		break;
	}

	/* fallback */
	initng_main_su_login();
}