0

Hi I have to create a game for two players where one player guesses the word starting on random char , min 3 letters long and should be in word base, the second player word should meet last 2 conditions plus should start on two last letters of the word provided by first player. Both players start with 3 lives. Example: random word:e firstPlayer:echo secondPlayer:hollow

Do you think that using multiple nested if statements will be fine? How to add random char at first attempt?

if(longer than 3){
   if(in word base){
        if(starting with 2 letters from previous last letters){
           currentPlayerPoints+=1;
           message="Thats right you got a point";
        }else{
           currentPlayerLives-=0;
           message="you didnt match the word";
        }
    }else{
        message="your word is not in database";
        currentPlayerLives-=0;
    }
}else{
    message="your word should be longer at least 3 letters long";
    currentPlayerLives-=0;
}
Lukasz
  • 1
  • 1
  • 1
    It's probably fine... Although I don't know how I feel about the subtracting zero part. For randomness, see [this answer](https://stackoverflow.com/questions/5887709/getting-random-numbers-in-java) – Kein May 03 '20 at 18:26
  • my code is a mess at this moment and above i added pseudo code but for random char i have somethibg like that: ` private char[] alphabet={'a','b','c','d','e','f','g','h','i','j','k','l','o','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; private char randomChar; randomChar=alphabet[(int)Math.floor(Math.random()*26)]; ` – Lukasz May 03 '20 at 20:28
  • Use [ascii values](http://www.asciitable.com/). Basically, each char has a numerical value (a=97, b=98, etc.). You can use this to your advantage and just get a random number from 97 to 122 inclusive, then cast to char. – Kein May 03 '20 at 20:40
  • Great idea, Thank you! – Lukasz May 03 '20 at 21:13

0 Answers0