コード例 #1
0
        public Form1()
        {
            InitializeComponent();

            Settings = new SettingsFile("settings.xml");

            // setup window
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
            this.Text = Settings["window_title"];


            this.Size = new Size(Convert.ToInt32(Settings["width"]), Convert.ToInt32(Settings["height"]));


            // set the game type
            if (Settings["game"] == "Crazy8")
            {
                game = GameType.CRAZY8;
            }
            else if (Settings["game"] == "Poker")
            {
                game = GameType.POKER;
            }
            else if (Settings["game"] == "Blackjack")
            {
                game = GameType.BLACKJACK;
            }


            // initialize the games

            switch (game)
            {
            case GameType.POKER:
                PokerBoard = new PokerGraphics(this.Width, this.Height, Settings["picture_list"]);
                Poker      = new PokerGame(PokerBoard);
                Poker.Play();
                break;

            case GameType.CRAZY8:
                Crazy8Board = new Crazy8Graphics(this.Width, this.Height, Settings["picture_list"]);
                Crazy8      = new Crazy8Game(Crazy8Board);
                Crazy8.Play();
                break;
            }
        }
コード例 #2
0
        /*
         * This is where all the real action takes place
         */
        public override void MouseButtonHandler(int Mx, int My, MouseButtons Mb, CardGame game)
        {
            Crazy8Game Game = (Crazy8Game)game; // downcast


            // first check to see if the mouse was clicked in one of the player cards
            // See if the mouse is in any of the player cards
            for (int i = 0; i < PlayerBox.Length; ++i)
            {
                if (PlayerBox[i].CheckPoint(Mx, My))
                {
                    int cardPosition = MouseInCardPosition(Mx, My, PlayerBox[i].Dimension);
                    // here we know what card was clicked

                    // the player is i
                    // the card is cardPosition
                    Game.MouseClickedInPlayerCard(i, cardPosition);

                    // we found where they clicked so lets return
                    return;
                }
            }

            if (newGameButton.CheckPoint(Mx, My))  // if the user clicks in on the new button we start a new game
            {
                game.Play();
            }
            else if (drawButton.CheckPoint(Mx, My)) // if the user clicks in the draw button we will tell the game that player wants to draw a new card
            {
                Game.MouseClickedOnDraw();
            }
            else if (drawButton.CheckPoint(Mx, My))// if the user clicks the undo button, we need to undo the players last action
            {
                Game.MouseClickedOnUndo();
            }
        }