예제 #1
0
파일: snake.cpp 프로젝트: Mara2020/Snake
// 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);
  }
}
예제 #2
0
파일: main.cpp 프로젝트: keitee/kb
   std::vector<unsigned int> fetch_unread_uids(std::string_view folder)
   {
      std::stringstream str;

      try
      {
         curl::curl_ios<std::stringstream> writer(str);

         curl::curl_easy easy(writer);
         easy.add<CURLOPT_URL>((url.data() + std::string("/") + folder.data() + std::string("/")).c_str());
         easy.add<CURLOPT_CUSTOMREQUEST>("SEARCH UNSEEN");
         setup_easy(easy);

         easy.perform();
      }
      catch (curl::curl_easy_exception const & error)
      {
         auto errors = error.get_traceback();
         error.print_traceback();
      }

      std::vector<unsigned int> uids;
      str.seekg(8, std::ios::beg);
      unsigned int uid;
      while (str >> uid)
         uids.push_back(uid);

      return uids;
   }
예제 #3
0
void main()
{   int gdriver = DETECT, gmode, errorcode;
    initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
    intro();
    levelmenu();
    clrscr();
    cleardevice();
    setbkcolor(RED);
    easy();
}
예제 #4
0
void start_download(curl::multi& multi, const std::string& url)
{
	std::auto_ptr<curl::easy> easy(new curl::easy(multi));
	
	// see 'Use server-provided file names' example for a more detailed implementation of this function which receives
	// the target file name from the server using libcurl's header callbacks
	std::string file_name = url.substr(url.find_last_of('/') + 1);
	
	easy->set_url(url);
	easy->set_sink(boost::make_shared<std::ofstream>(file_name.c_str(), std::ios::binary));
	easy->async_perform(boost::bind(handle_download_completed, boost::asio::placeholders::error, url, easy.get()));
	
	active_downloads.insert(easy);
}
예제 #5
0
void shakil::turna()
{ne2=0;
 long int xxx;
 for(xxx=1;xxx<=11;xxx++)
 { result=0;
  if(xxx==1)
  easy();
  if(xxx>1)
  {n=xxx;
  get();}
  mixed();

  if(ne2==10)
  break;
      }

}
예제 #6
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;
}
예제 #7
0
파일: main.cpp 프로젝트: keitee/kb
   std::string get_folders()
   {
      std::stringstream str;
      try
      {
         curl::curl_ios<std::stringstream> writer(str);

         curl::curl_easy easy(writer);
         easy.add<CURLOPT_URL>(url.data());
         setup_easy(easy);

         easy.perform();
      }
      catch (curl::curl_easy_exception const & error)
      {
         auto errors = error.get_traceback();
         error.print_traceback();
      }

      return str.str();
   }
예제 #8
0
파일: main.cpp 프로젝트: keitee/kb
   std::string fetch_email(std::string_view folder, unsigned int uid)
   {
      std::stringstream str;

      try
      {
         curl::curl_ios<std::stringstream> writer(str);

         curl::curl_easy easy(writer);
         easy.add<CURLOPT_URL>((url.data() + std::string("/") + folder.data() + std::string("/;UID=") + std::to_string(uid)).c_str());
         setup_easy(easy);

         easy.perform();
      }
      catch (curl::curl_easy_exception error)
      {
         auto errors = error.get_traceback();
         error.print_traceback();
      }

      return str.str();
   }
예제 #9
0
파일: main.cpp 프로젝트: keitee/kb
   std::string examine_folder(std::string_view folder)
   {
      std::stringstream str;
      try
      {
         curl::curl_ios<std::stringstream> writer(str);

         curl::curl_easy easy(writer);
         easy.add<CURLOPT_URL>(url.data());
         easy.add<CURLOPT_CUSTOMREQUEST>((std::string("EXAMINE ") + folder.data()).c_str());
         setup_easy(easy);

         easy.perform();
      }
      catch (curl::curl_easy_exception const & error)
      {
         auto errors = error.get_traceback();
         error.print_traceback();
      }

      return str.str();
   }
