+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    America's Army Subscriber
    Join Date
    Feb 2008
    Posts
    27

    [Tutorial]Tetris

    Hi guys,

    Found this in my stuff.

    This tetris game was made by a friend of mine called Jason for two purposes:

    Purpose 1: For people to learn C++

    Purpose: You know inbetween rounds when you are dead, and also bored out your skull waiting for one noob to kill the other noob or for time to run out. Well he made this game with the idea in mind to inject into AA for something to do between rounds

    Enjoy!

    Header: CImg.h

    Code:
    /*------------------------------------------------------------------------------------------------------
      
      File        : CImg.h 
      Description : Main file of `CImg : The C++ Template Image Library'.
      Author      : David Tschumperlé
      Institution : Initially developped at ODYSSEE Lab, INRIA Sophia Antipolis.
     
      This program is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published by
      the Free Software Foundation; either version 2 of the License, or
      (at your option) any later version.
      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.
      
      ----------------------------------------------------------------------------------------------------*/
    
    #ifndef cimg_include
    #define cimg_include
    #include <cstdio>
    #include <cstdlib>
    #include <cstdarg>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    
    /*-------------------------------------------------------------
    
    
      Detect and set CImg configuration flags
    
      
      If compilation flags are not adapted to your system, you can
      set them to correct values, before including
      the file CImg.h.
    
    
      -------------------------------------------------------------*/
    
    typedef unsigned int   uint;              //!< small typename for \a unsigned \a int.
    typedef unsigned char  uchar;             //!< small typename for \a unsigned \a char.
    typedef unsigned short ushort;            //!< small typename for \a unsigned \a short.
    struct CImgStats;
    struct CImgDisplay;
    struct CImgException;
    template<typename T=float> struct CImg;
    template<typename T=float> struct CImgl;
    template<typename T=float> struct CImgROI;
    
    // Overcome VisualC++ 6.0 and DMC compilers namespace bug
    #if ( defined(_MSC_VER) && _MSC_VER<=1200 ) || defined(__DMC__)
    #define std
    #endif
    
    // Autodetection of the current OS
    #ifndef cimg_OS
    #if defined(sun) || defined(__sun)        
    // Solaris
    #define cimg_OS            0
    #ifndef cimg_display_type
    #define cimg_display_type  1
    #endif
    #elif defined(linux) || defined(__linux) || defined(__CYGWIN__)
    // Linux
    #define cimg_OS            1
    #ifndef cimg_display_type
    #define cimg_display_type  1
    #endif
    #ifndef cimg_color_term
    #define cimg_color_term
    #endif
    #elif defined(_WIN32) || defined(__WIN32__)
    // Windows
    #define cimg_OS            2
    #ifndef cimg_display_type
    #define cimg_display_type  2
    #endif
    #elif defined(__MACOSX__) || defined(__APPLE__)
    // Mac OS X
    #define cimg_OS            3
    #ifndef cimg_display_type
    #define cimg_display_type  1
    #endif
    #else 
    // Unknow configuration
    #define cimg_OS           -1
    #ifndef cimg_display_type
    #define cimg_display_type  0
    #endif
    #endif
    #endif
    // Other configuration flags
    #ifndef cimg_debug
    #define cimg_debug         1
    #endif
    
    // Architecture-dependent includes
    #if cimg_OS!=2
    #include <sys/time.h>
    #include <unistd.h>
    #else
    #ifndef _WIN32_WINNT
    #define _WIN32_WINNT 0x0400     // Overcome bug in macro definition in winuser.h (allow the use of TrackMouseEvent() )
    #endif
    #include <windows.h>
    #endif
    #if cimg_display_type==1
    #include <X11/Xlib.h>
    #include <X11/Xutil.h>
    #include <pthread.h>
    static pthread_mutex_t* cimg_mutex = NULL;
    static pthread_t*       cimg_event_thread = NULL;
    static CImgDisplay*     cimg_wins[1024];
    static Display*         cimg_displayX11 = NULL;
    static volatile uint    cimg_nb_wins = 0;
    static volatile bool    cimg_thread_finished = false;
    static uint             cimg_bits = 0;
    static GC*              cimg_gc = NULL;
    #endif
    
    /*----------------------------------------------------
    
    
    
      Definition of the CImg Exception Classes
    
    
    
      -------------------------------------------------*/
    
    #if cimg_debug>=1
    #if cimg_display_type!=2
    #define cimg_exception_print(str) std::fprintf(stderr,"<CImg Error> %s",str);
    #else
    #define cimg_exception_print(str) MessageBox(NULL,str,"<CImg Error>",MB_OK);
    #endif
    #else
    #define cimg_exception_print(str)
    #endif
    #define cimg_exception_err(etype)                                       \
      char tmp[1024];                                                       \
      va_list ap;                                                           \
      va_start(ap,format);                                                  \
      std::vsprintf(message,format,ap);                                     \
      va_end(ap);                                                           \
      std::sprintf(tmp,"<Error cause> %s \n\nGeneral : %s\n\n",             \
                   message,etype);                                          \
      cimg_exception_print(tmp)
    
    //! This class is used to throw general exceptions, and is the base class of all CImg exceptions.
    struct CImgException {
      char message[1024];
      CImgException() { message[0]='\0'; }
      CImgException(const char *format,...) {
        cimg_exception_err("This error has been generated by a 'CImgException' throw, corresponding to a general exception problem."); 
      }
    };
    //! This class is used to throw an exception related to a non suitable instance encountered in a library function call.
    struct CImgInstanceException : CImgException { 
      CImgInstanceException(const char *format,...) {
        cimg_exception_err("This error has been generated by a 'CImgInstanceException' throw.\n\
    The instance passed through the function above has a bad structure (perhaps an empty image, list or display object ?)");
      }};
    //! This class is used to throw an exception related to invalid arguments encountered in a library function call.
    struct CImgArgumentException : CImgException { 
      CImgArgumentException(const char *format,...) { 
        cimg_exception_err("This error has been generated by a 'CImgArgumentException' throw.\n\
    At least one argument passed to the function above has been considered as not valid.");
      }};
    //! This class is used to throw an exception related to Input/Output file problems encountered in a library function call.
    struct CImgIOException : CImgException { 
      CImgIOException(const char *format,...) {
        cimg_exception_err("This error has been generated by a 'CImgIOException' throw.\n\
    When trying to load or save a file, the function above has encountered a problem.");
      }};
    //! This class is used to throw an exception related to display problems encountered in a library function call.
    struct CImgDisplayException : CImgException {
      CImgDisplayException(const char *format,...) {
        cimg_exception_err("This error has been generated by a 'CImgDisplayException' throw.\n\
    When trying to operate on a CImgDisplay instance, the function above encountered a problem."); 
      }};
    Only allowed to post 20,000 charcters on these forums, so you can download the rest of the tut by clicking the hyperlink below.

    Tetris Download - Click Here

  2. #2
    Alliance of Valiant Arms Subscriber
    Join Date
    Nov 2009
    Posts
    269
    Ty, i hope it' ll be nicely !

  3. #3
    America's Army Subscriber
    Join Date
    May 2008
    Posts
    777
    not bad at all had a try of it


  4. #4
    America's Army Subscriber
    Join Date
    Feb 2008
    Posts
    27
    It can get addictive, haha the speed gets annoyingly fast though :/


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts