player.cpp

来自「编译并且测试成功的虚拟机」· C++ 代码 · 共 48 行

CPP
48
字号
#include "stdafx.h"

#include "Player.h"
#include "Logger.h"

const int INTVAL_HP = 0;
const int INTVAL_SCORE = 1;
const int INTVAL_LOGMSG = 2;

// Declare the external variable:
Player* Player::theInstance = NULL;

Player::Player() {
  hp = 0;
  score = 0;
}


Player* Player::instance() {
	if (theInstance == NULL)
	  theInstance = new Player();
	  
	return theInstance;
}


void Player::setInt(const string& name, int nr, int value) {
  switch (nr) {
    case INTVAL_HP:
     hp = value;
     printf("hp: %i\n", hp);
     Log("hp: %i", hp);
     break;
    case INTVAL_SCORE:
     score = value;
     printf("score: %i\n", score);
     Log("score: %i", score);
     break;
    case INTVAL_LOGMSG:
     printf("%s\n", name.c_str());
     Log("%s", name.c_str());
     break;
    default:
     Log("ERROR - unknown player intval: %i", nr);
     break;
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?