using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace tanchishe1
{
public partial class Form3 : Form
{
Snake snake;
food food;
public Form3()
{
InitializeComponent();
snake = new Snake();
food = new food();
movetimer.Enabled = false;// //movetimer?????????????
movetimer.Interval = snake.Speed;
}
private void kaishi_Click(object sender, EventArgs e)
{
movetimer.Enabled = true;
}
private void zxks_Click(object sender, EventArgs e)
{
panel1.Invalidate();
snake.resetSnake();
this.textBox1.Text = "0";
this.textBox2.Text = "0";
}
private void zanting_Click(object sender, EventArgs e)
{
movetimer.Enabled = false;
}
private void tuichu_Load(object sender, EventArgs e)
{
this.Close();
}
private void panel1_Paint(object sender, PaintEventArgs e)//作用是????
{
Graphics g = e.Graphics;
movetimer.Interval = snake.Speed;
snake.Draw(g);
if(snake.Live==false)
{
movetimer.Enabled = false;
}
if(snake.Body[0].X==food.Position.X&&snake.Body[0].Y==food.Position.Y)
{
snake.Eat(food);
food.Exist = false;
this.textBox1.Text = snake.Score.ToString();
this.textBox2.Text = (snake.Number - 2).ToString();
}
if(!food.Exist)
{
food.Position = food.creatDan();
food.Exist = true;
food.Draw(g);
}
else
{
food.Draw(g);
}
g.Dispose();
}
private void xianshifenshu_Click(object sender, EventArgs e)
{
int zuidachengji;
try
{
FileStream aFile = new FileStream(@"../../temp.txt.", FileMode.Open);//??????如何引用
StreamReader sr = new StreamReader(aFile);
zuidachengji = Int32.Parse(sr.ReadLine());
textBox3.Text = zuidachengji.ToString();
sr.Close();
}
catch(IOException ex)
{
Console.WriteLine(ex.Message);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if(comboBox1.SelectedItem.ToString()=="1级")
{
snake.Speed = 200;
}
if (comboBox1.SelectedItem.ToString() == "2级")
{
snake.Speed = 130;
}
if (comboBox1.SelectedItem.ToString() == "3级")
{
snake.Speed = 100;
}
if (comboBox1.SelectedItem.ToString() == "4级")
{
snake.Speed = 50;
}
if (comboBox1.SelectedItem.ToString() == "5级")
{
snake.Speed = 30;
}
}
private void movetimer_Tick(object sender, EventArgs e)
{
snake.Move(panel1.Size);
panel1.Invalidate();
panel1.Update();
}
}
}