private void Update()
    {
        if (enemyCount > 0 || playerCount > 0)
        {
            if (enemyCount > 0 && playerCount == 0 && _spotState != SpotState.Enemy)
            {
                _spotState = SpotState.Enemy;

                team = Team.Enemy;
            }
            else if (playerCount > 0 && enemyCount == 0 && _spotState != SpotState.Player)
            {
                _spotState = SpotState.Player;

                team = Team.Player;
            }
            else if (enemyCount > 0 && playerCount > 0 && _spotState != SpotState.Contested)
            {
                _spotState = SpotState.Contested;
            }
        }
        else
        {
            if (_spotState != SpotState.Neutral)
            {
                _spotState = SpotState.Neutral;
            }
        }

        if (_spotState != SpotState.Neutral && _spotState != SpotState.Contested)
        {
            GameEventManager.TriggerEvent(new Score_GameEvent(ScoreEventType.AddScore, team, 10 * playerCount * Time.deltaTime));
        }
    }
        // [EnableCors(origins: "*", headers: "*", methods: "*")]
        public async Task <IHttpActionResult> GetSpotState(string id)//
        {
            SpotState spotState = await db.SpotStates.Where(x => x.TS == db.SpotStates.Max(p => p.TS)).FirstAsync();

            if (spotState == null)
            {
                return(NotFound());
            }

            return(Ok(spotState));
            //return CreatedAtRoute("DefaultApi", new { id = spotState }, spotState);
        }
        /// <summary>
        /// Get winner of game
        /// </summary>
        /// <param name="tempstate"></param>
        public void GetWinner(SpotState spotstate)
        {
            if (GameState != false)
            {
                GetWin(spotstate);

                if (foundWinPattern)
                {
                    if (spotstate == SpotState.X)
                    {
                        winner = IdentifyWinner.player;
                    }

                    else if (spotstate == SpotState.O)
                    {
                        winner = IdentifyWinner.computer;
                    }
                }

                CheckGameState();
            }
        }
