我正在制作角色扮演游戏,只是为了好玩,并了解有关SOLID原则的更多信息.我关注的第一件事就是SRP.我有一个"角色"类,代表游戏中的角色.它有Name,Health,Mana,AbilityScores等等.
现在,通常我也会在我的Character类中放置方法,所以它看起来像这样......
public class Character
{
public string Name { get; set; }
public int Health { get; set; }
public int Mana { get; set; }
public Dictionary<AbilityScoreEnum, int>AbilityScores { get; set; }
// base attack bonus depends on character level, attribute bonuses, etc
public static void GetBaseAttackBonus();
public static int RollDamage();
public static TakeDamage(int amount);
}
Run Code Online (Sandbox Code Playgroud)
但是由于SRP,我决定将所有方法都移到一个单独的类中.我将该类命名为"CharacterActions",现在方法签名看起来像这样......
public class CharacterActions
{
public static void GetBaseAttackBonus(Character character);
public static int RollDamage(Character character);
public static TakeDamage(Character character, int amount);
} …
Run Code Online (Sandbox Code Playgroud) 给定一个数组,其所有元素都是正数,找到一个子序列的最大总和,其约束条件是序列中没有2个数字应该在数组中相邻.所以3 2 7 10应该返回13(3和10的总和)或3 2 5 10 7应该返回15(3,5和7的总和).
我尝试使用所有可能允许的总和,然后找到最大值(蛮力方法)但是有更好的方法.例如[3 2 7 10]我总和3,7和2,10并取最大值.
更多例子:
假设我使用smtpclient将我的电子邮件提交到我的本地smtp服务器.我如何知道电子邮件是否被正式发送?
我在Visual Studio中有一个ASP.NET项目,并添加了一个经典的asp论坛应用程序.当我在我的localhost机器(带有IIS的XP专业版)上运行它时,我得到"这种类型的页面没有被提供,因为它已被明确禁止".
该项目的ASP.NET和经典ASP都在同一个项目中运行.
如何配置我的机器和/或Visual Studio项目来运行asp应用程序?
这个应用程序在我们的Web服务器上运行良好,但我需要修改它并在localhost上调试.
谢谢,
詹姆士
我只是Objective-C的初学者,它的语法只是让我失去理智.
我正在'尝试'在iphone 3.0上工作.
直到知道我已经了解到:
那么我们如何调用我们选择的函数/方法呢?
在C,C++,JAVA,C#的旧语言格式中,我们有一个main()函数来完成我们的控制工作,但它在Obj-c中的main()是什么?
我知道有一个main()函数,但我几乎不知道它是如何工作的.
以下代码允许用户单击闪存卡的问题并显示答案.
问题是它显示所有闪存卡的所有答案.
如何传递每个闪卡的ID,以便用户可以单击标题并切换问题打开和关闭?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript"
src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.4.0");
google.setOnLoadCallback(function() {
$("div > div.answer").hide();
$("div > div.question").click(function() {
$("div > div.answer").fadeIn("slow");
});
});
</script>
<style>
div.flashcard {
margin: 0 10px 10px 0;
}
div.flashcard div.question {
background-color:#ddd;
width: 400px;
padding: 5px;
}
div.flashcard div.answer {
background-color:#eee;
width: 400px;
padding: 5px;
}
</style>
</head>
<body>
<div id="1" class="flashcard">
<div class="question">Who was Wagner?</div>
<div class="answer">German composer, conductor, theatre director and …
Run Code Online (Sandbox Code Playgroud) 我在XML文件上保存二维坐标,其结构类似于:
<?xml version="1.0" encoding="utf-8" ?>
<grid>
<coordinate time="78">
<initial>540:672</initial>
<final>540:672</final>
</coordinate>
</grid>
Run Code Online (Sandbox Code Playgroud)
我可以打开XML文件并通过XmlTextReader读取它,但是我如何专门遍历坐标以检索初始节点和最终节点之间的时间属性和数据,格式类似于:
string initial = "540:672";
string final = "540:672";
int time = 78;
Run Code Online (Sandbox Code Playgroud)
我的新代码:
//Read the XML file.
XDocument xmlDoc = XDocument.Load("C:\\test.xml");
foreach (var coordinate in xmlDoc.Descendants("coordinate"))
{
this.coordinates[this.counter][0] = coordinate.Attribute("time").Value;
this.coordinates[this.counter][1] = coordinate.Element("initial").Value;
this.coordinates[this.counter][2] = coordinate.Element("final").Value;
this.counter++;
};
Run Code Online (Sandbox Code Playgroud)
但现在我收到此错误:
"对象引用未设置为对象的实例."
XML
<?xml version="1.0" encoding="utf-8"?>
<grid>
<coordinate time="62">
<initial>540:672</initial>
<final>540:672</final>
</coordinate>
...
<coordinate time="46">
<initial>176:605</initial>
<final>181:617</final>
</coordinate>
</grid>
Run Code Online (Sandbox Code Playgroud)
跳过一些坐标标签以适应,但它们都有时间属性和初始/最终子标签.
全局
uint counter = 0;
// Coordinates to …
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种在运行时反转任意NSColor值的方法,并且似乎没有任何内置方法可以这样做.
我将使用类别扩展NSColor
如下:
NSColor * invertedColor = [someOtherColor inverted];
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的类别方法原型:
@implementation NSColor (MyCategories)
- (NSColor *)inverted
{
NSColor * original = [self colorUsingColorSpaceName:
NSCalibratedRGBColorSpace];
return ...?
}
@end
Run Code Online (Sandbox Code Playgroud)
任何人都可以填补空白吗?这不一定是完美的,但我希望它有所帮助.即:
[[[NSColor someColor] inverted] inverted]
会导致颜色非常接近原始颜色
[[NSColor whiteColor] inverted]
会非常接近 [NSColor blackColor]
反转的颜色将位于色轮的相对侧.(红色和绿色,黄色和紫罗兰色等)
alpha值应保持与原始值相同NSColor
.我只是想要反转颜色,而不是透明度.
更新3 :(现在颜色!)
事实证明,使用补色(颜色与原始色调相差180°的颜色)还不够,因为白色和黑色实际上没有色调值.从phoebus提供的答案开始,这就是我想出的:
CGFloat hue = [original hueComponent];
if (hue >= 0.5) { hue -= 0.5; } else { hue += 0.5; }
return …
Run Code Online (Sandbox Code Playgroud) __init__()
创建对象时调用该函数.__init__()
在创建对象函数之后再次调用它是否可以?
instance = cls(p1=1, p2=2)
# some code
instance.__init__(p1=123, p2=234)
# some more code
instance.__init__(p1=23, p2=24)
Run Code Online (Sandbox Code Playgroud)
为什么有人想要调用__init__()
已经创建的对象?
好问题.我想重新初始化实例的字段.
c# ×3
algorithm ×1
asp-classic ×1
asp.net ×1
c ×1
cocoa ×1
coordinates ×1
foreach ×1
function ×1
grid ×1
iis ×1
invert ×1
javascript ×1
jquery ×1
nscolor ×1
objective-c ×1
python ×1
r ×1
smtpclient ×1
xml ×1