コード例 #1
0
        // TODO: refactor to load FEN instead
        private void SpawnPiecesRow(TabletopSession session, IEntityManager entityManager, string color, MapCoordinates left, float separation = 1f)
        {
            const string piecesRow = "rnbqkbnr";

            var(mapId, x, y) = left;

            for (int i = 0; i < 8; i++)
            {
                switch (piecesRow[i])
                {
                case 'r':
                    session.Entities.Add(entityManager.SpawnEntity(color + "Rook", new MapCoordinates(x + i * separation, y, mapId)).Uid);
                    break;

                case 'n':
                    session.Entities.Add(entityManager.SpawnEntity(color + "Knight", new MapCoordinates(x + i * separation, y, mapId)).Uid);
                    break;

                case 'b':
                    session.Entities.Add(entityManager.SpawnEntity(color + "Bishop", new MapCoordinates(x + i * separation, y, mapId)).Uid);
                    break;

                case 'q':
                    session.Entities.Add(entityManager.SpawnEntity(color + "Queen", new MapCoordinates(x + i * separation, y, mapId)).Uid);
                    break;

                case 'k':
                    session.Entities.Add(entityManager.SpawnEntity(color + "King", new MapCoordinates(x + i * separation, y, mapId)).Uid);
                    break;
                }
            }
        }
コード例 #2
0
        private void SpawnPieces(TabletopSession session, IEntityManager entityManager, string color, MapCoordinates left, float separation = 1f)
        {
            var(mapId, x, y) = left;
            // If white is being placed it must go from bottom->up
            var reversed = (color == "White") ? 1 : -1;

            for (int i = 0; i < 3; i++)
            {
                var x_offset = i % 2;
                if (reversed == -1)
                {
                    x_offset = 1 - x_offset;             // Flips it
                }
                for (int j = 0; j < 8; j += 2)
                {
                    // Prevents an extra piece on the middle row
                    if (x_offset + j > 8)
                    {
                        continue;
                    }

                    EntityUid tempQualifier4 = entityManager.SpawnEntity(color + "CheckerPiece", new MapCoordinates(x + (j + x_offset) * separation, y + i * reversed * separation, mapId));
                    session.Entities.Add(tempQualifier4);
                }
            }
        }
コード例 #3
0
        // TODO: Un-hardcode the rest of entity prototype IDs, probably.

        public override void SetupTabletop(TabletopSession session, IEntityManager entityManager)
        {
            var chessboard = entityManager.SpawnEntity(ChessBoardPrototype, session.Position.Offset(-1, 0));

            session.Entities.Add(chessboard.Uid);

            SpawnPieces(session, entityManager, session.Position.Offset(-4.5f, 3.5f));
        }
コード例 #4
0
        // TODO: refactor to load FEN instead
        private void SpawnPawns(TabletopSession session, IEntityManager entityManager, string color, MapCoordinates left, float separation = 1f)
        {
            var(mapId, x, y) = left;

            for (int i = 0; i < 8; i++)
            {
                session.Entities.Add(entityManager.SpawnEntity(color + "Pawn", new MapCoordinates(x + i * separation, y, mapId)).Uid);
            }
        }
コード例 #5
0
        public override void SetupTabletop(TabletopSession session, IEntityManager entityManager)
        {
            var board = entityManager.SpawnEntity(BackgammonBoardPrototype, session.Position);

            const float borderLengthX = 7.35f; //BORDER
            const float borderLengthY = 5.60f; //BORDER

            const float boardDistanceX = 1.25f;
            const float pieceDistanceY = 0.80f;

            float GetXPosition(float distanceFromSide, bool isLeftSide)
            {
                var pos = borderLengthX - (distanceFromSide * boardDistanceX);

                return(isLeftSide ? -pos : pos);
            }

            float GetYPosition(float positionNumber, bool isTop)
            {
                var pos = borderLengthY - (pieceDistanceY * positionNumber);

                return(isTop ? pos : -pos);
            }

            void AddPieces(
                float distanceFromSide,
                int numberOfPieces,
                bool isBlackPiece,
                bool isTop,
                bool isLeftSide)
            {
                for (int i = 0; i < numberOfPieces; i++)
                {
                    session.Entities.Add(entityManager.SpawnEntity(isBlackPiece ? BlackPiecePrototype : WhitePiecePrototype, session.Position.Offset(GetXPosition(distanceFromSide, isLeftSide), GetYPosition(i, isTop))));
                }
            }

            // Top left
            AddPieces(0, 5, true, true, true);
            // top middle left
            AddPieces(4, 3, false, true, true);
            // top middle right
            AddPieces(5, 5, false, true, false);
            // top far right
            AddPieces(0, 2, true, true, false);
            // bottom left
            AddPieces(0, 5, false, false, true);
            // bottom middle left
            AddPieces(4, 3, true, false, true);
            // bottom middle right
            AddPieces(5, 5, true, false, false);
            // bottom far right
            AddPieces(0, 2, false, false, false);
        }
