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 19:45:32 by gychoi           ###   ########.fr       */
 10  /*                                                                            */
 11  /* ************************************************************************** */
 12  
 13  #include "ClapTrap.hpp"
 14  #include "ScavTrap.hpp"
 15  #include <iostream>
 16  
 17  void	testCaseOne(void)
 18  {
 19  	ScavTrap	scavOne("ScavOne");
 20  	ClapTrap	clapOne("ClapOne");
 21  	int			round = 0;
 22  
 23  	while (scavOne.getEnergy() && clapOne.getEnergy())
 24  	{
 25  		std::cout << "Round " << round++ + 1 << std::endl;
 26  
 27  		scavOne.beRepaired(15);
 28  		clapOne.beRepaired(15);
 29  		unsigned int	prevEnergy = scavOne.getEnergy();
 30  		scavOne.attack(clapOne.getName());
 31  		if (prevEnergy != 0)
 32  			clapOne.takeDamage(scavOne.getAttack());
 33  		prevEnergy = clapOne.getEnergy();
 34  		clapOne.attack(scavOne.getName());
 35  		if (prevEnergy != 0)
 36  			scavOne.takeDamage(clapOne.getAttack());
 37  		std::cout << std::endl;
 38  	}
 39  }
 40  
 41  void	testCaseTwo(void)
 42  {
 43  	ScavTrap	scavTwo("ScavTwo");
 44  	int			round = 0;
 45  
 46  	while (round < 5)
 47  	{
 48  		std::cout << "Round " << round++ + 1 << std::endl;
 49  
 50  		scavTwo.guardGate();
 51  		scavTwo.beRepaired(10);
 52  		std::cout << std::endl;
 53  	}
 54  }
 55  
 56  void	testCaseThree(void)
 57  {
 58  	ScavTrap	scavThree("ScavThree");
 59  	ScavTrap	scavFour(scavThree);
 60  	int			round = 0;
 61  
 62  	while (scavThree.getEnergy() && scavFour.getEnergy())
 63  	{
 64  		std::cout << "Round " << round++ + 1 << std::endl;
 65  
 66  		std::cout << "INFO: Original scavThree attacks." << std::endl;
 67  		unsigned int	prevEnergy = scavThree.getEnergy();
 68  		scavThree.attack(scavFour.getName());
 69  		if (prevEnergy != 0)
 70  			scavFour.takeDamage(scavThree.getAttack());
 71  		std::cout << "INFO: scavThree clone attacks." << std::endl;
 72  		prevEnergy = scavFour.getEnergy();
 73  		scavFour.attack(scavThree.getName());
 74  		if (prevEnergy != 0)
 75  			scavThree.takeDamage(scavFour.getAttack());
 76  		std::cout << std::endl;
 77  	}
 78  }
 79  
 80  void	testCaseFour(void)
 81  {
 82  	ScavTrap	scavFive("ScavFive");
 83  	ScavTrap	scavSix("ScavSix");
 84  	ClapTrap*	cp = &scavSix;
 85  
 86  	scavFive.attack(cp->getName());
 87  	cp->attack(scavFive.getName());
 88  	std::cout << std::endl;
 89  }
 90  
 91  void	testCaseFive(void)
 92  {
 93  	ClapTrap*	clapTwo = new ScavTrap();
 94  
 95  	clapTwo->attack("dummy");
 96  	delete clapTwo;
 97  }
 98  
 99  int	main(void)
100  {
101  	std::cout << "Case 1: Unnessesary Violence" << std::endl;
102  	testCaseOne();
103  	std::cout << '\n' << "Case 2: Guard the Gate" << std::endl;
104  	testCaseTwo();
105  	std::cout << '\n' << "Case 3: Fight with reflection" << std::endl;
106  	testCaseThree();
107  	std::cout << '\n' << "Case 4: Up-Casting" << std::endl;
108  	testCaseFour();
109  	std::cout << '\n' << "Case 5: Dynamic allocation with Up-Casting" << std::endl;
110  	testCaseFive();
111  	return (EXIT_SUCCESS);
112  }