26
PL in C++ 2014.8.6 박박박 BattleShip Game #5

[Pl in c++] 10. battleship game 5

Embed Size (px)

Citation preview

Page 1: [Pl in c++] 10. battleship game 5

PL in C++

2014.8.6박민근

BattleShip Game #5

Page 2: [Pl in c++] 10. battleship game 5

수업전 질문

http://agebreak.clbnow.com

Page 3: [Pl in c++] 10. battleship game 5

Class 전방 선언

Page 4: [Pl in c++] 10. battleship game 5

헤더 파일엔 include 가 없다 ?!!

Page 5: [Pl in c++] 10. battleship game 5

헤더파일의 Include 제거

Player.h Player.cpp

헤더 파일의 Include 는 적을 수록 좋다 !!• 컴파일 속도가 빨라진다 . (Include 는 파일의 내용을 삽입 (!) 하는 것 )

• 각 파일간의 의존도 ( 커플링 ) 을 제거 한다 .

Page 6: [Pl in c++] 10. battleship game 5

짝 만들기

Page 7: [Pl in c++] 10. battleship game 5

Player 클래스

Page 8: [Pl in c++] 10. battleship game 5

class Player

배 객체들을 가지고 있다• Aircraft, Battleship, Cruiser, Destroyer(x2)

내 배들을 배치한다 .

상대방의 공격에 피격 체크 결과를 알려준다 .

맵 객체들을 가지고 있다 .

상대방을 공격 한다 .

Page 9: [Pl in c++] 10. battleship game 5

class Player

배 객체들을 가지고 있다• Aircraft, Battleship, Cruiser, Destroyer(x2)

내 배들을 배치한다 .

상대방의 공격에 피격 체크 결과를 알려준다 .

맵 객체들을 가지고 있다 .

상대방을 공격 한다 .

Page 10: [Pl in c++] 10. battleship game 5

#pragma once

///  게임을 진행하는 플레이어 클래스class Player{public:    Player();    ~Player();}; 

#pragma once#include "Aircraft.h"#include "Battleship.h"#include "Cruiser.h"#include "Destroyer.h"

///  게임을 진행하는 플레이어 클래스class Player{public:    Player();    ~Player();    

protected:    //  배 객체들 Aircraft    m_Aircraft;    Battleship  m_Battleship;    Cruiser     m_Cruiser;    Destroyer   m_Destroyer[2];};

Page 11: [Pl in c++] 10. battleship game 5

class Player

배 객체들을 가지고 있다• Aircraft, Battleship, Cruiser, Destroyer(x2)

내 배들을 배치한다 .

상대방의 공격에 피격 체크 결과를 알려준다 .

맵 객체들을 가지고 있다 .

상대방을 공격 한다 .

Page 12: [Pl in c++] 10. battleship game 5

class Player

내 배들의 위치를 출력하자 .

int _tmain(int argc, _TCHAR* argv[]){     Player player;    player.SetupShips();    player.PrintShips();

    getchar();

    return 0;}

Page 13: [Pl in c++] 10. battleship game 5

class Player

배 객체들을 가지고 있다• Aircraft, Battleship, Cruiser, Destroyer(x2)

내 배들을 배치한다 .

상대방의 공격에 피격 체크 결과를 알려준다 .

맵 객체들을 가지고 있다 .

상대방을 공격 한다 .

Page 14: [Pl in c++] 10. battleship game 5

GameMan-ager

Page 15: [Pl in c++] 10. battleship game 5

class GameManager

두명의 Player 객체를 생성한다 .

한쪽이 공격을 한다 .

다른 쪽이 피격 결과를 알려준다 .

한쪽의 배가 모두 격추 될 때까지 반복한다 .

Page 16: [Pl in c++] 10. battleship game 5

class GameManager{public:    GameManager();    ~GameManager();

    void Init();    void Start();

protected:    //  우선 1 단계 .     //  어택커와 디펜더를 구별하고 ,  한쪽은 공격만 ,  한쪽은 히트체크만 한다 .    Player m_Attacker;    Player m_Defender;};

Page 17: [Pl in c++] 10. battleship game 5

격추된 배의 구별

Page 18: [Pl in c++] 10. battleship game 5

결과값의 추가

Page 19: [Pl in c++] 10. battleship game 5

그런데 ??

Page 20: [Pl in c++] 10. battleship game 5

그런데 ??

CShip::HitCheck()

CShip 이 자식 클래스의 종류를

알아야만 한다 .

부모가 태어날 자식들을 다 미리 알고

만들어져야 한다는게 말이 될까 ??

Page 21: [Pl in c++] 10. battleship game 5
Page 22: [Pl in c++] 10. battleship game 5
Page 23: [Pl in c++] 10. battleship game 5
Page 24: [Pl in c++] 10. battleship game 5

오버라이딩 - 정의• 부모 클래스의 메소드를 호출한 후에 내용을 추가한다 .

• 자식 클래스의 내용을 먼저 처리하고 , 부모 메소드를 호출

• 완전히 다른 내용으로 바꾸기

Page 25: [Pl in c++] 10. battleship game 5

class GameManager

Attacker 와 Defender

Attacker 는 랜덤으로 공격 한다

Defender 는 히트 체크를 한다

진행 상황을 출력한다 .

한쪽의 배가 모두 격추 될 때까지 반복한다 .

몇턴이 걸렸는지 출력한다 .

Page 26: [Pl in c++] 10. battleship game 5

수업후 질문

http://agebreak.clbnow.com