I learned a bit of C# a few years ago but never used it again and forgot most of what I'd learned. I'm trying it out again and am a bit confused about how it works. I am writing a very simple card game using Sharpdevelop and would like a bit of help. Could you pleas let me know where I'm going wrong in the following:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace CardGame
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
cardCount cc = new cardCount();
CardStatus Card1 = new CardStatus();
Card1.setFace(true);
Card1.setType(1);
CardStatus Card2 = new CardStatus();
Card2.setFace(true);
Card2.setType(1);
CardStatus Card3 = new CardStatus();
Card3.setFace(true);
Card3.setType(2);
CardStatus Card4 = new CardStatus();
Card4.setFace(true);
Card4.setType(2);
CardStatus Card5 = new CardStatus();
Card5.setFace(true);
Card5.setType(3);
CardStatus Card6 = new CardStatus();
Card6.setFace(true);
Card6.setType(3);
int ct = Card1.getType();
}
void Card1Click(object sender, EventArgs e)
{
int ans = cc.getcardCount();
Bitmap kingPic = (Bitmap)Image.FromFile("C:\\Documents and Settings\\ahoe\\My Documents\\SharpDevelop Projects\\CardGame\\king.jpg");
if (ans < 2)
{
cc.inccardCount(1);
if (ct = 1)
{
Card1Button.BackgroundImage = kingPic;
}
}
}
}
}
Basically I want to set up 6 card objects when the program starts and use them when I click on one of the cards, but within the code for the button click it can't reference the cards I set up when the program starts. There is something fundamental about C# or perhaps OO programming in general which I don't seem to be getting - any help would be much appreciated!
Errors:
The name 'cc' does not exist in the current context (CS0103) - C:\Documents and Settings\xxxx\My Documents\SharpDevelop Projects\CardGame\MainForm.cs:62,14
The name 'cc' does not exist in the current context (CS0103) - C:\Documents and Settings\xxxx\My Documents\SharpDevelop Projects\CardGame\MainForm.cs:68,5
The name 'ct' does not exist in the current context (CS0103) - C:\Documents and Settings\xxxx\My Documents\SharpDevelop Projects\CardGame\MainForm.cs:70,9


Sign In
Create Account

Back to top









