//Page 40: Unit Test for Player class
//Player must have a health that is greater than 0
//When the character is created.
namespace UnitTestingSample
{
class PlayerTests
{
public bool TestPlayerIsAliveWhenBorn()
{
Player p = new Player(); //ERROR: 'UnitTestingSample.Player.Player()' is inaccessible due to its protection level
if (p.Health > 0)
{
return true; //pass test
}
return false; //fail test
}//end function
}//end class
}//end namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Page 41
//Player class has default health which is 10
//when his character is created
namespace UnitTestingSample
{
class Player
{
public int Health { get; set; }
Player() //constructor
{
Health = 10;
}
}
}
===============
ほら、これが私を悲しませるものです。
このコードは、「C# ゲーム プログラミング: 真剣なゲーム作成のために」という書籍からのものです。
この本のCD-ROMから全く同じコードを入手しました。そのサンプル コードは問題ありませんが、私のコードにはエラーがあります。
C# を使用してゲーム コーディングを作成するのはこれが初めてです。しかし、私が理解したように、私のものはうまくいくはずです。しかし、コンパイラはそうは思わないようです。
どうすればこれを修正できますか?