예제 #1
0
파일: keyb.c 프로젝트: skawouter/Netux
int keyb_handle(){
	short inp = inb(0x60);
	char keys[2];
	switch( inp )
	{
		case 0x0e : 	
				keys[0] = 8;
				keys[1] = 0;	
				handleinput(keys);
		
	}
	if (inp-16 < 43) {
		static const char keybmap[44]={'q','w','e','r','t','y','u','i','o','p',0,0,1,0,'a','s','d','f','g','h','j','k','l',0,0,0,0,0,'z','x','c','v','b','n','m',0,0,0,0,0,0,' '};
		keys[1] = 0;
		keys[0] = keybmap[inp-16];
		handleinput(keys);	
	}
	if (inp-16 > 43 && inp-16 < 100) {
		writenumber(inp);
	}
	return 1;
}
예제 #2
0
파일: main.c 프로젝트: arik181/myshell
int main(int argc, char ** argv)
{
	unsigned state = DEFAULT;
	unsigned * stateptr = &state;
	listptr historyptr;

	initialize(argc,argv,stateptr,&historyptr);

	char inputstring[MAXLINESIZE];
	char * strptr = &inputstring[0];

	/*** Main loop: 
	 * Print a prompt, 
	 * get input, 
	 * tokenize ***/
	while(!feof(stdin) && !(*stateptr & QUIT))
	{
        prettyprompt();
        getinput(inputstring);

		/*** If the user simply hits return, do nothing. ***/
		if (inputstring[0] != '\n')
		{
			/*** Otherwise, deal with input ***/
			handleinput(strptr,stateptr,historyptr);

			chomp(inputstring);

			/*** Add the string to history ***/
			/*** If there was no history error ***/
			if (NO_HISTERROR)
				addstring(inputstring,historyptr);
		}
	}

	cleanup(historyptr);
	return 0;
}
예제 #3
0
void Game()
{
	SDL::Screen screen;
	SDL::GetVideoSurface(screen);
	SDL::Event events;
	SDL::Rect updaterects[6];
	SDL::Rect all(0, 0, 640, 480);
	SDL::Rect ballrect, play1rect, comrect;
	int ballvx, ballvy;
	bool playerwon = false;

	Score score;
	Ball ball(309, 229, 11, 11, ((rand() % 4) + 2), -((rand() % 4) + 2));
	Computer computer(629, 187, 11, 106);

	Paddle playerone(0, 187, 11, 106);
	HandleInput handleinput(playerone);

	while(!handleinput)
	{
		// Update everything
		ball.Update();
		playerone.Update();
		computer.UpdateAI(ball);

		// needed for game logic
		ballrect = ball.Get(ballvx, ballvy);
		play1rect = playerone.Get();
		comrect = computer.Get();

		// check if it hit the paddle for player and then the same for computer
		if((ballrect.x <= 11) &&
				(ballrect.y >= play1rect.y) &&
				((ballrect.y+11) <= play1rect.y + 106))
		{
			ball.SetVel(-ballvx, ballvy);
		}

		if(((ballrect.x + 11) >= 629) &&
				(ballrect.y >= comrect.y) &&
				((ballrect.y+11) <= comrect.y + 106))
		{
			ball.SetVel(-ballvx, ballvy);
		}

		// scoring if it goes past either paddle
		if(ballrect.x+10 < 11)
		{
			ball.Set(309, 229, 11, 11, ((rand() % 4) + 2), ((rand() % 4) + 2));
			score.m_Two++;
		}

		if(ballrect.x+10 > 629)
		{
			ball.Set(309, 229, 11, 11, -((rand() % 4) + 2), -((rand() % 4) + 2));
			score.m_One++;
		}

		// somene's won
		if(score.m_One > 9)
		{
			std::cout << "Congrats, you won." << std::endl;
			playerwon = true;
			break;
		}
		if(score.m_Two > 9)
		{
			std::cout << "Sorry, you lost, try again." << std::endl;
			break;
		}

		// drawing code
		screen.FillRect(all, 0);

		updaterects[0] = ball.Draw(screen);
		updaterects[1] = computer.Draw(screen);
		updaterects[2] = playerone.Draw(screen);
		score.Draw(screen, updaterects[3], updaterects[4]);

		// see if we're double buffering, if so, do a screen Flip
		if((screen.Get()->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
			screen.Flip();
		else
		{
			updaterects[5] = all;
			screen.UpdateRects(6, updaterects);
		}

		// Poll for new events, then wait a bit
		events.Poll(handleinput);
		Delay();
	}
}