Advertisement
sondrex76

Snake v.0.031

Oct 30th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Snake
  12. {
  13.    
  14.     public partial class Form1 : Form
  15.     {
  16.         public bool error { get; set; }
  17.         public string moving { get; set; }
  18.         public int x { get; set; }
  19.         public int xPoint { get; set; }
  20.         public int y { get; set; }
  21.         public int yPoint { get; set; }
  22.         public string lastmovement { get; set; }
  23.         public bool CBstate { get; set; }
  24.         public bool CBchange { get; set; }
  25.         public bool running { get; set; }
  26.         public int points { get; set; }
  27.         public Form1()
  28.         {
  29.             InitializeComponent();
  30.             lblDifficulty.Text = "Medium";
  31.             Bstop.Hide();
  32.             error = true;
  33.             CBstate = false;
  34.             lblhead.Hide();
  35.             lblPoint.Hide();
  36.             moving = lastmovement = "Up";
  37.             points = 0;
  38.         }
  39.  
  40.         private void Tbspeed_Scroll(object sender, EventArgs e)
  41.         {
  42.             switch (Tbspeed.Value)
  43.             {
  44.                 case 1:
  45.                     lblDifficulty.Text = "Uber Noob mode";
  46.                     timer.Interval = 1500;
  47.                     break;
  48.                 case 2:
  49.                     lblDifficulty.Text = "Noob mode";
  50.                     timer.Interval = 1000;
  51.                     break;
  52.                 case 3:
  53.                     lblDifficulty.Text = "meh mode";
  54.                     timer.Interval = 750;
  55.                     break;
  56.                 case 4:
  57.                     lblDifficulty.Text = "Avarege";
  58.                     timer.Interval = 500;
  59.                     break;
  60.                 case 5:
  61.                     lblDifficulty.Text = "Hard";
  62.                     timer.Interval = 250;
  63.                     break;
  64.                 case 6:
  65.                     lblDifficulty.Text = "Really Hard";
  66.                     timer.Interval = 125;
  67.                     break;
  68.                 case 7:
  69.                     lblDifficulty.Text = "Hardcore";
  70.                     timer.Interval = 50;
  71.                     CBwall.Checked = true;
  72.                     break;
  73.             }
  74.  
  75.             if (Tbspeed.Value > 4)
  76.             {
  77.                 CBwall.Checked = true;
  78.                 CBwall.Enabled = false;
  79.                 CBchange = true;
  80.             }
  81.             else
  82.             {
  83.                 CBwall.Enabled = true;
  84.  
  85.                 if (CBchange == false)
  86.                 {
  87.                     CBstate = CBwall.Checked;
  88.                 }
  89.                 else
  90.                 {
  91.                     CBwall.Checked = CBstate;
  92.                 }
  93.  
  94.                 CBchange = false;
  95.             }
  96.             lblDebug.Text = CBstate + ", " + points;
  97.         }
  98.  
  99.         private void Bactivate_Click(object sender, EventArgs e)
  100.         {
  101.             Random r = new Random();
  102.             error = false;
  103.             x = r.Next(3, 7);
  104.             y = r.Next(3, 7);
  105.             TLPsnake.Controls.Add(lblhead, x,y);
  106.             Bstop.Show();
  107.             Bactivate.Hide();
  108.             lblhead.Show();
  109.             timer.Start();
  110.             running = true;
  111.         }
  112.  
  113.         private void Bstop_Click(object sender, EventArgs e)
  114.         {
  115.             error = true;
  116.             Bstop.Hide();
  117.             Bactivate.Show();
  118.             lblhead.Hide();
  119.             lblPoint.Hide();
  120.             timer.Stop();
  121.         }
  122.         private void Down(object sender, KeyEventArgs e)
  123.         {
  124.             switch (e.KeyCode.ToString())
  125.             {
  126.                 case "W":
  127.                     moving = "Up";
  128.                     break;
  129.                 case "A":
  130.                     moving = "Left";
  131.                     break;
  132.                 case "D":
  133.                     moving = "Right";
  134.                     break;
  135.                 case "S":
  136.                     moving = "Down";
  137.                     break;
  138.             }
  139.             if ((moving == "Left" && lastmovement == "Right") ||
  140.                 (moving == "Right" && lastmovement == "Left") ||
  141.                 (moving == "Down" && lastmovement == "Up") ||
  142.                 (moving == "Up" && lastmovement == "Down"))
  143.             {
  144.                 moving = lastmovement;
  145.             }
  146.  
  147.            
  148.         }
  149.         private void timer1_Tick(object sender, EventArgs e)
  150.         {
  151.                 switch (moving)
  152.                 {
  153.                     case "Up":
  154.                         y = y - 1;
  155.                         break;
  156.                     case "Left":
  157.                         x = x - 1;
  158.                         break;
  159.                     case "Right":
  160.                         x = x + 1;
  161.                         break;
  162.                     case "Down":
  163.                         y = y + 1;
  164.                         break;
  165.                 }
  166.  
  167.                 lastmovement = moving;
  168.  
  169.                 if ((x > 9 || x < 0 || y > 9 || y < 0) && CBwall.Checked == true)
  170.                 {
  171.                     error = true;
  172.                 }
  173.                 else
  174.                 {
  175.                     if (CBwall.Checked == false)
  176.                     {
  177.                         if (x > 9)
  178.                         {
  179.                             x = 0;
  180.                         }
  181.                         if (y > 9)
  182.                         {
  183.                             y = 0;
  184.                         }
  185.                         if (x < 0)
  186.                         {
  187.                             x = 9;
  188.                         }
  189.                         if (y < 0)
  190.                         {
  191.                             y = 9;
  192.                         }
  193.                     }
  194.                 }
  195.                 lblDebug.Text = moving + ", " + points;
  196.  
  197.                 lblPoint.Show();
  198.  
  199.             if (error == true)
  200.             {
  201.                 Bstop.PerformClick();
  202.             }
  203.             else
  204.             {
  205.                 if (xPoint == x && yPoint == y)
  206.                 {
  207.                     running = true;
  208.                     TLPsnake.Controls.Remove(lblPoint);
  209.                     points = points + 1;
  210.                 }
  211.                  
  212.                
  213.                 TLPsnake.Controls.Add(lblhead, x, y);
  214.                 if (running == true)
  215.                 {
  216.                     Random r = new Random();
  217.                     while (xPoint == x && yPoint == y)
  218.                         {
  219.                     xPoint = r.Next(0, 9);
  220.                     yPoint = r.Next(0, 9);
  221.                         }
  222.                     TLPsnake.Controls.Add(lblPoint, xPoint, yPoint);
  223.  
  224.                     running = false;
  225.                 }
  226.                 else
  227.                 {
  228.  
  229.                 }
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.             }
  237.         }
  238.  
  239.         private void CBwall_CheckedChanged(object sender, EventArgs e)
  240.         {
  241.  
  242.         }
  243.     }
  244.  
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement