C# 建筑类

C# 建筑类,c#,android,C#,Android,所以我有一个扫雷游戏的旧代码,我正试图用C#将它添加到一个移动版本中。这听起来可能很愚蠢,但我以前从未使用过,但出于某种原因,它不允许我实例化我的游戏类。有什么帮助吗 主要游戏扫雷舰=新游戏带下划线 using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS; namespace

所以我有一个扫雷游戏的旧代码,我正试图用C#将它添加到一个移动版本中。这听起来可能很愚蠢,但我以前从未使用过,但出于某种原因,它不允许我实例化我的游戏类。有什么帮助吗

主要
游戏扫雷舰=新游戏带下划线

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace App3
{
[Activity(Label = "App3", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {

        base.OnCreate(bundle);

      SetContentView(Resource.Layout.Main);

      GridLayout gl = (GridLayout)FindViewById(Resource.Id.MineField);

        // Set our view from the "main" layout resource


        Button[] cells = new Button[100];

        Game mineSweeper = new Game;

        var i = 0;
        foreach (Button b in cells)
        {
            cells[i] = new Button(this);
            cells[i].Click += new EventHandler(button_Click);
            gl.AddView(cells[i]);
            i++;
        }


    }
    private void addButtions()
    {

    }

    protected void button_Click(object sender, EventArgs e)
    {
        Button button = sender as Button;
        // identify which button was clicked and perform necessary actions

        button.Text = ("!");
        button.Enabled = false;
    }
}
}


您的游戏类位于解决方案项中,您应该向解决方案中添加一个单独的类库项目,并向其中添加您的游戏和单元格类。 然后右键单击App3 References并选择Add reference,检查新创建的项目并单击Ok。 确保这些类被标记为public。 您似乎忘记了实例化中的括号,这是打字错误吗?无论如何,请按如下方式实例化您的类:

Game mineSweeper = new Game();

检查是否已在启动项目中添加包含游戏类型的程序集的引用。你是如何定义游戏的。您是否通过public access关键字向公众提供了对它的访问权限?

您的游戏类在哪里?
Game mineswipper=new Game()是的。我刚刚将类添加到App3部分,它似乎很喜欢。或者有没有一种合适的方式将它们放在哪里?不,你的应用程序中没有太多的层,只需将它们放在App3项目中即可。