| CODE |
| #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int tries = 0, guess = 0, theNumber = ( 1 + rand() % 1000 ); srand(( unsigned ) time( NULL )); printf("\tGUESS THE NUMBER\n\n" "I have guessed a number between 1 and 1000\n" "and you have to try to guess it!\n\n"); /*game loop*/ do { printf("Enter your guess: "); scanf("%d", &guess); tries++; if ( guess < theNumber ) { printf("\nTOO LOW!\n"); } if ( guess > theNumber ) { printf("\nTOO HIGH!\n"); } } while ( guess != theNumber ); /*user has guessed it*/ printf("\n\nYou got it! It took %d tries!\n", tries); return 0; } |
| CODE |
| class Sugababes { public: Sugababes( std::string, int ); ~Sugababes(); private: std::string name; int age; }; Sugababes Keisha( "", 0 ); Sugababes Heidi( "", 0 ); Amelle( "",0 ); |
| CODE |
| /*** * Example of ENEMY AI * By Peter Watts (c) 2009 ****/ void trackPlayerMovement ( Client *client, Enemy *enemy, int &rx, int &ry ) { /*is the player moving*/ if ( client->station( reutrn true )) { status = TRUE; } else { referToPlayerEngine( client ); } /*player is moving - so keep count of player button presses*/ int playerPress = getPadTypeAndCount( ++variable ); /*is the player stood behind or infront or to the side*/ returnMaximumMoveTotal( client->ClientState ); enum BESTMOVES { NORTH, SOUTH, EAST, WEST }; /*enemy cannot reach player*/ if ( enemy->isNear() == FALSE ) { return 2; } if ( enemy->isNearLeftRight() == FALSE ) { return 3; } typedef struct { int hit, miss; } nextAction( client, enemy ); } |
| CODE |
| // Example of a player class // (c) 2009 Peter Watts // a class is a 'blue print' for an object // it defines its scope, abilites and features Class Player { public: Player(); ~Player(); private: usigned long health; string name; bool *deadoralive; signed long score; }; // this is a constructor // it initilizes all data members to a // default state Player::Player() { health = 100; name = "Millie"; *deadoralive = false; // void pointer score = 0; } // this is a destructor // the compiler calls this when the program terminates // it destroys the created object Player::~Player() { for (;; ) { if ( gameEnd == true ) { std::cout << "\nDestructor called...\n" << "Destryoing all player objects\n"; } } // main int main ( void ) { // now I create a player 'object' Player play; engine->startGame( &play ); return EXIT_SUCCESS; } |