Hi!
I am currently trying to code a scenario where there is an AI who asks basic questions that have a positive response or a negative response (Yes/no) the problem is, the code runs straight through the method that is used to see if it negative or positive. I want it to wait for when you answer the question and then do different methods depending on which one was picked. Here is my code:
Any and all help is appreciated, thanks for your time.
import greenfoot.*;
/**
* Write a description of class AI here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class AI extends Actor
{
String Opensentance;
String greeting;
String opsgreeting;
String condquestion;
int opening = 1;
int interest = Greenfoot.getRandomNumber(100);
int Userhappiness = 50;
/**
* Act - do whatever the AI wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (opening == 1)
{
System.out.println("A = positive response. s = negative response");
}
if (interest < 60)
{
greeting = "Hi";
}
else
{
greeting = "Wussup";
}
opsgreeting = "Goodbye";
condquestion = "are you okay?";
if (opening == 1)
{
opensentance();
}
}
public void opensentance()
{
System.out.println(greeting + " " + condquestion);
opening = 2;
condresponse();
}
public void condresponse()
{
if (Greenfoot.isKeyDown("a"))
{
Userhappiness +=50;
System.out.println("positive response.");
}
else if (Greenfoot.isKeyDown("d"))
{
Userhappiness -=50;
act();
}
}
}
