示例#1
0
        private bool getAndPlayWords(string onBoard, int startX, int startY, bool isvert)
        {
            string[] lines     = System.IO.File.ReadAllLines("clean.txt");
            string   myletters = uit.GetPlayerLetters();
            string   word      = "";
            bool     wordworks = false;

            foreach (string line in lines)
            {
                if (line.Contains(onBoard) && line.Length < (onBoard.Length + myletters.Length))
                {
                    word = RemoveString(line, onBoard);

                    for (int x = 0; x < word.Length; x++)
                    {
                        if (myletters.Contains(word [x].ToString()))
                        {
                            myletters = RemoveString(myletters, word [x].ToString());
                            wordworks = true;
                        }
                        else
                        {
                            myletters = uit.GetPlayerLetters();
                            wordworks = false;
                            break;
                        }
                    }
                    if (wordworks)
                    {
                        if (isvert)
                        {
                            if (!vertDone.ContainsKey(word))
                            {
                                vertDone.Add(word, new int[] { startX, startY - line.IndexOf(onBoard [0]) });
                            }
                        }
                        else
                        {
                            if (!horDone.ContainsKey(word))
                            {
                                horDone.Add(word, new int[] { startX - line.IndexOf(onBoard [0]), startY });
                            }
                        }
                    }
                }
            }

            for (int i = horDone.Count - 1; i >= 0; --i)
            {
                //Console.WriteLine ("HOR: " + horDone.Keys [i]);
                if (playWord(horDone.Keys[i], horDone.Values[i][0], horDone.Values[i][1], false))
                {
                    return(true);
                }
            }
            for (int i = vertDone.Count - 1; i >= 0; --i)
            {
                //Console.WriteLine ("VERT: " + vertDone.Keys [i]);
                if (playWord(vertDone.Keys[i], vertDone.Values[i][0], vertDone.Values[i][1], true))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.TransparentBlack);

            //TODO: Add your drawing code her
            spriteBatch.Begin();
            if (ui.GetController().GameEnd() == false)
            {
                drawTextString(ui.GetLetterSelected().ToString(), 40, 16, 16);

                int boardX    = 200;
                int boardY    = 10;
                int boardsize = 350;
                int bw        = 2;          // Border width
                int bricksy   = boardsize + 30;

                //BRÄDE BAKGRUND:
                spriteBatch.Draw(ikonen, new Rectangle(boardX, boardY, boardsize, boardsize), Color.White);

                //KNAPPAR:
                spriteBatch.Draw(putword, new Rectangle(200, bricksy + boardsize / 7, 100, 50), Color.White);
                spriteBatch.Draw(newbricks, new Rectangle(200 + 120, bricksy + boardsize / 7, 100, 50), Color.White);
                spriteBatch.Draw(clear, new Rectangle(200 + 240, bricksy + boardsize / 7, 100, 50), Color.White);

                //SKRIVA UT BRÄDET:
                var t = new Texture2D(GraphicsDevice, 1, 1);
                t.SetData(new[] { Color.White });
                spriteBatch.Draw(t, new Rectangle(boardX, boardY, bw, boardsize), Color.White);                   // Left
                spriteBatch.Draw(t, new Rectangle(boardX + boardsize, boardY, bw, boardsize), Color.White);       // Right
                spriteBatch.Draw(t, new Rectangle(boardX, boardY, boardsize, bw), Color.White);                   // Top
                spriteBatch.Draw(t, new Rectangle(boardX, boardY + boardsize, boardsize, bw), Color.White);       // Bottom
                for (int i = 1; i < 15; i++)
                {
                    spriteBatch.Draw(t, new Rectangle(boardX, boardY + i * boardsize / 15, boardsize, bw), Color.White);
                    spriteBatch.Draw(t, new Rectangle(boardX + i * boardsize / 15, boardY, bw, boardsize), Color.White);
                }

                //SKRIVA UT SPELARENS BRICKOR:
                spriteBatch.Draw(t, new Rectangle(boardX, bricksy, boardsize, bw), Color.White);
                spriteBatch.Draw(t, new Rectangle(boardX, bricksy + boardsize / 7, boardsize, bw), Color.White);
                for (int i = 0; i < 8; i++)
                {
                    spriteBatch.Draw(t, new Rectangle(boardX + i * boardsize / 7, bricksy, bw, boardsize / 7), Color.White);
                }

                drawTextString(ui.GetPlayerLetters(), boardsize / 7, boardX, bricksy);
                String name   = ui.GetPlayerName();
                String points = ui.GetScore().ToString();

                drawTextString(points, 60 / points.Length, boardX + boardsize + 40, bricksy - 100);
                drawTextString(name, 160 / name.Length, boardX + boardsize + 40, bricksy);

                DrawBoard(350, 200, 10);
            }
            else
            {
                string winner = ui.GetWinnerName();
                drawTextString(winner + " won", 300 / winner.Length + 4, 100, 100);
            }

            spriteBatch.End();
            base.Draw(gameTime);
        }