コード例 #6
0
        private void SpawnPieces(TabletopSession session, IEntityManager entityManager, MapCoordinates topLeft, float separation = 1f)
        {
            var(mapId, x, y) = topLeft;

            // Spawn all black pieces
            SpawnPiecesRow(session, entityManager, "Black", topLeft, separation);
            SpawnPawns(session, entityManager, "Black", new MapCoordinates(x, y - separation, mapId), separation);

            // Spawn all white pieces
            SpawnPawns(session, entityManager, "White", new MapCoordinates(x, y - 6 * separation, mapId), separation);
            SpawnPiecesRow(session, entityManager, "White", new MapCoordinates(x, y - 7 * separation, mapId), separation);

            // Extra queens
            session.Entities.Add(entityManager.SpawnEntity("BlackQueen", new MapCoordinates(x + 9 * separation + 9f / 32, y - 3 * separation, mapId)).Uid);
            session.Entities.Add(entityManager.SpawnEntity("WhiteQueen", new MapCoordinates(x + 9 * separation + 9f / 32, y - 4 * separation, mapId)).Uid);
        }
コード例 #7
0
        private void SpawnPieces(TabletopSession session, IEntityManager entityManager, MapCoordinates topLeft, float separation = 1f)
        {
            var(mapId, x, y) = topLeft;

            // Spawn all black pieces
            SpawnPieces(session, entityManager, "Black", topLeft, separation);

            // Spawn all white pieces
            SpawnPieces(session, entityManager, "White", new MapCoordinates(x, y - 7 * separation, mapId), separation);

            // Queens
            for (int i = 1; i < 4; i++)
            {
                EntityUid tempQualifier = entityManager.SpawnEntity("BlackCheckerQueen", new MapCoordinates(x + 9 * separation + 9f / 32, y - i * separation, mapId));
                session.Entities.Add(tempQualifier);

                EntityUid tempQualifier1 = entityManager.SpawnEntity("WhiteCheckerQueen", new MapCoordinates(x + 8 * separation + 9f / 32, y - i * separation, mapId));
                session.Entities.Add(tempQualifier1);
            }
        }
コード例 #8
0
        /// <summary>
        ///     Ensures that a <see cref="TabletopSession"/> exists on a <see cref="TabletopGameComponent"/>.
        ///     Creates it and sets it up if it doesn't.
        /// </summary>
        /// <param name="tabletop">The tabletop game in question.</param>
        /// <returns>The session for the given tabletop game.</returns>
        private TabletopSession EnsureSession(TabletopGameComponent tabletop)
        {
            // We already have a session, return it
            // TODO: if tables are connected, treat them as a single entity. This can be done by sharing the session.
            if (tabletop.Session != null)
            {
                return(tabletop.Session);
            }

            // We make sure that the tabletop map exists before continuing.
            EnsureTabletopMap();

            // Create new session.
            var session = new TabletopSession(TabletopMap, GetNextTabletopPosition());

            tabletop.Session = session;

            // Since this is the first time opening this session, set up the game
            tabletop.Setup.SetupTabletop(session, EntityManager);

            Logger.Info($"Created tabletop session number {tabletop} at position {session.Position}.");

            return(session);
        }
