Posts

Showing posts from July, 2022

My React Native Journey - 11 - Creating a master list of words for the Wordle game.

Creating a master list words for the game So far, we have worked with the code to work with one word "hello". Now, we will arrange it so that the game is able to select random words from a list. Vadim's tutorial selects a daily word, going by the day, between 1 and 366. So there would be 366 words in his list, and if there are more, they will never be selected. I have kept the same approach, except for a slight deviation that he maintains the list of words in the App.js code itself, I chose to move it to another file. I created a data folder in the root directory, and initially played with trying to read a text file (words.txt) or CSV file (words.csv). It seems there is no easy way of doing this, and honestly, I didn't try very hard. So, I created a words.js file, which exports the list of words, like so. Note that there are 366 words in this list. export const words_list = ['amaze,'amuse,'abyss'....366 words]; So, here is the code in the App.js file:...

My React Native Journey - 10 - Sharing Wordle success on social media

 Sharing success on social media In the Wordle game, users post their success by hiding the individual words guessed and only showing the colored squares. This lets other users understand how many tries the poster took to arrive at the correct word. How is this done? When the user wins, we send out a message saying he won. In addition, we show a clickable text field, called Share. On press of this text field, we execute a function called shareScore, which will return the colored rows, and also copy the same to clipboard. For the clipboard,  import * as Clipboard from "expo-clipboard"; Alert.alert('Hurraayy', 'You won', [{text: 'Share', onPress: shareScore}]); Function shareScore: const shareScore = () => {     const textShare = rows.map(                                 (row,i) => row.map(                           ...

My React Native Journey - 9 - Implementing Wordle Game Won or Lost Logic

 Handling the Game Won or Lost State  If all the letters in the previous row are the same as that in the selected word, the game ends with a message "You have won!".  else, if there are no more tries left, the game ends with the message "Try again tomorrow". Everytime the row changes, the app looks in the previous row, and for each element in the row, it validates it against the letter positions in the selected word. We use the useEffect hook for the purpose. useEffect (() => {     if ( curRow > 0 ) {       checkGameState ();     }   }, [ curRow ])   const checkGameState = () => {       if ( checkifWon ()) {       Alert . alert ( 'Hurraayy' , 'You won' )      } else if ( checkifLost ()) {       Alert . alert ( "Meh" , "Try again tomorrow" )      }   };   const checkifWon = () => {       const row ...