Пример #1
0
        public void GetWordListFourByFourShape()
        {
            /*
             *  x o x o
             *  o x o x
             *  x o x o
             *  o x o x
             */

            _gameBoard.ClearBoard();

            var xTile = new Tile("x");
            var oTile = new Tile("o");

            _gameBoard.SetBoardSpace(xTile, 0, 0);
            _gameBoard.SetBoardSpace(xTile, 0, 2);
            _gameBoard.SetBoardSpace(xTile, 1, 1);
            _gameBoard.SetBoardSpace(xTile, 1, 3);
            _gameBoard.SetBoardSpace(xTile, 2, 0);
            _gameBoard.SetBoardSpace(xTile, 2, 2);
            _gameBoard.SetBoardSpace(xTile, 3, 1);
            _gameBoard.SetBoardSpace(xTile, 3, 3);

            _gameBoard.SetBoardSpace(oTile, 0, 1);
            _gameBoard.SetBoardSpace(oTile, 0, 3);
            _gameBoard.SetBoardSpace(oTile, 1, 0);
            _gameBoard.SetBoardSpace(oTile, 1, 2);
            _gameBoard.SetBoardSpace(oTile, 2, 1);
            _gameBoard.SetBoardSpace(oTile, 2, 3);
            _gameBoard.SetBoardSpace(oTile, 3, 0);
            _gameBoard.SetBoardSpace(oTile, 3, 2);

            var wordList = _gameBoard.GetWordList();

            Assert.IsTrue(wordList.Count == 8);

            int xoxoCount = 0;
            int oxoxCount = 0;
            foreach (var word in wordList)
            {
                if (word._string == "xoxo")
                {
                    xoxoCount++;
                }
                else if (word._string == "oxox")
                {
                    oxoxCount++;
                }
            }

            Assert.AreEqual(xoxoCount, 4);
            Assert.AreEqual(oxoxCount, 4);

            _gameBoard.ClearBoard();
        }
Пример #2
0
        public void ClearNonEmptyBoard()
        {
            var newTile = new Tile("A");

            _gameBoard.SetBoardSpace(newTile, 0, 0);
            _gameBoard.SetBoardSpace(newTile, GameBoard.BoardSpaceDimension - 1, 0);
            _gameBoard.SetBoardSpace(newTile, 0, GameBoard.BoardSpaceDimension - 1);
            _gameBoard.SetBoardSpace(newTile, GameBoard.BoardSpaceDimension - 1, GameBoard.BoardSpaceDimension - 1);

            _gameBoard.ClearBoard();
            var wordList = _gameBoard.GetWordList();

            Assert.IsTrue(wordList.Count == 0);
        }
Пример #3
0
 /// <summary>
 /// Server initiated dump action
 /// </summary>
 public void DumpReceived(Tile tileOne, Tile tileTwo)
 {
     //ToDo: Use the arguments here and remove those tiles instead of 2 random ones.
     SelectRandomTileFromPile();
     SelectRandomTileFromPile();
 }
Пример #4
0
 public void returnTileToHand(Tile returningTile)
 {
     _currentHand.Add(returningTile);
 }
Пример #5
0
 public void removeTileFromHand(Tile tile)
 {
     var tileToRemove = _currentHand.FirstOrDefault(t => t.TileContents == tile.TileContents);
     _currentHand.Remove(tileToRemove);
 }
Пример #6
0
 public void PeelActionReceived(Tile incomingTile)
 {
     _playerTileSet.returnTileToHand(incomingTile);
 }
Пример #7
0
 public void ReturnTileToRack(string tileContents)
 {
     var newTile = new Tile(tileContents);
     _playerTileSet.returnTileToHand(newTile);
 }
Пример #8
0
 public void RemoveTileFromRack(string tileContents)
 {
     var newTile = new Tile(tileContents);
     _playerTileSet.removeTileFromHand(newTile);
 }
Пример #9
0
        /// <summary>
        /// This method is invoked whenever someone from the server performs a 
        /// dump action.
        /// </summary>
        /// <param name="actionSender">The person who performed the dump action</param>
        /// <param name="returnedTile"></param>
        public async Task<List<Tile>> PerformDumpAction(string actionSender, Tile returnedTile)
        {
            var tiles = _tileManager.PerformDumpAction(returnedTile);


            //
            // If the dump failed, return an empty tile list
            //

            if (tiles == null)
            {
                return new List<Tile>();
            }

            var viewModel = GameBoardViewModel.GetInstance();

            _gameDataLogger.LogMove(actionSender, viewModel.GameTime, MoveType.Dump);

            viewModel.TilePileCount -= 2;

            var serverProxy = ServerProxy.GetInstance();

            if (serverProxy.messageSender != null)
            {
                // ToDo: Send the actionsender name here instead of the client name in case it's a bot that's dumping.
                await serverProxy.messageSender.SendMessage(PacketType.c_Dump);
            }

            return tiles;
        }
