Inheritance: TXADrawableComponent
コード例 #1
0
        public MapScreen(GameState initial)
        {
            latestGameState = initial;

            for (int i = 0; i < board.Length; i++)
            {
                board[i] = new GUITile[Board.GetRowLength(i)];

                for (int j = 0; j < board[i].Length; j++)
                {
                    bool    omit = OmittedTile(GetTerrainIndex(i, j));
                    GUITile tile = new GUITile(j, i, latestGameState.Board.GetTile(i, j), omit);
                    AddDrawableComponent(tile);
                    board[i][j] = tile;
                }
            }

            //Entire Screen size: GraphicsAdapter.DefaultAdapter.CurrentDisplayMode


            const int logWidth = 350;

            //int gameH = graphics.Viewport.Height;
            //int gameW = graphics.Viewport.Width;
            const int screenWidth  = 1280;
            const int screenHeight = 720;

            //Debug.WriteLine(string.Format("width {0}, height {1}", gameW, gameH));

            gamelog = new GUILogList <GUIBufferTextBlock>(new Vector2((screenWidth - logWidth) / TXAGame.SCALE, 1 / TXAGame.SCALE), screenHeight - 2, logWidth - 1);

            //AddButton(new TXAButton(new Vector2(750 / TXAGame.SCALE, 50 / TXAGame.SCALE), "Debug Log"), InsertText);

            AddDrawableComponent(gamelog);

            robber = new GUIRobber(GetRobberPos());

            AddDrawableComponent(robber);

            latestGameState.GetLatestEvents(int.MaxValue).Skip(gamelog.Count).ForEach(a => InsertLogEvent(a.ToString()));
            //lastLogPoll = DateTime.Now;

            //Test Roads and pieces
            UpdateGameState(initial);
        }
コード例 #2
0
ファイル: MapScreen.cs プロジェクト: rasmusgreve/catan
        public MapScreen(GameState initial)
        {
            latestGameState = initial;

            for (int i = 0; i < board.Length; i++)
            {
                board[i] = new GUITile[Board.GetRowLength(i)];

                for (int j = 0; j < board[i].Length; j++)
                {
                    bool omit = OmittedTile(GetTerrainIndex(i, j));
                    GUITile tile = new GUITile(j, i, latestGameState.Board.GetTile(i, j), omit);
                    AddDrawableComponent(tile);
                    board[i][j] = tile;
                }
            }

            //Entire Screen size: GraphicsAdapter.DefaultAdapter.CurrentDisplayMode

            const int logWidth = 350;

            //int gameH = graphics.Viewport.Height;
            //int gameW = graphics.Viewport.Width;
            const int screenWidth = 1280;
            const int screenHeight = 720;

            //Debug.WriteLine(string.Format("width {0}, height {1}", gameW, gameH));

            gamelog = new GUILogList<GUIBufferTextBlock>(new Vector2((screenWidth-logWidth)/TXAGame.SCALE, 1/TXAGame.SCALE),screenHeight-2, logWidth-1);

            //AddButton(new TXAButton(new Vector2(750 / TXAGame.SCALE, 50 / TXAGame.SCALE), "Debug Log"), InsertText);

            AddDrawableComponent(gamelog);

            robber = new GUIRobber(GetRobberPos());

            AddDrawableComponent(robber);

            latestGameState.GetLatestEvents(int.MaxValue).Skip(gamelog.Count).ForEach(a => InsertLogEvent(a.ToString()));
            //lastLogPoll = DateTime.Now;

            //Test Roads and pieces
            UpdateGameState(initial);
        }
コード例 #3
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
        }