以下のコードをコンパイルして画面上に
fire と表示したいのですが、
毎回異なる文字列が画面に表示されてしまいます。
原因はクラスの値が勝手に書き換わってしまっているからでしょうか?
原因と対処法を知りたいです。よろしくお願いします。
#include "DxLib.h"
#include <string>
#include <iostream>
using namespace std;
class unitdata{
public:
// string name;
string type1;
// string type2;
int HP;
int strengh;
int magic;
};
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
unitdata lavalord;
//lavalord.name = "lava lord";
lavalord.type1 = "fire";
//lavalord.type2 = "none";
//lavalord.HP = 120;
//lavalord.strength = 12;
lavalord.magic = 18;
// ウインドウモードに変更
ChangeWindowMode( TRUE ) ;
if( DxLib_Init() == -1 ) // DXライブラリ初期化処理
{
return -1; // エラーが起きたら直ちに終了
}
int Color;
// 白色の値を取得
Color = GetColor( 255 , 255 , 255 ) ;
int number ;
// 文字列の描画
//DrawFormatString( 250 , 240 - 16 , Color , lavalord.name );
DrawFormatString( 250 , 240 - 40 ,Color , "%s", lavalord.type1 );
//DrawFormatString( 250 , 240 - 60 , Color , lavalord.type2 );
//DrawFormatString( 250 , 240 - 80 , Color , lavalord.HP );
//DrawFormatString( 250 , 240 - 100 , Color , lavalord.strength );
//DrawFormatString( 250 , 240 - 120, Color ,lavalord.type1 );
WaitKey() ; // キーの入力待ち(『WaitKey』を使用)
DxLib_End() ; // DXライブラリ使用の終了処理
return 0 ; // ソフトの終了
}