예제 #1
0
        //This method resets the Animator and then calls it to get the starting image, gets a new word and word score, sets up views for new word and resets the keyboard buttons.
        private void NewGame()
        {
            BtnNewGame.Visibility = ViewStates.Invisible;
            MyAnimator            = new Animator();
            DisplayImg.SetImageResource(MyAnimator.GetNextResource());
            WordPicker myWordPicker = new WordPicker(WordList);

            Word = myWordPicker.GetRandomWord();
            Score s = new Score();

            WordScore = s.GetScore(Word);
            DisplayWord.RemoveAllViews();
            foreach (var letter in Word)
            {
                DisplayWord.AddView(new TextView(this)
                {
                    Text = letter.ToString(), TextSize = 50, TransformationMethod = new PasswordTransformationMethod()
                });
            }
            foreach (Button key in KeyboardButtons)
            {
                key.Visibility = ViewStates.Visible;
                key.Enabled    = true;
            }
        }
예제 #2
0
 // Update is called once per frame
 void Update()
 {
     if (遊戲進行中)
     {
         遊戲結束.SetActive(false);
         New_player1.移動();
         New_player2.移動();
         if (排球.檢查得分() && 可得分)
         {
             加分();
             遊戲進行中 = !結束了沒();
             if (遊戲進行中)
             {
                 可得分            = false;
                 Time.timeScale = 0.3f;
                 StartCoroutine(重新載入());
             }
         }
     }
     else
     {
         string 誰贏了 = Player1_score == 15 ? "Player 1" : "Player 2";
         顯示文字        = new AddOnce(顯示文字, 誰贏了);
         結束顯示文字.text = 顯示文字.輸出文字(結束顯示文字.text);
         遊戲結束.SetActive(true);
         if (Input.anyKeyDown)
         {
             SceneManager.LoadScene("GameOver");
         }
     }
     排球.移動();
     排球.檢查碰撞();
     排球.殺球控制(排球, New_player1, New_player2);
 }
예제 #3
0
 public void DisposeWord()
 {
     currentWord = null;
     EnableCharacter(currentWordCharacter);
     StartCoroutine(DestroyWord(displayWords[currentWordCharacter]));
     displayWords.Remove(currentWordCharacter);
 }
        public static bool IsThereA(string guessLetter) // Credit to DRapp for this
        {
            if (usedLetters.Contains(guessLetter) == false)
            {
                int maxlength = QuoteAnswer.Length;
                bool anyMatch = false;
                for (int i = 0; i < QuoteAnswer.Length; i++)
                {
                    if (QuoteAnswer.Substring(i, 1).Equals(guessLetter))
                    {
                        anyMatch = true;
                        DisplayWord = DisplayWord.Substring(0, i) + guessLetter + DisplayWord.Substring(i + 1);
                    }
                }
                usedLetters.Add(guessLetter);
                return anyMatch;

            }
            if (usedLetters.Contains(guessLetter))
            {
                Console.WriteLine("Oh!  You have already used:");
                usedLetters.ForEach(item => Console.Write(item + " "));
                Console.WriteLine(" ");
            }
            return true;
        }
예제 #5
0
    public DisplayWord Spawn(Transform canvas)
    {
        GameObject  wordObj     = Instantiate(wordPrefab, canvas.position, Quaternion.identity, canvas);
        DisplayWord displayWord = wordObj.GetComponent <DisplayWord>();

        return(displayWord);
    }
예제 #6
0
파일: Word.cs 프로젝트: UllR/MonoType_2
    public Word(string _word, DisplayWord _display)
    {
        word      = _word;
        typeIndex = 0;

        display = _display;
        display.SetWord(word);
    }
예제 #7
0
    public Word(string word, DisplayWord display)
    {
        this.word = word;
        index     = 0;

        this.display = display;
        display.PlaceWord(word);
    }
예제 #8
0
 private void CheckWhetherWordIsGuessed()
 {
     if (!DisplayWord.Contains("_"))
     {
         IsWordGuessed = true;
         Console.WriteLine("You guessed it right");
     }
 }
