我想以最惯用的方式实现以下内容
玩家在地图上.
如果他用箭头处于同一位置,他将获得1点伤害
如果他与一个生物处于相同的位置,他的伤害等于生物的hp
如果他用硬币处于同一位置,他就得到1美元
如果他与药物处于相同的位置,他会治愈1
这是为交互编写的存根:
open System
[<AbstractClass>]
type ActorBase(x,y,symbol)=
member this.X:int=x
member this.Y:int=y
member this.Symbol:char=symbol
type Medication(x,y)=
inherit ActorBase(x,y,'?')
type Coin(x,y)=
inherit ActorBase(x,y,'$')
type Arrow(x,y,symbol,targetX,targetY) =
inherit ActorBase(x,y,symbol)
member this.TargetX=targetX
member this.TargetY=targetY
[<AbstractClass>]
type CreatureBase(x,y,symbol,hp) =
inherit ActorBase(x,y,symbol)
member this.HP:int=hp
type Player(x,y,hp, score) =
inherit CreatureBase(x,y,'@',hp)
member this.Score = score
type Zombie(x,y,hp,targetX,targetY) =
inherit CreatureBase(x,y,'z',hp)
member this.TargetX=targetX
member this.TargetY=targetY
let playerInteraction (player:Player) (otherActor:#ActorBase):unit =
printfn "Interacting with %c" otherActor.Symbol
match (otherActor :> ActorBase) with
| :? CreatureBase …Run Code Online (Sandbox Code Playgroud) 我试图根据这个例子在电晕中创建我自己的类 它看起来像:
local car={};
local car_mt = { __index=car };
function car.new()
local ncar=
{
img=display:newImage("test_car.png");
}
return setmetatable(ncar,car_mt);
end
return car;
Run Code Online (Sandbox Code Playgroud)
它被称为等级:
local pcar=require("car")
...
function scene:enterScene( event )
local group = self.view
physics.start();
local car1=pcar.new();
end
Run Code Online (Sandbox Code Playgroud)
图像存在于同一文件夹中,但我得到:
坏参数#-2到newImage(代理预期,得到零)
我在网上看到了一些类似的问题,在我看来,newImage()它不知道在哪里放置图片.但是,如果将它用于任何阶段的课程怎么说呢?
在Arduino IDE中,我可以创建具有自定义类型的变量,但不能从函数返回自定义类型:
这样编译
struct Timer
{
Timer()
{
}
};
Timer t;
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
int main()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这会产生Timer does not name a type错误:
struct Timer
{
Timer()
{
}
};
Timer get_timer()
{
return Timer();
}
void setup() {
// put your setup code here, to run once:
}
void loop() …Run Code Online (Sandbox Code Playgroud) 我想了解这个答案的代码
type Mult = Mult with
static member inline ($) (Mult, v1: 'a list) = fun (v2: 'b list) ->
v1 |> List.collect (fun x -> v2 |> List.map (fun y -> (x, y))) : list<'a * 'b>
static member inline ($) (Mult, v1:'a ) = fun (v2:'a) -> v1 * v2 :'a
let inline (*) v1 v2 = (Mult $ v1) v2
Run Code Online (Sandbox Code Playgroud)
F#可以解决重载成员.(因为它不支持成员的currying).所以,我认为,它也适用于方法
但它没有:
type Mult = Mult with
static member inline Do (Mult, v1: 'a list) …Run Code Online (Sandbox Code Playgroud) 如果我的类有一个注释的公共属性(通过构造函数赋值),我可以从具有相同名称的构造函数参数的描述中引用它的描述吗?
public class MyClass
{
/// <summary>
/// x description
/// </summary>
public int x { get; private set; }
/// <summary>
/// y description
/// </summary>
public int y { get; private set; }
/// <summary>
/// Constructor description
/// </summary>
/// <param name="x">How do I reference x description from here?</param>
/// <param name="y">And y description?</param>
public MyClass(int x, int y)
{
this.x = x;
this.y = y;
}
}
Run Code Online (Sandbox Code Playgroud) Reactive Extensions有一个Observable.Start()功能.
Visual Studio告诉我它
通过可观察的序列异步调用结果.
它有返回类型 IObservable<Unit>
MDSN所说的Unit就是它
代表无效.
但为什么我需要代表void?
我读了这个答案并尝试用NAudio.Midi播放一个音符:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NAudio.Midi;
using System.Threading;
namespace SoundVision10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//Thread.Sleep inside GUI is just for example
using (MidiOut midiOut = new MidiOut(0))
{
midiOut.Volume = 65535;
midiOut.Send(MidiMessage.StartNote(60, 127, 0).RawData);
MessageBox.Show("Sent");
Thread.Sleep(1000);
midiOut.Send(MidiMessage.StopNote(60, 0, 0).RawData);
Thread.Sleep(1000);
} …Run Code Online (Sandbox Code Playgroud) 在这里,我发现了一个看起来像这样的变量定义:
struct sockaddr *ai_addr;
Run Code Online (Sandbox Code Playgroud)
它似乎是定义一个指向类型变量的指针struct sockaddr,但是
1)struct是一个关键字
2)struct sockaddr test;产生错误
aggregate 'sockaddr test' has incomplete type and cannot be defined
Run Code Online (Sandbox Code Playgroud)
(我在gcc 4.7.1下工作)