Beispiel #4
0
            protected override void OnDraw(Renderer spriterenderer, double elapsedGameTime, float opacity)
            {
                base.OnDraw(spriterenderer, elapsedGameTime, opacity);
                this.hitAreaCache.Clear();

                var curMap = this.DataContext as WorldMapInfo;

                if (curMap == null)
                {
                    return;
                }

                TextureItem baseImg = curMap.BaseImg;

                SpotState[] spotState = new SpotState[curMap.MapList.Count];

                if (curMap.QuestLimit != null && this.SelectedQuestIndex > -1 && this.SelectedQuestIndex < curMap.QuestLimit.Count)
                {
                    for (int i = 0; i <= this.SelectedQuestIndex; i++)
                    {
                        var quest = curMap.QuestLimit[i];
                        //重写底图
                        if (quest.BaseImg != null)
                        {
                            baseImg = quest.BaseImg;
                        }
                        else if (quest.IsDefault)
                        {
                            baseImg = curMap.BaseImg;
                        }
                        //重写spot属性

                        if (quest.IsDefault)
                        {
                            for (int j = 0; j < spotState.Length; j++)
                            {
                                spotState[j].IsOverride = true;
                                spotState[j].IsVisible  = false;
                            }
                        }
                        foreach (var spotIndex in quest.CloseMaps)
                        {
                            spotState[spotIndex].IsOverride = true;
                            spotState[spotIndex].IsVisible  = true;
                            spotState[spotIndex].IsOpen     = false;
                            spotState[spotIndex].ImgType    = quest.CloseMapImageType ?? -1;
                        }
                        foreach (var spotIndex in quest.OpenMaps)
                        {
                            spotState[spotIndex].IsOverride = true;
                            spotState[spotIndex].IsVisible  = true;
                            spotState[spotIndex].IsOpen     = true;
                            spotState[spotIndex].ImgType    = -1;
                        }
                    }
                }

                var baseOrigin = new PointF((int)this.Width / 2, (int)this.Height / 2);

                var drawOrder = new List <DrawItem>();
                var addItem   = new Action <TextureItem, object>((texture, obj) =>
                {
                    drawOrder.Add(new DrawItem()
                    {
                        Target = obj, TextureItem = texture
                    });
                });

                //获取鼠标位置
                var     mousePos = InputManager.Current.MouseDevice.GetPosition(this);
                MapSpot curSpot  = null;

                //绘制底图
                if (baseImg != null)
                {
                    addItem(baseImg, null);
                }

                //绘制link
                foreach (var link in curMap.MapLinks)
                {
                    if (link.LinkImg != null)
                    {
                        var pos = new PointF(mousePos.X - (baseOrigin.X - link.LinkImg.Origin.X),
                                             mousePos.Y - (baseOrigin.Y - link.LinkImg.Origin.Y));
                        if (link.LinkImg.HitMap?[(int)pos.X, (int)pos.Y] ?? false)
                        {
                            addItem(link.LinkImg, link);
                        }
                    }
                }

                //绘制地图点
                for (int i = 0, i0 = curMap.MapList.Count; i < i0; i++)
                {
                    var spot     = curMap.MapList[i];
                    int spotType = spot.Type;
                    if (spotState[i].IsOverride) //重写判定
                    {
                        if (!spotState[i].IsVisible)
                        {
                            continue;
                        }
                        if (!spotState[i].IsOpen) //close
                        {
                            if (spotState[i].ImgType > -1)
                            {
                                spotType = spotState[i].ImgType;
                            }
                        }
                    }

                    var texture = this.FindResource("mapImage/" + spotType) as TextureItem;
                    if (texture != null)
                    {
                        var item = new TextureItem()
                        {
                            Texture = texture.Texture,
                            Origin  = new PointF(-spot.Spot.X + texture.Origin.X, -spot.Spot.Y + texture.Origin.Y),
                            Z       = 128 + texture.Z
                        };
                        if (spot.IsPreBB && curMap.BaseImg != null) //pre-bb地图点调整
                        {
                            item.Origin.X += curMap.BaseImg.Origin.X;
                            item.Origin.Y += curMap.BaseImg.Origin.Y;
                        }
                        addItem(item, spot);

                        //判断鼠标位置绘制path
                        if (spot.Path != null)
                        {
                            var rect = new Rect(baseOrigin.X - item.Origin.X, baseOrigin.Y - item.Origin.Y, texture.Texture.Width, texture.Texture.Height);
                            if (rect.Contains(mousePos))
                            {
                                addItem(spot.Path, null);
                            }
                        }
                    }

                    if (this.CurrentMapID != null && spot.MapNo.Contains(this.CurrentMapID.Value))
                    {
                        curSpot = spot;
                    }
                }

                //绘制当前地图标记
                if (curSpot != null)
                {
                    var posTexture = this.FindResource("curPos") as TextureItem;
                    if (posTexture != null)
                    {
                        var item = new TextureItem()
                        {
                            Texture = posTexture.Texture,
                            Origin  = new PointF(-curSpot.Spot.X + posTexture.Origin.X, -curSpot.Spot.Y + posTexture.Origin.Y),
                            Z       = 255,
                        };
                        addItem(item, null);
                    }
                }

                //开始绘制
                foreach (var item in drawOrder.OrderBy(_item => _item.TextureItem.Z))
                {
                    var tex = item.TextureItem;
                    if (tex != null)
                    {
                        var pos  = new PointF(baseOrigin.X - tex.Origin.X, baseOrigin.Y - tex.Origin.Y);
                        var size = new Size(tex.Texture.Width, tex.Texture.Height);
                        spriterenderer.Draw(tex.Texture,
                                            new PointF(this.RenderPosition.X + pos.X, this.RenderPosition.Y + pos.Y),
                                            size,
                                            new ColorW(1f, 1f, 1f, opacity),
                                            false);

                        item.Position = pos;
                        this.hitAreaCache.Add(item);
                    }
                }
            }
