home *** CD-ROM | disk | FTP | other *** search
/ UnrealScript Game Programming All in One / UnrealScriptGameProgrammingAllInOne.iso / UGPAIOListings / UGPAIOListingsCh16 / CH16LIST / Classes / CH16_03LIST.uc < prev    next >
Encoding:
Text File  |  2006-02-17  |  2.5 KB  |  99 lines

  1. // %PARAMETERS = "CH16LIST C:\UT2004"
  2. //Identifies the package
  3. //CH16_03LIST.uc
  4.  
  5. class CH16_03LIST extends Commandlet;
  6.  
  7. //#1
  8. //Set up an enumeration at class scope
  9. enum COMPASS
  10. {
  11.      EAST,           //sequential numbering begins at 0
  12.      NORTH_EAST,
  13.      NORTH,
  14.      NORTH_WEST,
  15.      WEST,
  16.      SOUTH_WEST,
  17.      SOUTH,
  18.      SOUTH_EAST    //final enumerated value is 7
  19.  };
  20.  
  21.    //#2
  22.    //Declare array at the class scope
  23.    var Array<float> rgCompassDegrees;
  24.  
  25.  
  26. function int Main(string Args){
  27.  
  28.    local int iRand;
  29.    local int iCtr;
  30.  
  31.    // Initialize elements of the array at the local scope
  32.    rgCompassDegrees[0] = 0;
  33.    rgCompassDegrees[1] = 45;
  34.    rgCompassDegrees[2] = 90;
  35.    rgCompassDegrees[3] = 135;
  36.    rgCompassDegrees[4] = 180;
  37.    rgCompassDegrees[5] = 225;
  38.    rgCompassDegrees[6] = 270;
  39.    rgCompassDegrees[7] = 315;
  40.  
  41.    iCtr = 0;
  42.  
  43.    //#3
  44.    while(iCtr <= COMPASS.SOUTH_EAST){
  45.       // Initialize the random identifier
  46.       iRand = Rand(COMPASS.SOUTH_EAST + 1);
  47.  
  48.     //#4
  49.       switch(iRand){
  50.          case COMPASS.EAST:
  51.            Log(Chr(10) $ "   Go East!  Degrees: "
  52.     //#5
  53.            //Retrieve the associated integer
  54.                        $ getDegrees(COMPASS.EAST) );
  55.            break;
  56.          case COMPASS.NORTH_EAST:
  57.            Log(Chr(10) $ "   Go North East! Degrees: "
  58.                        $ getDegrees(COMPASS.NORTH_EAST) );
  59.            break;
  60.          case COMPASS.NORTH:
  61.            Log(Chr(10) $ "   Go North! Degrees: "
  62.                        $ getDegrees(COMPASS.NORTH) );
  63.            break;
  64.          case COMPASS.NORTH_WEST:
  65.            Log(Chr(10) $ "   Go North West! Degrees: "
  66.                        $ getDegrees(COMPASS.NORTH_WEST) );
  67.            break;
  68.          case COMPASS.WEST:
  69.            Log(Chr(10) $ "   Go West! Degrees: "
  70.                        $ getDegrees(COMPASS.WEST) );
  71.            break;
  72.          case COMPASS.SOUTH_WEST:
  73.            Log(Chr(10) $ "   Go South West! Degrees: "
  74.                        $ getDegrees(COMPASS.SOUTH_WEST) );
  75.            break;
  76.          case COMPASS.SOUTH:
  77.            Log(Chr(10) $ "   Go South! Degrees: "
  78.                        $ getDegrees(COMPASS.SOUTH) );
  79.            break;
  80.          case COMPASS.SOUTH_EAST:
  81.            Log(Chr(10) $ "   Go South East!  "
  82.                        $ getDegrees(COMPASS.SOUTH_EAST));
  83.            break;
  84.       };
  85.  
  86.      iCtr++;
  87.     }//end while
  88.  
  89.     return 0;
  90. }//end Main()
  91.  
  92.  
  93. // #6
  94. //COMPASS data type as the argument
  95. function int getDegrees(COMPASS com){
  96.    return rgCompassDegrees[com];
  97. }
  98.  
  99.