Example #1
0
 protected Eidos(SerializationInfo info, StreamingContext ctxt)
 {
     _owner = (Player)info.GetValue("Owner", typeof(Player));
     _name = (string)info.GetValue("Name",typeof(string));
     _isDestroyed = (bool)info.GetValue("IsDestroyed", typeof(bool));
     _tacticalPosition = (Point)info.GetValue("Position", typeof(Point));
 }
 private void addShipToPlayer(Ship s, Player p)
 {
     int countOfClass = p.Ships.Where(f => f.ClassName == s.ClassName).Count();
     Ship shipToAdd = s.Clone();
     shipToAdd.Name = string.Format("{0} - {1}", s.ClassName, (countOfClass + 1).ToString("000"));
     shipToAdd.Owner = p;
     p.Ships.Add(shipToAdd);
 }
Example #3
0
 /// <summary>
 /// Instantiates a Ship based on the XML description, cloning Parts and Hull from 
 /// available objects and assigns ownership to supplied Player
 /// </summary>
 /// <param name="description">XElement containing full description of this Ship</param>
 /// <param name="partsList">List of ShipParts to clone components from</param>
 /// <param name="hullsList">List of ShipHulls to clone hull from</param>
 /// <param name="player">Player to assign ownership to</param>
 public Ship(XElement description, List<EidosPart> partsList, List<ShipHull> hullsList, Player player)
 {
     this.ClassName = description.Attribute("className").Value;
     this.HP.Max = int.Parse(description.Element("MaxHP").Value);
     this.MP.Max = int.Parse(description.Element("MaxMP").Value);
     foreach (XElement SPE in description.Element("shipParts").Elements())
         this.Parts.Add(((ShipPart)partsList.First(f => f.Name == SPE.Value)).Clone());
     if (description.Element("ShipHull") != null)
         if (hullsList.Where(f => f.Name == description.Element("ShipHull").Value).Count() > 0)
             this.HullType = hullsList.First(f => f.Name == description.Element("ShipHull").Value).Clone();
     this._owner = player;
 }
Example #4
0
 public AddPlayers(Game gameState)
 {
     this.GameState = gameState;
     GameState.Players = new PlayerCollection();
     Player one = new Player("Frank", "Furters", "Necrons", false, 0);
     GameState.Players.Add(one);
     Player two = new Player("Joe (AI:4)", "Shmoes", "Orks", true, 4);
     GameState.Players.Add(two);
     InitializeComponent();
     initIconSets();
     lbxPlayerList.ItemsSource = GameState.Players;
     lbxPlayerList.UpdateLayout();
 }
 private void btnAddPlayer_Click(object sender, RoutedEventArgs e)
 {
     string PlayerName = tbxPlayerName.Text;
     string EmpireName = tbxEmpireName.Text;
     string IconSet = cbxIconSet.SelectedValue.ToString();
     bool IsAI = (chbIsAI.IsChecked==true?true:false);
     int Aggressiveness = AggressivenessValue;
     Player p = new Player(string.Format("{0}{1}",PlayerName,(IsAI?string.Format(" (AI:{0})",AggressivenessValue):string.Empty)), EmpireName, IconSet, IsAI, AggressivenessValue);
     Players.Add(p);
     lbxPlayerList.UpdateLayout();
     tbxPlayerName.Text = string.Empty;
     tbxEmpireName.Text = string.Empty;
     cbxIconSet.SelectedIndex = -1;
 }
        public StrategicWindow(Game gameState, Player currentPlayer = null, StarSystem currentSystem = null, System.Drawing.Point currentSystemLoc = new System.Drawing.Point(), Ship currentShip = null)
        {
            InitializeComponent();
            #region Bindings
            lbxTargetShips.ItemsSource = SelectedShipList;
            #endregion
            initImages();
            this.GameState = gameState;
            this.currentPlayer = currentPlayer;
            this.currentSystem = currentSystem;
            this.currentShip = currentShip;

            initGalaxyMap();
            ShowSystemMap(currentSystem);
            scrollGalaxyGridToSystem(currentSystem);
            highlightSelectedSystem(currentSystem);
            selectSystemCoordinates(currentSystemLoc);
        }
 void initShips(Player p)
 {
     this.ExistingShips.Clear();
     // load source document, hulls and parts
     XDocument xdoc = XDocument.Load(string.Format("Empires\\{0}\\Ships.xml",p.IconSet));
     foreach (XElement shipElement in xdoc.Descendants("ship"))
     {
         Ship ship = new Ship(shipElement, GameState.ExistingParts, GameState.ExistingHulls, p);
         ship.Origin = new System.Drawing.Point();
         Image img = new Image();
         if (File.Exists(string.Format("Empires\\{0}\\Images\\{1}", p.IconSet, ship.HullType.ImageURL)))
         {
             BitmapImage src = new BitmapImage();
             src.BeginInit();
             src.UriSource = new Uri(string.Format("Empires\\{0}\\Images\\{1}", p.IconSet, ship.HullType.ImageURL), UriKind.Relative); ;
             src.CacheOption = BitmapCacheOption.OnLoad;
             src.EndInit();
             img.Source = src;
         }
         img.Height = 32;
         img.Width = 32;
         img.Stretch = Stretch.None;
         img.SetValue(Panel.ZIndexProperty, 10);
         ship.Image = img;
         ExistingShips.Add(ship);
     }
 }
 void initAddPlayerWindow(PlayerCollection playerList)
 {
     this.Players = playerList;
     Players.Clear();
     Player one = new Player("Frank", "Furters", "Necrons",false,0);
     Players.Add(one);
     Player two = new Player("Joe (AI:4)", "Shmoes", "Orks",true,4);
     Players.Add(two);
     InitializeComponent();
     initIconSets();
     lbxPlayerList.ItemsSource = Players;
     lbxPlayerList.UpdateLayout();
 }
        private void endTurn()
        {
            // process end-of-turn actions
            if (GameState.Players[GameState.Players.Count - 1] == currentPlayer)
                ProcessTurnResults();

            // set current to next player and first ship
            currentPlayer = GameState.Players.Next();
            currentPlayer.Ships.ResetIndex();
            currentShip = null;
            //txbCurrentPlayer.Text = currentPlayer.Name;
            //imgCurrentPlayerIcon.Source = currentPlayer.Icon.Source;

            // perform Start Of Turn for current player's ships
            foreach (Ship s in currentPlayer.Ships)
                s.StartOfTurn();

            // refresh menu options for ships
            RefreshSystemContextMenuImages();
            ClearSelectedCurrentShip();

            // "focus" on home system for current player
            ShowSystemMap(currentPlayer.HomeSystem);
            scrollGalaxyGridToSystem(currentPlayer.HomeSystem);

            //if (currentPlayer.IsAI)
            //{
            //    try
            //    {
            //        currentPlayer.ExecuteAI(GameState);
            //        initHandlers(currentPlayer);
            //        EndTurn();
            //    }
            //    catch (Exception ex)
            //    {
            //        if (LogEverything)
            //            Logger(ex);
            //    }
            //}
        }