Beispiel #5
0
        static SpotState ParseSpotState(JToken data, Currency currency)
        {
            // {
            //   "averagePrice": "439.42",
            //   "completedTradeAmount": "0.01",
            //   "createdDate": 1456152164000,
            //   "id": 199990737,
            //   "orderId": 199990737,
            //   "sigTradeAmount": "0.01",   // May be missing. Means zero.
            //   "sigTradePrice": "439.42",  // May be missing. Means zero.
            //   "status": 2,
            //   "symbol": "btc_usd",
            //   "tradeAmount": "0.01",
            //   "tradePrice": "4.39",
            //   "tradeType": "buy",
            //   "tradeUnitPrice": "439.51",
            //   "unTrade": "0"
            // }
            var res = new SpotState()
            {
                Timestamp   = Util.Time.FromUnixMillis((long)data["createdDate"]),
                OrderId     = (long)data["orderId"],
                OrderStatus = Serialization.ParseOrderStatus((int)data["status"]),
                Product     = new Spot()
                {
                    Currency = currency
                },
                Amount = new Amount()
                {
                    Price    = data["tradeUnitPrice"].AsDecimal(),
                    Quantity = data["tradeAmount"].AsDecimal(),
                },
                CumFillQuantity = data["completedTradeAmount"].AsDecimal(),
                AvgFillPrice    = data["averagePrice"].AsDecimal(),
            };

            // Infer CoinType from "symbol". E.g., "btc_usd" => CoinType.Btc.
            string symbol = (string)data["symbol"];

            Condition.Requires(symbol, "symbol").IsNotNullOrEmpty();
            if (symbol.StartsWith("btc"))
            {
                res.Product.CoinType = CoinType.Btc;
            }
            else if (symbol.StartsWith("ltc"))
            {
                res.Product.CoinType = CoinType.Ltc;
            }
            else
            {
                throw new ArgumentException("Unknown value of `symbol`: " + symbol);
            }

            string type = (string)data["tradeType"];

            Condition.Requires(type, "type").IsNotNullOrEmpty();
            if (type == "buy" || type == "market_buy")
            {
                res.Amount.Side = Side.Buy;
            }
            else if (type == "sell" || type == "market_sell")
            {
                res.Amount.Side = Side.Sell;
            }
            else
            {
                throw new ArgumentException("Unknown value of `type`: " + type);
            }

            // sigTradeAmount and sigTradePrice are optional fields.
            JToken fillQuantity = data["sigTradeAmount"];

            if (fillQuantity != null)
            {
                res.FillQuantity = fillQuantity.AsDecimal();
            }
            JToken fillPrice = data["sigTradePrice"];

            if (fillPrice != null)
            {
                res.FillPrice = fillPrice.AsDecimal();
            }

            return(res);
        }
        /// <summary>
        /// chechs if someone win
        /// </summary>
        /// <param name="boxState"></param>
        private void GetWin(SpotState boxState)
        {
            #region Horizontalcheck

            short segindex = 0;
            short temp     = maxRowSize;
            short temp2    = 0;

            for (short j = 0; j < maxRowSize; ++j)
            {
                for (short i = temp2; i < temp; ++i)
                {
                    if (spotValues[i] != boxState)
                    {
                        GameState       = true;
                        foundWinPattern = false;
                        break;
                    }
                    else if (spotValues[i] == boxState)
                    {
                        winSegments[segindex++] = i;
                        GameState       = false;
                        foundWinPattern = true;
                    }
                }

                if (foundWinPattern)
                {
                    break;
                }

                segindex = 0;
                temp    += maxRowSize;
                temp2   += 2 + 1;
            }

            #endregion

            if (foundWinPattern)
            {
                return;
            }

            #region VerticalCheck

            segindex = 0;
            temp     = 6;
            temp2    = 0;
            short temp3 = temp2;

            for (short j = 0; j < maxcolSize; ++j)
            {
                for (short i = temp2; i <= temp; i += 3)
                {
                    if (spotValues[i] != boxState)
                    {
                        GameState       = true;
                        foundWinPattern = false;
                        break;
                    }

                    else if (spotValues[i] == boxState)
                    {
                        winSegments[segindex++] = i;
                        GameState       = false;
                        foundWinPattern = true;
                    }
                }

                if (foundWinPattern)
                {
                    break;
                }

                segindex = 0;
                temp    += 1;
                temp3   += 1;
                temp2    = temp3;
            }

            #endregion

            //if winner pattern for horizontal and vertical patterns is found return
            if (foundWinPattern)
            {
                return;
            }

            //chech diagonals
            #region diagonalCheck

            segindex = 0;
            temp     = 8;
            temp2    = 0;
            short incr = 4;

            for (short j = 0; j < maxcolSize - 1; ++j)
            {
                for (short i = temp2; i <= temp; i += incr)
                {
                    if (spotValues[i] != boxState)
                    {
                        GameState       = true;
                        foundWinPattern = false;
                        break;
                    }
                    else if (spotValues[i] == boxState)
                    {
                        winSegments[segindex++] = i;
                        GameState       = false;
                        foundWinPattern = true;
                    }
                }

                //if pattern is found
                if (foundWinPattern)
                {
                    break;
                }

                segindex = 0;
                temp    -= 2;
                temp2   += 2;
                incr    -= 2;
            }
            #endregion
        }
 private Material GetGraphic(SpotState spotIndex) => subGraphics[(int)spotIndex]?.MatSingle;