Пример #1
0
        public override void LoadContent()
        {
            if (Game.OptionsCurrent.SquareSize <= 0)
            {
                Model pm         = Game.Content.Load <Model>(@"Models\Square");
                float squareSize = Utilities.CalculateModelRadius(pm) * 1.13f;

                Game.StatusCurrent.GameOpts = new GameOptions(squareSize, Vector3.Zero);
            }

            //initialise the camera
            camera = new CubicalCamera(50f, Game, 5);

            //initialises the squares
            bool red = false;

            for (int i = 0; i < 5; i++)
            {
                float yPos = Game.OptionsCurrent.SquareSize * (i);
                for (int j = 0; j < 5; j++)
                {
                    float zPos = Game.OptionsCurrent.SquareSize * j;
                    for (int k = 0; k < 5; k++)
                    {
                        float xPos = Game.OptionsCurrent.SquareSize * k;

                        Color color;
                        if (red)
                        {
                            color = Game.StatusCurrent.ColorBlackSquares;
                        }
                        else
                        {
                            color = Game.StatusCurrent.ColorWhiteSquares;
                        }
                        red = !red;

                        Square pm2 = new Square((Raumschach)this.Game,
                                                new Square.ChessboardPosition(k, i, j))
                        ;

                        pm2.WorldTransform = Matrix.CreateTranslation(
                            Game.OptionsCurrent.LeftBottom + new Vector3(xPos, yPos, zPos)
                            );

                        squares[k, i, j] = pm2;
                    }
                }
            }
            Game.Logics.ResetMatchParameters();
            ChessboardLogics.Init(10000, 8);

            UpdateSquares();

            camera.LoadContent();

            Game.FormCollection["frmGamePlayScreen"].Show();

            base.LoadContent();
        }
Пример #2
0
        public Raumschach()
        {
            //this.TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 20);
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            logics = new ChessboardLogics(this);
            //Full Screen Mode
            this.graphics.PreferredBackBufferWidth  = 1280;
            this.graphics.PreferredBackBufferHeight = 720;

            //this.graphics.IsFullScreen = true;


            // Create the screen manager component.
            screenManager = new ScreenManager(this);

            Components.Add(screenManager);


            screenManager.AddScreen(new MainMenuScreen(), null);
            //GamePlayScreen gps = new GamePlayScreen();
            //gps.DebugMode = true;
            //screenManager.AddScreen(gps, 0);
        }
Пример #3
0
 private void DoMove(object sender, PlayerIndexEventArgs e)
 {
     Game.StatusCurrent.Result   = (PossibleResult)ChessboardLogics.GetResult();
     to.OccupyingPiece           = from.OccupyingPiece;
     from.OccupyingPiece         = null;
     to.OccupyingPiece.PieceType = (PiecesTypes)Math.Abs(ChessboardLogics.GetPieceBySquare(to.index)) - 1;
     OnExit(sender, e);
 }
Пример #4
0
        void ExecuteComputerMove(object state)
        {
            if (SelectedPiece != null)
            {
                SelectedPiece.IsSelected = false;
                SelectedPiece            = null;
                foreach (Square sqr in squares)
                {
                    sqr.IsSelected = false;
                }
            }

            string move = ChessboardLogics.GetAndMakeNextComputerMove();

            Game.StatusCurrent.Result = (PossibleResult)ChessboardLogics.GetResult();

            string strFrom  = move.Substring(0, 3);
            string strTo    = move.Substring(3, 3);
            string strPromo = String.Empty;

            try{ strPromo = move.Substring(6, 1); }catch (ArgumentOutOfRangeException) {};

            Square from = GetSquareFromString(strFrom);
            Square to   = GetSquareFromString(strTo);

            //move the piece
            Piece p = from.OccupyingPiece;

            from.OccupyingPiece         = null;
            to.OccupyingPiece           = p;
            to.OccupyingPiece.PieceType = (PiecesTypes)Math.Abs(ChessboardLogics.GetPieceBySquare(to.index)) - 1;
            //UpdateSquares();

            Game.FormCollection["frmGamePlayScreen"]["lblTurn"].Text =
                "It's " + Game.StatusCurrent.SideToMove + " turn";
            Game.FormCollection["frmGamePlayScreen"]["lblComputerMove"].Text =
                "Computer has moved " + strFrom + strTo;
            Game.FormCollection["frmGamePlayScreen"]["lblComputerTime"].Text = String.Empty;

            IsComputerMoving = false;
        }
