//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# Game Programming: For Serious Game Creation”的书。
我从本书的 CD-ROM 中得到了完全相同的代码。该示例代码很好,而我的有错误。
这是我第一次使用 C# 编写游戏编码。但是,据我了解,我的应该可以工作。但是,看起来编译器不这么认为。
我怎样才能解决这个问题?