예제 #9
0
파일: Word.cs 프로젝트: ghadji/Unity
    public Word(string word, DisplayWord display)
    {
        this.word  = word;
        typedIndex = 0;

        this.display = display;
        display.setWord(this.word);
    }
예제 #10
0
 /// <summary>
 /// Method takes in List of integers and a char.
 /// Every integer in List of integers corresponds to an index of <c>DisplayWord</c> that is changed from '-' to the search char.
 /// Newly-created string is assigned to <c>DisplayWord</c>.
 /// Method returns nothing.
 /// </summary>
 /// <param name="indexList">List of integers representing the indices where the search char is found in <c>TargetWord</c></param>
 /// <param name="c">search char</param>
 public void ReplaceDash(List <int> indexList, char c)
 {
     char[] charArray = DisplayWord.ToCharArray();
     foreach (var i in indexList)
     {
         charArray[i] = Char.ToLower(c);
     }
     DisplayWord = new string(charArray);
 }
예제 #11
0
파일: Word.cs 프로젝트: phazeless/Typer
    public Word(string _word, DisplayWord _display)
    {
        word  = _word;
        index = 0;


        display = _display;
        display.ShowWord(word);
    }
예제 #12
0
    public DisplayWord SpawnWord()
    {
        Vector3 randomPosition = new Vector3(Random.Range(-2.5f, 2.5f), 7f);

        GameObject  wordObj     = Instantiate(PrefabWord, randomPosition, Quaternion.identity, Canvas);
        DisplayWord wordDisplay = wordObj.GetComponent <DisplayWord>();

        return(wordDisplay);
    }
예제 #13
0
        /// <summary>
        /// This method is invoked every few seconds and sends a random word from the list
        /// </summary>
        /// <param name="state"></param>
        public void sendData(object state)
        {
            //Random class to get a index
            Random        randNum      = new Random();
            WordEventArgs WordEventObj = new WordEventArgs();
            //get the index and bind it to wordeventags
            int dataIndex = randNum.Next(0, ltDllData.Count);

            WordEventObj.Spelling = ltDllData[dataIndex].Spelling;
            if (DisplayWord != null)
            {
                DisplayWord.Invoke(this, WordEventObj);
            }
        }
예제 #14
0
        //Check if any Text Views in the DisplayWord linear layoout still have their text masked by the PasswordWordTransformation method. If any letters are still hidden word is not complete.
        private bool CheckIfComplete()
        {
            bool complete = true;

            for (int i = 0; i < DisplayWord.ChildCount; i++)
            {
                TextView myTextView = (TextView)DisplayWord.GetChildAt(i);
                if (myTextView.TransformationMethod != null)
                {
                    complete = false;
                }
            }

            return(complete);
        }
예제 #15
0
        private void Letter_Click(object sender, EventArgs e)
        {
            //When a letter button is clicked create a reference to it by casting the sender object to a button, then get the text from the button and disable it.
            Button clickedButton = (Button)sender;
            String Letter        = clickedButton.Text;

            clickedButton.Enabled = false;

            //If letter matches any the the DisplayWord's TextView's text property then remove the password mask and set correctGuess bool to true.
            bool correctGuess = false;

            for (int i = 0; i < DisplayWord.ChildCount; i++)
            {
                TextView myTextView = (TextView)DisplayWord.GetChildAt(i);
                if (myTextView.Text == Letter.ToLower())
                {
                    myTextView.TransformationMethod = null;
                    correctGuess = true;
                }
            }
            //If it was a correct guess then add points and check if the word is complete, if so then the player wins.
            if (correctGuess)
            {
                WordScore += 2;
                if (CheckIfComplete())
                {
                    //WIN CONDITION alert the player, update profile score and call GameFinished method.
                    Toast.MakeText(this, "YOU WIN! +" + WordScore + "points!", ToastLength.Long).Show();
                    Score.Text = "Player Score: " + (Marks + WordScore).ToString();
                    GameFinished();
                }
            }
            else
            //Guess was wrong, decrement points, call the animator to get next image, if animatator is out of images the player loses.
            {
                WordScore -= 1;
                DisplayImg.SetImageResource(MyAnimator.GetNextResource());
                if (MyAnimator.EndOfResources)
                {
                    //LOSE CONDITION alert the player, update profile score and call GameFinished method.
                    Toast.MakeText(this, "YOU LOSE! -" + LossPoints + "points!\nThe word was " + Word, ToastLength.Long).Show();
                    // PlayerProfile.HighScore -= LossPoints;
                    Score.Text = "Player Score: " + (Marks - LossPoints).ToString();
                    GameFinished();
                }
            }
        }
