Skip to content

Create a program

LucBerge edited this page Mar 17, 2021 · 6 revisions

Architecture

  • fr.B4D.program contains the program API, you don't need to change the files to create a program.
  • fr.B4D.programs.tutorials contains all the tutorials.
  • fr.B4D.programs.[category] contains all the programs related to a specific category.

Create the class

Here is a starter code for your first program :

package fr.B4D.programs;

import fr.B4D.bot.B4D;
import fr.B4D.bot.Person;
import fr.B4D.program.CancelProgramException;
import fr.B4D.program.Category;
import fr.B4D.program.FullInventoryException;
import fr.B4D.program.Place;
import fr.B4D.program.Program;
import fr.B4D.program.ProgramInterface;
import fr.B4D.program.StopProgramException;
import net.sourceforge.tess4j.TesseractException;

public final class MY_CLASS{
		public final static Program MY_PROGRAM= new Program(Place.Astrub, Category.Quete, "Sub-category", "Name", new Channel[] {Channel.PRIVATE, Channel.GENERAL}, Status.AVAILABLE, new ProgramInterface() {
		public void intro(Person person) {
			//Run once at the beginning
		}
		public void cycle(Person person) throws FullInventoryException, TesseractException, StopProgramException, CancelProgramException {
			//Run n times
		}
		public void outro(Person person) {
			//Run once at the end
		}
	});
}

Explanations

  • public final static Program MY_PROGRAM : Create a MY_PROGRAM constant of type Program.
  • new Program(...) : Call the program builder to create the object. Here are the parameters :
    • Place.Astrub : The program starts in Astrub.
    • Category.Quete : Categorised as a Quest.
    • Sub-category : Program sub-category name.
    • Name : Program name.
    • new Channel[] {Channel.PRIVATE, Channel.GENERAL} : Only private and general channels will be displayed.
    • Status.AVAILABLE : The available status will be enabled.
    • new ProgramInterface() {...} : Program functions. Three function to implement.
      • public void intro(Person person){...} : Run once at the beginning.
      • public void cycle(Person person){...} : Run n times.
      • public void outro(Person person){...} : Run once at the end.

For more details, refer to the JavaDoc or go check programs source codes.

Integration

In the Program.java file under the fr.B4D.program package. You have to add your program to the list by adding programs.add(MY_CLASS.MY_PROGRAM).


You can check the to do programs list if you don't have any idea. Some programs cannot be done since the corresponding API doesn't exists yet.

In your program, you will probably have to use the APIs to interact, exchange, move...

Clone this wiki locally