Dem0n
Active member
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
Hope someone can help me =) I tried search on google but didnt get that :S
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();
}
}
}