Exemplo n.º 1
0
/*
 * makeboard:
 *	Print out the initial board on the screen
 */
void
makeboard(void)
{
	mvaddstr(SCORE_Y + 0, SCORE_X,
	    "+---------------------------------------+");
	mvaddstr(SCORE_Y + 1, SCORE_X,
	    "|  Score:   0     YOU                   |");
	mvaddstr(SCORE_Y + 2, SCORE_X,
	    "| *.....:.....:.....:.....:.....:.....  |");
	mvaddstr(SCORE_Y + 3, SCORE_X,
	    "| *.....:.....:.....:.....:.....:.....  |");
	mvaddstr(SCORE_Y + 4, SCORE_X,
	    "|                                       |");
	mvaddstr(SCORE_Y + 5, SCORE_X,
	    "| *.....:.....:.....:.....:.....:.....  |");
	mvaddstr(SCORE_Y + 6, SCORE_X,
	    "| *.....:.....:.....:.....:.....:.....  |");
	mvaddstr(SCORE_Y + 7, SCORE_X,
	    "|  Score:   0      ME                   |");
	mvaddstr(SCORE_Y + 8, SCORE_X,
	    "+---------------------------------------+");
	gamescore();
}
Exemplo n.º 2
0
	void snake::game()
	{
	void main();
		
		x=43; y=12; length=6;
		score=0;
		
		for(;;)
		{
			while (!kbhit())
			{
				if ((eatx==x)&&(eaty==y))
				{
					gamescore();
					eatxy();
					length=length+2;
				}
				
				gotoxy(x,y);
				cout<<"";
				
		/*		for (int i=1; i<=length+1; i++)
				{
					if (newkey==72)
					{
						gotoxy(x,y+i);
						a[i]=x; b[i]=y+i;
					}	
					
					if (newkey==75)
					{
						gotoxy(x+i,y);
						a[i]=x+i; b[i]=y;
					}	
					
					if (newkey==80)
					{
						gotoxy(x,y-i);
						a[i]=x; b[i]=y-i;
					}
					
					if (newkey==77)
					{
						gotoxy(x-i,y);
						a[i]=x-i; b[i]=y;
					}
					
					if (i==length+1)
					cout<<" ";
					
					else
					cout<<"Û";
				}	*/
				
				delay(speed);
				gotoxy(x,y);
				
				checkcollision();
				
				if (newkey==72)
				y--;
				
				if (newkey==75)
				x--;
				
				if (newkey==80)
				y++;
				
				if (newkey==77)
				x++;
				
				if (newkey==27)
				programmer();
				
				if (newkey==13)
				getch();
				
				if (newkey==110)
				main();
				
				cout<<" ";
				
			}
		
			newkey=getch();
			
			if (newkey==0)
			newkey=getch();
			
		}	
	}
Exemplo n.º 3
0
/*
 * game:
 *	Play one game up to glimit points.  Actually, we only ASK the
 *	player what card to turn.  We do a random one, anyway.
 */
void
game(void)
{
	int i, j;
	bool flag;
	bool compcrib;

	makedeck(deck);
	shuffle(deck);
	if (gamecount == 0) {
		flag = TRUE;
		do {
			if (!rflag) {			/* player cuts deck */
				char *foo;

				/* This is silly, but we should parse user input
				 * even if we're not actually going to use it.
				 */
				do {
					msg(quiet ? "Cut for crib? " :
				    "Cut to see whose crib it is -- low card wins? ");
					foo = get_line();
					if (*foo != '\0' && ((i = atoi(foo)) < 4 || i > 48))
						msg("Invalid cut");
					else
						*foo = '\0';
				} while (*foo != '\0');
			}
			i = arc4random_uniform(CARDS);	/* random cut */
			do {	/* comp cuts deck */
				j = arc4random_uniform(CARDS);
			} while (j == i);
			addmsg(quiet ? "You cut " : "You cut the ");
			msgcard(deck[i], FALSE);
			endmsg();
			addmsg(quiet ? "I cut " : "I cut the ");
			msgcard(deck[j], FALSE);
			endmsg();
			flag = (deck[i].rank == deck[j].rank);
			if (flag) {
				msg(quiet ? "We tied..." :
				    "We tied and have to try again...");
				shuffle(deck);
				continue;
			} else
				compcrib = (deck[i].rank > deck[j].rank);
		} while (flag);
		do_wait();
		clear();
		makeboard();
		refresh();
	} else {
		makeboard();
		refresh();
		werase(Tablewin);
		wrefresh(Tablewin);
		werase(Compwin);
		wrefresh(Compwin);
		msg("Loser (%s) gets first crib", (iwon ? "you" : "me"));
		compcrib = !iwon;
	}

	pscore = cscore = 0;
	flag = TRUE;
	do {
		shuffle(deck);
		flag = !playhand(compcrib);
		compcrib = !compcrib;
	} while (flag);
	++gamecount;
	if (cscore < pscore) {
		if (glimit - cscore > 60) {
			msg("YOU DOUBLE SKUNKED ME!");
			pgames += 4;
		} else
			if (glimit - cscore > 30) {
				msg("YOU SKUNKED ME!");
				pgames += 2;
			} else {
				msg("YOU WON!");
				++pgames;
			}
		iwon = FALSE;
	} else {
		if (glimit - pscore > 60) {
			msg("I DOUBLE SKUNKED YOU!");
			cgames += 4;
		} else
			if (glimit - pscore > 30) {
				msg("I SKUNKED YOU!");
				cgames += 2;
			} else {
				msg("I WON!");
				++cgames;
			}
		iwon = TRUE;
	}
	gamescore();
}