Beispiel #1
0
        public void start()
        {
            map.clearBoard();
            pictureBox1.Image = map.kép;

            Dictionary <Keys, Vector> keyboardMapping1 = new Dictionary <Keys, Vector>();
            Dictionary <Keys, Vector> keyboardMapping2 = new Dictionary <Keys, Vector>();

            //Player 1
            keyboardMapping1.Add(Keys.W, new Vector("up"));
            keyboardMapping1.Add(Keys.S, new Vector("down"));
            keyboardMapping1.Add(Keys.A, new Vector("left"));
            keyboardMapping1.Add(Keys.D, new Vector("right"));
            //Player 2
            keyboardMapping2.Add(Keys.I, new Vector("up"));
            keyboardMapping2.Add(Keys.K, new Vector("down"));
            keyboardMapping2.Add(Keys.J, new Vector("left"));
            keyboardMapping2.Add(Keys.L, new Vector("right"));

            snake.Clear();
            snake.Add(new Snake(map, new Vector(2, 5), new Vector(0, 0), player1, keyboardMapping1));
            snake.Add(new Snake(map, new Vector(map.mapSize - 2, 5), new Vector(0, 0), player2, keyboardMapping2));

            applelist.Clear();
            for (int i = 0; i < appleCount; i++)
            {
                generateRandomApple();
            }

            drawElements();

            for (int l = 0; l < applelist.Count; l++)
            {
                repositionApple(applelist[l]);
            }

            timer1.Start();
            pictureBox1.Visible = true;
            started             = !started;
            textBox1.Enabled    = false;
            textBox2.Enabled    = false;
            button1.Text        = "Stop";
        }
Beispiel #2
0
        public void start()
        {
            map.clearBoard();
            pictureBox1.Image = map.kép;

            snake.Clear();

            string[] directions = new string[]
            {
                "Up", "Down", "Left", "Right"
            };

            for (int i = 0; i < Convert.ToInt32(Config.Instance.Get("PlayerCount")); i++) //TODO: Snakes on top of each other fix
            {
                Dictionary <Keys, Vector> keyboardMapping = new Dictionary <Keys, Vector>();
                for (int j = 0; j < directions.Length; j++)
                {
                    if (Config.Instance.IDExists(directions[j] + (i + 1)) && Config.Instance.Get(directions[j] + (i + 1)) != "")
                    {
                        keyboardMapping.Add((Keys)Enum.Parse(typeof(Keys), Config.Instance.Get(directions[j] + (i + 1))), new Vector(directions[j]));
                    }
                    else
                    {
                        MessageBox.Show("Keybind " + (directions[j] + (i + 1)) + " was not set!", directions[j] + (i + 1));
                        return;
                    }
                }

                Color snakeColor;
                if (Config.Instance.IDExists("Color" + (i + 1)))
                {
                    snakeColor = Color.FromArgb(Convert.ToInt32(Config.Instance.Get("Color" + (i + 1))));
                }
                else
                {
                    MessageBox.Show("Color" + (i + 1) + " was not set!");
                    return;
                }

                snake.Add(new Snake(map, new Vector(rnd1.Next(map.mapSize), rnd1.Next(map.mapSize)), snakeColor, keyboardMapping));
            }

            appleCount = Convert.ToInt32(Config.Instance.Get("AppleCount"));

            appleList.Clear();
            for (int i = 0; i < appleCount; i++)
            {
                generateRandomApple();
            }

            drawElements();

            for (int l = 0; l < appleList.Count; l++)
            {
                repositionApple(appleList[l]);
            }

            timer1.Start();
            pictureBox1.Visible                    = true;
            started                                = !started;
            textBox1.Enabled                       = false;
            textBox2.Enabled                       = false;
            szinToolStripMenuItem.Enabled          = false;
            appleSettingsToolStripMenuItem.Enabled = false;
            controlsToolStripMenuItem.Enabled      = false;
            button1.Text                           = "Stop";
        }