2013-03-27 87 views
2

我相信这个答案远没有我的大脑看起来那么困难,但我似乎无法弄清楚这一点。类型或命名空间'定时器'名称不存在于名称空间'系统'

我正在尝试为我开始的游戏设置一个计时器,下面主要介绍一些基本知识。我甚至用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) 
    { 

    } 

} 

}

+0

@JonathonReinhart - 是啊,我只注意到。 – Tim 2013-03-27 05:02:18

+0

这是什么类型的项目? (WinForms,WPF,控制台等)以及您定位的.NET版本是什么?也许你错过了对'System.dll'的引用在解决方案资源管理器中检查你的项目引用文件夹以引用系统' – 2013-03-27 05:02:42

+0

在我的情况下,相同的代码正在编译。 – Popeye 2013-03-27 05:05:22

回答

3

MSDN告诉我们,System.Timers.Timer是从System.dll中。

命名空间:System.Timers

集:System(在System.dll中)

这听起来像你缺少System.dll参考。请确保您引用它:

enter image description here

+0

不会包含在每个新项目中?我想你可以在意外删除它... – BlackICE 2013-03-27 05:06:50

+0

@大卫是的,应该。但那是我能想到的唯一会导致这个错误的事情。 – 2013-03-27 05:07:52

+0

谢谢你们!我现在正在研究它......我的解决方案资源管理器中没有单独的参考,所以我的猜测是这是什么错误......我甚至没有注意到。但希望这有效。 – evan10593 2013-03-27 05:14:22

相关问题