Пример #1
0
        private void btnSaveUser_Click(object sender, RoutedEventArgs e)
        {
            bool validName = true;

            if (txtName.Text != null && txtName.Text != "")
            {
                using (db = new G2776_2Entities1())
                {
                    var pelaajat = from p in db.Player
                                   select p;
                    foreach (var p in pelaajat)
                    {
                        if (p.PlayerName == txtName.Text)
                        {
                            validName = false;
                            MessageBox.Show("Selected Player name already in use! Please select another");
                        }
                    }

                    if (validName)
                    {
                        db.Player.Add(new Player(txtName.Text));
                        db.SaveChanges();
                        MessageBox.Show("New Player created successfully");
                        refreshComboboxes();
                    }
                }
            }
        }
Пример #2
0
 private void cmbGame_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     lblOpponent.Content = "Opponent: ";
     lblMap.Content      = "Map: ";
     if (cmbGame.SelectedIndex < 0)
     {
         return;
     }
     try
     {
         using (db = new G2776_2Entities1())
         {
             int gID   = (int)cmbGame.Items[cmbGame.SelectedIndex];
             int ghpID = ghpIDs[cmbGame.SelectedIndex];
             //string asd = cmbPlayer.Items[cmbGame.SelectedIndex].ToString();
             //int.TryParse(asd, out gID);
             var info = from a in db.Player
                        join ghp in db.Game_has_Player
                        on a.PlayerID equals ghp.PlayerID
                        where ghp.GameID == gID
                        //where ghp.Game_has_PlayerID != ghpID
                        select a;
             foreach (var q in info)
             {
                 lblOpponent.Content = "Opponent: " + q.PlayerName;
             }
         }
         //    MySqlCommand cmd = new MySqlCommand("SELECT Game_has_Player.PlayerID FROM Game_has_Player WHERE Game_has_Player.Game_has_PlayerID = '" + cmbGame.Items[cmbGame.SelectedIndex] + "';", con);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Пример #3
0
        private void btnNewGame_Click(object sender, RoutedEventArgs e)
        {
            Game            g = new Game(mapIDs[cmbMap.SelectedIndex]);
            Game_has_Player ghp1;
            Game_has_Player ghp2;

            using (db = new G2776_2Entities1())
            {
                db.Game.Add(g);
                db.SaveChanges();

                var game = from gam in db.Game
                           orderby gam.GameID descending
                           select gam;
                foreach (var a in game) // purkkaa, foreachin sijaan pitäis vaan ensimmäistä alkiota käyttää...
                {
                    ghp1 = new Game_has_Player(a.GameID, pID[cmbPlayer.SelectedIndex]);
                    ghp2 = new Game_has_Player(a.GameID, pID[cmbOpponent.SelectedIndex]);
                    db.Game_has_Player.Add(ghp1);
                    db.Game_has_Player.Add(ghp2);
                    break;
                }
                db.SaveChanges();
            }
            // start game with given map and players
        }
Пример #4
0
        private void cmbPlayer_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            cmbGame.Items.Clear();
            ghpIDs.Clear();

            lblOpponent.Content = "Opponent: ";
            lblMap.Content      = "Map: ";
            try
            {
                using (db = new G2776_2Entities1())
                {
                    int pnro = pID[cmbPlayer.SelectedIndex];
                    var game = from g in db.Game
                               join ghp in db.Game_has_Player
                               on g.GameID equals ghp.GameID
                               where ghp.PlayerID.Equals(pnro)
                               select new
                    {
                        g,
                        ghp
                    };

                    foreach (var a in game)
                    {
                        if (cmbGame.Items.Contains(a.g.GameID))
                        {
                            continue;
                        }
                        cmbGame.Items.Add(a.g.GameID);
                        ghpIDs.Add(a.ghp.Game_has_PlayerID);
                    }
                }
                //MySqlCommand cmd = new MySqlCommand("SELECT Game_has_PlayerID FROM Game_has_Player WHERE Game_has_Player.PlayerID ='" + cmbPlayer.Items[cmbPlayer.SelectedIndex] + "';", con);

                /*
                 *
                 * var game = from g in db.Game_has_Player
                 *             where g.PlayerID == pID[cmbPlayer.SelectedIndex]
                 *             select g;
                 *
                 *
                 *
                 * int pid;
                 * MySqlCommand cmd1 = new MySqlCommand("SELECT GameID FROM Game_has_Player WHERE PlayerID = '" + cmbPlayer.Items[cmbPlayer.SelectedIndex] + "';",con);
                 * MySqlDataReader reader;
                 * reader = cmd1.ExecuteReader();
                 * while (reader.Read())
                 * {
                 *  int.TryParse(reader.GetString(0), out pid);
                 *  MySqlCommand cmd2 = new MySqlCommand("SELECT PlayerName FROM Player WHERE PlayerID ='" + pid + "';", con);
                 *
                 * }
                 */
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Пример #5
0
        public StartWindow()
        {
            InitializeComponent();
            pID    = new List <int>();
            ghpIDs = new List <int>();
            mapIDs = new List <int>();
            db     = new G2776_2Entities1();
            refreshComboboxes();

            /*
             * try
             * {
             *
             *
             *  con = new MySqlConnection(str);
             *  con.Open();
             *  MySqlCommand cmd = new MySqlCommand("SELECT PlayerID FROM Player", con);
             *
             *  MySqlDataReader reader;
             *  reader = cmd.ExecuteReader();
             *  pelaajaIDt = new List<int>();
             *  int apu = -1;
             *  while (reader.Read())
             *  {
             *      int.TryParse(reader.GetString(0), out apu);
             *      pelaajaIDt.Add(apu);
             *      cmbPlayer.Items.Add(apu);
             *      apu = -1;
             *  }
             *
             * }
             * catch (Exception ex)
             * {
             *  MessageBox.Show(ex.ToString());
             *  MessageBox.Show(ex.InnerException.ToString());
             *
             * }
             * finally
             * {
             *  con.Close();
             * }
             * */
        }
Пример #6
0
        public StartWindow()
        {
            InitializeComponent();
            pID = new List<int>();
            ghpIDs = new List<int>();
            mapIDs = new List<int>();
            db = new G2776_2Entities1();
            refreshComboboxes();
            /*
            try
            {

                
                con = new MySqlConnection(str);
                con.Open();
                MySqlCommand cmd = new MySqlCommand("SELECT PlayerID FROM Player", con);

                MySqlDataReader reader;
                reader = cmd.ExecuteReader();
                pelaajaIDt = new List<int>();
                int apu = -1;
                while (reader.Read())
                {
                    int.TryParse(reader.GetString(0), out apu);
                    pelaajaIDt.Add(apu);
                    cmbPlayer.Items.Add(apu);
                    apu = -1;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                MessageBox.Show(ex.InnerException.ToString());

            }
            finally
            {
                con.Close();
            }
             * */
        }
Пример #7
0
        public MapEditor()
        {
            InitializeComponent();
            fillTemplate();
            map   = new List <Tile>();
            mapID = -1;

            using (G2776_2Entities1 db = new G2776_2Entities1())
            {
            }

            for (int i = 0; i < 15; i++)
            {
                for (int j = 0; j < 15; j++)
                {
                    map.Add(new Tile(i, j, -3, new Terrain(1, "Plains", "LightYellow"), null, null, null));
                }
            }
            drawMap();
        }
Пример #8
0
        public MapEditor()
        {
            InitializeComponent();
            fillTemplate();
            map = new List<Tile>();
            mapID = -1;

            using (G2776_2Entities1 db = new G2776_2Entities1())
            {
                
            }

            for (int i = 0; i < 15; i++)
            {
                for (int j = 0; j < 15; j++)
                {
                    map.Add(new Tile(i, j, -3, new Terrain(1, "Plains", "LightYellow"), null, null, null));
                }

            }
            drawMap();

        }
Пример #9
0
        public MapEditor(int mappi)
        {
            InitializeComponent();
            fillTemplate();
            map   = new List <Tile>();
            mapID = mappi;
            using (G2776_2Entities1 db = new G2776_2Entities1())
            {
                var m = from b in db.Map.Include("Tile")
                        where b.MapID == mappi
                        select b;
                foreach (Map c in m)
                {
                    oldMapName      = c.MapName;
                    txtMapname.Text = c.MapName;
                }
            }
            try
            {
                using (G2776_2Entities1 db = new G2776_2Entities1())
                {
                    var tiles = from a in db.Tile
                                where a.MapID == mappi
                                select a;

                    foreach (Tile t in tiles)
                    {
                        if (t.PlayerID != null)
                        {
                            using (G2776_2Entities1 player = new G2776_2Entities1())
                            {
                                var pla = (from pl in player.Player
                                           where pl.PlayerID == t.PlayerID
                                           select pl).First();
                                t.Player = pla;
                            }
                        }
                        if (t.TerrainID != null)
                        {
                            using (G2776_2Entities1 terrain = new G2776_2Entities1())
                            {
                                var ter = (from te in terrain.Terrain
                                           where te.TerrainID == t.TerrainID
                                           select te).First();
                                t.Terrain = ter;
                            }
                        }
                        if (t.ConstructionID != null)
                        {
                            using (G2776_2Entities1 construction = new G2776_2Entities1())
                            {
                                var con = (from co in construction.Construction
                                           where co.ConstructionID == t.ConstructionID
                                           select co).First();
                                t.Construction = con;
                            }
                        }
                        if (t.CityID != null)
                        {
                            using (G2776_2Entities1 city = new G2776_2Entities1())
                            {
                                var cit = (from ci in city.City
                                           where ci.CityID == t.CityID
                                           select ci).First();
                                t.City = cit;
                            }
                        }
                        if (t.ArmyID != null)
                        {
                            using (G2776_2Entities1 army = new G2776_2Entities1())
                            {
                                var arm = (from ar in army.Army.Include("Unit")
                                           where ar.ArmyID == t.ArmyID
                                           select ar).First();
                                t.Army = arm;
                                foreach (Unit u in arm.Unit)
                                {
                                    arm.AddUnit(u);
                                }
                            }

                            /*
                             * using (G2776_2Entities1 units = new G2776_2Entities1())
                             * {
                             *  var uni = from un in units.Unit
                             *            where un.ArmyID == t.ArmyID
                             *            select un;
                             *  foreach (Unit unit in uni)
                             *  {
                             *      t.Army.Unit.Add(new Unit(unit.UnitName,unit.UnitHealth,(int)unit.UnitOffense,(int)unit.UnitDefense,unit.UnitRanged,(int)unit.UnitRangedDefense,(int)unit.UnitPosition));
                             *      //t.Army.Unit.Add(unit);
                             *  }
                             * }*/
                        }

                        /*
                         * Tile temp = new Tile(t.TileX,t.TileY);
                         * if (t.PlayerID != null)
                         * {
                         *  temp.PlayerID = t.PlayerID;
                         * }
                         *
                         * if (t.Terrain != null)
                         * {
                         *  temp.Terrain = t.Terrain;
                         *  temp.TerrainID = t.TerrainID;
                         * }
                         * if (t.Construction != null)
                         * {
                         *  temp.Construction = t.Construction;
                         *  temp.ConstructionID = t.ConstructionID;
                         * }
                         * if (t.City != null)
                         * {
                         *  temp.City = t.City;
                         *  temp.CityID = t.CityID;
                         * }
                         * if (t.Army != null)
                         * {
                         *  temp.Army = t.Army;
                         *  temp.ArmyID = t.ArmyID;
                         * }
                         * map.Add(temp);
                         * */
                        map.Add(t);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                MessageBox.Show(ex.InnerException.ToString());
            }
            drawMap();
        }
Пример #10
0
        private void btnSaveAndExit_Click(object sender, RoutedEventArgs e)
        {
            //int mapID = -1;
            try
            {
                using (G2776_2Entities1 db = new G2776_2Entities1())
                {
                    if (mapID < 0 || txtMapname.Text != oldMapName)
                    {
                        if (txtMapname.Text != null && txtMapname.Text != "")
                        {
                            db.Map.Add(new Map(txtMapname.Text));
                        }
                        else
                        {
                            MessageBox.Show("Give a name for the map");
                            return;
                        }
                        db.SaveChanges();

                        var mappi = from m in db.Map
                                    orderby m.MapID descending
                                    select m;
                        foreach (var a in mappi)
                        {
                            mapID = a.MapID;
                            break;
                        }
                    }


                    foreach (Tile t in map)
                    {
                        t.MapID = mapID;

                        /*
                         * if (t.Army != null)
                         * {
                         *  db.Army.Add(t.Army);
                         *  foreach (Unit u in t.Army.Unit)
                         *  {
                         *      db.Unit.Add(u);
                         *  }
                         * }
                         * if (t.City != null)
                         * {
                         *  db.City.Add(t.City);
                         * }
                         * if (t.Construction != null)
                         * {
                         *  db.Construction.Add(t.Construction);
                         * }
                         * if (t.Terrain != null)
                         * {
                         *  db.Terrain.Add(t.Terrain);
                         * }*/
                        var player = (from p in db.Player
                                      where p.PlayerID == t.PlayerID
                                      select p).First();
                        t.Player = player;

                        var terrain = (from ter in db.Terrain
                                       where ter.TerrainType == t.Terrain.TerrainType
                                       select ter).First();
                        t.Terrain = terrain;
                        db.Tile.Add(t);
                        db.SaveChanges();
                    }
                    db.SaveChanges();
                }
                MessageBox.Show("Map saved successfully.");
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                MessageBox.Show(ex.InnerException.ToString());
            }
        }
Пример #11
0
        public MapEditor(int mappi)
        {
            InitializeComponent();
            fillTemplate();
            map = new List<Tile>();
            mapID = mappi;
            using (G2776_2Entities1 db = new G2776_2Entities1())
            {
                var m = from b in db.Map.Include("Tile")
                        where b.MapID == mappi
                        select b;
                foreach (Map c in m)
                {
                    oldMapName = c.MapName;
                    txtMapname.Text = c.MapName;
                }

            }
            try
            {
                using (G2776_2Entities1 db = new G2776_2Entities1())
                {

                    var tiles = from a in db.Tile
                                where a.MapID == mappi
                                select a;

                    foreach (Tile t in tiles)
                    {
                        if (t.PlayerID != null)
                        {
                            using (G2776_2Entities1 player = new G2776_2Entities1())
                            {
                                var pla = (from pl in player.Player
                                           where pl.PlayerID == t.PlayerID
                                           select pl).First();
                                t.Player = pla;
                            }
                        }
                        if (t.TerrainID != null)
                        {
                            using (G2776_2Entities1 terrain = new G2776_2Entities1())
                            {
                                var ter = (from te in terrain.Terrain
                                           where te.TerrainID == t.TerrainID
                                           select te).First();
                                t.Terrain = ter;
                            }
                        }
                        if (t.ConstructionID != null)
                        {
                            using (G2776_2Entities1 construction = new G2776_2Entities1())
                            {
                                var con = (from co in construction.Construction
                                           where co.ConstructionID == t.ConstructionID
                                           select co).First();
                                t.Construction = con;
                            }
                        }
                        if (t.CityID != null)
                        {
                            using (G2776_2Entities1 city = new G2776_2Entities1())
                            {
                                var cit = (from ci in city.City
                                           where ci.CityID == t.CityID
                                           select ci).First();
                                t.City = cit;
                            }
                        }
                        if (t.ArmyID != null)
                        {
                            using (G2776_2Entities1 army = new G2776_2Entities1())
                            {
                                var arm = (from ar in army.Army.Include("Unit")
                                           where ar.ArmyID == t.ArmyID
                                           select ar).First();
                                t.Army = arm;
                                foreach (Unit u in arm.Unit)
                                {
                                    arm.AddUnit(u);
                                }
                            }
                            
                            /*
                            using (G2776_2Entities1 units = new G2776_2Entities1())
                            {
                                var uni = from un in units.Unit
                                          where un.ArmyID == t.ArmyID
                                          select un;
                                foreach (Unit unit in uni)
                                {
                                    t.Army.Unit.Add(new Unit(unit.UnitName,unit.UnitHealth,(int)unit.UnitOffense,(int)unit.UnitDefense,unit.UnitRanged,(int)unit.UnitRangedDefense,(int)unit.UnitPosition));
                                    //t.Army.Unit.Add(unit);
                                }
                            }*/
                        }
                        /*
                        Tile temp = new Tile(t.TileX,t.TileY);
                        if (t.PlayerID != null)
                        {
                            temp.PlayerID = t.PlayerID;
                        }
                    
                        if (t.Terrain != null)
                        {
                            temp.Terrain = t.Terrain;
                            temp.TerrainID = t.TerrainID;
                        }
                        if (t.Construction != null)
                        {
                            temp.Construction = t.Construction;
                            temp.ConstructionID = t.ConstructionID;
                        }
                        if (t.City != null)
                        {
                            temp.City = t.City;
                            temp.CityID = t.CityID;
                        }
                        if (t.Army != null)
                        {
                            temp.Army = t.Army;
                            temp.ArmyID = t.ArmyID;
                        }
                        map.Add(temp);
                         * */
                        map.Add(t);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                MessageBox.Show(ex.InnerException.ToString());
            }
            drawMap();
        }
Пример #12
0
        private void btnSaveAndExit_Click(object sender, RoutedEventArgs e)
        {
            //int mapID = -1;
            try
            {
                using (G2776_2Entities1 db = new G2776_2Entities1())
                {
                    if (mapID < 0 || txtMapname.Text != oldMapName)
                    {
                        if (txtMapname.Text != null && txtMapname.Text != "")
                        {
                            db.Map.Add(new Map(txtMapname.Text));
                        }
                        else
                        {
                            MessageBox.Show("Give a name for the map");
                            return;
                        }
                        db.SaveChanges();

                        var mappi = from m in db.Map
                                    orderby m.MapID descending
                                    select m;
                        foreach (var a in mappi)
                        {
                            mapID = a.MapID;
                            break;
                        }
                    }
                    

                    foreach (Tile t in map)
                    {
                        t.MapID = mapID;
                        /*
                        if (t.Army != null)
                        {
                            db.Army.Add(t.Army);
                            foreach (Unit u in t.Army.Unit)
                            {
                                db.Unit.Add(u);
                            }
                        }
                        if (t.City != null)
                        {
                            db.City.Add(t.City);
                        }
                        if (t.Construction != null)
                        {
                            db.Construction.Add(t.Construction);
                        }
                        if (t.Terrain != null)
                        {
                            db.Terrain.Add(t.Terrain);
                        }*/
                        var player = (from p in db.Player
                                     where p.PlayerID == t.PlayerID
                                     select p).First();
                        t.Player = player;

                        var terrain = (from ter in db.Terrain
                                       where ter.TerrainType == t.Terrain.TerrainType
                                       select ter).First();
                        t.Terrain = terrain;
                        db.Tile.Add(t);
                        db.SaveChanges();
                    }
                    db.SaveChanges();
                }
                MessageBox.Show("Map saved successfully.");
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                MessageBox.Show(ex.InnerException.ToString());
            }
            
        }
Пример #13
0
        private void cmbPlayer_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            cmbGame.Items.Clear();
            ghpIDs.Clear();
            
            lblOpponent.Content = "Opponent: ";
            lblMap.Content = "Map: ";
            try
            {

                using (db = new G2776_2Entities1())
                {
                    int pnro = pID[cmbPlayer.SelectedIndex];
                    var game = from g in db.Game
                               join ghp in db.Game_has_Player
                               on g.GameID equals ghp.GameID
                               where ghp.PlayerID.Equals(pnro)
                               select new 
                               {
                                   g,
                                   ghp
                               };

                    foreach (var a in game)
                    {
                        if (cmbGame.Items.Contains(a.g.GameID)) continue;
                        cmbGame.Items.Add(a.g.GameID);
                        ghpIDs.Add(a.ghp.Game_has_PlayerID);
                    }
                }
                //MySqlCommand cmd = new MySqlCommand("SELECT Game_has_PlayerID FROM Game_has_Player WHERE Game_has_Player.PlayerID ='" + cmbPlayer.Items[cmbPlayer.SelectedIndex] + "';", con);

                /*
                 * 
                 * var game = from g in db.Game_has_Player
                               where g.PlayerID == pID[cmbPlayer.SelectedIndex]
                               select g;
                 * 
                 * 
                 * 
                int pid;
                MySqlCommand cmd1 = new MySqlCommand("SELECT GameID FROM Game_has_Player WHERE PlayerID = '" + cmbPlayer.Items[cmbPlayer.SelectedIndex] + "';",con);
                MySqlDataReader reader;
                reader = cmd1.ExecuteReader();
                while (reader.Read())
                {
                    int.TryParse(reader.GetString(0), out pid);
                    MySqlCommand cmd2 = new MySqlCommand("SELECT PlayerName FROM Player WHERE PlayerID ='" + pid + "';", con);

                }
                */

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            
        }
Пример #14
0
        private void btnSaveUser_Click(object sender, RoutedEventArgs e)
        {
            bool validName = true;
            if (txtName.Text != null && txtName.Text != "")
            {
                using (db = new G2776_2Entities1())
                {
                    var pelaajat = from p in db.Player
                                   select p;
                    foreach (var p in pelaajat)
                    {
                        if (p.PlayerName == txtName.Text)
                        {
                            validName = false;
                            MessageBox.Show("Selected Player name already in use! Please select another");
                        }
                    }

                    if (validName)
                    {
                        db.Player.Add(new Player(txtName.Text));
                        db.SaveChanges();
                        MessageBox.Show("New Player created successfully");
                        refreshComboboxes();
                    }
                }
            }
        }
Пример #15
0
 private void btnNewGame_Click(object sender, RoutedEventArgs e)
 {
     Game g = new Game(mapIDs[cmbMap.SelectedIndex]);
     Game_has_Player ghp1;
     Game_has_Player ghp2;
     using (db = new G2776_2Entities1())
     {
         db.Game.Add(g);
         db.SaveChanges();
         
         var game = from gam in db.Game
                    orderby gam.GameID descending
                    select gam;
         foreach (var a in game) // purkkaa, foreachin sijaan pitäis vaan ensimmäistä alkiota käyttää...
         {
             ghp1 = new Game_has_Player(a.GameID, pID[cmbPlayer.SelectedIndex]);
             ghp2 = new Game_has_Player(a.GameID, pID[cmbOpponent.SelectedIndex]);
             db.Game_has_Player.Add(ghp1);
             db.Game_has_Player.Add(ghp2);
             break;
         }
         db.SaveChanges();
         
     }
     // start game with given map and players
 }
Пример #16
0
 private void cmbGame_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     lblOpponent.Content = "Opponent: ";
     lblMap.Content = "Map: ";
     if (cmbGame.SelectedIndex < 0) return;
     try
     {
         using (db = new G2776_2Entities1())
         {
             int gID = (int)cmbGame.Items[cmbGame.SelectedIndex];
             int ghpID = ghpIDs[cmbGame.SelectedIndex];
             //string asd = cmbPlayer.Items[cmbGame.SelectedIndex].ToString();
             //int.TryParse(asd, out gID);
             var info = from a in db.Player
                        join ghp in db.Game_has_Player
                        on a.PlayerID equals ghp.PlayerID
                        where ghp.GameID == gID
                        //where ghp.Game_has_PlayerID != ghpID
                        select a;
             foreach (var q in info)
             {
                 lblOpponent.Content = "Opponent: " + q.PlayerName;
             }
         }
     //    MySqlCommand cmd = new MySqlCommand("SELECT Game_has_Player.PlayerID FROM Game_has_Player WHERE Game_has_Player.Game_has_PlayerID = '" + cmbGame.Items[cmbGame.SelectedIndex] + "';", con); 
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }