示例#1
0
 /// <summary>
 /// Helper method for taking action upon a button press
 /// </summary>
 /// <param name="b">The button that has been pressed</param>
 private void ButtonAction(Button b)
 {
     Contract.Requires(b != null);
     Contract.Ensures(
         game.State == GameState.StartUp
         ||
         (PirateHost.IsValidGameName(serverName.Text)
              ? (game.Host != null && game.Client != null && game.PlayingGame != null
                 && game.State == GameState.InGame)
              : game.State == GameState.CreateGame));
     var str = b.Name;
     switch(str) {
         case "creategame":
             if(serverName.Text == "" || !PirateHost.IsValidGameName(serverName.Text)) {
                 return;
             }
             var players = numberOfPlayers.ParseInput();
             var sName = serverName.Text;
             var host = new PirateHost(4939);
             host.Start(sName, players);
             var client = new PirateClient(game.PlayerName, host.Ip, 4939);
             PirateClientCommands.SendPlayerInfo(client);
             var playingGame = new Game();
             game.GameName = sName;
             game.MaxPlayers = players;
             game.Host = host;
             game.Client = client;
             client.SetGame(playingGame);
             game.PlayingGame = playingGame;
             game.State = GameState.InGame;
             break;
         case "cancelcg":
             game.State = GameState.StartUp;
             break;
     }
 }
示例#2
0
        /// <summary>
        /// Set up the create game screen
        /// </summary>
        private void SetUp()
        {
            backGround = new Sprite { Color = Color.White };
            var x = game.Window.ClientBounds.Width / 2 - 400 / 2;
            var y = game.Window.ClientBounds.Height / 2 - 400 / 2;
            backGround.Position = new Vector2(x, y);

            var cgX = x;
            var cgY = y + 325;
            createGame = new Button("creategame", cgX, cgY);

            var cancelX = x + 250;
            var cancelY = y + 325;
            cancel = new Button("cancelcg", cancelX, cancelY);

            var rect = new Rectangle(x + 250, y + 200, 100, 50);
            numberOfPlayers = new Numberbox(rect, "volumebox", 1) { Limit = 5, Number = 5 };
            numberOfPlayers.Text = numberOfPlayers.Number.ToString();

            var sRect = new Rectangle(x + 150, y + 100, 250, 75);
            serverName = new Textbox(sRect, "playername");
            serverName.MoveText(45);

            namePos = new Vector2(x + 10, y + 125);
            playersPos = new Vector2(x + 10, y + 225);

            buttons = new List<Button> { this.cancel, this.createGame };
        }
示例#3
0
 /// <summary>
 /// Helper method for taking action upon a button press
 /// </summary>
 /// <param name="b">The button to take action upon</param>
 private void ButtonAction(Button b)
 {
     Contract.Requires(b != null);
     var str = b.Name;
     switch(str) {
         case "joingame":
             game.State = GameState.JoinGame;
             break;
         case "creategame":
             game.State = GameState.CreateGame;
             break;
         case "rules":
             rulesEnabled = true;
             break;
         case "settings":
             playername.Text = this.game.PlayerName;
             settingsEnabled = true;
             break;
         case "back":
             rulesEnabled = false;
             break;
         case "cancel":
             CancelChanges();
             settingsEnabled = false;
             break;
         case "apply":
             if(this.ApplyChanges()) {
                 settingsEnabled = false;
             }
             break;
         case "exit":
             game.State = GameState.Exit;
             break;
     }
 }
示例#4
0
 /// <summary>
 /// Set up the settings menu
 /// </summary>
 private void SetUpSettings()
 {
     settingsButton = new List<Button>();
     settings = new Sprite { Color = Color.White };
     int settingsX = game.Window.ClientBounds.Width / 2 - 600 / 2;
     int settingsY = game.Window.ClientBounds.Height / 2 - 468 / 2;
     settings.Position = new Vector2(settingsX, settingsY);
     int cancelX = settingsX + 425;
     int cancelY = settingsY + 400;
     cancel = new Button("cancel", cancelX, cancelY);
     settingsButton.Add(cancel);
     int applyX = settingsX + 40;
     int applyY = settingsY + 400;
     apply = new Button("apply", applyX, applyY);
     settingsButton.Add(apply);
     var rect = new Rectangle(settingsX + (600-325), settingsY + 100, 250, 75);
     playername = new Textbox(rect, "playername") { Text = this.game.PlayerName };
     playername.MoveText(45);
     playerNamePos = new Vector2(settingsX+100, settingsY + 125);
     var volumeRect = new Rectangle(settingsX + (600 - 325) + 100, settingsY + 185, 100, 50);
     var a = (int)(game.MusicVolume * 100);
     volume = new Numberbox(volumeRect, "volumebox", 3) { Number = a, Limit = 100 };
     volume.Text = volume.Number.ToString();
     volumePos = new Vector2(settingsX + 100, settingsY + 200);
     scoreboardPos = new Vector2(settingsX + 100, settingsY + 250);
     menuPos = new Vector2(settingsX + 100, settingsY + 325);
 }
示例#5
0
 /// <summary>
 /// Helper method for setting a name if none has been specified yet
 /// </summary>
 private void SetName()
 {
     settingname = true;
     namePopUp = new Sprite();
     namePopUp.LoadContent(this.Content, "PopUp");
     int x = this.Window.ClientBounds.Width / 2 - namePopUp.Tex.Width / 2;
     int y = this.Window.ClientBounds.Height / 2 - namePopUp.Tex.Height / 2;
     namePopUp.Position = new Vector2(x, y);
     var rect = new Rectangle(x + (namePopUp.Tex.Width - 250), y + 50, 250, 75);
     textbox = new Textbox(rect, "playername") { Text = this.PlayerName, Typable = true };
     textbox.MoveText(45);
     textbox.LoadContent(this.Content);
     int okX = x + namePopUp.Tex.Width / 2 - 75;
     int okY = y + 150;
     ok = new Button("ok", okX, okY);
     ok.LoadContent(this.Content);
 }
示例#6
0
 /// <summary>
 /// Set up the rules menu
 /// </summary>
 public void SetUpRules()
 {
     rules = new Sprite { Color = Color.White };
     int rulesX = game.Window.ClientBounds.Width / 2 - 450 / 2;
     int rulesY = game.Window.ClientBounds.Height / 2 - 588 / 2;
     rules.Position = new Vector2(rulesX, rulesY);
     int backX = (rulesX + 450) / 2 + Button.Width / 2;
     int backY = (rulesY + 515);
     back = new Button("back", backX, backY);
 }
示例#7
0
 /// <summary>
 /// Helper method for taking action upon a button press
 /// </summary>
 /// <param name="b">The button that has been pressed</param>
 private void ButtonAction(Button b)
 {
     if(b == null) {
         return;
     }
     var str = b.Name;
     switch(str) {
         case "ok":
             if(Regex.IsMatch(textbox.Text, @"^\w{3,20}$")) {
                 settingname = false;
                 this.PlayerName = textbox.Text;
             } else {
                 settingname = true;
             }
             break;
     }
 }
示例#8
0
        /// <summary>
        /// Set up the screen
        /// </summary>
        private void SetUp()
        {
            backGround = new Sprite() { Color = Color.White };
            var x = game.Window.ClientBounds.Width / 2 - 800 / 2;
            var y = game.Window.ClientBounds.Height / 2 - 500 / 2;
            backGround.Position = new Vector2(x, y);

            var serversX = x + 75;
            var serversY = y + 75;

            serversRectangle = new Rectangle(serversX, serversY, 650, 30);
            this.SetUpServers();

            xButton = new Button("X", x + 650, game.Window.ClientBounds.Height / 2 - 500 / 2 - 10);
            var buttonx = x + 650;
            var buttony = game.Window.ClientBounds.Height / 2 + 200;
            back = new Button("backjoingame", buttonx, buttony);
            buttonx -= Button.Width;
            refreshButton = new Button("refresh", buttonx, buttony);
            buttonx -= Button.Width;
            joinGameButton = new Button("jointhisgame", buttonx, buttony);
            buttons = new List<Button> { this.xButton, this.refreshButton, this.joinGameButton, this.back };
        }
示例#9
0
 /// <summary>
 /// Helper method for taking action upon a button press
 /// </summary>
 /// <param name="b">The button that has been pressed</param>
 private void ButtonAction(Button b)
 {
     Contract.Requires(b != null);
     var str = b.Name;
     switch(str) {
         case "jointhisgame":
             this.JoinSelectedGame();
             break;
         case "refresh":
             this.Refresh();
             break;
         case "backjoingame":
             game.State = GameState.StartUp;
             break;
         case "X":
             game.State = GameState.StartUp;
             break;
     }
 }
示例#10
0
        /// <summary>
        /// Set up the ingame screen
        /// </summary>
        private void SetUp()
        {
            if(game.Host == null) {
                hosting = false;
            } else {
                host = game.Host;
                hosting = true;
            }
            client = game.Client;
            gameName = game.GameName;
            maxPlayers = game.MaxPlayers;

            client.Disconnected += OnDisconnected;
            client.BetRequested += OnBetRequest;
            client.CardRequested += OnCardRequest;
            client.Game.RoundStarted += OnGameStarted;
            client.Game.GameFinished += OnGameFinished;
            client.Game.RoundFinished += OnRoundFinished;

            cards = new List<CardSprite>();

            inJoinbackGround = new Sprite { Color = Color.White };
            var x = game.Window.ClientBounds.Width / 2 - 400 / 2;
            var y = game.Window.ClientBounds.Height / 2 - 500 / 2;
            inJoinbackGround.Position = new Vector2(x, y);

            leaveGame = new Button("leavegame", x + 250, y + 450);

            if(hosting) {
                startGame = new Button("startgame", x, y + 450);
            }

            playerPos = new Vector2(x + 20, y + 85);

            maxPlayerPos = new Vector2(x + 175, y + 85);

            gamePos = new Vector2(x + 5, y + 60);

            namesRectangle = new Rectangle(x + 5, y + 150, 200, 30);

            menu = new Sprite { Color = Color.White };
            var menuX = game.Window.ClientBounds.Width / 2 - 300 / 2;
            var menuY = game.Window.ClientBounds.Height / 2 - 420 / 2;
            menu.Position = new Vector2(menuX, menuY);
            menuX += 75;
            menuY += 100;
            resumeGame = new Button("resumegame", menuX, menuY);
            menuY += Button.Height;
            menuleaveGame = new Button("leavegame", menuX, menuY);
            menuY += Button.Height;
            exitGame = new Button("exitgame", menuX, menuY);
            menuButtons = new List<Button> { this.menuleaveGame, this.resumeGame, this.exitGame };

            var rect = new Rectangle(900, 520, 100, 50);
            betBox = new Numberbox(rect, "bettingbox", 2) { Limit = 10, Number = 0, Locked = false };
            betBox.Text = betBox.Number.ToString();

            bet = new Button("bet", 860,  565);

            cardSize = new Rectangle(5, 615, 100, 120);

            scoreRectangle = new Rectangle(1024-175, 0, 75, 20);

            scoreOverlayRect = new Rectangle(1024-177, 0, 177, 520);

            ingameBottom = new Rectangle(0,615, 1024, 120);
        }
示例#11
0
        /// <summary>
        /// Helper method for taking action upon a button press
        /// </summary>
        /// <param name="b">The button that has been pressed</param>
        private void ButtonAction(Button b)
        {
            Contract.Requires(b != null);
            var str = b.Name;
            switch(str) {
                case "startgame":
                    if(host.Game.Players.Count >= Game.MinPlayersInGame && host.Game.Players.Count <= Game.MaxPlayersInGame) {
                        host.StartGame();

                    }
                    break;
                case "bet":
                    if(client.Game.Round.PlayerBets[client] > -1) {
                        return;
                    }
                    betBox.Locked = true;
                    hasBet = true;
                    break;
                case "resumegame":
                    showMenu = false;
                    break;
                case "leavegame":
                    client.Disconnect();
                    game.Client = null;
                    if(hosting) {
                        host.Stop();
                        game.Host = null;
                    }
                    game.State = GameState.StartUp;
                    break;
                case "exitgame":
                    client.Disconnect();
                    game.Client = null;
                    if(hosting) {
                        host.Stop();
                        game.Host = null;
                    }
                    game.State = GameState.Exit;
                    break;
            }
        }