import org.lwjgl.input.Keyboard;
import cpw.mods.fml.client.FMLClientHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import java.util.Random;
import net.minecraft.client.gui.GuiTextField;
public class GuiTest extends GuiScreen{ //GuiTest - наш класс. Унаследуем от GuiScreen
protected GuiTextField inputField; //Это поле ввода
int first = 0;//первое слагаемое
int second = 0;//второе слагаемое
public void initGui()//инициализация гуи
{
Random rand = new Random();//
first = rand.nextInt(10); //создаем два рандомных числа от 0 до 10
second = rand.nextInt(10); //
Keyboard.enableRepeatEvents(true);
this.inputField = new GuiTextField(this.fontRendererObj, 4, this.height - 12, this.width - 4, 12);
this.inputField.setMaxStringLength(100);
this.inputField.setEnableBackgroundDrawing(false);
this.inputField.setFocused(true);
this.inputField.setText("");
this.inputField.setCanLoseFocus(false);
}
public boolean doesGuiPauseGame()
{
return true;//это чтобы была пауза (можно поставить false, тогда паузы не будет)
}
protected void keyTyped(char p_73869_1_, int p_73869_2_)// если нажата клавиша
{
if (p_73869_2_ == Keyboard.KEY_E)
{
try
{
if(Integer.parseInt(inputField.getText().toLowerCase()) == first+ second)
{
Keyboard.enableRepeatEvents(false);
this.mc.displayGuiScreen((GuiScreen)null);
this.mc.setIngameFocus();
return;
}
}
catch(NumberFormatException ex)
{
}
}
if (p_73869_2_ == 1)//если нажать ESC - проверить решение
{
try
{
if(Integer.parseInt(inputField.getText().toLowerCase()) == first+ second)
{
Keyboard.enableRepeatEvents(false);
this.mc.displayGuiScreen((GuiScreen)null);
this.mc.setIngameFocus();
return;
}
}
catch(NumberFormatException ex)
{
}
}
if(p_73869_2_ == Keyboard.KEY_RETURN) //если нажать Enter - проверить решение
{
try
{
if(Integer.parseInt(inputField.getText().toLowerCase()) == first+ second)
{
Keyboard.enableRepeatEvents(false);
this.mc.displayGuiScreen((GuiScreen)null);
this.mc.setIngameFocus();
return;
}
}
catch(NumberFormatException ex)
{
}
}
else
{
this.inputField.textboxKeyTyped(p_73869_1_, p_73869_2_);//если нажата другая клавиша - ввести
}
}
public void updateScreen()
{
super.updateScreen();
this.inputField.updateCursorCounter();
}
public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_)
{
this.drawDefaultBackground();
drawRect(2, this.height - 14, this.width - 2, this.height - 2, Integer.MIN_VALUE);
this.inputField.drawTextBox();
this.drawCenteredString(this.fontRendererObj, first + " + " + second + " = ", this.width / 2, 20, 16777215);
}
}