コード例 #9
0
        public override void SetupTabletop(TabletopSession session, IEntityManager entityManager)
        {
            var board = entityManager.SpawnEntity(ParchisBoardPrototype, session.Position);

            const float x1 = 6.25f;
            const float x2 = 4.25f;

            const float y1 = 6.25f;
            const float y2 = 4.25f;

            var center = session.Position;

            // Red pieces.
            session.Entities.Add(entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x1, -y1)).Uid);
            session.Entities.Add(entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x1, -y2)).Uid);
            session.Entities.Add(entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x2, -y1)).Uid);
            session.Entities.Add(entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x2, -y2)).Uid);

            // Green pieces.
            session.Entities.Add(entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x1, -y1)).Uid);
            session.Entities.Add(entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x1, -y2)).Uid);
            session.Entities.Add(entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x2, -y1)).Uid);
            session.Entities.Add(entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x2, -y2)).Uid);

            // Yellow pieces.
            session.Entities.Add(entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x1, y1)).Uid);
            session.Entities.Add(entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x1, y2)).Uid);
            session.Entities.Add(entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x2, y1)).Uid);
            session.Entities.Add(entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x2, y2)).Uid);

            // Blue pieces.
            session.Entities.Add(entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x1, y1)).Uid);
            session.Entities.Add(entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x1, y2)).Uid);
            session.Entities.Add(entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x2, y1)).Uid);
            session.Entities.Add(entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x2, y2)).Uid);
        }
コード例 #10
0
        public override void SetupTabletop(TabletopSession session, IEntityManager entityManager)
        {
            var board = entityManager.SpawnEntity(ParchisBoardPrototype, session.Position);

            const float x1 = 6.25f;
            const float x2 = 4.25f;

            const float y1 = 6.25f;
            const float y2 = 4.25f;

            var center = session.Position;

            // Red pieces.
            EntityUid tempQualifier = entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x1, -y1));

            session.Entities.Add(tempQualifier);
            EntityUid tempQualifier1 = entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x1, -y2));

            session.Entities.Add(tempQualifier1);
            EntityUid tempQualifier2 = entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x2, -y1));

            session.Entities.Add(tempQualifier2);
            EntityUid tempQualifier3 = entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x2, -y2));

            session.Entities.Add(tempQualifier3);

            // Green pieces.
            EntityUid tempQualifier4 = entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x1, -y1));

            session.Entities.Add(tempQualifier4);
            EntityUid tempQualifier5 = entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x1, -y2));

            session.Entities.Add(tempQualifier5);
            EntityUid tempQualifier6 = entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x2, -y1));

            session.Entities.Add(tempQualifier6);
            EntityUid tempQualifier7 = entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x2, -y2));

            session.Entities.Add(tempQualifier7);

            // Yellow pieces.
            EntityUid tempQualifier8 = entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x1, y1));

            session.Entities.Add(tempQualifier8);
            EntityUid tempQualifier9 = entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x1, y2));

            session.Entities.Add(tempQualifier9);
            EntityUid tempQualifier10 = entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x2, y1));

            session.Entities.Add(tempQualifier10);
            EntityUid tempQualifier11 = entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x2, y2));

            session.Entities.Add(tempQualifier11);

            // Blue pieces.
            EntityUid tempQualifier12 = entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x1, y1));

            session.Entities.Add(tempQualifier12);
            EntityUid tempQualifier13 = entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x1, y2));

            session.Entities.Add(tempQualifier13);
            EntityUid tempQualifier14 = entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x2, y1));

            session.Entities.Add(tempQualifier14);
            EntityUid tempQualifier15 = entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x2, y2));

            session.Entities.Add(tempQualifier15);
        }
コード例 #11
0
 /// <summary>
 ///     Method for setting up a tabletop. Use this to spawn the board and pieces, etc.
 ///     Make sure you add every entity you create to the Entities hashset in the session.
 /// </summary>
 /// <param name="session">Tabletop session to set up. You'll want to grab the tabletop center position here for spawning entities.</param>
 /// <param name="entityManager">Dependency that can be used for spawning entities.</param>
 public abstract void SetupTabletop(TabletopSession session, IEntityManager entityManager);