Inheritance: TXADrawableComponent
Exemplo n.º 1
0
        public void UpdateGameState(GameState state)
        {
            Console.WriteLine("UpdateGameState called");

            latestGameState = state;

            #region Roads
            Dictionary<Edge, int> allRoads = latestGameState.Board.GetAllRoads();

            foreach (KeyValuePair<Edge, int> road in allRoads)
            {
                int tile1 = road.Key.FirstTile;
                int tile2 = road.Key.SecondTile;

                if (roads.Exists(r => r.Tile1 == tile1 && r.Tile2 == tile2))
                {
                    continue;
                }

                Edge t1Coord = GetTerrainCoords(tile1);
                Edge t2Coord = GetTerrainCoords(tile2);

                Vector2 diffVector = board[t2Coord.FirstTile][t2Coord.SecondTile].Position / TXAGame.SCALE -
                                     board[t1Coord.FirstTile][t1Coord.SecondTile].Position / TXAGame.SCALE;

                Vector2 placeVector = (board[t1Coord.FirstTile][t1Coord.SecondTile].Position/TXAGame.SCALE)+(diffVector/2);

                float rotation = 0;

                const float value = (float) (Math.PI/3);

                if (diffVector.X < 0)
                {
                    rotation = value*2;
                }
                else if (diffVector.X < diffVector.Y)
                {
                    rotation = value;
                }

                GUIRoad newRoad = new GUIRoad(placeVector,rotation,road.Value, tile1, tile2);
                newRoad.Visible = true;

                AddDrawableComponent(newRoad);

            }
            #endregion

            #region Pieces
            Dictionary<Intersection, Piece> piecelist = state.Board.GetAllPieces();

            foreach (KeyValuePair<Intersection, Piece> piece in piecelist)
            {
                int t1 = piece.Key.FirstTile;
                int t2 = piece.Key.SecondTile;
                int t3 = piece.Key.ThirdTile;

                GUIPiece alreadyPiece = pieces.FirstOrDefault(e => e.Tile1 == t1 && e.Tile2 == t2 && e.Tile3 == t3);

                if (alreadyPiece != null)
                {
                    if (alreadyPiece.Type == Token.Settlement && piece.Value.Token == Token.City)
                    {
                        alreadyPiece.Type = Token.City;
                    }
                    continue;
                }

                Vector2 diffVector = t1 + 1 == t2
                                         ? new Vector2(GUITile.TileWidth()/2, GUITile.TileHeight()/4)
                                         : new Vector2(0, GUITile.TileHeight()/2);

                Edge t1C = GetTerrainCoords(t1);

                Vector2 placePos = board[t1C.FirstTile][t1C.SecondTile].Position/TXAGame.SCALE + diffVector;

                GUIPiece newPiece = new GUIPiece(placePos, piece.Value.Player, piece.Value.Token, t1, t2, t3);
                newPiece.Visible = true;

                pieces.Add(newPiece);

                AddDrawableComponent(newPiece);
            }
            #endregion

            #region Robber
            robber.UpdateRobberPosition(GetRobberPos());
            #endregion

            #region GameLog

            latestGameState.GetLatestEvents(int.MaxValue).Skip(gamelog.Count).ForEach(a => InsertLogEvent(a.ToString()));
            //Console.WriteLine(events.Count);
            //events.ForEach(a => InsertLogEvent(a.ToString()));
            //lastLogPoll = DateTime.Now;
            #endregion
        }
Exemplo n.º 2
0
        public void UpdateGameState(GameState state)
        {
            Console.WriteLine("UpdateGameState called");

            latestGameState = state;

            #region Roads
            Dictionary <Edge, int> allRoads = latestGameState.Board.GetAllRoads();

            foreach (KeyValuePair <Edge, int> road in allRoads)
            {
                int tile1 = road.Key.FirstTile;
                int tile2 = road.Key.SecondTile;

                if (roads.Exists(r => r.Tile1 == tile1 && r.Tile2 == tile2))
                {
                    continue;
                }

                Edge t1Coord = GetTerrainCoords(tile1);
                Edge t2Coord = GetTerrainCoords(tile2);

                Vector2 diffVector = board[t2Coord.FirstTile][t2Coord.SecondTile].Position / TXAGame.SCALE -
                                     board[t1Coord.FirstTile][t1Coord.SecondTile].Position / TXAGame.SCALE;

                Vector2 placeVector = (board[t1Coord.FirstTile][t1Coord.SecondTile].Position / TXAGame.SCALE) + (diffVector / 2);

                float rotation = 0;

                const float value = (float)(Math.PI / 3);

                if (diffVector.X < 0)
                {
                    rotation = value * 2;
                }
                else if (diffVector.X < diffVector.Y)
                {
                    rotation = value;
                }

                GUIRoad newRoad = new GUIRoad(placeVector, rotation, road.Value, tile1, tile2);
                newRoad.Visible = true;



                AddDrawableComponent(newRoad);
            }
            #endregion

            #region Pieces
            Dictionary <Intersection, Piece> piecelist = state.Board.GetAllPieces();

            foreach (KeyValuePair <Intersection, Piece> piece in piecelist)
            {
                int t1 = piece.Key.FirstTile;
                int t2 = piece.Key.SecondTile;
                int t3 = piece.Key.ThirdTile;

                GUIPiece alreadyPiece = pieces.FirstOrDefault(e => e.Tile1 == t1 && e.Tile2 == t2 && e.Tile3 == t3);

                if (alreadyPiece != null)
                {
                    if (alreadyPiece.Type == Token.Settlement && piece.Value.Token == Token.City)
                    {
                        alreadyPiece.Type = Token.City;
                    }
                    continue;
                }

                Vector2 diffVector = t1 + 1 == t2
                                         ? new Vector2(GUITile.TileWidth() / 2, GUITile.TileHeight() / 4)
                                         : new Vector2(0, GUITile.TileHeight() / 2);

                Edge t1C = GetTerrainCoords(t1);

                Vector2 placePos = board[t1C.FirstTile][t1C.SecondTile].Position / TXAGame.SCALE + diffVector;

                GUIPiece newPiece = new GUIPiece(placePos, piece.Value.Player, piece.Value.Token, t1, t2, t3);
                newPiece.Visible = true;

                pieces.Add(newPiece);

                AddDrawableComponent(newPiece);
            }
            #endregion

            #region Robber
            robber.UpdateRobberPosition(GetRobberPos());
            #endregion

            #region GameLog

            latestGameState.GetLatestEvents(int.MaxValue).Skip(gamelog.Count).ForEach(a => InsertLogEvent(a.ToString()));
            //Console.WriteLine(events.Count);
            //events.ForEach(a => InsertLogEvent(a.ToString()));
            //lastLogPoll = DateTime.Now;
            #endregion
        }