Esempio n. 1
0
 public bool placeTile(Tile tile, int currentPlayer)
 {
     List<Tile> playerHand = playersHands.ElementAt<List<Tile>>(currentPlayer);
     if (tile != null && !placedpieces.Contains(tile) && playerHand.Contains(tile))
     {
         placedpieces.Add(tile);
         playerHand.Remove(tile);
         Tile nextTile = getRandomTile();
         if (nextTile != null) { playerHand.Add(nextTile); }
         return true;
     }
     return false;
 }
Esempio n. 2
0
        public void Draw(SpriteBatch spriteBatch, Tile clickedOnTile = null)
        {
            DrawAvaliableTiles(spriteBatch, clickedOnTile);

            foreach (Piece p in board)
            {
                p.Draw(spriteBatch, cameraOffset + new Vector2 (0, startOfBoard - oldStartOfBoard));
            }

            cameraOffset = Vector2.Zero;
            oldStartOfBoard = startOfBoard;
            startOfBoard = 0;
        }
Esempio n. 3
0
        public void DrawAvaliableTiles(SpriteBatch spriteBatch, Tile clickedOnTile = null)
        {
            List<Tile> bag = tileBag.GetPlayersBag(currentPlayer);
            int yvalue = 0;
            int offset = 0;
            for (int i = 0; i<bag.Count<Tile>(); i++)
            {
                if (((i-offset) * 100) > Game1.screenWidth)
                {
                    yvalue += (int)Game1.height;
                    offset = i;
                }

                Tile tile = bag.ElementAt<Tile>(i);
                if (tile != clickedOnTile)
                {
                    tile.Draw(spriteBatch, new Vector2(50 + 100 * (i - offset), 50 + yvalue), true, true);
                }
            }

            if(offset == bag.Count<Tile>())
            {
                startOfBoard = yvalue;
            }
            else
            {
                startOfBoard = yvalue + Game1.height;
            }

            Color colour = chooseColour();

            spriteBatch.Draw(Game1.tilebagtexture,
                            new Rectangle(0, 0, Game1.screenWidth, (int)startOfBoard),
                            null,
                            colour,
                            0,
                            Vector2.Zero,
                            SpriteEffects.None,
                            0.6f);
        }
Esempio n. 4
0
 public void PlaceTile(Tile tile)
 {
     this.tile = tile;
     tile.PlaceTile(location);
 }
Esempio n. 5
0
 public bool IsCompatible(Tile tile, float x, float y)
 {
     if (this.tile == null && where.Contains(new Point((int)x, (int)y)))
     {
         Color[] colours = tile.getColours();
         for(int i = 0; i < 6; i++)
         {
             Color thisColour = colours[i];
             if (adjacentPieces((AdjacentPiece)i) == null) { continue; }
             Tile otherTile = adjacentPieces((AdjacentPiece)i).tile;
             if (otherTile == null) { continue; }
             Color thatColour = otherTile.getColours()[(i+3)%6];
             if (thisColour == null || thatColour == null) { continue; }
             if (thisColour != thatColour) { return false; }
         }
         return true;
     }
     return false;
 }
Esempio n. 6
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            MouseState ms = Mouse.GetState();
            if (ms.LeftButton == ButtonState.Pressed)
            {
                if (movingCamera)
                {
                    board.moveCamera(ms.X, ms.Y, previousMouse.X, previousMouse.Y);
                }
                else
                {
                    if (previousMouse == null || previousMouse.LeftButton == ButtonState.Released)
                    {
                        clickedOnTile = board.getTileOnScreen(ms.X, ms.Y);
                        if (clickedOnTile == null) { movingCamera = true; }
                    }
                    if (clickedOnTile != null)
                    {
                        clickedOnTile.SetLocation(new Vector2(ms.X, ms.Y));
                    }
                }
            }
            else if (ms.LeftButton == ButtonState.Released && previousMouse.LeftButton == ButtonState.Pressed)
            {
                if (clickedOnTile != null)
                {
                    board.PlaceTile(clickedOnTile, ms.X, ms.Y);
                    clickedOnTile = null;
                }
                else if (movingCamera)
                {
                    movingCamera = false;
                }
            }
            else
            {
                clickedOnTile = null;
            }

            if (clickedOnTile != null && /*Keyboard.GetState().IsKeyDown(Keys.Right)) //*/ms.RightButton == ButtonState.Pressed && previousMouse.RightButton == ButtonState.Released)
            {
                clickedOnTile.Rotate();
            }

            previousMouse = ms;

            // TODO: Add your update logic here

            base.Update(gameTime);
        }
Esempio n. 7
0
        public void PlaceTile(Tile tile, float x, float y)
        {
            foreach (Piece piece in board)
            {
                if (piece.IsCompatible(tile, x, y) && tileBag.placeTile(tile, currentPlayer))
                {
                    piece.PlaceTile(tile);

                    updateBoard(piece);

                    swapPlayersTurn();
                    break;
                }
            }
        }