Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Basic Image Processing
- AUTHOR: Frank Valcarcel
- FSU ID: fav12
- RECITATION SECTION NUMBER: 14
- TA NAME: James McClain
- COURSE INFORMATION: COP 3330; T,R 3:35 - 4:50PM
- Project Number: 4
- Due Date: October 31, 2012
- SUMMARY
- INPUT
- BAD DATA CHECKING:
- When a file is streamed in, the file type is verified to insure the user has
- selected a PPM file, and that it is of type P3. At that time, the integers
- within the file header are validated larger than 0 and the stream operator
- also determines if enough "pixel" elements are available for the files width
- and height. On output, we truncate any pixel values to be between o and the
- specific image's depth value.
- OUTPUT
- The program will echoprint all input. The ostream << operator is overloaded
- to output the PPM file data to both the console and an output file.
- SAMPLE OUPUT
- DATA STRUCTURES
- ASSUMPTIONS
- */
- #include <iostream>
- #include <iomanip>
- #include <algorithm> // for forcing input to lowercase
- #include <vector> // for creating/storing dynamic sub-class objects
- #include <fstream> // for file read
- #include <unistd.h> // for using system commands and invoking delays
- #include "balrog.h"
- #include "cyberdemon.h"
- #include "elf.h"
- #include "human.h"
- #include "functions.h"
- using namespace std;
- typedef Creature* CreaturePtr;
- void loadPlayers (ifstream& is, vector<CreaturePtr>& GoodGuys,
- vector<CreaturePtr>& BadGuys);
- void battle (vector<CreaturePtr>& attacks, vector<CreaturePtr>& defends);
- // main delegator
- int main ()
- {
- string playerName, fileName, move;
- ifstream fileIn;
- vector<CreaturePtr> GoodGuys;
- vector<CreaturePtr> BadGuys;
- title();
- cout << setw(37) << "Enter your name: ";
- cin >> playerName;
- cout << endl;
- cout << setw(23) << playerName << ", prepare for battle!\n" << endl;
- /*
- chooseCharacter();
- sleep(5);
- system("clear");
- */
- cout << "Enter a filename, " << playerName << " the "
- << characterType(playersCharacter) << "... (include .txt)" << endl;
- cout << "Filename: ";
- cin >> fileName;
- while (!validateFileExtension(fileName)) {
- cout << "File type is invalid. TXT files only." << endl;
- cout << "Enter a filename to open (include .txt), or be slain! : ";
- cin >> fileName;
- fileIn.open( fileName.c_str() );
- }
- if (fileIn.fail() ) {
- cout << "Failed to open input file." << endl;
- cout << "Enter a filename to open (include .txt), or be slain! : ";
- cin >> fileName;
- fileIn.open( fileName.c_str() );
- }
- cout << "file opened" << endl; // DELETE ME!!!
- loadPlayers (fileIn, GoodGuys, BadGuys);
- cin >> move;
- fileIn.close();
- return (0);
- }
- void loadPlayers (ifstream& is, vector<CreaturePtr>& GoodGuys,
- vector<CreaturePtr>& BadGuys) {
- int species, strength, hitpoints;
- int count = 0;
- string line;
- if( is.good() ){
- for (int i = 0; i < 4; i++) {
- cout << "in good guy while loop... I should read data!" << endl; // DELETE ME!!!
- is >> species >> strength >> hitpoints;
- cout << species << strength << hitpoints;
- // if human type
- if(species == 0)
- {
- cout << "did I make it here? ";
- GoodGuys.push_back(new Human(strength, hitpoints));
- count ++;
- cout << "Good Human " << i << endl;
- }
- // if cyberdemon type
- else if(species == 1)
- {
- GoodGuys.push_back(new CyberDemon(strength, hitpoints));
- count ++;
- cout << "Good CyberDemon " << i << endl;
- }
- // if balrog type
- else if(species == 2)
- {
- GoodGuys.push_back(new Balrog(strength, hitpoints));
- count ++;
- cout << "Good Balrog " << i << endl;
- }
- // if elf type
- else if(species == 3)
- {
- GoodGuys.push_back(new Elf(strength, hitpoints));
- count ++;
- cout << "Good Elf " << i << endl;
- }
- // if data is invalid
- else {
- cout << is << " ";
- cout << "Error in file. Invalid creature. " << endl;
- return;
- }// end else
- }
- if (count >= 4) {
- for (int i = 0; i < 4; i++) {
- cout << "in bad guy loop... I should read data!" << endl; // DELETE ME!!!
- is >> species >> strength >> hitpoints;
- if (species > 0) {
- cout << "bad species greater than zero" << endl;
- }
- else {
- cout << "Error in file. Invalid creature. " << endl;
- return;
- }// end else
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement