コード例 #1
0
ファイル: World.cs プロジェクト: u1201441/CS3500_SpaceWars
 /// <summary>
 /// This method "kills" a star and adds it to a list to respawn (for boss mode only).
 /// </summary>
 /// <param name="ship"></param>
 public void KillStar(Star star)
 {
     lock (starDictionary)
     {
         this.RemoveStar(star.GetID());
         star.Died();
         deadStarDictionary.Add(star.GetID(), star);
     }
 }
コード例 #2
0
ファイル: World.cs プロジェクト: u1201441/CS3500_SpaceWars
        /// <summary>
        /// This method will either add a new star to the world, or
        /// update a current star with a new star depending on
        /// the projectile's ID.
        /// </summary>
        /// <param name="newStar"></param>
        public void addStar(Star newStar)
        {
            int starId = newStar.GetID();

            lock (starDictionary)
            {
                if (starDictionary.ContainsKey(starId))
                {
                    starDictionary.Remove(starId);
                    starDictionary.Add(newStar.GetID(), newStar);
                }
                else
                {
                    starDictionary.Add(newStar.GetID(), newStar);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// If Star s does not exist in stars adds it. If the id already exists
        /// in Star, updates reference in stars to s.
        /// </summary>
        public void AddStar(Star star)
        {
            // if the star is null then do nothing
            if (star == null)
            {
                return;
            }

            // if the star is in the world then replace the old star with the passed in star
            else if (stars.ContainsKey(star.GetID()))
            {
                stars[star.GetID()] = star;
            }
            // if the star is not in the world then add it to the world
            else
            {
                stars.Add(star.GetID(), star);
            }
        }
コード例 #4
0
ファイル: World.cs プロジェクト: u1201441/CS3500_SpaceWars
        /// <summary>
        /// Spawns a star using the properties of an existing star. Used for respawning existing stars which have been killed (boss mode only.) Spawn location is retained from initial star.
        /// </summary>
        /// <param name="star">star to be respawned</param>
        public void respawnStar(Star star)
        {
            Vector2D newLoc  = new Vector2D(star.GetLocation());
            Star     newStar = new Star(star.GetID(), newLoc, star.GetMass());

            // Set ship's modifiable variables
            newStar.SetHP(BossHealth);

            this.addStar(newStar);
        }
コード例 #5
0
        /// <summary>
        /// Acts as a drawing delegate for DrawObjectWithTransform
        /// After performing the necessary transformation (translate/rotate)
        /// DrawObjectWithTransform will invoke this method
        /// </summary>
        /// <param name="o">The object to draw</param>
        /// <param name="e">The PaintEventArgs to access the graphics</param>
        private void StarDrawer(object o, PaintEventArgs e)
        {
            Star   star = o as Star;
            Bitmap starSprite;
            int    x, y;
            Point  p;

            x = WorldSpaceToImageSpace(this.Size.Width, (int)star.GetLocation().GetX());
            y = WorldSpaceToImageSpace(this.Size.Width, (int)star.GetLocation().GetY());
            p = new Point(x - (STAR_SIZE.Width / 2), y - (STAR_SIZE.Height / 2));

            if (theWorld.GetMarioMode())
            {
                starSprite = marioStar;
            }
            else
            {
                starSprite = starSprites[star.GetID() % starSprites.Count];
            }

            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            e.Graphics.DrawImage(starSprite, p);
        }
コード例 #6
0
        public void ReceiveData(SocketState state)
        {
            StringBuilder          sb       = state.sb;
            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                MissingMemberHandling = MissingMemberHandling.Error
            };

            try
            {
                char[]   separator = new char[] { '\n' };
                string[] strArray  = sb.ToString().Split(separator, StringSplitOptions.RemoveEmptyEntries);
                int      length    = strArray.Length;
                if (sb.ToString()[sb.Length - 1] != '\n')
                {
                    length--;
                }
                List <Ship> list  = new List <Ship>();
                List <Ship> list2 = new List <Ship>();
                for (int i = 0; i < length; i++)
                {
                    string json = strArray[i];
                    if ((json[0] == '{') && (json[json.Length - 1] == '}'))
                    {
                        Ship       item       = null;
                        Projectile projectile = null;
                        Star       star       = null;
                        JObject    obj1       = JObject.Parse(json);
                        JToken     token      = obj1["ship"];
                        JToken     token2     = obj1["proj"];
                        if (token != null)
                        {
                            item = JsonConvert.DeserializeObject <Ship>(json, settings);
                        }
                        if (token2 != null)
                        {
                            projectile = JsonConvert.DeserializeObject <Projectile>(json, settings);
                        }
                        if (obj1["star"] != null)
                        {
                            star = JsonConvert.DeserializeObject <Star>(json, settings);
                        }
                        World world = this.world;
                        lock (world)
                        {
                            if (item != null)
                            {
                                if (this.world.GetShips().ContainsKey(item.GetID()))
                                {
                                    if (this.world.GetShips()[item.GetID()].Alive && !item.Alive)
                                    {
                                        list2.Add(item);
                                    }
                                }
                                else
                                {
                                    list.Add(item);
                                }
                                this.world.GetShips()[item.GetID()] = item;
                            }
                            if (projectile != null)
                            {
                                if (projectile.IsAlive())
                                {
                                    this.world.GetProjectiles()[projectile.GetID()] = projectile;
                                }
                                else if (this.world.GetProjectiles().ContainsKey(projectile.GetID()))
                                {
                                    this.world.GetProjectiles().Remove(projectile.GetID());
                                }
                            }
                            if (star != null)
                            {
                                this.world.GetStars()[star.GetID()] = star;
                            }
                        }
                        sb.Remove(0, json.Length + 1);
                    }
                }
                foreach (Ship ship2 in list2)
                {
                    this.ShipDied(ship2);
                }
                foreach (Ship ship3 in list)
                {
                    this.NewShip(ship3);
                }
                this.FrameTick();
            }
            catch (JsonReaderException)
            {
            }
            catch (Exception)
            {
            }
            state.call_me = new Action <SocketState>(this.ReceiveData);
            Networking.RequestMoreData(state);
        }