Simple Snake game Label error

Dem0n

Active member
Joined
Apr 1, 2013
Messages
82
Reaction score
0
Location
Winland ^^
I've tried make some simple snake game on Visual C# 2010,but I got some problems :/
Here is errors

Error 3 Cannot implicitly convert type 'string' to 'System.Windows.Forms.Label'
Error 1 The name 'score' does not exist in the current context
Error 2 The name 'score' does not exist in the current context

Code:
       private void timer1_Tick(object sender, EventArgs e)
        {
            snakeScoreLabel.Text = Convert.ToString(score);

            if (down) { snake.moveDown(); }
            if (up) { snake.moveUp(); }
            if (right) { snake.moveRight(); }
            if (left) { snake.moveLeft(); }

            for (int i = 0; i < snake.SnakeRec.Length; i++)
            {
                if (snake.SnakeRec[i].IntersectsWith(food.foodRec))
                {
                    snake.growSnake();
                    food.foodLocation(randFood);
                }
            }

            collisions();
            this.Invalidate();
            
        }

        public void collisions()
        {
            for (int i = 1; i < snake.SnakeRec.Length; i++)
            {
                if (snake.SnakeRec[0].IntersectsWith(snake.SnakeRec[i]))
                {
                    timer1.Enabled = false;
                    MessageBox.Show("R.I.P Snake is dead R.I.P ");
                }
            }

            if(snake.SnakeRec[0].X < 0 || snake.SnakeRec[0].X > 290)
            {
                timer1.Enabled = false;
                MessageBox.Show("R.I.P Snake is dead R.I.P ");
            }

            if(snake.SnakeRec[0].Y < 0 || snake.SnakeRec[0].Y > 290)
            {
                restart();
            }
        }

        public void restart()
        {
            timer1.Enabled = false;
            MessageBox.Show("R.I.P Snake is dead R.I.P ");
            snakeScoreLabel.Text = "0";
            score = 0;//error
            spaceBarLabel = ("Press Space bar to begin");//1st. ERROR LINE 
            snake = new Snake();
        }
    }
}
Hope someone can help me =) I tried search on google but didnt get that :S
 

0x_

Wtf I'm not new....
Administrator
Joined
Feb 18, 2013
Messages
1,119
Reaction score
166
spaceBarLabel = Needs to be spaceBarLabel.Text |spaceBarLabel = is just the refrence to that object.

And to the other 2 error, where you define score?
 

Dem0n

Active member
Joined
Apr 1, 2013
Messages
82
Reaction score
0
Location
Winland ^^
spaceBarLabel = Needs to be spaceBarLabel.Text |spaceBarLabel = is just the refrence to that object.

And to the other 2 error, where you define score?
Im not sure but this is full source of my "Form1.cs"
http://pastebin.com/R2wUYNTZ
And did you mean spaceBarLabel like this spaceBarLabel.Text |spaceBarLabel = "Press Space to continue";
 

Wut

Well-known member
Joined
Mar 1, 2013
Messages
338
Reaction score
1
[quote author="0x688"]spaceBarLabel = Needs to be spaceBarLabel.Text |spaceBarLabel = is just the refrence to that object.

And to the other 2 error, where you define score?
Im not sure but this is full source of my "Form1.cs"
http://pastebin.com/R2wUYNTZ
And did you mean spaceBarLabel like this spaceBarLabel.Text |spaceBarLabel = "Press Space to continue";[/quote]




Wut is Score = score(0); ?
try
int score;


and

spaceBarLabel.Text = "Press Space to continue";
 

Dem0n

Active member
Joined
Apr 1, 2013
Messages
82
Reaction score
0
Location
Winland ^^
[quote author="Dem0n"][quote author="0x688"]spaceBarLabel = Needs to be spaceBarLabel.Text |spaceBarLabel = is just the refrence to that object.

And to the other 2 error, where you define score?
Im not sure but this is full source of my "Form1.cs"
http://pastebin.com/R2wUYNTZ
And did you mean spaceBarLabel like this spaceBarLabel.Text |spaceBarLabel = "Press Space to continue";[/quote]




Wut is Score = score(0); ?
try
int score;


and

spaceBarLabel.Text = "Press Space to continue";[/quote]
Oh now i didnt get any errors but my snake is retarted o_O And after 3sec my game freeze :/
Need full source of my game to get that problem :S
 

Wut

Well-known member
Joined
Mar 1, 2013
Messages
338
Reaction score
1
Oh now i didnt get any errors but my snake is retarted o_O And after 3sec my game freeze :/
Need full source of my game to get that problem :S


Use XNA for games in c#
 

Dem0n

Active member
Joined
Apr 1, 2013
Messages
82
Reaction score
0
Location
Winland ^^
Oh now i didnt get any errors but my snake is retarted o_O And after 3sec my game freeze :/
Need full source of my game to get that problem :S


Use XNA for games in c#
Oh but is way to get that problem solved without download that XNA?
 

Wut

Well-known member
Joined
Mar 1, 2013
Messages
338
Reaction score
1
[quote author="paulica"]
Oh now i didnt get any errors but my snake is retarted o_O And after 3sec my game freeze :/
Need full source of my game to get that problem :S


Use XNA for games in c#
Oh but is way to get that problem solved without download that XNA?[/quote]


I need to see the Snake and Food class

Anyways, did u enabled the timer ?
 

Dem0n

Active member
Joined
Apr 1, 2013
Messages
82
Reaction score
0
Location
Winland ^^
I need to see the Snake and Food class
Anyways, did u enabled the timer ?
Snake.cs
http://pastebin.com/AN0e3eV4
And Food.cs
http://pastebin.com/G9sTA24c
And I enable timer on there:
Code:
      public void collisions()
        {
            for (int i = 1; i < snake.SnakeRec.Length; i++)
            {
                if (snake.SnakeRec[0].IntersectsWith(snake.SnakeRec[i]))
                {
                    timer1.Enabled = false;
                    MessageBox.Show("R.I.P Snake is dead R.I.P ");
                }
            }

            if(snake.SnakeRec[0].X < 0 || snake.SnakeRec[0].X > 290)
            {
                timer1.Enabled = false;
                MessageBox.Show("R.I.P Snake is dead R.I.P ");
            }

            if(snake.SnakeRec[0].Y < 0 || snake.SnakeRec[0].Y > 290)
            {
                timer1.Enabled = true;//HEREEEE
                restart();
            }
        }

C#-is more different language :/
 
Top