In the Linux environment, to find pinball game code. __linux

Source: Internet
Author: User
Tags rand sprintf usleep
Http://zhidao.baidu.com/link?url=njqA2CMP_H0URs9n-O3uNWR4GEChkVK9aINGoDHIgy38Q_ Sdgas2lgzvi7penn6hmdjjroix5vvmaf3qhruink #include <curses.h> #include <stdio.h> #include <signal.h > #include <sys/types.h> #include <pthread.h> #include <errno.h> #include <unistd.h> # Include <fcntl.h> #include <sys/stat.h> #include <string.h> #include <stdlib.h> #define MIN (a,b
) a<b?a:b #define MAX (a,b) a>b?a:b int running;
int prunning;
int quit;
int step[2];
int ballx;

int Bally;
int Barx;

int bary;
int D;
float D1;
int FD;
Char buf[1024];
int mrunning = 1;
Char *bar = "___";
Char ball = ' O ';
void PA ();
void ShowMsg ();

void Newgame ();
	void Paint () {clear ();
		while (prunning) {clear ();
		Mvaddstr (Bary,barx,bar);
		MVADDCH (Bally,ballx,ball);
		Refresh ();

	Usleep (100000);
} pthread_exit (NULL);
	} void Ballmove () {int ret;
	Unlink ("Record.txt");
	bally = LINES-2; FD = open ("Record.txt", o_creat| o_rdwr,0666);
	if (FD < 0) {perror ("create");
	Exit (1);
			while (1) {while (running) {memset (buf,0,sizeof (BUF));
			BALLX = D;
				if (ballx = = COLS) {d =-1;
				Ballx= COLS-1;

			Beep ();
				} if (Ballx <0) {d = 1;
				BALLX = 0;
			Beep ();
			} bally-= D1;
			/*if (bally = = LINES) {//srand (Time (NULL));

			D1 = (rand ()%10)/(10.0) +1.0;
			D1 = 1;
			bally = LINES-1;

			Beep ();
				}*/if (Bally < 0) {//srand (Time (NULL));
				D1 = (rand ()%10)/(10.0) + 1.0;
				D1 =-1;
				bally= 0;
			Beep ();
			  }/*if (LINES-2 = = bally) {d1 = 1;
			  bally = LINES-2;
			  Beep ();
				}*/else if (bally = = LINES) {char tmp[] = "ball move over\n";
				Write (Fd,tmp,strlen (TMP));
				running = 0;
				prunning = 0;
				Quit = 0;
				Clear ();
				Mvaddstr (12,15, "Game over!, thank to play next time!");
				Refresh ();
				Mvaddstr (13,15, "Input ' n ' restart, ' Q ' exit the game, ' R ' Return the Menu"); Refresh ();
				Attron (A_bold);
				Mvaddstr (14,17, "please input:");
				Refresh ();
				Move (14,25);	

			Break
				else if ((bally = = bary) && (Ballx >=step[0) && (ballx <= step[1))) {D1 = 1;
				bally = LINES-1;
				Char temp[]= "The ball click the bar\n";
				Write (Fd,temp,strlen (temp));
			Beep ();
			} sprintf (buf, "x =%d, y =%d\n", ballx,bally);
			Write (Fd,buf,strlen (BUF));
		Usleep (100000);
	} if (0 = prunning) break;
	}//close (FD);

Pthread_exit (NULL);
	} void Barmove () {chtype input;
	Clear ();
	Char buf[100];

	keypad (stdscr,true);
	bary = LINES-1;
	Mvaddstr (Bary,barx,bar); quit&& (input = Getch ()) &&input!=err while quit&& (input = Getch ()) &&input!=err) {i
			F (!quit) {char tmp[] = "bar move over 1\n";
			Write (Fd,tmp,strlen (TMP));
		Break
				switch (input) {Case Key_left:barx = MAX (barx-1,0);
				memset (buf,0,sizeof (BUF));
				Step[0]-= 1;
				STEP[1]-= 1; SprintF (buf, "step[0] =%d, step[1]=%d \ n", step[0],step[1]);
				Write (Fd,buf,strlen (BUF));
			Break
				Case Key_right:memset (buf,0,sizeof (BUF));
				Barx = MIN (barx+1,cols-1-10);
				STEP[0] + + 1;
				STEP[1] + + 1;
				sprintf (BUF, "step[0] =%d, step[1]=%d \ n", step[0],step[1]);
				Write (Fd,buf,strlen (BUF));
			Break
					Case ' R ': {char tmp[] = "bar move over 2\n";
					Write (Fd,tmp,strlen (TMP));
					prunning = 0;
					running = 0;
						if (running && prunning) {prunning = 0;
						running = 0;

					Quit = 0;
						else if (prunning &&!running)//If the pause {prunning = 0 is pressed;
						running = 0;
						Quit = 0;

					ShowMsg ();

					else {quit = 0;
					} showmsg ();
				Break
				Case ' P ': PA ();	
			Break
						Case ' Q ': {if (prunning&&running)//If the program is running {prunning = 0;
						running = 0;
						Quit = 0;
					ShowMsg (); else if (prunning &&!running)//If the pause {prunning = 0 is pressed;
						running = 0;
						Quit = 0;

					ShowMsg ();
						else//directly exit {quit = 0;
						mrunning = 0;
						prunning = 0;
					running = 0;
				} break;
				Case ' n ': newgame ();
		Break
	} char tmp[] = "bar move over 3\n";
	Write (Fd,tmp,strlen (TMP));
	Close (FD);

Pthread_exit (NULL);

	} void ShowMsg () {//attron (a_bold);
	Clear ();
	Mvaddstr (10,30, "Welcome to the game!");
	Refresh ();
	Attroff (A_underline);
	Mvaddstr (11,25, "Help:");
	Refresh ();
	Mvaddstr (12,26, "' N ': Start a new game.");
	Refresh ();
	Mvaddstr (13,26, "' Q ': Quit the game.");
	Refresh ();
	Mvaddstr (14,26, "' P ':P ause the game.");
	Refresh ();
	Mvaddstr (15,26, "' R ': Return the menu.");

Refresh ();
	} void Newgame () {pthread_t pid,pid2,pid3,pid4;
	prunning = 1;
	running = 1;
	Quit = 1;
	Step[0] = 10;
	STEP[1] = 19;
	bally = LINES-1;
	bary = LINES-1;
	Barx = 10;
	BALLX = 10;
	D1 = 1;
	D = 1;

Paint Pthread_create (&pid,null, (void *) paint,null); //Wooden bar Rolling Pthread_create (&pid2,null, (void *) barmove,null);

	Ball rolling Pthread_create (&pid3,null, (void *) ballmove,null);
	Pthread_join (Pid,null);
	Pthread_join (Pid2,null);
	Pthread_join (Pid3,null);
	Pthread_create (&pid4,null, (void *) pa,null);
Pthread_join (Pid4,null);
	} void PA () {if (running) running = 0;

else running = 1;
	int main () {pthread_t pid4;
	Char buf[100];
	INITSCR ();
	Crmode ();
	NoEcho ();
	Chtype input;
	keypad (stdscr,true);
	ShowMsg ();
	Pthread_create (&pid4,null, (void *) pa,null);
					while (input = Getch ()) {switch (input) {case ' n ': {newgame () mrunning&&;
				Break
					Case ' Q ': {mrunning = 0;	
				Break
	}} endwin ();

return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.