类型或名称空间'Timers'名称在名称空间'System'中不存在

时间:2013-03-27 04:55:54

标签: c# visual-studio-2010 timer namespaces system

我确信这个问题的答案远不如我的大脑看起来那么难,但我似乎无法想象这一点。

我正在尝试为我正在开始的游戏设置一个计时器,主要是跟着一个教程来完成基础知识。我甚至用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)
    {

    }

}

}

1 个答案:

答案 0 :(得分:3)

MSDN告诉我们System.Timers.Timer来自System.dll。

  

命名空间:System.Timers

     

程序集:系统(在System.dll中)

听起来你错过了对System.dll的引用。确保您引用它:

enter image description here