예제 #16
0
    public DisplayWord Spawn()
    {
        Vector3    position   = new Vector3(Random.Range(-2.3f, 2.3f), 7f, -1f);
        GameObject wordPrefab = Instantiate(wordObject, position, Quaternion.identity);

        switch (GetComponent <WordManager>().enemyType)
        {
        case 1: wordPrefab.GetComponent <SpriteRenderer>().sprite = sprite[Random.Range(0, 2)]; break;

        case 2: wordPrefab.GetComponent <SpriteRenderer>().sprite = sprite[Random.Range(3, 5)]; break;

        case 3: wordPrefab.GetComponent <SpriteRenderer>().sprite = sprite[Random.Range(6, 8)]; break;

        case 4: wordPrefab.GetComponent <SpriteRenderer>().sprite = sprite[Random.Range(9, 11)]; break;
        }
        wordPrefab.AddComponent <PolygonCollider2D>();
        wordPrefab.GetComponent <PolygonCollider2D>().isTrigger = true;
        DisplayWord Display = wordPrefab.GetComponent <DisplayWord>();


        return(Display);
    }
예제 #17
0
 void Update()
 {
     foreach (char character in Input.inputString)
     {
         if (currentWord == null)
         {
             if (unavailableCharacters.Contains(character))
             {
                 currentWord = displayWords[character].GetComponent <DisplayWord>();
                 currentWord.Type(character);
                 currentWordCharacter = character;
             }
             else
             {
                 TypingError(character);
             }
         }
         else
         {
             currentWord.Type(character);
         }
     }
 }
예제 #18
0
        /// <summary>
        /// Create model object
        /// </summary>
        /// <param name="filePath">Path to file</param>
        public void CreateModel(string filePath)
        {
            Reset();
            var validationResult = _crozzleFileValidator.Validate(filePath);

            if (_crozzleConfig == null)
            {
                throw new ModelLoadException("Configuration is not loaded!\n Please load configuration at first");
            }

            _crozzle.ValidationResult = validationResult + _crozzleConfig.ValidationResult;

            if (_crozzle.ValidationResult.Critical)
            {
                throw new ModelLoadException($"Critical errors in files: {_crozzle.ValidationResult}");
            }

            var fileName = filePath.Split('\\').Last();

            _crozzle.Name = fileName;
            _crozzle.SetConfig(_crozzleConfig);

            LoadFile(filePath);

            foreach (var @string in file)
            {
                if (!_headerIsSet)
                {
                    var header = @string.Split(',');
                    _crozzle.DifficultyLevel      = (Difficult)Enum.Parse(typeof(Difficult), header[0], true);
                    _crozzle.WordsCount           = int.Parse(header[1]);
                    _crozzle.RowsCount            = int.Parse(header[2]);
                    _crozzle.ColumnsCount         = int.Parse(header[3]);
                    _crozzle.HorizontalWordsCount = int.Parse(header[4]);
                    _crozzle.VerticalWordsCount   = int.Parse(header[5]);

                    _headerIsSet = true;
                    continue;
                }

                if (!_wordsDictionaryIsSet)
                {
                    var wordsList = @string.Split(',')
                                    .ToList();
                    _crozzle.WordsDictionary = wordsList;

                    _wordsDictionaryIsSet = true;
                    continue;
                }

                var word            = new DisplayWord();
                var wordPreferences = @string.Split(',');
                word.Orientation        = (WordOrientation)Enum.Parse(typeof(WordOrientation), wordPreferences[0], true);
                word.HorizontalPosition = int.Parse(wordPreferences[1]);
                word.VerticalPosition   = int.Parse(wordPreferences[2]);
                word.Word = wordPreferences[3];
                _crozzle.DisplayedWords.Add(word);
            }

            _crozzle.SetLoadingComplete();
        }
