Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Snake
- {
- public partial class Form1 : Form
- {
- public bool error { get; set; }
- public string moving { get; set; }
- public int x { get; set; }
- public int xPoint { get; set; }
- public int y { get; set; }
- public int yPoint { get; set; }
- public string lastmovement { get; set; }
- public bool CBstate { get; set; }
- public bool CBchange { get; set; }
- public bool running { get; set; }
- public int points { get; set; }
- public Form1()
- {
- InitializeComponent();
- lblDifficulty.Text = "Medium";
- Bstop.Hide();
- error = true;
- CBstate = false;
- lblhead.Hide();
- lblPoint.Hide();
- moving = lastmovement = "Up";
- points = 0;
- }
- private void Tbspeed_Scroll(object sender, EventArgs e)
- {
- switch (Tbspeed.Value)
- {
- case 1:
- lblDifficulty.Text = "Uber Noob mode";
- timer.Interval = 1500;
- break;
- case 2:
- lblDifficulty.Text = "Noob mode";
- timer.Interval = 1000;
- break;
- case 3:
- lblDifficulty.Text = "meh mode";
- timer.Interval = 750;
- break;
- case 4:
- lblDifficulty.Text = "Avarege";
- timer.Interval = 500;
- break;
- case 5:
- lblDifficulty.Text = "Hard";
- timer.Interval = 250;
- break;
- case 6:
- lblDifficulty.Text = "Really Hard";
- timer.Interval = 125;
- break;
- case 7:
- lblDifficulty.Text = "Hardcore";
- timer.Interval = 50;
- CBwall.Checked = true;
- break;
- }
- if (Tbspeed.Value > 4)
- {
- CBwall.Checked = true;
- CBwall.Enabled = false;
- CBchange = true;
- }
- else
- {
- CBwall.Enabled = true;
- if (CBchange == false)
- {
- CBstate = CBwall.Checked;
- }
- else
- {
- CBwall.Checked = CBstate;
- }
- CBchange = false;
- }
- lblDebug.Text = CBstate + ", " + points;
- }
- private void Bactivate_Click(object sender, EventArgs e)
- {
- Random r = new Random();
- error = false;
- x = r.Next(3, 7);
- y = r.Next(3, 7);
- TLPsnake.Controls.Add(lblhead, x,y);
- Bstop.Show();
- Bactivate.Hide();
- lblhead.Show();
- timer.Start();
- running = true;
- }
- private void Bstop_Click(object sender, EventArgs e)
- {
- error = true;
- Bstop.Hide();
- Bactivate.Show();
- lblhead.Hide();
- lblPoint.Hide();
- timer.Stop();
- }
- private void Down(object sender, KeyEventArgs e)
- {
- switch (e.KeyCode.ToString())
- {
- case "W":
- moving = "Up";
- break;
- case "A":
- moving = "Left";
- break;
- case "D":
- moving = "Right";
- break;
- case "S":
- moving = "Down";
- break;
- }
- if ((moving == "Left" && lastmovement == "Right") ||
- (moving == "Right" && lastmovement == "Left") ||
- (moving == "Down" && lastmovement == "Up") ||
- (moving == "Up" && lastmovement == "Down"))
- {
- moving = lastmovement;
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- switch (moving)
- {
- case "Up":
- y = y - 1;
- break;
- case "Left":
- x = x - 1;
- break;
- case "Right":
- x = x + 1;
- break;
- case "Down":
- y = y + 1;
- break;
- }
- lastmovement = moving;
- if ((x > 9 || x < 0 || y > 9 || y < 0) && CBwall.Checked == true)
- {
- error = true;
- }
- else
- {
- if (CBwall.Checked == false)
- {
- if (x > 9)
- {
- x = 0;
- }
- if (y > 9)
- {
- y = 0;
- }
- if (x < 0)
- {
- x = 9;
- }
- if (y < 0)
- {
- y = 9;
- }
- }
- }
- lblDebug.Text = moving + ", " + points;
- lblPoint.Show();
- if (error == true)
- {
- Bstop.PerformClick();
- }
- else
- {
- if (xPoint == x && yPoint == y)
- {
- running = true;
- TLPsnake.Controls.Remove(lblPoint);
- points = points + 1;
- }
- TLPsnake.Controls.Add(lblhead, x, y);
- if (running == true)
- {
- Random r = new Random();
- while (xPoint == x && yPoint == y)
- {
- xPoint = r.Next(0, 9);
- yPoint = r.Next(0, 9);
- }
- TLPsnake.Controls.Add(lblPoint, xPoint, yPoint);
- running = false;
- }
- else
- {
- }
- }
- }
- private void CBwall_CheckedChanged(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement