酷丁鱼,所有方法

7 篇文章 0 订阅
1 篇文章 0 订阅

干货

// Decompiled by DJ v3.12.12.101 Copyright 2016 Atanas Neshkov  Date: 2018/9/19 7:43:19
// Home Page:  http://www.neshkov.com/dj.html - Check often for new version!
// Source File Name:   Kudingyu.java
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

//代码里叫sprite精灵 我们的精灵叫酷丁鱼


public class Kudingyu
extends Frame
implements TGKeyHandler,
TGMouseHandler,
WindowListener {
    //颜色、形状、方向等常量
    public static int DELAYEDTIME = 50;	//延迟时间,可能是刷新间隔
    public static final int DEFAULT_CANVAS_HEIGHT = 600;	//画布高度
    public static final int DEFAULT_CANVAS_WIDTH = 600;	//画布宽度



    public static final int BLACK = 0;	//黑色
    public static final int BLUE = 1;	//蓝色
    public static final int GREEN = 2;	//绿色
    public static final int CYAN = 3;	//蓝绿色
    public static final int RED = 4;	//红色
    public static final int MAGENTA = 5;	//品红
    public static final int YELLOW = 6;	//黄色
    public static final int WHITE = 7;	//白色
    public static final int BROWN = 8;	//棕色
    public static final int TAN = 9;	//棕褐色
    public static final int FOREST = 10;	//森林色??
    public static final int AQUA = 11;	//水,水溶液??
    public static final int SALMON = 12;	//鲑鱼色??
    public static final int VIOLET = 13;	//紫罗兰色
    public static final int ORANGE = 14;	//橙色
    public static final int GRAY = 15;	//灰色
    public static final int NAVY = 16;	//深蓝色
    public static final int SKYBLUE = 17;	//天蓝色
    public static final int LIME = 18;	//绿黄色
    public static final int STEELBLUE = 19;	//钢铁之蓝??
    public static final int CHOCOLATE = 20;//巧克力色
    public static final int PURPLE = 21;	//紫色
    public static final int GOLD = 22;	//金色
    public static final int LIGHTGRAY = 23;	//发光的灰色??
    public static final int PERU = 24;	//秘鲁色??
    public static final int WHEAT = 25;	//小麦色
    public static final int PALEGREEN = 26;	//暗绿色
    public static final int LIGHTBLUE = 27;	//发光的蓝色??
    public static final int KHAKI = 28;	//卡其色
    public static final int PINK = 29;	//粉色
    public static final int LAWNGREEN = 30;//草地绿色
    public static final int OLIVE = 31;	//橄榄色
    public static final int MAX_LOGO_COLOR = 31;//最大logo色????

//导游样式?
    public static final int COURIER = 0;
    public static final int COURIER_BOLD = 1;
    public static final int COURIER_ITALIC = 2;
    public static final int COURIER_BOLD_ITALIC = 3;
//无衬线样式?
    public static final int SANS_SERIF = 4;
    public static final int SANS_SERIF_BOLD = 5;
    public static final int SANS_SERIF_ITALIC = 6;
    public static final int SANS_SERIF_BOLD_ITALIC = 7;

//衬线样式
    public static final int SERIF = 0;
    public static final int SERIF_BOLD = 1;
    public static final int SERIF_ITALIC = 2;
    public static final int SERIF_BOLD_ITALIC = 3;
//四个角度 对应的方向
    public static final int NORTH = 0;
    public static final int EAST = 90;
    public static final int SOUTH = 180;
    public static final int WEST = 270;


//箭头样式
    public static final int TURTLE = 0;
    public static final int ARROW = 1;
    public static final int BALL = 2;
    public static final int BOX = 3;
    public static final int CROSS = 4;
    public static final int TRIANGLE = 5;
    public static final int DIAMOND = 6;


//线帽样式
    public static final int LINECAP_BUTT = 0;
    public static final int LINECAP_ROUND = 1;
    public static final int LINECAP_SQUARE = 2;
//第一、指定序列、最后样式
    public static final int FIRST_USER_SUPPLIED_SHAPE = 32;
    public static final int NUM_USER_SUPPLIED_SHAPES = 96;
    public static final int LAST_USER_SUPPLIED_SHAPE = 127;



    private int mouseX;
    private int mouseY;
    private TGCanvas canvas;
    private Sprite turtle;
    private static SpritePixels[] userSuppliedImages = new SpritePixels[96];

    public Kudingyu() {
        this(600, 600);
    }

    public Kudingyu(int width, int height) {
        this.addWindowListener(this);
        this.setTitle("\u897f\u6e38\u7f16\u7a0b\u4f5c\u4e1a");
        this.canvas = new TGCanvas(width, height);
        this.canvas.setBackground(Color.white);
        this.canvas.addKeyHandler(this);
        this.canvas.addMouseHandler(this);
        this.add("Center", this.canvas);
        Insets insets = this.getInsets();
        this.setPreferredSize(new Dimension(width += insets.left + insets.right, height += insets.top + insets.bottom));
        this.pack();
        this.setVisible(true);
        this.canvas.requestFocusInWindow();
        this.turtle = new Sprite(this.canvas);
    }




//窗口载入函数
    @Override
    public void tgKeyPressed(int keyNum) {
        this.keypressed(keyNum);
    }

    @Override
    public void tgKeyReleased(int keyNum) {
    }

    @Override
    public void tgKeyTyped(char keyChar) {
    }

    @Override
    public void tgMouseClicked(int x, int y) {
    }

    @Override
    public void tgMouseMoved(int x, int y) {
    }

    @Override
    public void windowActivated(WindowEvent we) {
    }

    @Override
    public void windowClosed(WindowEvent we) {
    }

    @Override
    public void windowClosing(WindowEvent we) {
        System.exit(0);
    }

    @Override
    public void windowDeactivated(WindowEvent we) {
    }

    @Override
    public void windowDeiconified(WindowEvent we) {
    }

    @Override
    public void windowIconified(WindowEvent we) {
    }

    @Override
    public void windowOpened(WindowEvent we) {
    }














//画圆浮点型    角度,半径

    public void arc(double angle, double radius) throws IllegalArgumentException {
        if (angle == 0.0 || radius == 0.0) {
            return;
        }
        if (radius <= 0.0) {
            throw new IllegalArgumentException("Illegal radius: " + radius);
        }
        this.turtle.arc(angle, radius);
    }


//画圆整型    角度  半径

    public void arc(int angle, int radius) throws IllegalArgumentException {
        this.arc((double)angle, (double)radius);
    }



//画圆整形 半径
    public void cycle(int radius) throws IllegalArgumentException {
        this.arc(360.0, (double)radius);
    }

//后退 浮点型
    public void back(double steps) {
        try {
            this.turtle.bk(steps);
        }
        catch (AbortException var3_2) {
        }
    }
//后退 整型
    public void back(int steps) {
        try {
            this.turtle.bk(steps);
        }
        catch (AbortException var2_2) {
        }
    }
//后退 浮点型 缩写
    public void bk(double steps) {
        try {
            this.turtle.bk(steps);
        }
        catch (AbortException var3_2) {
        }
    }
//后退 整形 缩写
    public void bk(int steps) {
        try {
            this.turtle.bk(steps);
        }
        catch (AbortException var2_2) {
        }
    }
//清除屏幕内容
    public void clean() {
        this.canvas.clean();
    }

//返回颜色名(数组)多个
    public int[] colorsunder() {
        return this.turtle.colorsunder();
    }
//返回颜色名 变量 单个
    public int colorunder() {
        return this.turtle.colorunder();
    }
//填充色彩
    public void fill() {
        try {
            Thread.sleep(DELAYEDTIME);
        }
        catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.turtle.fill();
    }
//step的加强版,更快速度到达目的地,使用浮点型变量
    public void fd(double steps) {
        try {
            this.turtle.fd(steps);
        }
        catch (AbortException var3_2) {
        }
    }
//step的加强版,更快速度到达目的地,使用整型变量
    public void fd(int steps) {
        try {
            this.turtle.fd(steps);
        }
        catch (AbortException var2_2) {
        }
    }
//酷丁鱼向正前方前进steps步
    public void forward(double steps) {
        try {
            this.turtle.fd(steps);
        }
        catch (AbortException var3_2) {
        }
    }
//酷丁鱼向前跑
    public void step(int steps) {
        try {
            Thread.sleep(DELAYEDTIME);
        }
        catch (InterruptedException e2) {
            e2.printStackTrace();
        }
        try {
            this.turtle.fd(steps);
        }
        catch (AbortException e2) {
        }
    }
//返回标签长度
    public int labelwidth(String label) {
        return this.turtle.getLabelWidth(label);
    }

    public double heading() {
        return this.turtle.heading();
    }
//去掉箭头
    public void hideturtle() {
        try {
            Thread.sleep(DELAYEDTIME);
        }
        catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.turtle.ht();
    }
//酷丁鱼回到原点(出生点)
    public void home() {
        try {
            this.turtle.home();
        }
        catch (AbortException var1_1) {
        }
    }
//hideturtle的缩写,相当于隐藏箭头
    public void ht() {
        this.turtle.ht();
    }
//判断Pen是否落下
    public boolean ispendown() {
        return this.turtle.ispendown();
    }
//无内容占位函数
    public void keypressed(int keyNum) {

    }
//显示一个标签,可以指定内容
    public void label(String text) {
        this.turtle.label(text);
    }
//左转degree度,浮点型
    public void left(double degrees) {
        try {
            this.turtle.lt(degrees);
        }
        catch (AbortException var3_2) {
        }
    }
//左转degree度,整型
    public void left(int degrees) {
        try {
            this.turtle.lt(degrees);
        }
        catch (AbortException var2_2) {
        }
    }
//载入一张图片,需提供图片文件位置,返回布尔型
    public boolean loadpicture(String fileName) {
        Image pictureImage = TGFileIO.getImage(fileName);
        if (pictureImage == null) {
            return false;
        }
        this.canvas.loadPicture(pictureImage);
        return true;
    }
//载入形状文件,提供形状文件位置,和形状索引,返回布尔型
    public boolean loadshape(String fileName, int shapeNum) {
        PixelRectangle pixRect = TGFileIO.getPixRect(fileName);
        if (pixRect == null) {
            return false;
        }
        int shapeIdx = shapeNum - 32;
        if (shapeNum < 0 || shapeNum > 96) {
            return false;
        }
        Kudingyu.userSuppliedImages[shapeIdx] = new UserTurtle(pixRect);
        return true;
    }
//left的缩写,左转degree度,浮点型
    public void lt(double degrees) {
        try {
            this.turtle.lt(degrees);
        }
        catch (AbortException var3_2) {
        }
    }
//left的缩写,左转degree度,整数型
    public void lt(int degrees) {
        try {
            this.turtle.lt(degrees);
        }
        catch (AbortException var2_2) {
        }
    }

    public int mousex() {
        return this.canvas.mousex();
    }

    public int mousey() {
        return this.canvas.mousey();
    }
//pendown的缩写,放下pen
    public void pd() {
        this.turtle.pd();
    }
//得到当前Pen的颜色
    public int pencolor() {
        return this.turtle.pencolor();
    }
//放下pen
    public void pendown() {
        try {
            Thread.sleep(DELAYEDTIME);
        }
        catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.turtle.pd();
    }
//抬起pen

    public void penup() {
        try {
            Thread.sleep(DELAYEDTIME);
        }
        catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.turtle.pu();
    }

    public TGPoint pos() {
        return this.turtle.pos();
    }

    public void pu() {
        this.turtle.pu();
    }

    public void right(double degrees) {
        try {
            this.turtle.rt(degrees);
        }
        catch (AbortException var3_2) {
        }
    }

    public void right(int degrees) {
        try {
            Thread.sleep(DELAYEDTIME);
        }
        catch (InterruptedException e2) {
            e2.printStackTrace();
        }
        try {
            this.turtle.rt(degrees);
        }
        catch (AbortException e2) {
        }
    }
//转任意角度
    public void turn(int degrees) {
        if (degrees > 0) {
            this.right(degrees);
        } else {
            this.left(Math.abs(degrees));
        }
    }
//右转90度
    public void turnRight() {
        this.right(90);
    }
//左转90度
    public void turnLeft() {
        this.left(90);
    }
//right turn 右转缩写 浮点型
    public void rt(double degrees) {
        try {
            this.turtle.rt(degrees);
        }
        catch (AbortException var3_2) {
        }
    }
//right turn 右转缩写 整型
    public void rt(int degrees) {
        try {
            this.turtle.rt(degrees);
        }
        catch (AbortException var2_2) {
        }
    }

    public void setbg(int logoColor) {
        this.canvas.setbg(logoColor);
    }

    public void seth(double degrees) {
        try {
            this.turtle.seth(degrees);
        }
        catch (AbortException var3_2) {
        }
    }

    public void seth(int degrees) {
        try {
            this.turtle.seth(degrees);
        }
        catch (AbortException var2_2) {
        }
    }

    public void setheading(double degrees) {
        try {
            this.turtle.seth(degrees);
        }
        catch (AbortException var3_2) {
        }
    }

    public void setheading(int degrees) {
        try {
            this.turtle.seth(degrees);
        }
        catch (AbortException var2_2) {
        }
    }

    public void setlabelfont(int fontNumber) throws IllegalArgumentException {
        if (fontNumber < 0 || fontNumber >= Sprite.NUM_FONTS) {
            throw new IllegalArgumentException("Illegal font number: " + fontNumber);
        }
        this.turtle.setlabelfont(fontNumber);
    }

    public void setlabelheight(int size) throws IllegalArgumentException {
        if (size < 1 || size > 100) {
            throw new IllegalArgumentException("Illegal label height: " + size);
        }
        this.turtle.setlabelheight(size);
    }

    public void setlinecap(int typeLinecap) throws IllegalArgumentException {
        switch (typeLinecap) {
            case 0: 
            case 1: 
            case 2: {
                this.turtle.setLinecap(typeLinecap);
                break;
            }
            default: {
                throw new IllegalArgumentException("Illegal linecap type: " + typeLinecap);
            }
        }
    }

    public void setpc(int colorNum) {
        this.turtle.setpc(colorNum);
    }

    public void setpencolor(int colorNum) {
        this.turtle.setpc(colorNum);
    }

    public void setPenPattern(int segmentSize) throws IllegalArgumentException {
        if (segmentSize < 0) {
            throw new IllegalArgumentException("Illegal segment size: " + segmentSize);
        }
        if (segmentSize == 0) {
            this.turtle.setPenPattern(null);
        } else {
            this.turtle.setPenPattern(new int[]{segmentSize, segmentSize});
        }
    }

    public void setPenPattern(int[] pattern) throws IllegalArgumentException {
        if (pattern == null || pattern.length == 0) {
            this.turtle.setPenPattern(null);
            return;
        }
        int idx = 0;
        while (idx < pattern.length) {
            if (pattern[idx] < 1) {
                throw new IllegalArgumentException("Illegal segment size: " + pattern[idx]);
            }
            ++idx;
        }
        this.turtle.setPenPattern(pattern);
    }

    public void setpensize(int width) {
        this.turtle.setpensize(width);
    }

    public void setpos(TGPoint pos) {
        this.setxy(pos);
    }

    public boolean setshape(int shapeNum) {
        return this.setshape(shapeNum, null);
    }

    public boolean setshape(int shapeNum, int[] params) {
        if (shapeNum >= 32 && shapeNum <= 127) {
            if (userSuppliedImages[shapeNum - 32] == null) {
                return false;
            }
            this.turtle.setshape(userSuppliedImages[shapeNum - 32]);
            return true;
        }
        return this.turtle.setshape(shapeNum, params);
    }

    public void setshape(SpritePixels newSpritePixels) {
        this.turtle.setshape(newSpritePixels);
    }

    public void setx(double newX) {
        try {
            this.turtle.setx(newX);
        }
        catch (AbortException var3_2) {
        }
    }

    public void setx(int newX) {
        try {
            this.turtle.setx(newX);
        }
        catch (AbortException var2_2) {
        }
    }

    public void setxy(double newX, double newY) {
        try {
            this.turtle.setxy(newX, newY);
        }
        catch (AbortException var5_3) {
        }
    }

    public void setxy(int newX, int newY) {
        try {
            Thread.sleep(DELAYEDTIME);
        }
        catch (InterruptedException e2) {
            e2.printStackTrace();
        }
        try {
            this.turtle.setxy(newX, newY);
        }
        catch (AbortException e2) {
        }
    }

    public void setxy(TGPoint newPt) {
        try {
            this.turtle.setxy(newPt);
        }
        catch (AbortException var2_2) {
        }
    }

    public void sety(double newY) {
        try {
            this.turtle.sety(newY);
        }
        catch (AbortException var3_2) {
        }
    }

    public void sety(int newY) {
        try {
            this.turtle.sety(newY);
        }
        catch (AbortException var2_2) {
        }
    }

    public int shapeheight() {
        return this.turtle.getSpritePixels().getHeight();
    }
//得到精灵的宽度
    public int shapewidth() {
        return this.turtle.getSpritePixels().getWidth();
    }

    public boolean shownp() {
        return this.turtle.shownp();
    }
//让箭头显示出来
    public void showturtle() {
        this.turtle.st();
    }
//让箭头显示出来,缩写
    public void st() {
        this.turtle.st();
    }
//酷丁鱼在原地留下影分身(在原地留下一个箭头形状)
    public void stamp() {
        this.turtle.stamp();
    }
//设置酷丁鱼真实航向
    public void throttle(int amt) {
        this.turtle.setThrottleSleepAmt(amt);
    }
//返回x坐标
    public int xcor() {
        return (int)this.turtle.xcor();
    }
//返回y坐标
    public int ycor() {
        return (int)this.turtle.ycor();
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值