Exemplo n.º 1
0
        private void CleanPlayerState(Player.Name playerToClean)
        {
            // Clean player
            Player cleanPlayer = new Player(playerToClean);

            GameStateManager.GetGame().SetPlayer(playerToClean, cleanPlayer);

            //Find Player Points Font
            Font.Name pointsFont = Font.Name.Uninitialized;
            Font.Name livesFont  = Font.Name.Uninitialized;
            switch (playerToClean)
            {
            case Player.Name.Player1:
                pointsFont = Font.Name.Player1Score;
                livesFont  = Font.Name.Player1Lives;
                break;

            case Player.Name.Player2:
                pointsFont = Font.Name.Player2Score;
                livesFont  = Font.Name.Player2Lives;
                break;
            }

            // Update Points display
            Font pPlayerScoreFont = FontManager.Find(pointsFont);

            Debug.Assert(pPlayerScoreFont != null);
            pPlayerScoreFont.UpdateMessage(cleanPlayer.GetPoints().ToString("D4"));

            // Update Lives display
            Font pPlayerLivesFont = FontManager.Find(livesFont);

            Debug.Assert(pPlayerLivesFont != null);
            pPlayerLivesFont.UpdateMessage("LIVES " + cleanPlayer.GetNumLives().ToString());
        }
Exemplo n.º 2
0
 private void Init()
 {
     _boardState = new Player.State[BoardSize, BoardSize];
     CreateBoard(BoardSize);
     player1.Source = _x;
     player2.Source = _o;
     _gameEnd       = false;
     _turn          = Player.Name.Player1;
     ShowPlayerTurn("Click on Button and start New Game");
 }
Exemplo n.º 3
0
        private void OnMouseButtonUp(object sender, MouseButtonEventArgs e)
        {
            var shape = (Shape)sender;

            if (!_gameStart)
            {
                return;
            }
            if (_gameEnd)
            {
                return;
            }

            var pos = ParseCurrentPosition(shape.Name);
            var i   = pos[0];
            var j   = pos[1];

            if (HexToSolidColor(shape.Fill.ToString()).ToString() ==
                HexToSolidColor(BrickFillColor).ToString())
            {
                switch (_turn)
                {
                case Player.Name.Player1:
                    shape.Fill        = new ImageBrush(_o);
                    _turn             = Player.Name.Player2;
                    _boardState[i, j] = Player.State.O;
                    break;

                case Player.Name.Player2:
                    shape.Fill        = new ImageBrush(_x);
                    _turn             = Player.Name.Player1;
                    _boardState[i, j] = Player.State.X;
                    break;

                case Player.Name.None:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            var result = new GameLogic().CheckWinner(_boardState, _boardState[i, j]);

            ShowPlayerTurn();

            if (result.Name == Player.Name.None.ToString())
            {
                return;
            }
            _gameEnd   = true;
            _gameStart = false;
            ShowPlayerTurn($"(: {_turn} Wins :)");
        }
Exemplo n.º 4
0
        public PlayerDeathObserver(Player.Name inPlayerName)
        {
            this.playerName = inPlayerName;

            switch (inPlayerName)
            {
            case Player.Name.Player1:
                livesFont = Font.Name.Player1Lives;
                break;

            case Player.Name.Player2:
                livesFont = Font.Name.Player2Lives;
                break;
            }
        }
Exemplo n.º 5
0
        public AddPlayerPointsObserver(Player.Name inPlayerName)
        {
            this.playerName = inPlayerName;

            switch (inPlayerName)
            {
            case Player.Name.Player1:
                pointsFont = Font.Name.Player1Score;
                break;

            case Player.Name.Player2:
                pointsFont = Font.Name.Player2Score;
                break;
            }
        }
Exemplo n.º 6
0
        public void SetPlayer(Player.Name playerName, Player inPlayer)
        {
            Debug.Assert(inPlayer != null);

            switch (playerName)
            {
            case Player.Name.Player1:
                this.player1 = inPlayer;
                break;

            case Player.Name.Player2:
                this.player2 = inPlayer;
                break;

            default:
                // something is wrong
                Debug.Assert(false);
                break;
            }
        }
Exemplo n.º 7
0
        public Player GetPlayer(Player.Name playerName)
        {
            Player pPlayer = null;

            switch (playerName)
            {
            case Player.Name.Player1:
                pPlayer = this.player1;
                break;

            case Player.Name.Player2:
                pPlayer = this.player2;
                break;

            default:
                // something is wrong
                Debug.Assert(false);
                break;
            }

            return(pPlayer);
        }
Exemplo n.º 8
0
 public Player(Player.Name name)
 {
     this.name     = name;
     this.numLives = 3;
     this.points   = 0;
 }
Exemplo n.º 9
0
 public PlayerDeathObserver(PlayerDeathObserver pdo)
 {
     this.playerName = pdo.playerName;
     this.livesFont  = pdo.livesFont;
 }