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/11 01:38:13 by gychoi ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #include "ClapTrap.hpp" 14 #include <iostream> 15 #include <string> 16 17 void testCaseTwo(std::string input) 18 { 19 if (input.empty()) 20 std::cout << "WARNING: The name of the ClapTrap being created is not visible." << std::endl; 21 ClapTrap clapUser(input); 22 ClapTrap clapOne("ClapOne"); 23 24 std::cout << "Case : Tug of War" << std::endl; 25 for (int i = 0; i < 11; i++) 26 { 27 std::cout << "Round " << i + 1 << std::endl; 28 29 unsigned int prevEnergy = clapOne.getEnergy(); 30 clapOne.attack(input); 31 if (prevEnergy != 0) 32 clapUser.takeDamage(clapOne.getAttack()); 33 std::cout << std::endl; 34 35 prevEnergy = clapUser.getEnergy(); 36 clapUser.attack(clapOne.getName()); 37 if (prevEnergy != 0) 38 clapOne.takeDamage(clapUser.getAttack()); 39 std::cout << std::endl; 40 } 41 } 42 43 void testCaseOne(void) 44 { 45 std::cout << "Case 1 : Tug of War" << std::endl; 46 ClapTrap clapOne("ClapOne"); 47 ClapTrap clapTwo("ClapTwo"); 48 49 for (int i = 0; i < 11; i++) 50 { 51 std::cout << "Round " << i + 1 << std::endl; 52 53 unsigned int prevEnergy = clapOne.getEnergy(); 54 clapOne.attack(clapTwo.getName()); 55 if (prevEnergy != 0) 56 clapTwo.takeDamage(clapOne.getAttack()); 57 std::cout << std::endl; 58 59 prevEnergy = clapTwo.getEnergy(); 60 clapTwo.attack(clapOne.getName()); 61 if (prevEnergy != 0) 62 clapOne.takeDamage(clapTwo.getAttack()); 63 std::cout << std::endl; 64 } 65 std::cout << std::endl; 66 67 std::cout << "Case 2 : Self-harm" << std::endl; 68 ClapTrap clapThree("ClapThree"); 69 70 for (int i = 0; i < 6; i++) 71 { 72 std::cout << "Round " << i + 1 << std::endl; 73 clapThree.takeDamage(2); 74 std::cout << std::endl; 75 } 76 std::cout << std::endl; 77 78 std::cout << "Case 3 : Over-heal" << std::endl; 79 ClapTrap clapFour("ClapFour"); 80 81 for (int i = 0; i < 11; i++) 82 { 83 std::cout << "Round " << i + 1 << std::endl; 84 clapFour.beRepaired(10); 85 std::cout << std::endl; 86 } 87 std::cout << std::endl; 88 89 std::cout << "Case 4 : Already Exhausted" << std::endl; 90 ClapTrap clapFive(clapFour); 91 92 for (int i = 0; i < 3; i++) 93 { 94 std::cout << "Round " << i + 1 << std::endl; 95 clapFive.takeDamage(0); 96 clapFive.beRepaired(10); 97 std::cout << std::endl; 98 } 99 std::cout << std::endl; 100 101 std::cout << "Case 5 : Already Destroyed" << std::endl; 102 ClapTrap clapSix; 103 clapSix = clapThree; 104 105 for (int i = 0; i < 3; i++) 106 { 107 std::cout << "Round " << i + 1 << std::endl; 108 clapSix.takeDamage(0); 109 clapSix.beRepaired(10); 110 std::cout << std::endl; 111 } 112 std::cout << std::endl; 113 114 std::cout << "Case 6 : Ultra Violence" << std::endl; 115 ClapTrap clapSeven("ClapSeven"); 116 117 clapSeven.takeDamage(3333333333); 118 std::cout << "Current " << clapSeven.getName() << " points of health is " << clapSeven.getHit() << std::endl; 119 std::cout << '\n' << std::endl; 120 121 std::cout << "Case 7 : Ultra Recovery" << std::endl; 122 ClapTrap clapEight("ClapEight"); 123 124 clapEight.beRepaired(3333333333); 125 std::cout << "Current " << clapEight.getName() << " points of health is " << clapEight.getHit() << std::endl; 126 std::cout << std::endl; 127 } 128 129 int main(int argc, char* argv[]) 130 { 131 if (argc < 2) 132 testCaseOne(); 133 else if (argc == 2) 134 testCaseTwo(argv[1]); 135 else 136 { 137 std::cout << "Only one argument is allowed." << std::endl; 138 return (EXIT_FAILURE); 139 } 140 return (EXIT_SUCCESS); 141 }