Example #10
0
        private void EndTurn()
        {
            try
            {
                // process end-of-turn actions
                if (GameState.Players[GameState.Players.Count - 1] == currentPlayer)
                    ProcessTurnResults();

                // set current to next player and first ship
                currentPlayer = GameState.Players.Next();
                currentPlayer.Ships.ResetIndex();
                currentShip = currentPlayer.Ships.GetNextShip();
                txbCurrentPlayer.Text = currentPlayer.Name;
                imgCurrentPlayerIcon.Source = currentPlayer.Icon.Source;

                // perform Start Of Turn for current player's ships
                foreach (Ship s in currentPlayer.Ships)
                    s.StartOfTurn();

                // highlight next player's ship
                AddHighlightImage(currentShip.TacticalPosition.X, currentShip.TacticalPosition.Y);

                // clear movement target image
                RemoveMoveTargetImage();

                // refresh menu options for ships
                RefreshContextMenuImages();

                // show current ship status
                ShowShipStatus(currentShip, spCurrentShip);

                // clear target window
                spTargetShip.Children.Clear();

                if (currentPlayer.IsAI)
                {
                    try
                    {
                        currentPlayer.ExecuteAI(GameState);
                        initHandlers(currentPlayer);
                        EndTurn();
                    }
                    catch (Exception ex)
                    {
                        if (LogEverything)
                            Logger(ex);
                    }
                }

            }
            catch (Exception ex)
            {
                if (LogEverything)
                    Logger(ex);
            }
        }
Example #11
0
        void BuildMap()
        {
            try
            {
                g.Children.Clear();
                currentPlayer = GameState.Players[0];
                txbCurrentPlayer.Text = currentPlayer.Name;
                imgCurrentPlayerIcon.Source = currentPlayer.Icon.Source;
                currentShip = currentPlayer.Ships[0];

                using (RNG rng = new RNG())
                {
                    for (int x = 0; x < GridDimensionX; x++)
                    {
                        for (int y = 0; y < GridDimensionY; y++)
                        {
                            AddBackgroundImage(x, y, rng.d(4));
                            AddContextMenuImage(x, y);
                            AddShipImages(x, y);
                            //AddLabel(x, y);

                            if (GameState.CombatLocations[x, y].IsBlocked)
                            {
                                try
                                {
                                    AddBlockedImage(x, y);
                                }
                                catch { MessageBox.Show("error in blocked images"); }
                            }
                        }
                    }
                }

                // highlight next player's ship
                AddHighlightImage(currentShip.TacticalPosition.X, currentShip.TacticalPosition.Y);

                ShowShipStatus(currentShip, spCurrentShip);
                lbxTargetShips.ItemsSource = SelectedLocShips;
                lbxTargetShips.UpdateLayout();
            }
            catch (Exception ex)
            {
                if (LogEverything)
                    Logger(ex);
            }
        }
Example #12
0
 void initHandlers(Player p)
 {
     try
     {
         foreach (Ship s in p.Ships)
         {
             s.OnShipDestroyed -= new StarShips.Delegates.ShipDelegates.ShipDestroyedEvent(onShipDestroyedHandler);
             s.OnShipDestroyed += new StarShips.Delegates.ShipDelegates.ShipDestroyedEvent(onShipDestroyedHandler);
             foreach (ITacticalWeaponOrder wo in s.Orders.Where(f => f is ITacticalWeaponOrder))
             {
                 wo.OnWeaponFired -= new OrderDelegates.TacticalWeaponFiredEvent(onWeaponFiredHandler);
                 wo.OnWeaponFired += new OrderDelegates.TacticalWeaponFiredEvent(onWeaponFiredHandler);
             }
             foreach (ITacticalMoveOrder mo in s.Orders.Where(f => f is ITacticalMoveOrder))
             {
                 mo.OnShipMove -= new OrderDelegates.TacticalShipMoveEvent(onShipMoveHandler);
                 mo.OnShipMove += new OrderDelegates.TacticalShipMoveEvent(onShipMoveHandler);
             }
         }
     }
     catch (Exception ex)
     {
         if (LogEverything)
             Logger(ex);
     }
 }