예제 #10
0
void Feed::CheckFeed() {
  m_lastChecked = boost::posix_time::microsec_clock::universal_time();
  cURL::EasyInterface easy(m_url, m_etag);
  switch (easy.PerformRequest()) {
    case 200: {
      m_etag = easy.GetResponseEtag();
      FeedValidator validator(easy.GetResponseData(), *this);
      validator.Validate(m_feedData);
      m_valid = true;
      if (m_valid) {
        CreateEntries(m_feedData);
      }
      return;
    }
    case 304: {
      m_valid = true;
      return;
    }
    default: {
      m_entries.clear();
      m_valid = false;
    }
  }
}
예제 #11
0
파일: ft_itoa.c 프로젝트: Xxdzs/42Projects
char		*ft_itoa(int n)
{
    char	*ret;
    int		i;
    int		neg;

    neg = n < 0 ? 1 : 0;
    ret = (char*)malloc(ft_nb_c(n) + 1);
    if (n == -2147483648 && easy(&ret))
        return (ret);
    i = ft_nb_c(n);
    n = neg == 1 ? -n : n;
    if (!ret)
        return (NULL);
    ret[i] = '\0';
    while (i-- + 1 - neg)
    {
        ret[i] = n % 10 + '0';
        n = n / 10;
    }
    if (neg == 1)
        ret[0] = '-';
    return (ret);
}
예제 #12
0
파일: Szit.cpp 프로젝트: rybycy/SzitTetris
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;
}
예제 #13
0
파일: DiffSet.cpp 프로젝트: Wint3rNuk3/Pew
int DiffSet::Run(sf::RenderWindow &window)
{
	//basic stuff
	running = true;
	IOdiff diff;
	selection = diff.ReadDiffSettings();
	Background bg("graphics//core//settings.jpg");

	//Sound
	IOsound iosound;
	iosound.ReadSoundSettings(volume);
	MenuSound sound;
	sound.LoadSoundBuffer();
	sound.setBuffer(volume);

	//buttons
	Text easy("easy", 70), normal("normal", 70), crazy("crazy", 70), info("enter = save, esc = back", 40);
	easy.setPosition(270, 150);
	normal.setPosition(270, 250);
	crazy.setPosition(270, 350);
	info.setPosition(50, 500);
	info.setColor(sf::Color(255, 128, 0));

	while (running)
	{
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
			{
				return -1;
			}
			
			//keyboard selection
			if (event.type == sf::Event::KeyPressed)
			{
				switch (event.key.code)
				{
				case sf::Keyboard::Up:
					if (selection > 1)
					{
						selection -= 1;
						sound.PlaySound("select");
					}
					else
					{
						selection = 1;
					}
					break;
				case sf::Keyboard::Down:
					if (selection < 3)
					{
						selection += 1;
						sound.PlaySound("select");
					}
					else
					{
						selection = 3;
					}
					break;
				case sf::Keyboard::Return:
					diff.WriteDiffSettings(selection);
					return 2;
					break;
				case sf::Keyboard::Escape:
					return 2;
					break;
				default:
					break;
				}
			}
		}
		//change the color depending on selection
		if (selection == 1)//easy
		{
			easy.setColor(sf::Color(255, 128, 0));
			normal.setColor(sf::Color(255, 255, 255));
			crazy.setColor(sf::Color(255, 255, 255));
		}
		else if (selection == 2)//normal
		{
			easy.setColor(sf::Color(255, 255, 255));
			normal.setColor(sf::Color(255, 128, 0));
			crazy.setColor(sf::Color(255, 255, 255));
		}
		else //crazy
		{
			easy.setColor(sf::Color(255, 255, 255));
			normal.setColor(sf::Color(255, 255, 255));
			crazy.setColor(sf::Color(255, 128, 0));
		}
		
		//draw stuff
		window.clear();

		bg.Render(window);
		easy.Render(window);
		normal.Render(window);
		crazy.Render(window);
		info.Render(window);

		window.display();
	}
	return -1;
}
예제 #14
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()));
}
예제 #15
0
void shakil::first()
{
   tm=0;
   showmouseptr();


 while(1)
{
 getmousepos(&button,&x,&y);
 if(tm==0)
 {
   hidemouseptr();
   setcolor(7);
   rectangle(105,105,345,155);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,110,7);
   rectangle(105,160,345,205);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,170,7);
   rectangle(105,210,345,255);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,220,7);
   rectangle(105,260,345,305);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,270,7);
   rectangle(105,310,345,345);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,320,7);
   setcolor(RED);
   settextstyle(1,0,5);
   outtextxy(130,106," NEW ");
   outtextxy(130,161," EASY ");
   outtextxy(130,211," EXIT ");
   outtextxy(95,255," LOAD GAME");
   outtextxy(105,300,"TURNAMENT");
   rectangle(100,100,350,350);
   tm=10;
   showmouseptr();
   }
   p=x;m=y;

 if(p>105&&p<345)
 {if((m>105&&m<155)&&tm!=1)
  {tm=1;
   hidemouseptr();
   setcolor(123);
   rectangle(105,105,345,155);
   setfillstyle(SOLID_FILL,123);
   floodfill(110,110,123);
   setcolor(7);
   rectangle(105,160,345,205);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,170,7);
   rectangle(105,210,345,255);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,220,7);
   rectangle(105,260,345,305);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,270,7);
   rectangle(105,310,345,345);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,320,7);
   setcolor(RED);
   settextstyle(1,0,5);
   outtextxy(130,106," NEW ");
   outtextxy(130,161," EASY ");
   outtextxy(130,211," EXIT ");
   outtextxy(95,255," LOAD GAME");
   outtextxy(105,300,"TURNAMENT");
   rectangle(100,100,350,350);
   showmouseptr();
  }
  if((m>160&&m<205)&&tm!=2)
  { tm=2;
    hidemouseptr();
    setcolor(123);
    rectangle(105,160,345,205);
    setfillstyle(SOLID_FILL,123);
    floodfill(110,170,123);
    setcolor(7);
    rectangle(105,105,345,155);
    setfillstyle(SOLID_FILL,7);
    floodfill(110,110,7);
    rectangle(105,210,345,255);
    setfillstyle(SOLID_FILL,7);
    floodfill(110,220,7);
    rectangle(105,260,345,305);
    setfillstyle(SOLID_FILL,7);
    floodfill(110,270,7);
    rectangle(105,310,345,345);
    setfillstyle(SOLID_FILL,7);
    floodfill(110,320,7);
    setcolor(RED);
    settextstyle(1,0,5);
    outtextxy(130,106," NEW ");
    outtextxy(130,161," EASY ");
    outtextxy(130,211," EXIT ");
    outtextxy(95,255," LOAD GAME");
    outtextxy(105,300,"TURNAMENT");
    rectangle(100,100,350,350);
    showmouseptr();
  }
   if((m>210&&m<255)&&tm!=3)
  { tm=3;
    hidemouseptr();
    setcolor(123);
    rectangle(105,210,345,255);
    setfillstyle(SOLID_FILL,123);
    floodfill(110,220,123);
    setcolor(7);
    rectangle(105,160,345,205);
    setfillstyle(SOLID_FILL,7);
    floodfill(110,170,7);
    rectangle(105,105,345,155);
    setfillstyle(SOLID_FILL,7);
    floodfill(110,110,7);
    rectangle(105,260,345,305);
    setfillstyle(SOLID_FILL,7);
    floodfill(110,270,7);
    rectangle(105,310,345,345);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,320,7);
    setcolor(RED);
    settextstyle(1,0,5);
    outtextxy(130,106," NEW ");
    outtextxy(130,161," EASY ");
    outtextxy(130,211," EXIT ");
    outtextxy(95,255," LOAD GAME");
    outtextxy(105,300,"TURNAMENT");
    rectangle(100,100,350,350);
    showmouseptr();
   }
   if((m>260&&m<305)&&tm!=4)
  {tm=4;
   hidemouseptr();
   setcolor(123);
   rectangle(105,260,345,305);
   setfillstyle(SOLID_FILL,123);
   floodfill(110,270,123);
   setcolor(7);
   rectangle(105,160,345,205);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,170,7);
   rectangle(105,210,345,255);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,220,7);
   rectangle(105,105,345,155);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,110,7);
   rectangle(105,310,345,345);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,320,7);
   setcolor(RED);
   settextstyle(1,0,5);
   outtextxy(130,106," NEW ");
   outtextxy(130,161," EASY ");
   outtextxy(130,211," EXIT ");
   outtextxy(95,255," LOAD GAME");
   outtextxy(105,300,"TURNAMENT");
   rectangle(100,100,350,350);
   showmouseptr();
  }
   if((m>310&&m<345)&&tm!=5)
  {tm=5;
   hidemouseptr();
   setcolor(123);
   rectangle(105,310,345,345);
   setfillstyle(SOLID_FILL,123);
   floodfill(110,320,123);
   setcolor(7);
   rectangle(105,160,345,205);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,170,7);
   rectangle(105,210,345,255);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,220,7);
   rectangle(105,105,345,155);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,110,7);

   rectangle(105,260,345,305);
   setfillstyle(SOLID_FILL,7);
   floodfill(110,270,7);

   setcolor(RED);
   settextstyle(1,0,5);
   outtextxy(130,106," NEW ");
   outtextxy(130,161," EASY ");
   outtextxy(130,211," EXIT ");
   outtextxy(95,255," LOAD GAME");
   outtextxy(105,300,"TURNAMENT");
   rectangle(100,100,350,350);
   showmouseptr();
  }
   if(m<105||m>345)
   if(tm!=0)
   tm=0;
    }
   else if(tm!=0)
   tm=0;

 if((button & 1)==1)
 {if(x>=105&&x<=345)
  { if(y>=210&&y<=255)
    break;
    if(y>=105&&y<=155)
    {result=0;
     hidemouseptr();
     new1();
     continue;
      }
    if(y>=160&&y<=250)
    {result=0;
    hidemouseptr();
    easy();
    continue;
    }
   if(y>=260&&y<=305)
   {result=0;
    save2();
    continue; }
   if(y>=310&&y<=345)
   {result=0;
   turna();
   continue;
   }
}}
delay(100);

}
}
예제 #16
0
파일: snake.cpp 프로젝트: Mara2020/Snake
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;
}
예제 #17
0
task three(){
easy();

}
예제 #18
0
int main()
{
	easy();
	hard();
}