2015-04-06 112 views
-1

所以我有一个扫雷游戏旧代码,我试图将它添加到C#移动版本。这听起来很愚蠢,但我从未使用过,但由于某种原因,它不会让我实例化我的Game类。任何帮助?建筑类

主要是Game mineSweeper = new Game;加下划线。

enter image description here

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; 
    } 
} 
} 
+0

你的游戏课在哪里? – 2015-04-06 00:39:23

+0

'游戏扫雷=新游戏();' – Alex 2015-04-06 00:40:11

+0

你刚刚在评论中输入的内容......这是_not_什么在你的代码(缺少括号)。错字? – 2015-04-06 00:42:06

回答

0

您的游戏类是在解决方案的项目,你应该一个单独的类库项目添加到解决方案,您的游戏和细胞类添加到它。 然后右键点击App3 References并选择添加引用,检查您新创建的项目,然后单击确定。 确保课程标记为公开。 你似乎忘记了你的实例中的括号,是否是一个错字?无论如何,这样实例化你的班级:

Game mineSweeper = new Game(); 
+0

是的。我只是将类添加到App3部分,它似乎很喜欢它。或者是否有适当的方式放置? – 2015-04-06 00:54:39

+0

不,您的应用中没有太多层,只需将它们留在App3项目中即可。 – 2015-04-06 01:00:16

0

检查你是否在启动项目中添加了包含类型游戏的程序集引用。另外你怎么定义游戏。你有没有公开访问它的公共访问关键字?