예제 #19
0
        static void Main()
        {
            Random random = new Random((int)DateTime.Now.Ticks);

            //Open a file from the folder and select a random word from it.
            string[] wordBank    = File.ReadAllLines(@"..\..\Level1.txt");
            string   GuessedWord = wordBank[random.Next(0, wordBank.Length)];

            string GuessedWordUpperCase = GuessedWord.ToUpper();
            //Take the length of the word and replace each symbol with "_"
            StringBuilder DisplayWord = new StringBuilder(GuessedWord.Length);

            DrawWord(GuessedWord, DisplayWord);
            List <char> GuessedLetters   = new List <char>();
            List <char> IncorrectLetters = new List <char>();


            bool win             = false;
            int  revealedletters = 0;
            int  level           = 1;

            string input;
            char   guess = ' ';

            // Game starts from Level 1
            while (lives > 0 && level == 1)
            {
                Console.Write("Guess a letter: ");

                input = Console.ReadLine().ToUpper();
                if (!string.IsNullOrWhiteSpace(input))
                {
                    guess = input[0];
                }
                else
                {
                    guess = ' ';
                }
                //Indicator that the user has already entered this letter.
                if (GuessedLetters.Contains(guess))
                {
                    Console.WriteLine("You've already tried '{0}', and it was correct!", guess);
                    continue;
                }
                else if (IncorrectLetters.Contains(guess))
                {
                    Console.WriteLine("You've already tried '{0}', and it was wrong!", guess);
                    continue;
                }

                //Replace each guessed letter on it's proper place of the displayed word.
                if (GuessedWordUpperCase.Contains(guess))
                {
                    GuessedLetters.Add(guess);

                    for (int i = 0; i < GuessedWord.Length; i++)
                    {
                        if (GuessedWordUpperCase[i] == guess)
                        {
                            DisplayWord[i] = GuessedWord[i];
                            revealedletters++;
                        }
                    }
                    Console.WriteLine(DisplayWord.ToString());
                }
                //If user has entered incorrect letter, system takes 1 life away and adds the letter to the list with incorrect guessed letters.
                else
                {
                    IncorrectLetters.Add(guess);

                    Console.WriteLine("Nope, there's no '{0}' in it!Attempts left: {1}", guess, lives - 1);
                    lives--;
                    Console.WriteLine(DisplayWord.ToString());
                }
                //When the number of revealed letters are equal to the total number of letters, player advances to level 2.
                if (revealedletters == GuessedWord.Length)
                {
                    level = 2;
                    Console.BackgroundColor = ConsoleColor.Green;
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Congratulations! You have passed level 1!");
                    Console.ResetColor();
                }

                //Method, drawing the Hangman
                DrawHangman(lives);
            }

            if (level == 2)
            {
                //system clears the list with correct and incorrect guessed letters. Clears the displayed word, resets the number of revealed letters
                //and takes a new word from a different file, containing more complex words.
                GuessedLetters.Clear();
                IncorrectLetters.Clear();
                lives = 8;
                DisplayWord.Clear();
                revealedletters = 0;
                wordBank        = File.ReadAllLines(@"..\..\Level2.txt");
                GuessedWord     = wordBank[random.Next(0, wordBank.Length)];

                GuessedWordUpperCase = GuessedWord.ToUpper();
                DisplayWord          = new StringBuilder(GuessedWord.Length);
                DrawWord(GuessedWord, DisplayWord);
                // START OF LEVEL 2
                while (lives > 0 && level == 2)
                {
                    //System repeats the same steps from level 1.
                    Console.Write("Guess a letter: ");

                    input = Console.ReadLine().ToUpper();
                    if (!string.IsNullOrWhiteSpace(input))
                    {
                        guess = input[0];
                    }
                    else
                    {
                        guess = ' ';
                    }

                    if (GuessedLetters.Contains(guess))
                    {
                        Console.WriteLine("You've already tried '{0}', and it was correct!", guess);
                        continue;
                    }
                    else if (IncorrectLetters.Contains(guess))
                    {
                        Console.WriteLine("You've already tried '{0}', and it was wrong!", guess);
                        continue;
                    }

                    if (GuessedWordUpperCase.Contains(guess))
                    {
                        GuessedLetters.Add(guess);

                        for (int i = 0; i < GuessedWord.Length; i++)
                        {
                            if (GuessedWordUpperCase[i] == guess)
                            {
                                DisplayWord[i] = GuessedWord[i];
                                revealedletters++;
                            }
                        }
                        Console.WriteLine(DisplayWord.ToString());
                    }

                    else
                    {
                        IncorrectLetters.Add(guess);

                        Console.WriteLine("Nope, there's no '{0}' in it!Attempts left: {1}", guess, lives - 1);
                        lives--;
                        Console.WriteLine(DisplayWord.ToString());
                    }

                    DrawHangman(lives);
                    //If the number of revealed letters is equal to the number of letters in the word for guessing, player advances to level 3.
                    if (revealedletters == GuessedWord.Length)
                    {
                        Console.BackgroundColor = ConsoleColor.Blue;
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Congratulations! You have passed level 2! Start of Level 3");
                        Console.ResetColor();
                        level++;
                    }
                }
            }
            if (level == 3)
            {
                //System repeats the same steps as from the start of level 3. It takes a new word from a file, filled with more complex words.
                GuessedLetters.Clear();
                IncorrectLetters.Clear();
                lives = 8;
                DisplayWord.Clear();
                revealedletters = 0;
                wordBank        = File.ReadAllLines(@"..\..\Level3.txt");
                GuessedWord     = wordBank[random.Next(0, wordBank.Length)];

                GuessedWordUpperCase = GuessedWord.ToUpper();
                DisplayWord          = new StringBuilder(GuessedWord.Length);
                DrawWord(GuessedWord, DisplayWord);
                // START OF LEVEL 3
                //As this is the last level, system will perform the cycle until the player has lives and until he does not win.
                while (lives > 0 && !win && level == 3)
                {
                    Console.WriteLine();
                    Console.WriteLine("Guess a letter: ");
                    input = Console.ReadLine().ToUpper();

                    if (!string.IsNullOrWhiteSpace(input))
                    {
                        guess = input[0];
                    }
                    else
                    {
                        guess = ' ';
                    }

                    if (GuessedLetters.Contains(guess))
                    {
                        Console.WriteLine("You've already tried '{0}', and it was correct!", guess);
                        continue;
                    }
                    else if (IncorrectLetters.Contains(guess))
                    {
                        Console.WriteLine("You've already tried '{0}', and it was wrong!", guess);
                        continue;
                    }

                    if (GuessedWordUpperCase.Contains(guess))
                    {
                        GuessedLetters.Add(guess);

                        for (int i = 0; i < GuessedWord.Length; i++)
                        {
                            if (GuessedWordUpperCase[i] == guess)
                            {
                                DisplayWord[i] = GuessedWord[i];
                                revealedletters++;
                            }
                        }
                    }
                    else
                    {
                        IncorrectLetters.Add(guess);

                        Console.WriteLine("Nope, there's no '{0}' in it!Attempts left: {1}", guess, lives - 1);
                        lives--;
                    }
                    DrawHangman(lives);
                    //If the number of revealed letters are equal to the number of guessed letters, user wins.
                    if (revealedletters == GuessedWord.Length)
                    {
                        win = true;
                    }

                    Console.WriteLine(DisplayWord.ToString());
                }
            }
            //Text, appearing when the player wins.
            if (win)
            {
                Console.BackgroundColor = ConsoleColor.Green;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Congratulations! You have won!");
                Console.ResetColor();
            }
            //Text, appearing when the player loses.
            else
            {
                Console.WriteLine("GAME OVER! The word was '{0}'", GuessedWord);
            }
        }