0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

C++用のスコアマネージャー

Last updated at Posted at 2025-04-28

C++で作ったスコアマネージャーです。ヘッダファイルで使用してください。テンプレートで製作しました。

// ScoreManager.h
#pragma once
#include

// テンプレートクラス: T はスコアの型(int や float など)に対応
template
class ScoreManager {
private:
T Score; // スコアを保持する変数

public:
// コンストラクタ: スコアを 0 に初期化
ScoreManager() : Score(0) {}

// スコアを加算(デフォルトで1加算)
void AddScore(T value = 1) {
    Score += value;
}

// スコアを減算(最低0まで)
void SubtractScore(T value = 1) {
    if (Score >= value)
        Score -= value;
    else
        Score = 0;  // マイナスにはならないように制御
}

// 現在のスコアを取得
T GetScore() const {
    return Score;
}

// スコアをリセット
void ResetScore() {
    Score = 0;
}

// スコアを出力(デバッグ用)
void PrintScore() const {
    std::cout << "Score: " << Score << std::endl;
}

};

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?