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)
    {

    }

}

}

4

1 回答 1

3

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

命名空间:System.Timers

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

听起来您缺少对System.dll. 确保你引用它:

在此处输入图像描述

于 2013-03-27T05:05:58.463 回答