실습과제 모음

CPP 게임 실습

TanSanC 2012. 9. 22. 14:50

CPP 게임 실습

#include <iostream>

using namespace std;

class Game

{  

public:

    virtual void start(){};

};

class BaseBall : public Game

{

public:

    void start(){

        cout << "BaseBall Start!!" << endl;

    };

};

class UpDown : public Game

{

public:

    void start(){

        cout << "UpDown Start!!" << endl;

    };

};

void main()

{

    Game* game[2];

    BaseBall baseball;

    UpDown updown;

    game[0] = &baseball;

    game[1] = &updown;

    int mode;

    cout << "====================" << endl;

    cout << "=1. BaseBall =======" << endl;

    cout << "====================" << endl;

    cout << "=2. UpDown==========" << endl;

    cout << "====================" << endl;

    cout << "input:" ;

    cin >> mode;

    system("cls");

    if( mode == 1 )

    {

        cout << "====================" << endl;

        cout << "=1. BaseBall =======" << endl;

        cout << "====================" << endl;

        game[0]->start();

    }

    else if( mode == 2 )

    {

        cout << "====================" << endl;

        cout << "=2. UpDown==========" << endl;

        cout << "====================" << endl;

        game[1]->start();

    }

}