【发布时间】:2013-03-17 03:21:51
【问题描述】:
我确信这个问题的答案远没有我的大脑想象的那么难,但我似乎无法弄清楚这一点。
我正在尝试为我正在开始的游戏设置一个计时器,主要是通过一个教程来了解基础知识。我什至用 EXACT 代码作为教程创建了一个新项目,但我不断收到相同的错误。尽管在教程中看到代码运行完美......
如果你能告诉我我在哪里搞砸了以及为什么,而不仅仅是更正代码,我将不胜感激。我将其作为一个学习项目进行,因此我想知道将来如何防止这种情况。提前致谢!
哦,我不知道这是否重要,但我使用的是 Microsoft Visual C# 2010 Express。
4 个错误,相同的消息。第 10、66、67 和 72 行。
using System;
using System.Collections.Generic;
namespace rout3reset
{
public class RogueLike
{
static bool isGameAlive = true;
static Player player;
static System.Timers.Timer World; //timer declare
public class Player //
{
public char CHR = '@'; // Symbol for player
public Vector position; // X, Y coordinates tracker
public string Name = "";
public short Health = 25; // Base health
public short Mana = 25; // Base Mana
public Player() //player constructor
{
position = new Vector(1, 1); // sets spawn point
}
public void Update() // get handle controls
{
}
}
public class AI //
{
}
public class Tree //
{
}
public class Vector
{
public short X;
public short Y;
public Vector(short X, short Y) // Main constructor
{
this.X = X;
this.Y = Y;
}
public Vector() // Overload of 1
{
this.X = 0;
this.Y = 0;
}
}
static void Main(string[] args)
{
Initialize();
do
{
player.Update();
}
while (isGameAlive);
}
static void Initialize()
{
World = new System.Timers.Timer(50); //Sets timer elapse point (50 milliseconds)
World.Elapsed += new System.Timers.ElapsedEventHandler(Draw); //Start timer
World.Start();
player = new Player();
}
static void Draw(object sender, System.Timers.ElapsedEventArgs e) // Handles world timer tick
{
Console.Clear();
Console.WriteLine("########################################"); //40 Spaces wide by 20 spaces tall
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("#--------------------------------------#");
Console.WriteLine("########################################");
Console.WriteLine("-{0} HP: {1} MP: {2}", player.Name, player.Health, player.Mana); //STAT BAR
Console.SetCursorPosition(player.position.X, player.position.Y); //sets proper char position for player symbol
Console.Write(player.CHR); //draws the players char
}
static void Updateworld() //update non-player, non-antagonist objects (trees, etc)
{
}
}
}
【问题讨论】:
-
@JonathonReinhart - 是的,我刚刚注意到了。
-
这是什么类型的项目? (WinForms、WPF、控制台等)您的目标是什么版本的 .NET?也许您缺少对
System.dll的引用 检查解决方案资源管理器中的项目引用文件夹以获取对System的引用 -
在我的情况下,相同的代码构建良好。
-
express 安装 .net 框架似乎有什么问题?从 1.1 版开始,这已包含在 System.dll 中:msdn.microsoft.com/en-us/library/system.timers.timer.aspx
标签: c# visual-studio-2010 timer namespaces system