main.cpp
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* main.cpp :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: gychoi <gychoi@student.42seoul.kr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2023/08/07 17:49:14 by gychoi #+# #+# */ 9 /* Updated: 2023/08/12 20:18:09 by gychoi ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #include "ClapTrap.hpp" 14 #include "ScavTrap.hpp" 15 #include "FragTrap.hpp" 16 #include <iostream> 17 18 void testCaseOne(void) 19 { 20 ScavTrap scavOne("ScavOne"); 21 FragTrap fragOne("FragOne"); 22 int round = 0; 23 24 while (scavOne.getEnergy() && fragOne.getEnergy()) 25 { 26 std::cout << "Round " << round++ + 1 << std::endl; 27 28 unsigned int prevEnergy = scavOne.getEnergy(); 29 scavOne.attack(fragOne.getName()); 30 if (prevEnergy != 0) 31 fragOne.takeDamage(scavOne.getAttack()); 32 prevEnergy = fragOne.getEnergy(); 33 fragOne.attack(scavOne.getName()); 34 if (prevEnergy != 0) 35 scavOne.takeDamage(fragOne.getAttack()); 36 std::cout << std::endl; 37 } 38 } 39 40 void testCaseTwo(void) 41 { 42 FragTrap fragTwo("FragTwo"); 43 int round = 0; 44 45 while (round < 5) 46 { 47 std::cout << "Round " << round++ + 1 << std::endl; 48 49 fragTwo.highFivesGuys(); 50 fragTwo.beRepaired(10); 51 std::cout << std::endl; 52 } 53 } 54 55 void testCaseThree(void) 56 { 57 FragTrap fragThree("FragThree"); 58 FragTrap fragFour(fragThree); 59 ClapTrap* cp = &fragFour; 60 61 fragThree.attack(cp->getName()); 62 cp->takeDamage(fragThree.getAttack()); 63 cp->attack(fragThree.getName()); 64 fragThree.takeDamage(cp->getAttack()); 65 std::cout << std::endl; 66 } 67 68 void testCaseFour(void) 69 { 70 ClapTrap* clapTwo = new FragTrap("FragFive"); 71 72 delete clapTwo; 73 } 74 75 void testCaseFive(void) 76 { 77 ScavTrap* scavTwo = new ScavTrap(); 78 FragTrap* fragSix = dynamic_cast<FragTrap*>(scavTwo); 79 80 std::cout << "dynamic casting between non-connective classes: " << fragSix << std::endl; 81 delete scavTwo; 82 } 83 84 void testCaseSix(void) 85 { 86 ClapTrap* clapThree = new FragTrap(); 87 FragTrap* fragSeven = dynamic_cast<FragTrap*>(clapThree); 88 89 std::cout << "dynamic casting between Base-Derieve classes: " << fragSeven << std::endl; 90 fragSeven->highFivesGuys(); 91 delete clapThree; 92 } 93 94 int main(void) 95 { 96 std::cout << "Case 1: Violence" << std::endl; 97 testCaseOne(); 98 std::cout << '\n' << "Case 2: I love you guys!" << std::endl; 99 testCaseTwo(); 100 std::cout << '\n' << "Case 3: Up-Casting" << std::endl; 101 testCaseThree(); 102 std::cout << '\n' << "Case 4: Dynamic allocation with Up-Casting" << std::endl; 103 testCaseFour(); 104 std::cout << '\n' << "Case 5: Dynamic Casting in non-connective classes" << std::endl; 105 testCaseFive(); 106 std::cout << '\n' << "Case 6: Dynamic Casting with Up-Casting" << std::endl; 107 testCaseSix(); 108 return (EXIT_SUCCESS); 109 }