Exemplo n.º 1
0
        public bool IsWordPutCorrect(Cell StartCell, bool Vertical, int Length)
        {
            int Index;
            Board.Board GameBoard = GameModel.GetBoard();
            Cell FirstNeighbour, SecondNeighbour;

            if(Vertical)
            {
                Index = StartCell.GetXColumnCoordinate();
                Row TempRow;

                for(int i = 0; i < Length; ++i)
                {
                    int y = StartCell.GetYRowCoordinate();
                    int x = StartCell.GetXColumnCoordinate();
                    TempRow = GameBoard.FindRow(y + i);

                    FirstNeighbour = TempRow.Get(x + 1);
                    SecondNeighbour = TempRow.Get(x - 1);

                    if(FirstNeighbour != null && FirstNeighbour.GetTile() != null)
                    {
                        return true;
                    }
                    if(SecondNeighbour != null && SecondNeighbour.GetTile() != null)
                    {
                        return true;
                    }
                }
            }
            else
            {
                Index = StartCell.GetYRowCoordinate();
                Column TempColumn;

                for(int i = 0; i < Length; ++i)
                {
                    int y = StartCell.GetYRowCoordinate();
                    int x = StartCell.GetXColumnCoordinate();
                    TempColumn = GameBoard.FindColumn(x + i);

                    FirstNeighbour = TempColumn.Get(y + 1);
                    SecondNeighbour = TempColumn.Get(y - 1);

                    if(FirstNeighbour != null && FirstNeighbour.GetTile() != null)
                    {
                        return true;
                    }
                    if(SecondNeighbour != null && SecondNeighbour.GetTile() != null)
                    {
                        return true;
                    }
                }
            }
            return false;
        }