Пример #5
0
        public void UpdateSquares()
        {
            //int[] board = new int[125];
            //ChessboardLogics.GetChessboard(out board);

            for (int i = 0; i < 125; i++)
            {
                Square sq = squares[
                    4 - (i % 5),
                    4 - (int)(i / 25),
                    4 - (i / 5) % 5
                            ];

                sq.index = i;

                int piece = ChessboardLogics.GetPieceBySquare(i);
                if (piece < 8)
                {
                    PiecesTypes pt = (PiecesTypes)(Math.Abs(piece) - 1);
                    SideType    st;
                    if (piece < 0)
                    {
                        st = SideType.Black;
                    }
                    else
                    {
                        st = SideType.White;
                    }

                    new Piece(pt, Game, sq, st, squares);
                }
                else
                {
                    sq.OccupyingPiece = null;
                }
            }
        }
Пример #6
0
 void knightMenuEntry_Selected(object sender, PlayerIndexEventArgs e)
 {
     ChessboardLogics.MakeMove(moveToMake + Piece.PiecesTypesLetters[PiecesTypes.Knight]);
     DoMove(sender, e);
 }
Пример #7
0
        private void btnLoad_OnRelease(object obj, EventArgs e)
        {
            string FEN = loadedGames[((ComboBox)formCollection["frmGamePlayScreen"]["cmbLoadGame"]).Text];

            ChessboardLogics.SetChessboardToFEN(FEN);
        }
Пример #8
0
        public override void HandleInput(InputState input)
        {
            KeyboardState keybState = Keyboard.GetState();

            if ((keybState.IsKeyUp(Keys.T) && (IsTKeyDown)))
            {
                IsTKeyDown = false;
            }
            if (((keybState.IsKeyDown(Keys.T))
                 &&
                 ((keybState.IsKeyDown(Keys.LeftControl)) || (keybState.IsKeyDown(Keys.RightControl))))
                &&
                (!IsTKeyDown))
            {
                IsTKeyDown = true;

                //facciamo in modo che se si tira indietro tutti i giocatori diventino umani
                foreach (Side s in Game.StatusCurrent.Sides)
                {
                    s.PlayerType = PlayerType.Human;
                }

                //ricarichiamo la form in modo che mostri i dati aggiornati
                Game.FormCollection["frmGamePlayScreen"].Show();

                ChessboardLogics.Takeback();
                UpdateSquares();
            }

            if (!ChessboardLogics.IsComputerThinking() && (Mouse.GetState().LeftButton == ButtonState.Pressed))
            {
                PositionableModel closestClickedModel = GetClosestClickedModel();

                if (closestClickedModel != null)
                {
                    if (closestClickedModel.GetType() == typeof(Square)) //it is a selected square for sure
                    {
                        Square sq   = closestClickedModel as Square;
                        string move = SelectedPiece.OccupiedSquare.ToString() +
                                      sq.ToString();

                        if (ChessboardLogics.IsPromo(move))
                        {
                            screenManager.AddScreen(
                                new PromotionSelectionMenuScreen(move, SelectedPiece.OccupiedSquare, sq),
                                this.controllingPlayer
                                );
                        }
                        else
                        {
                            ChessboardLogics.MakeMove(move);
                            Game.StatusCurrent.Result = (PossibleResult)ChessboardLogics.GetResult();
                            //move the piece
                            SelectedPiece.OccupiedSquare.OccupyingPiece = null;
                            sq.OccupyingPiece = SelectedPiece;
                            Game.FormCollection["frmGamePlayScreen"]["lblTurn"].Text = "It's " + Game.StatusCurrent.SideToMove + " turn";

                            //UpdateSquares();
                            //if (Game.StatusCurrent.SideToMove == SideType.White)
                            //    Game.StatusCurrent.SideToMove = SideType.Black;
                            //else
                            //    Game.StatusCurrent.SideToMove = SideType.White;
                        }
                        SelectedPiece.IsSelected = false;
                        SelectedPiece            = null;
                        foreach (Square sqr in squares)
                        {
                            sqr.IsSelected = false;
                        }
                    }
                    else //else it's a piece
                    {
                        Piece clickedPiede = closestClickedModel as Piece;
                        if (clickedPiede.Side == Game.StatusCurrent.SideToMove)
                        {
                            if (SelectedPiece != null)
                            {
                                SelectedPiece.IsSelected = false;
                            }
                            //select all moveable squares
                            SelectedPiece            = closestClickedModel as Piece;
                            SelectedPiece.IsSelected = true;
                            string from = SelectedPiece.OccupiedSquare.ToString();

                            foreach (Square sq in squares)
                            {
                                string to = sq.ToString();
                                if (ChessboardLogics.CanMove(from + to) != 0)
                                {
                                    sq.IsSelected = true;
                                }
                                else
                                {
                                    sq.IsSelected = false;
                                }
                            }
                        }
                    }
                }
            }

            base.HandleInput(input);
        }