Пример #10
0
        public void GetWordListYDimension()
        {
            var aTile = new Tile("a");
            var bTile = new Tile("b");
            var cTile = new Tile("c");
            var dTile = new Tile("d");
            var eTile = new Tile("e");
            var fTile = new Tile("f");

            _gameBoard.ClearBoard();

            _gameBoard.SetBoardSpace(aTile, 0, 0);
            _gameBoard.SetBoardSpace(bTile, 0, 1);
            _gameBoard.SetBoardSpace(cTile, 0, 2);
            _gameBoard.SetBoardSpace(dTile, 0, 3);
            _gameBoard.SetBoardSpace(eTile, 0, 4);
            _gameBoard.SetBoardSpace(fTile, 0, 5);

            var wordList = _gameBoard.GetWordList();

            Assert.IsTrue(wordList.Count == 1);
            Assert.AreEqual("abcdef", wordList[0]._string);
            _gameBoard.ClearBoard();
        }
Пример #11
0
        public void GetWordListOnInvalidBoard()
        {
            const string testWord = "Hello";

            var newTile = new Tile(testWord);

            _gameBoard.ClearBoard();

            _gameBoard.SetBoardSpace(newTile, 0, 0);
            _gameBoard.SetBoardSpace(newTile, GameBoard.BoardSpaceDimension - 1, 0);
            _gameBoard.SetBoardSpace(newTile, 0, GameBoard.BoardSpaceDimension - 1);
            _gameBoard.SetBoardSpace(newTile, GameBoard.BoardSpaceDimension - 1, GameBoard.BoardSpaceDimension - 1);

            var wordList = _gameBoard.GetWordList();

            //
            // This is an invalid game board, so expected word count length is 0
            //

            Assert.IsTrue(wordList.Count == 0);

            _gameBoard.ClearBoard();
        }
Пример #12
0
        public void GetWordListHollowBoxShape()
        {
            /*
             *  b o b
             *  o   o
             *  b o b
             */

            _gameBoard.ClearBoard();

            var bTile = new Tile("b");
            var oTile = new Tile("o");

            _gameBoard.SetBoardSpace(bTile, 5, 5);
            _gameBoard.SetBoardSpace(bTile, 5, 7);
            _gameBoard.SetBoardSpace(bTile, 7, 5);
            _gameBoard.SetBoardSpace(bTile, 7, 7);

            _gameBoard.SetBoardSpace(oTile, 5, 6);
            _gameBoard.SetBoardSpace(oTile, 6, 5);
            _gameBoard.SetBoardSpace(oTile, 6, 7);
            _gameBoard.SetBoardSpace(oTile, 7, 6);

            var wordList = _gameBoard.GetWordList();

            Assert.IsTrue(wordList.Count == 4);

            foreach (var word in wordList)
            {
                Assert.AreEqual("bob", word._string);
            }

            _gameBoard.ClearBoard();
        }
Пример #13
0
        public void SetBoardSpace(Tile tile, int i, int j)
        {
            Debug.Assert(i >= 0);
            Debug.Assert(i < BoardSpaceDimension);
            Debug.Assert(j >= 0);
            Debug.Assert(j < BoardSpaceDimension);

            if (tile.TileContents.Length > 0)
            {
                _boardMatrix[i, j]._isOccupied = true;
                _boardMatrix[i, j]._tile = tile;
            }
        }
