Python代码:声呐搜索

import random


class OceanTreasure:
    def __init__(self):
        self.__board = [['~'] * 60 for row in range(15)]
        self.__chests = []
        while len(self.__chests) < 3:
            coord = [str(random.randint(0, 59)), str(random.randint(0, 14))]
            if coord not in self.__chests:
                self.__chests.append(coord)

    def getChests(self):
        # returns the list of coordinates of the chests still to be found.
        return self.__chests

    def getTreasuresLeft(self):
        # returns the number of treasure chests still to be found.
        return len(self.__chests)

    def dropSonar(self, x, y, sonar):
        distance = self.checkDistance(x, y)
        if distance == None:
            sonar = 'O'
        elif distance == 0:
            self.__chests.remove([x, y])
            sonar = 'X'
        elif distance > 0:
            sonar = str(distance)
        elif distance < 0:
            if distance == -1:
                sonar = 'a'
            elif distance == -2:
                sonar = 'b'
            elif distance == -3
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值