Skip to content

Instantly share code, notes, and snippets.

@donghee
Created May 24, 2023 05:16
Show Gist options
  • Save donghee/baec82962fa5d48182e7280e5383d5b7 to your computer and use it in GitHub Desktop.
Save donghee/baec82962fa5d48182e7280e5383d5b7 to your computer and use it in GitHub Desktop.
// @file main.cpp
// @author Donghee Park
//
// Copyright (c) 2023 Donghee Park, all rights reserved
#include <iostream>
class Marine {
int hp;
int coord_x, coord_y;
int damage;
bool is_dead;
public:
Marine();
Marine(int x, int y);
int attack();
void be_attacked(int damage_earn);
void move(int x, int y);
void show_status();
};
Marine::Marine() {
hp = 50;
coord_x = coord_y = 0;
damage = 5;
is_dead = false;
}
Marine::Marine(int x, int y) {
coord_x = x;
coord_y = y;
hp = 50;
damage = 5;
is_dead = false;
}
void Marine::move(int x, int y) {
coord_x = x;
coord_y = y;
}
int Marine::attack() { return damage; }
void Marine::be_attacked(int damage_earn) {
hp -= damage_earn;
if (hp <= 0) is_dead = true;
}
void Marine::show_status() {
std::cout << " Marine " << std::endl;
std::cout << " Location : (" << coord_x << ", " << coord_y << ")" << std::endl;
std::cout << " HP : " << hp << std::endl;
}
int main() {
Marine marine1(2, 3);
Marine marine2(3, 5);
marine1.show_status();
marine2.show_status();
std::cout << "마린 1이 마린 2 공격" << std::endl;
marine2.be_attacked(marine1.attack());
marine1.show_status();
marine2.show_status();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment