忍者ブログ
  • 2024.08
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 2024.10
[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

【2024/09/19 11:47 】 |
Server.h
Server.h
サーバのクラスです。実際にオンラインで稼動させる場合は
オブジェクトを生成するのではなく、実際のサーバをいじくる
関数を記述する必要があります。手元で遊ぶ分にはサーバに扮した
オブジェクトを生成すれば十分です。

class Server{
 private:
  int acNum;
  int naNum;
  const static int MAX_AC_NUM = 50;
  const static int MAX_NA_NUM = 16;
  Account* ac[MAX_AC_NUM];
  Nation* na[MAX_NA_NUM];
  const int searchEmptyAcIndex();
  const int searchEmptyNaIndex();
  template <class T> const static bool typeIsAc(T arg){
    return (typeid(arg)) == (typeid(Account));
  }
  template <class T> const static bool typeIsNa(T arg){
    return (typeid(arg)) == (typeid(Nation));
  }
  const static bool isHit(const int myHIT, const int enemySP);

 public:
 Server():acNum(0), naNum(0), ac(), na(){}
  ~Server(){
    for(int i=0;i<acNum;i++){
      delete ac[i];
      ac[i] = NULL;
    }
    for(int i=0;i<naNum;i++){
      delete na[i];
      na[i] = NULL;
    }
  }
  int makeAc(){
    const int index = searchEmptyAcIndex();
    makeAc(index);
    return index;
  }
  void makeAc(const int index);
  void delAc(const int index);
  Account& getAc(int index){
    Account& ac = *Server::ac[index];
    return ac;
  }
  int makeNa(const char * const name){
    const int index = searchEmptyNaIndex();
    makeNa(index, name);
    return index;
  }
  void makeNa(const int index, const char * const name);
  void delNa(const int index);
  Nation* getNation(const int i){
    if((0<=i)&&(i<naNum)){
      return na[i];
    }else{
      std::cout << "not alloc na[" << i << ']' <<std::endl;
      return NULL;
    }
  }
  const int getNationNum(){return naNum;}
  const int getAccountNum(){return acNum;}
  const int getMaxNationNum(){return MAX_NA_NUM;}
  const static int getWeaponCost(const Weapon w);
  const static int getProtectCost(const Protect p);
  const static int getWeaponAT(const Weapon w);
  const static int getProtectGU(const Protect p);
  const static int getProtectSP(const Protect p);
  const static int getWeaponHIT(const Weapon w);
  const static int getWeaponAttackNum(const Weapon w);
  const static int getWeaponEN(const Weapon w);
  const static int calcDamage(const int myAT, const int rivalGU, const int rivalSP, const int myHIT, const int myAttackNum);
};


PR
【2013/03/08 03:19 】 | EBの箱 | 有り難いご意見(0)
<<Game.h | ホーム | Nation.h>>
有り難いご意見
貴重なご意見の投稿














<<前ページ | ホーム | 次ページ>>