小鱼征服鼠标宏—第二天—给出鼠标XY坐标让其点击

昨天,做了怎么获取x,y的地址,今天就做输入地址,鼠标“啪”一下闪现过去点他一下,话不多说上代码。


public class Click {
    static double x ;
    static double y ;
    public static void main(String[] args) {
        Robot robot = null;
        Scanner scanner = new Scanner(System.in);
        x = scanner.nextDouble();
        y = scanner.nextDouble();
        System.out.println(x + "\t" + y);
        try {
            robot = new Robot();
        } catch (AWTException e) {
            e.printStackTrace();
        }
        robot.mouseMove((int) x, (int) y);

        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
    }
    }

做到这里,想在给用户一个确认的机会

中间加个判断吧

后面想了想,判断错了还要重新来,还是加个循环吧

public class Click2 {
static int a=0;
    static double x ;
    static double y ;
    public static void main(String[] args) {
        while (a==0){
                Robot robot = null;
                Scanner scanner = new Scanner(System.in);
            System.out.println("请输入鼠标X坐标");
                x = scanner.nextDouble();
            System.out.println("请输入鼠标Y坐标");
                y = scanner.nextDouble();

                System.out.println(x + "\t" + y);
                try {
                    robot = new Robot();
                } catch (AWTException e) {
                    e.printStackTrace();
                }
                robot.mouseMove((int) x, (int) y);
                System.out.println("是否是该位置,不是请输入0,是请输入非零数");
                a= scanner.nextInt();
                if (a == 1 ) {
                    robot.mousePress(InputEvent.BUTTON1_MASK);
                    robot.mouseRelease(InputEvent.BUTTON1_MASK);
                }else {
                    System.out.println("请重新输入");
                }
            }
        }
}

ok  第二天到此为止

关注我那八个小粉丝,你们是我前进的动力,出乎意料呀。哈哈哈

这里是一个简单的大鱼吃小鱼的 Python 代码示例: ```python class Fish: def __init__(self, size, direction): self.size = size self.direction = direction def eat(self, other_fish): if self.size > other_fish.size: self.size += other_fish.size return True else: return False def move(self): if self.direction == "right": self.direction = "left" else: self.direction = "right" class Aquarium: def __init__(self, fish_list): self.fish_list = fish_list def update(self): for i in range(len(self.fish_list)): current_fish = self.fish_list[i] # Move fish current_fish.move() # Check if fish can eat other fish for j in range(i+1, len(self.fish_list)): other_fish = self.fish_list[j] if current_fish.direction == other_fish.direction: continue if current_fish.eat(other_fish): self.fish_list.pop(j) break if __name__ == "__main__": # Create fish fish1 = Fish(5, "right") fish2 = Fish(3, "left") fish3 = Fish(2, "right") fish4 = Fish(1, "left") # Add fish to aquarium aquarium = Aquarium([fish1, fish2, fish3, fish4]) # Simulate fish movement and eating for 10 iterations for i in range(10): aquarium.update() print([fish.size for fish in aquarium.fish_list]) ``` 这个代码模拟了一个简单的水族馆环境,其中包含多条鱼。每条鱼有一个大小和一个移动方向(左或右)。在每个时间步长里,每条鱼都会移动,并且如果它的方向和其他鱼的方向不同,它会尝试吃掉其他鱼中大小比它小的鱼。如果它成功吃掉了一条鱼,那么它的大小会增加。每个时间步长后,程序将打印出每条鱼的大小。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值