Thread: 2 games by woh else...

  1. #1
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683

    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

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    nice

    Why didnt you include the source

    had one little problem....

    Why didnt the snake move by itself?
    What is C++?

  3. #3
    Much older and wiser Fountain's Avatar
    Join Date
    Dec 2001
    Location
    Engeeeerland
    Posts
    1,158
    yeh, kinda nice
    Such is life.

  4. #4
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    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.......

  5. #5
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    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.
    What is C++?

  6. #6
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    um... in other words...

    You need to make a loop the would increase the grid position but delay it between movements.
    What is C++?

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    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

  8. #8
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Ok guys here is the new updated snake game that moves on its own etc etc ttc....... Try it out

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    i have the same problems,

    cant u post the sourcecode please

  10. #10
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Well i have solved the problem of making the snake move.. CHack out my last attachement.. snake.zip

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. When done right, PC games are amazing
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 08-13-2008, 05:32 PM
  2. Violent video games?
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 58
    Last Post: 04-26-2006, 01:43 PM
  3. Video Games Industry. 5 years left.
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 12-10-2002, 10:52 PM
  4. Starting games - books? api?
    By SeanMSimonsen in forum Game Programming
    Replies: 22
    Last Post: 11-27-2002, 09:09 PM