当前位置: 首页>>代码示例>>Python>>正文


Python Vector.get方法代码示例

本文整理汇总了Python中vector.Vector.get方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.get方法的具体用法?Python Vector.get怎么用?Python Vector.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vector.Vector的用法示例。


在下文中一共展示了Vector.get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import get [as 别名]
class Queue:

    def __init__(self):
        self.__queue = Vector()

    # Adds value to the end of the Queue.
    # Complexity: O(1)
    def push(self, value):
        self.__queue.add(value)

    # Returns value from the front of the Queue and removes it.
    # Complexity: O(1)
    def pop(self):
        if self.__queue.size() > 0:
            first_elemet = self.__queue.get(0)
            temp_vector = Vector()
            for i in range(0, self.__queue.size()):
                if i > 0:
                    temp_vector.add(self.__queue.get(i))
            self.__queue = temp_vector
            return first_elemet
        else:
            return None

    # Returns value from the front of the Queue without removing it.
    # Complexity: O(1)
    def peak(self):

        if self.__queue.size != 0:
            return self.__queue.get(0)
        return None

    # Returns the number of elements in the Queue.
    # Complexity: O(1)
    def size(self):
        return self.__queue.size()

    def getQueue(self):
        return self.__queue.getVector()
开发者ID:presian,项目名称:HackBulgaria,代码行数:41,代码来源:my_queue.py

示例2: __init__

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import get [as 别名]
class Ship:
    def __init__(self, x=50, y=50):
        self.pos = Vector(x, y);
        self.speed = Vector();
        self.accel = Vector();
        self.angle = 0;
        self.tmpAngle = 0;
        self.canShoot = 1;
        self.shootLimiter = Timer(2);
        self.keyb = 1;

        self.keys = {
            "up":0,
            "down":0,
            "left":0,
            "right":0,
            "shoot":0
            };
        self.mouse = Vector(0,0);
        self.mShoot = 0;
        
        self.accel.x = 1;
        self.points = (
            Vector(0,-10),
            Vector(0,10),
            Vector(30,0)
            );

    def update(self, shoot_function, index):
        if self.canShoot:
            self.shootLimiter.reset();
        else:
            self.canShoot = self.shootLimiter.update();
        if self.keyb:
            if self.keys["up"]:       self.accel.y = -0.5;
            elif self.keys["down"]:   self.accel.y = 0.5;
            else:
                self.accel.y = 0;
                self.speed.y *= 0.98;
            if self.keys["left"]:     self.accel.x = -0.5;
            elif self.keys["right"]:  self.accel.x = 0.5;
            else:
                self.accel.x = 0;
                self.speed.x *= 0.98;
            if self.keys["shoot"] and self.canShoot:
                self.canShoot = 0;
                self.shootLimiter.reset();
                shoot_function(index);
        else:
            if self.accel.hyp() < 1: self.accel = Vector(0,1);
            self.accel.rot_to(self.mouse.minus(self.pos).angle());
            if self.mshoot and self.canShoot:
                self.canShoot = 0;
                self.shootLimiter.reset();
                shoot_function(index);

        if not self.accel.isNull(): self.angle = self.accel.angle();
        self.speed.add(self.accel);
        if not self.speed.isNull():
            hyp = self.speed.hyp();
            if hyp > 10:
                self.speed.set_length(10);
            
        self.pos.add(self.speed);
        bounce = self.pos.moveWithinBounds(Vector(800, 600));
        if bounce:
            if bounce   == 1: self.speed.x = -self.speed.x;
            elif bounce == 2: self.speed.y = -self.speed.y;

    def hit(self):
        pass;

    def set_keys(self, up, down, left, right, shoot):
        self.keyb = 1;
        self.keys["up"] = up;
        self.keys["down"] = down;
        self.keys["left"] = left;
        self.keys["right"] = right;
        self.keys["shoot"] = shoot;

    def set_mouse(self, mpos, mshoot):
        self.keyb = 0;
        self.mouse.x = mpos[0];
        self.mouse.y = mpos[1];
        self.mshoot = mshoot;
    
    def net_data(self):
        # [0] = ( posX, posY )
        # [1] = ( speedX, speedY )
        # [2] = angle
        # ( ( posX, posY ), ( speedX, speedY ), angle )
        return (self.pos.get(1), self.speed.get(1), int(self.angle * 100));

    @staticmethod
    def collide(ships, shots, explosions=0):
        for i in ships:
            for shot in shots:
                if ships[i].pos.dist_to(shot.pos) < 10:
                    ships[i].hit();

#.........这里部分代码省略.........
开发者ID:strykejern,项目名称:strykejern-pythonGame,代码行数:103,代码来源:ship.py

示例3: Vector

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import get [as 别名]
    assert myVector.capacity() == 20

    myVector = Vector()
    myVector.add('numberOne')
    myVector.add('numberTwo')
    assert myVector.pop() == 'numberTwo'
    assert myVector.pop() == 'numberOne'
    assert myVector.size() == 0
    assert myVector.capacity() == 20

    myVector = Vector()
    myVector.insert(0, 'Hello')
    assert myVector.size() == 1
    assert myVector.capacity() == 20
    assert myVector.pop() == 'Hello'
    assert myVector.get(0) is None
    assert myVector.size() == 0
    assert myVector.capacity() == 20

    myVector = Vector()
    myVector.add('Hello')
    myVector.add('Hello2')
    myVector.remove(0)
    assert myVector.get(0) == 'Hello2'
    assert myVector.size() == 1
    assert myVector.capacity() == 20

    myVector = Vector()
    myVector.add('Hello')
    myVector.add('Hello2')
    myVector.remove(1)
开发者ID:nacholibre,项目名称:Algo-1,代码行数:33,代码来源:vector_test.py

示例4: int

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import get [as 别名]
# test if vector.py is callable externally and if it works well
import sys, os
if os.getcwd() not in sys.path:
        sys.path.append(os.getcwd())
from vector import Vector

# run-time loopy
instr = 1
while instr > 0:
    instr = int(input('(0)EXIT\n(1)INSERT\n(2)ADD\n(3)GET\n(4)REMOVE\n(5)POP\n(6)SIZE\n(7)CAPACITY\n'))
    if instr == 1:
        ind = int(input('Index?\n'))
        val = input('Value?\n')
        print (Vector.insert(ind, val))
    elif instr == 2:
        val = input ('Value?\n')
        print (Vector.add(val))
    elif instr == 3:
        ind = int(input('Index?\n'))
        print (Vector.get(ind))
    elif instr == 4:
        ind = int(input('Index?\n'))
        print (Vector.remove(ind))
    elif instr == 5:
        print (Vector.pop())
    elif instr == 6:
        print (Vector.size())
    elif instr == 7:
        print (Vector.capacity())
开发者ID:brada1,项目名称:Algo-1,代码行数:31,代码来源:vector_test.py


注:本文中的vector.Vector.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。