home *** CD-ROM | disk | FTP | other *** search
/ UnrealScript Game Programming All in One / UnrealScriptGameProgrammingAllInOne.iso / UGPAIOListings / UGPAIOListingsCh20 / CH20LIST / Classes / CH20_08LIST.uc < prev    next >
Encoding:
Text File  |  2006-02-28  |  2.8 KB  |  86 lines

  1. // %PARAMETERS = "CH20LIST C:\UT2004"
  2. //Identifies the package
  3. //CH20_08LIST.uc
  4. //This class provides you with a demonstration of
  5. //Polymorphism using Prop, SoundProp, and BackProp
  6.  
  7. class CH20_08LIST extends Commandlet;
  8. function int Main(string Args)
  9. {
  10.   //#1
  11.   local SoundProp firstSndProp;
  12.   local StageProp firstStgProp;
  13.   local Array<Prop> rgProps;
  14.  
  15.   firstSndProp = new class'SoundProp';
  16.   firstStgProp = new class'StageProp';
  17.  
  18.   Log(Chr(10)$ "   Using polymorphism " $ Chr(10)  );
  19.   //#2
  20.   firstSndProp.setName("Sirens.");
  21.   firstSndProp.setAction("Play");
  22.   firstSndProp.setPPos(2);
  23.   firstSndProp.setNumber(222);
  24.  
  25.   firstStgProp.setName("Vista of canyon");
  26.   firstStgProp.setAction("R");
  27.   firstStgProp.setNumber(444);
  28.  
  29.   //#3
  30.   //For the sound
  31.   Log(Chr(10) $ "   SoundProp name: " $ firstSndProp.getName());
  32.   Log(          "   SoundProp number: " $ firstSndProp.getNumber());
  33.   Log(          "   SoundProp action: " $ firstSndProp.getAction());
  34.  
  35.   //For the back scene
  36.   Log(Chr(10) $ "   StageProp name: " $ firstStgProp.getName());
  37.   Log(          "   StageProp number: " $ firstStgProp.getNumber());
  38.   Log(          "   StageProp action: " $ firstStgProp.getAction());
  39.  
  40. //#4
  41. //Assign the objects to an array of the Prop type
  42.   rgProps[0] = firstSndProp;
  43.   rgProps[1] = firstStgProp;
  44.  
  45.  //Polymorphism used to store both types of object in
  46.  //a Prop array
  47.  
  48.   Log(Chr(10) $ "  Polymorphism: Store and retrieve "
  49.                                 $ "objects using a Prop array");
  50.  
  51.   Log(Chr(10) $ "   SoundProp name: " $ rgProps[0].getName());
  52.   Log(          "   SoundProp number: " $ rgProps[0].getNumber());
  53.   Log(          "   SoundProp action: " $ firstStgProp.getAction());
  54.  
  55.   //For the back scene
  56.   Log(Chr(10) $ "   StageProp name: " $ rgProps[1].getName());
  57.   Log(          "   StageProp number: " $ rgProps[1].getNumber());
  58.   Log(          "   StageProp action: " $ rgProps[1].getAction());
  59.  
  60. //#5
  61.  //Polymorphism used to pass both types of argument
  62.  //to a function defined with the type of the parent class
  63.  
  64.    Log(Chr(10) $ "  Pass both objects to a function defined ");
  65.    Log(          "  with Prop as the argument type");
  66.    Log(          "  Again, this is Polymorphism");
  67.  
  68.    //The same function accepts the two data types
  69.    showProp(firstSndProp);
  70.    showProp(firstStgProp);
  71.  
  72.    return 0;
  73. }
  74.  
  75. //#6
  76.  
  77. //-----------------------showProp-------------------------------
  78. public function showProp(Prop locProp){
  79.   Log(Chr(10) $ "   " $ locProp.class
  80.                                   $ ":  " $  locProp.getName());
  81.   Log(          "   " $ locProp.class
  82.                                   $ ":  " $  locProp.getNumber());
  83.   Log(          "   " $ locProp.class
  84.                                   $ ":  " $  locProp.getAction());
  85. }
  86.