Exemplo n.º 2
0
 public Cell(Cell ToCopyCell)
 {
     this.CellCoordinates = new Coordinates(ToCopyCell.GetXColumnCoordinate(), ToCopyCell.GetYRowCoordinate());
     this.WordMultiplier = ToCopyCell.GetWordMultiplier();
     this.LetterMultiplier = ToCopyCell.GetLetterMultiplier();
     if(ToCopyCell.GetTile() != null)
     {
         this.Tile = new Tile(ToCopyCell.GetTile());
     }
     else
     {
         this.Tile = null;
     }
     this.Visited = ToCopyCell.IsVisited();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Metoda sprawdza czy da sie zgodnie z zasadami gry ulozyc slowo, ktora zaczyna sie od pola przekazanego w argumencie wywolania
        /// </summary>
        /// <param name="StartCell"></param>
        /// <param name="Vertical">Flaga informujaca czy sprawdzamy czy slowo da sie ulozyc w pionie czy poziomie</param>
        /// <returns></returns>
        public bool IsPositionCorrect(Cell StartCell, bool Vertical)
        {
            Container ConsideredContainer;
            Container LeftNeighbour;
            Container RightNeighbour;
            int CellIndex;
            Cell TempCell;

            if(Vertical) //jesli sprawdzamy czy da sie ulozyc slowo pionowo
            {
                ConsideredContainer = GameBoard.FindColumn(StartCell);
                CellIndex = StartCell.GetYRowCoordinate();
                LeftNeighbour = GameBoard.FindColumn(StartCell.GetXColumnCoordinate() - 1);
                RightNeighbour = GameBoard.FindColumn(StartCell.GetXColumnCoordinate() + 1);
            }
            else
            {
                ConsideredContainer = GameBoard.FindRow(StartCell);
                CellIndex = StartCell.GetXColumnCoordinate();
                LeftNeighbour = GameBoard.FindRow(StartCell.GetYRowCoordinate() - 1);
                RightNeighbour = GameBoard.FindRow(StartCell.GetYRowCoordinate() + 1);
            }

            TempCell = ConsideredContainer.Get(CellIndex - 1);
            if(TempCell != null) //Sprawdzenie, czy ponad polem nie znajduje sie juz jakis znak
            {
                if(TempCell.IsVisited())
                {
                    return false;
                }
            }

            if(StartCell.IsVisited())
            {
                for(int i = CellIndex + 1; i < GameBoard.GetBoardSide(); ++i) //Sprawdzenie, czy za rozpatrywanym polem pozostały jakies wolne pola
                {
                    if(!ConsideredContainer.Get(i).IsVisited())
                    {
                        return true;
                    }
                }
                return false;
            }

            if(GetFirstLetterDistance(ConsideredContainer, CellIndex + 1) <= Configuration.MaxLetterNumber) //plus jeden bo zaczynamy od pierwszego zajetego pola
            {
                return true;
            }
            if(GetFirstLetterDistance(LeftNeighbour, CellIndex) <= Configuration.MaxLetterNumber)
            {
                return true;
            }
            if(GetFirstLetterDistance(RightNeighbour, CellIndex) <= Configuration.MaxLetterNumber)
            {
                return true;
            }
            return false;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Metoda sprawdzajaca czy wlozenie slowa nie sprawi ze na planszy znajda sie ciagi znakow nie bedace slowami
        /// </summary>
        /// <param name="Word"></param>
        /// <param name="StartCell"></param>
        /// <param name="Vertical"></param>
        /// <returns></returns>
        public bool IsMoveCorrect(String Word, Cell StartCell, bool Vertical)
        {
            int Index;

            if(Vertical)//Sprawdzenie czy wstawienie slowa nie spowodowalo polaczenia ze soba dwoch slow na planszy tworzac tym samym niepoprawne slowo
            {
                Column TempColumn = GameBoard.FindColumn(StartCell.GetXColumnCoordinate());
                String NewWord = String.Copy(Word);
                Index = StartCell.GetYRowCoordinate() + Word.Length; //Indeks pola bezposrednio za slowem.

                if(Index < GameBoard.GetBoardSide())
                {
                    Cell TempCell = TempColumn.Get(Index);

                    while(TempCell != null && TempCell.IsVisited())
                    {
                        NewWord += TempCell.GetTile().GetLetter();
                        TempCell = TempColumn.Get(++Index);
                    }
                }

                if(!GameDictionary.Exists(NewWord))
                {
                    return false;
                }
            }
            else
            {
                Row TempRow = GameBoard.FindRow(StartCell.GetYRowCoordinate());
                String NewWord = String.Copy(Word);
                Index = StartCell.GetXColumnCoordinate() + Word.Length; //Indeks pola bezposrednio za slowem.

                if(Index < GameBoard.GetBoardSide())
                {
                    Cell TempCell = TempRow.Get(Index);

                    while(TempCell != null && TempCell.IsVisited())
                    {
                        NewWord += TempCell.GetTile().GetLetter();
                        TempCell = TempRow.Get(++Index);
                    }
                }

                if(!GameDictionary.Exists(NewWord))
                {
                    return false;
                }
            }

            if(Vertical)//Sprawdzenie czy wstawienie slowa nie spowodowalo utworzenia niepoprawnych slow prostopadle do kierunku wstawiania slowa
            {
                Index = StartCell.GetXColumnCoordinate();
                Row TempRow;

                for(int i = 0; i < Word.Length; ++i)
                {
                    TempRow = GameBoard.FindRow(StartCell.GetYRowCoordinate() + i);
                    String NewWord = String.Empty;

                    foreach(Cell TempCell in TempRow)
                    {
                        if(TempCell.GetXColumnCoordinate() == Index)
                        {
                            NewWord += Word[i];
                        }
                        else if(TempCell.GetTile() != null)
                        {
                            NewWord += TempCell.GetTile().GetLetter();
                        }
                        else if(TempCell.GetXColumnCoordinate() > Index) //Ulozone zostalo cale slowo
                        {
                            if(NewWord.Length > 1)
                            {
                                if(!GameDictionary.Exists(NewWord))
                                {
                                    return false;
                                }
                            }
                            break;
                        }
                        else
                        {
                            NewWord = String.Empty;
                        }
                    }
                    if(NewWord.Length > 1)//Jesli slowo konczy sie przy krawedzi planszy
                    {
                        if(!GameDictionary.Exists(NewWord))
                            return false;
                    }
                }
            }
            else
            {
                Index = StartCell.GetYRowCoordinate();
                Column TempColumn;

                for(int i = 0; i < Word.Length; ++i)
                {
                    TempColumn = GameBoard.FindColumn(StartCell.GetXColumnCoordinate() + i);
                    String NewWord = String.Empty;

                    foreach(Cell TempCell in TempColumn)
                    {
                        if(TempCell.GetYRowCoordinate() == Index)
                        {
                            NewWord += Word[i];
                        }
                        else if(TempCell.GetTile() != null)
                        {
                            NewWord += TempCell.GetTile().GetLetter();
                        }
                        else if(TempCell.GetYRowCoordinate() > Index)
                        {
                            if(NewWord.Length > 1)
                            {
                                if(!GameDictionary.Exists(NewWord))
                                {
                                    return false;
                                }
                            }
                            break;
                        }
                        else
                        {
                            NewWord = String.Empty;
                        }
                    }
                    if(NewWord.Length > 1)//Jesli slowo konczy sie przy krawedzi planszy
                    {
                        if(!GameDictionary.Exists(NewWord))
                            return false;
                    }
                }
            }
            return true;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Metoda sprawdzajaca, jaka musi byc najmniejsza dlugosc slowa, ktore zaczynac sie bedzie od pola przekazanego w argumencie wywolania, aby ulozenie go moglo byc zgodne z zasadami gry.
        /// </summary>
        /// <param name="StartCell">Pole, od ktorego zaczynamy ulozenie slowa</param>
        /// <param name="Vertical">true jeśli układamy slowo w pionie, false w przeciwnym razie</param>
        /// <returns></returns>
        public int GetMinLength(Cell StartCell, bool Vertical)
        {
            Container ConsideredContainer;
            Container LeftNeighbour;
            Container RightNeighbour;
            int CellIndex;
            Cell TempCell;

            int MinLength = 0;
            int ActualMinLength = GameBoard.GetBoardSide() + 1;

            if(Vertical) //jesli sprawdzamy czy da sie ulozyc slowo pionowo
            {
                ConsideredContainer = GameBoard.FindColumn(StartCell);
                CellIndex = StartCell.GetYRowCoordinate();
                LeftNeighbour = GameBoard.FindColumn(StartCell.GetXColumnCoordinate() - 1);
                RightNeighbour = GameBoard.FindColumn(StartCell.GetXColumnCoordinate() + 1);
            }
            else
            {
                ConsideredContainer = GameBoard.FindRow(StartCell);
                CellIndex = StartCell.GetXColumnCoordinate();
                LeftNeighbour = GameBoard.FindRow(StartCell.GetYRowCoordinate() - 1);
                RightNeighbour = GameBoard.FindRow(StartCell.GetYRowCoordinate() + 1);
            }

            bool FirstLetter = false; //czy napotkalismy juz jakas litere
            for(int i = 0; i < Configuration.MaxLetterNumber; ++i)
            {
                TempCell = ConsideredContainer.Get(CellIndex + i);

                if(TempCell == null)
                {
                    break;
                }

                if(TempCell.IsVisited())
                {
                    if(!FirstLetter)
                    {
                        FirstLetter = true;
                    }
                }
                else
                {
                    if(FirstLetter)
                    {
                        ActualMinLength = MinLength;
                        break;
                    }
                }
                ++MinLength;
            }

            TempCell = ConsideredContainer.Get(CellIndex + Configuration.MaxLetterNumber);
            if(TempCell != null && TempCell.IsVisited()) //Jesli siodme pole za polem startowym w rozwazanym kontenerze jest zajete
            {
                for(int i = Configuration.MaxLetterNumber; i < GameBoard.GetBoardSide(); ++i)
                {
                    TempCell = ConsideredContainer.Get(CellIndex + i);

                    if(TempCell == null || !TempCell.IsVisited())
                    {
                        ActualMinLength = ActualMinLength > MinLength ? MinLength : ActualMinLength;
                        break;
                    }
                    ++MinLength;
                }
            }
            else
            {
                if(FirstLetter)
                {
                    ActualMinLength = ActualMinLength > MinLength ? MinLength : ActualMinLength;
                }
            }

            MinLength = GetFirstLetterDistance(LeftNeighbour, CellIndex);
            ActualMinLength = ActualMinLength > MinLength ? MinLength : ActualMinLength;

            MinLength = GetFirstLetterDistance(RightNeighbour, CellIndex);
            ActualMinLength = ActualMinLength > MinLength ? MinLength : ActualMinLength;

            return ActualMinLength;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Metoda zliczajaca punkty ktore otrzyma gracz za ulozenie okreslonego slowa w okreslone miejsce
        /// </summary>
        /// <param name="Word"></param>
        /// <param name="StartCell"></param>
        /// <param name="Vertical"></param>
        /// <returns></returns>
        public int CountPoints(String Word, Cell StartCell, bool Vertical)
        {
            int Points = 0;
            Container ConsideredContainer;
            int CellIndex;

            if(Vertical)
            {
                ConsideredContainer = GameBoard.FindColumn(StartCell);
                CellIndex = StartCell.GetYRowCoordinate();
            }
            else
            {
                ConsideredContainer = GameBoard.FindRow(StartCell);
                CellIndex = StartCell.GetXColumnCoordinate();
            }

            Points += CountWord(ConsideredContainer, CellIndex);

            if(Vertical)
            {
                int Index = StartCell.GetXColumnCoordinate();
                Row TempRow;
                var NewWordParamteres = new Tuple<int, int>(0, 0);

                for(int i = 0; i < Word.Length; ++i)
                {
                    TempRow = GameBoard.FindRow(StartCell.GetYRowCoordinate() + i);

                    if(!TempRow.Get(Index).IsVisited())
                    {
                        NewWordParamteres = GetWordInfo(TempRow, Index);
                        int StartIndex = NewWordParamteres.Item2;

                        if(NewWordParamteres.Item1 > 1)
                        {
                            Points += CountWord(TempRow, StartIndex);
                        }
                    }
                }
            }
            else
            {
                int Index = StartCell.GetYRowCoordinate();
                Column TempColumn;
                var NewWordParamteres = new Tuple<int, int>(0, 0);

                for(int i = 0; i < Word.Length; ++i)
                {
                    TempColumn = GameBoard.FindColumn(StartCell.GetXColumnCoordinate() + i);

                    if(!TempColumn.Get(Index).IsVisited())
                    {
                        NewWordParamteres = GetWordInfo(TempColumn, Index);
                        int StartIndex = NewWordParamteres.Item2;

                        if(NewWordParamteres.Item1 > 1)
                        {
                            Points += CountWord(TempColumn, StartIndex);
                        }
                    }
                }
            }
            return Points;
        }