Advertisement
Guest User

c++ creatures, dynamic object creation

a guest
Nov 13th, 2012
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.29 KB | None | 0 0
  1. /*  Basic Image Processing
  2.  
  3.  AUTHOR: Frank Valcarcel
  4.  FSU ID: fav12
  5.  RECITATION SECTION NUMBER: 14
  6.  TA NAME: James McClain
  7.  COURSE INFORMATION: COP 3330; T,R 3:35 - 4:50PM
  8.  Project Number: 4
  9.  Due Date: October 31, 2012
  10.  
  11.  SUMMARY
  12.  
  13.  
  14.  
  15.  INPUT
  16.  
  17.  
  18.  BAD DATA CHECKING:
  19.  When a file is streamed in, the file type is verified to insure the user has
  20.  selected a PPM file, and that it is of type P3. At that time, the integers
  21.  within the file header are validated larger than 0 and the stream operator
  22.  also determines if enough "pixel" elements are available for the files width
  23.  and height. On output, we truncate any pixel values to be between o and the
  24.  specific image's depth value.
  25.  
  26.  OUTPUT
  27.  The program will echoprint all input. The ostream << operator is overloaded
  28.  to output the PPM file data to both the console and an output file.
  29.  
  30.  SAMPLE OUPUT
  31.  
  32.  
  33.  
  34.  DATA STRUCTURES
  35.  
  36.  
  37.  ASSUMPTIONS
  38.  
  39.  
  40. */
  41.  
  42. #include <iostream>
  43. #include <iomanip>
  44. #include <algorithm>        // for forcing input to lowercase
  45. #include <vector>           // for creating/storing dynamic sub-class objects
  46. #include <fstream>          // for file read
  47. #include <unistd.h>         // for using system commands and invoking delays
  48.  
  49. #include "balrog.h"
  50. #include "cyberdemon.h"
  51. #include "elf.h"
  52. #include "human.h"
  53.  
  54. #include "functions.h"
  55.  
  56. using namespace std;
  57.  
  58. typedef Creature* CreaturePtr;
  59. void loadPlayers (ifstream& is, vector<CreaturePtr>& GoodGuys,
  60.                   vector<CreaturePtr>& BadGuys);
  61. void battle (vector<CreaturePtr>& attacks, vector<CreaturePtr>& defends);
  62.  
  63.  
  64.  
  65. // main delegator
  66. int main ()
  67. {
  68.     string playerName, fileName, move;
  69.     ifstream fileIn;
  70.    
  71.     vector<CreaturePtr> GoodGuys;
  72.     vector<CreaturePtr> BadGuys;
  73.    
  74.     title();
  75.    
  76.     cout << setw(37) << "Enter your name: ";
  77.     cin >> playerName;
  78.     cout << endl;
  79.     cout << setw(23) << playerName << ", prepare for battle!\n" << endl;
  80.    
  81.     /*
  82.      
  83.     chooseCharacter();
  84.    
  85.     sleep(5);
  86.     system("clear");
  87.      
  88.     */
  89.    
  90.     cout << "Enter a filename, " << playerName << " the "
  91.          << characterType(playersCharacter) << "... (include .txt)" << endl;
  92.    
  93.     cout << "Filename: ";
  94.     cin >> fileName;
  95.    
  96.     while (!validateFileExtension(fileName)) {
  97.        
  98.         cout << "File type is invalid. TXT files only." << endl;
  99.         cout << "Enter a filename to open (include .txt), or be slain! : ";
  100.         cin >> fileName;
  101.        
  102.         fileIn.open( fileName.c_str() );
  103.     }
  104.    
  105.     if (fileIn.fail() ) {
  106.         cout << "Failed to open input file." << endl;
  107.         cout << "Enter a filename to open (include .txt), or be slain! : ";
  108.         cin >> fileName;
  109.        
  110.         fileIn.open( fileName.c_str() );
  111.     }
  112.    
  113.     cout << "file opened" << endl; // DELETE ME!!!
  114.    
  115.     loadPlayers (fileIn, GoodGuys, BadGuys);
  116.    
  117.     cin >> move;
  118.    
  119.     fileIn.close();
  120.    
  121.     return (0);
  122. }
  123.  
  124.  
  125.  
  126. void loadPlayers (ifstream& is, vector<CreaturePtr>& GoodGuys,
  127.                   vector<CreaturePtr>& BadGuys) {
  128.    
  129.     int species, strength, hitpoints;
  130.     int count = 0;
  131.     string line;
  132.    
  133.     if( is.good() ){
  134.        
  135.         for (int i = 0; i < 4; i++) {
  136.            
  137.             cout << "in good guy while loop... I should read data!" << endl; // DELETE ME!!!
  138.        
  139.             is >> species >> strength >> hitpoints;
  140.             cout << species << strength << hitpoints;
  141.            
  142.             // if human type
  143.             if(species == 0)
  144.             {
  145.                 cout << "did I make it here? ";
  146.                 GoodGuys.push_back(new Human(strength, hitpoints));
  147.                 count ++;
  148.                 cout << "Good Human " << i << endl;
  149.             }
  150.             // if cyberdemon type
  151.             else if(species == 1)
  152.             {
  153.                 GoodGuys.push_back(new CyberDemon(strength, hitpoints));
  154.                 count ++;
  155.                 cout << "Good CyberDemon " << i << endl;
  156.             }
  157.             // if balrog type
  158.             else if(species == 2)
  159.             {
  160.                 GoodGuys.push_back(new Balrog(strength, hitpoints));
  161.                 count ++;
  162.                 cout << "Good Balrog " << i << endl;
  163.             }
  164.             // if elf type
  165.             else if(species == 3)
  166.             {
  167.                 GoodGuys.push_back(new Elf(strength, hitpoints));
  168.                 count ++;
  169.                 cout << "Good Elf " << i << endl;
  170.             }
  171.             // if data is invalid
  172.             else {
  173.                 cout << is << " ";
  174.                 cout << "Error in file. Invalid creature. " << endl;
  175.                 return;
  176.             }// end else
  177.         }
  178.            
  179.         if (count >= 4) {
  180.            
  181.             for (int i = 0; i < 4; i++) {
  182.                
  183.                 cout << "in bad guy loop... I should read data!" << endl; // DELETE ME!!!
  184.                
  185.                 is >> species >> strength >> hitpoints;
  186.                
  187.                 if (species > 0) {
  188.                     cout << "bad species greater than zero" << endl;
  189.                 }
  190.                
  191.                 else {
  192.                     cout << "Error in file. Invalid creature. " << endl;
  193.                     return;
  194.                 }// end else
  195.             }
  196.         }
  197.     }
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement