-
2 games by woh else...
Hey guys check out the 2 game my groups have done.. One is the snake and the other is called cow n bull.. Extract all the files then run .. or else the prog wont work.. Snake is the normal snake game.. Cow n bull is where u guess the number till u arrive at the correct one
if the secret number is 123
if you enter 456 you will get 0 cow o bull
156 1 bull 0 cow since 1 is there
516 1 cow 0 bull.. since 1 is there but not in same position
123 3 bull 0 cow and u win the game.. Hope u can figure it out
and note that you cannot enter 0 and numbers which repeat like 111 or 113 or 313 etc etc
Post your coments to improve the 2 games...
Bye
-
nice :D
Why didnt you include the source :(
had one little problem....
Why didnt the snake move by itself?
-
-
Yes thats the problem.. I am not able to make the snake move by itself.. It comes to getch() and waits for the arraow key input.. How do i solve this.. Please help me.......
-
Well if your "get player move func is like this:
Code:
void change_location ( const char modex, const char modey )
{
grid[x][y] = CLEAR;
if ( modex == '+' ) x++;
else if ( modex == '-' ) x--;
if ( modey == '+' ) y++;
else if ( modey == '-' ) y--;
grid[x][y] = FILL;
}
.
.
.
switch ( move ) {
case UP: change_location ( 0, '-' ); break;
case DOWN: change_location ( 0, '+' ); break;
case LEFT: change_location ( '-', 0 ); break;
case RIGHT: change_location ( '+', 0 ); break;
default:
perror ( "Invalid input" );
}
ten it would go like this:
Code:
for ( ; ; ) {
if ( direction == x )
change_location ( change, 0 );
else
change_location ( 0, change );
pause_for_input ( &move );
switch ( move ) {
case LEFT:
change_location ( '-', 0 );
direction = ( direction == x ) ? y : x;
break;
case RIGHT:
change_location ( '+', 0 );
direction = ( direction == x ) ? y : x;
break;
}
/* Reset change so that direction
** is incremented or decremented
** accordingly
*/
}
Thanks to Prelude for showing me this excellent method.
-
um... in other words...
You need to make a loop the would increase the grid position but delay it between movements.
-
look at using kbhit()
This will return true if the key board has been hit, then you can use getch to detect which key it is
if( kbhit() )
{
//get the char here using getch()
//change snake direction if necessary
}
//now move the snake based on the direction
well that is what i would do
post your source if you need help using kbhit
-
Ok guys here is the new updated snake game that moves on its own etc etc ttc....... Try it out
-
i have the same problems,
cant u post the sourcecode please
-
Well i have solved the problem of making the snake move.. CHack out my last attachement.. snake.zip