示例#1
0
        // New game
        private void button1_Click(object sender, EventArgs e)
        {
            GameForm newForm = new GameForm();

            newForm.Show();

            MainForm.CurrentGameForm = newForm;
        }
示例#2
0
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     using (GameForm form = new GameForm())
     {
         form.Exec();
         form.Close();
     }
 }
示例#3
0
        /// <summary>
        /// Label which opens up a new form with a game.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GameLabel_Click(object sender, EventArgs e)
        {
            var path1 = @"../../../player1.xml";
            var path2 = @"../../../player2.xml";

            if (File.Exists(path1) && File.Exists(path2))
            {
                if (MessageBox.Show("Would you like to continue the previous game?", "Save", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    try
                    {
                        var xml = new XmlParser();
                        player1 = xml.Deserialize(path1);
                        player2 = xml.Deserialize(path2);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Your xml file was crashed!...");
                        return;
                    }
                    var gameForm = new GameForm(player1, player2);
                    gameForm.ShowDialog();
                }
                else
                {
                    if (player1 != null && player2 != null)
                    {
                        var gameForm = new GameForm(player1, player2);
                        gameForm.ShowDialog();
                        player1 = null;
                        player2 = null;
                    }
                    else
                    {
                        MessageBox.Show("You haven't chosen your heroes yet!");
                    }
                }
            }
            else
            {
                if (player1 != null && player2 != null)
                {
                    var gameForm = new GameForm(player1, player2);
                    gameForm.ShowDialog();
                    player1 = null;
                    player2 = null;
                }
                else
                {
                    MessageBox.Show("You haven't chosen your heroes yet!");
                }
            }
        }
示例#4
0
        public void EnemyAttacksPlayer()
        {
            var map = new string[] { "BBBBBBBBBB",
                                     "B########B",
                                     "BPE##GGGGB",
                                     "BGGGGGGGGB" };
            var level  = Level.FromLines(map, 1);
            var enemy  = (Enemy)level.Entities.Where(x => x is Enemy).FirstOrDefault();
            var player = (Player)level.Entities.Where(x => x is Player).FirstOrDefault();
            var form   = new GameForm(level);

            Application.Run(form);
            Assert.AreEqual(player.HP, 0);
        }
示例#5
0
        public void IsAnimationWorks()
        {
            var map = new string[] { "BBBB",
                                     "B##B",
                                     "BP#B",
                                     "BGGB" };
            var level = Level.FromLines(map, 1);
            var form  = new GameForm(level);

            Application.Run(form);
            var player = form.player;

            player.Run(1, form.physics);
            Assert.IsTrue(player.currentSprite != player.originalSprite);
        }
示例#6
0
        public void EnemyFollowsPlayer()
        {
            var map = new string[] { "BBBBBBBBBB",
                                     "B#######EB",
                                     "BP###GGGGB",
                                     "BGGGGGGGGB" };
            var level  = Level.FromLines(map, 1);
            var enemy  = (Enemy)level.Entities.Where(x => x is Enemy).FirstOrDefault();
            var player = (Player)level.Entities.Where(x => x is Player).FirstOrDefault();
            var form   = new GameForm(level);

            Application.Run(form);
            var distance = player.Location - enemy.Location;

            Assert.IsTrue(distance.Length < 20);
        }
示例#7
0
        public void DoRun()
        {
            var map = new string[] { "BBBB",
                                     "B##B",
                                     "BP#B",
                                     "BGGB" };
            var level   = Level.FromLines(map, 1);
            var physics = new Physics(level);
            var player  = level.Entities.Where(x => x is Player).FirstOrDefault();
            var form    = new GameForm(level);
            var start   = player.Location;

            Application.Run(form);
            player.IsRight = true;
            form.Close();
            Assert.AreEqual(player.Location, start + new Vector(20, 0));
        }
示例#8
0
        public void DoGravity()
        {
            var map = new string[] { "BBBBB",
                                     "B#P#B",
                                     "B###B",
                                     "BGGGB" };
            var level   = Level.FromLines(map, 1);
            var physics = new Physics(level);
            var player  = level.Entities.Where(x => x is Player).FirstOrDefault();

            Assert.IsFalse(physics.CollideObstacle(player, Block.Ground).Contains("down"));
            var form = new GameForm(level);

            Application.Run(form);
            form.Close();
            Assert.IsTrue(physics.CollideObstacle(player, Block.Ground).Contains("down"));
        }
示例#9
0
        public void button1_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {
                GameForm game = new GameForm();
                this.Hide();
                game.ShowDialog();
                this.Close();

                /*
                 * if (lowEnd != null && highEnd != null)
                 * {
                 *  if (lowNumber < highNumber)
                 *  {
                 *
                 *  }
                 *
                 * }*/
            }
            catch (Exception ex)
            {
                txtrun.Text = (ex.Message);
            }
        }