Пример #14
0
        /// <summary>
        /// Resets the pile
        /// </summary>
        private async Task<bool> CreateNewPileSet()
        {
            bool isReady = true;

            _pile.Clear();


            //
            // Read the tile information from the TileSet XML file to create the initial
            // pool of tiles.
            //

            StorageFile file = null;

            try
            {
                var uri = new Uri(Filename);
                file = await StorageFile.GetFileFromApplicationUriAsync(uri).AsTask().ConfigureAwait(false);
            }
            catch (FileNotFoundException)
            {
                //ToDo: do some shit
                isReady = false;
            }

            if (file != null)
            {
                using (var stream = await file.OpenReadAsync())
                {
                    using (var reader = XmlReader.Create(stream.AsStreamForRead()))
                    {
                        reader.ReadToFollowing("TileSet");

                        while (!reader.EOF)
                        {
                            reader.ReadToFollowing("Letter");

                            var tileContents = reader.GetAttribute("Value");

                            if (reader.MoveToAttribute("Count"))
                            {
                                var count = reader.ReadContentAsInt();

                                for (var i = 0; i < count; i++)
                                {
                                    var newTile = new Tile { TileContents = tileContents };
                                    _pile.Add(newTile);
                                }
                            }
                        }
                    }
                }
            }

            return isReady;
        }
        /// <summary>
        /// Maps to a dump now.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async void boxOne_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
        {
            var gameController = GameController.GetInstance();

            var box = sender as Grid;

            if (box == null)
            {
                return;
            }
            var textBlock = box.Children[1] as TextBlock;

            var returnedTile = new Tile(textBlock.Text);

            //ToDo: The line below is super hacky...yuck yuck.  Should not use app.clientbuddyinstance here, but instead use the performdumpaction method of humanplayer.cs
            var tiles = await gameController.PerformDumpAction(Settings.Alias, returnedTile);


            //
            // If there aren't enough tiles left for a dump, then return the tile back to the 
            // rack.
            //

            if (tiles.Count == 0)
            {
                return;
            }

            else
            {
                if (box.Parent == TileRackUi)
                {
                    _tileRack.RemoveTile(box);
                    gameController.RemoveTileFromRack(textBlock.Text);
                }

                foreach (var tile in tiles)
                {
                    var newTile = CreateLetterTile(tile.TileContents);
                    _tileRack.AddTile(newTile);
                    gameController.ReturnTileToRack(tile.TileContents);
                }

                //ToDo: Figure out how to move this shit back to XAML...God damn it XAML.
                var scaleXAnimation = new DoubleAnimation();
                scaleXAnimation.Duration = TimeSpan.FromMilliseconds(500);
                scaleXAnimation.To = 0;
                Storyboard.SetTargetProperty(scaleXAnimation, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)");

                var scaleYAnimation = new DoubleAnimation();
                scaleYAnimation.Duration = TimeSpan.FromMilliseconds(500);
                scaleYAnimation.To = 0;
                Storyboard.SetTargetProperty(scaleYAnimation, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");

                var rotationAnimation = new DoubleAnimation();
                rotationAnimation.Duration = TimeSpan.FromMilliseconds(500);
                rotationAnimation.To = 720;
                Storyboard.SetTargetProperty(rotationAnimation, "(UIElement.RenderTransform).(CompositeTransform.Rotation)");

                var TileVanishStoryboard = new Storyboard();

                TileVanishStoryboard.Children.Add(scaleXAnimation);
                TileVanishStoryboard.Children.Add(scaleYAnimation);
                TileVanishStoryboard.Children.Add(rotationAnimation);


                box.RenderTransform = new CompositeTransform();
                box.RenderTransformOrigin = new Point(.5, .5);

                //Storyboard.SetTarget(TileVanishStoryboard, box);
                //TileVanishStoryboard.Begin();
                //TileVanishStoryboard.Completed += TileSpinAndVanish_Completed;

                TileSpinAndVanish.Stop();
                Storyboard.SetTarget(TileSpinAndVanish, box);
                TileSpinAndVanish.Begin();
                PlayDumpAnimation(Settings.Alias);

                TileSpinAndVanish.Completed += TileSpinAndVanish_Completed;

                // ToDo: Remove this sleep and use the TileSpinAndVanishCompleted EH.
                await Task.Delay(500);


                //
                // Clear the game board spot from where the tile was dumped
                //

                var curColumn = (int)box.GetValue(Grid.ColumnProperty);
                var curRow = (int)box.GetValue(Grid.RowProperty);

                gameController = GameController.GetInstance();
                gameController.ClearBoardSpace(_westLimit + curColumn, _northLimit + curRow);

                
                box.Visibility = Visibility.Collapsed;
                GameBoard.Children.Remove(box);

                //_playedTiles.Remove(box); huh?  what's the purpose of this...


            }
        }
Пример #16
0
        /// <summary>
        /// User (not server) initiated dump action
        /// </summary>
        /// <param name="returnedTile"></param>
        /// <returns>null if dump failed, otherwise returns 3 tiles.</returns>
        public List<Tile> PerformDumpAction(Tile returnedTile)
        {
            var tiles = SelectRandomTileSetFromPile(3);


            //
            // If the dump action failed (b/c there aren't enough tiles left to do a dump, then
            // don't return the tile to the pile.  Instead, let the GameController return it 
            // back to the tile rack.
            //

            if (tiles != null)
            {
                _pile.Add(returnedTile);
            }

            return tiles;
        }
Пример #17
0
        /// <summary>
        /// Methods that interface between the GameBoard UI and the game board data class of the
        /// GameController.
        /// </summary>
        #region Game Board UI Interface

        public void SetBoardSpace(string contents, int i, int j)
        {
            var newTile = new Tile(contents);
            _gameBoard.SetBoardSpace(newTile, i, j);
        }