質問

So I'm rather a newbie when it comes to programming especially in c# i have an error i need help with?

So I'm trying to create a rpg system i started out before all else with the battle system which i just barely began my code which is store in Form1.cs is such

    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public class Variables{

       public Graphics character;
        private void Form1_Load(object sender, EventArgs e){
        }


        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Up:
                    Player.Top = Player.Top - 5;
                    Battle.Steps = Battle.Steps + 10;
                    break;
                case Keys.Down:
                    Player.Top = Player.Top + 5;
                    Battle.Steps = Battle.Steps + 10;
                    break;
                case Keys.Left:
                    Player.Left = Player.Left - 5;
                    Battle.Steps = Battle.Steps + 10;
                    break;
                case Keys.Right:
                    Player.Left = Player.Left + 5;
                    Battle.Steps = Battle.Steps + 10;
                    break;
            }
            if (Battle.Steps == 100)
            {
                Battle.Fight = true;
            }
        }
    }
}

and Battle.cs is

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication1
{

   public class Battle
    {
      public static bool Fight {get; set;}
       public static int Steps; 
       public void Fight (){


    if (Fight == true)
    {

    }
       }
    }
}

However I'm getting an error Error Ambiguity between 'WindowsFormsApplication1.Battle.Fight' and 'WindowsFormsApplication1.Battle.Fight()' when i try to access the variable in form 1 and also when i try to edit in in Battle.cs What's going on how do i fix this or is there a better way to do this?

役に立ちましたか?

解決

The Best I can figure without actually seeing your battle class is that you have a variable named Fight and a method Fight such as.

public class form
{
    {
        Battle battle = new Battle();
        battle.Fight = true;
        battle.Fight();

    }
}

public class Battle
{
    public bool Fight = false;
    public bool Fight()
    {
        return true;
    }
}

This would cause ambiguity as if you call fight it would have a hard time figuring out whether you are calling the variable or the method. To Fix this maybe give your variable or your function a different name. Such as if the variable Fight is just a bool to see if they are in a Fight or should get into a fight maybe name the variable InFight or ShouldFight.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top