বুধবার, ১২ আগস্ট, ২০১৫

pygame assignment maze creation and image change



import os
import pygame

# -- Global constants

# Colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (50, 50, 255)
YELLOW = (255, 255, 0)
GREEN = (100,100,0)
GRAY = (155,155,0)


# Screen dimensions
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600


class Player(pygame.sprite.Sprite):
    """ This class represents the bar at the bottom that the player
    controls. """



    # Constructor function
    def __init__(self, x, y):
        # Call the parent's constructor
        super().__init__()

        # Set height, width
        self.image = pygame.Surface([10, 10]) #change the box color
        try:
            self.image=pygame.image.load(os.path.join("data","hello.png"))
        except:
            self.image.fill(YELLOW)

        # Make our top-left corner the passed-in location.
        self.rect = self.image.get_rect()
        self.rect.y = y
        self.rect.x = x

        # Set speed vector
        self.change_x = 0
        self.change_y = 0
        self.walls = None

    def changecolor(self,COLOR):
        self.image.fill(COLOR)

    # this method reduce the player size
    #def reduceplayersize(size):

    def changespeed(self, x, y):
        """ Change the speed of the player. """
        self.change_x += x
        self.change_y += y



    def update(self):
        """ Update the player position. """
        # Move left/right
        self.rect.x += self.change_x

        # Did this update cause us to hit a wall?
        block_hit_list = pygame.sprite.spritecollide(self, self.walls, False)
        for block in block_hit_list:
            # self.image= pygame.Surface([10,10]) #when the box is heat the wall then
            # self.image.fill(GREEN)                #the box size rduce and make color RED
            # If we are moving right, set our right side to the left side of
            # the item we hit
            if self.change_x > 0:
                self.rect.right = block.rect.left
            else:
                # Otherwise if we are moving left, do the opposite.
                self.rect.left = block.rect.right

        # Move up/down
        self.rect.y += self.change_y

        # Check and see if we hit anything
        block_hit_list = pygame.sprite.spritecollide(self, self.walls, False)
        for block in block_hit_list:

            # Reset our position based on the top/bottom of the object.
            if self.change_y > 0:
                self.rect.bottom = block.rect.top
            else:
                self.rect.top = block.rect.bottom


class Wall(pygame.sprite.Sprite):
    """ Wall the player can run into. """
    def __init__(self, x, y, width, height):
        """ Constructor for the wall that the player can run into. """
        # Call the parent's constructor
        super().__init__()

        # Make a blue wall, of the size specified in the parameters
        self.image = pygame.Surface([width, height])
        self.image.fill(BLUE)

        # Make our top-left corner the passed-in location.
        self.rect = self.image.get_rect()
        self.rect.y = y
        self.rect.x = x


# Call this function so the Pygame library can initialize itself
pygame.init()

# Create an 800x600 sized screen
screen = pygame.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT])

# Set the title of the window
pygame.display.set_caption('Test')

# List to hold all the sprites
all_sprite_list = pygame.sprite.Group()

# Make the walls. (x_pos, y_pos, width, height)
wall_list = pygame.sprite.Group()

wall = Wall(0, 0, 10, 600)
wall_list.add(wall)
all_sprite_list.add(wall)

wall = Wall(10, 0, 790, 10)
wall_list.add(wall)
all_sprite_list.add(wall)

wall = Wall(10, 200, 100, 10)
wall_list.add(wall)
all_sprite_list.add(wall)




wall = Wall(100, 100, 10, 100)
wall_list.add(wall)
all_sprite_list.add(wall)

wall = Wall(100, 150, 50, 10)
wall_list.add(wall)
all_sprite_list.add(wall)

wall = Wall(790, 0, 10, 790)
wall_list.add(wall)
all_sprite_list.add(wall)

wall = Wall(10, 590, 790, 10)
wall_list.add(wall)
all_sprite_list.add(wall)

x_pos= 150

for i in range(1,21):
    if(i%2!=0):
        x_pos=x_pos+30
        wall = Wall(x_pos, 10, 10, 125)
        wall_list.add(wall)
        all_sprite_list.add(wall)
    else:
        x_pos=x_pos+30
        wall = Wall(x_pos, 50, 10, 125)
        wall_list.add(wall)
        all_sprite_list.add(wall)

wall = Wall(125, 150, 10, 165)
wall_list.add(wall)
all_sprite_list.add(wall)

y_pos= 155

for i in range(1,6):
    if(i%2!=0):
        y_pos=y_pos+30
        wall = Wall(125, y_pos, 650, 10)
        wall_list.add(wall)
        all_sprite_list.add(wall)
    else:
        y_pos=y_pos+30
        wall = Wall(155, y_pos, 650, 10)
        wall_list.add(wall)
        all_sprite_list.add(wall)

wall = Wall(70, 200, 10, 200)
wall_list.add(wall)
all_sprite_list.add(wall)

wall = Wall(40, 410, 10, 130)
wall_list.add(wall)
all_sprite_list.add(wall)

x_pos= 90

for i in range(1,23):
    if(i%2!=0):
        x_pos=x_pos+30
        wall = Wall(x_pos, 410, 10, 140)
        wall_list.add(wall)
        all_sprite_list.add(wall)
    else:
        x_pos=x_pos+30
        wall = Wall(x_pos, 380, 10, 90)
        wall_list.add(wall)
        all_sprite_list.add(wall)


# Create the player paddle object
player = Player(50, 50)
player.walls = wall_list

all_sprite_list.add(player)

clock = pygame.time.Clock()

done = False

while not done:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                player.changespeed(-3, 0)
            elif event.key == pygame.K_RIGHT:
                player.changespeed(3, 0)
            elif event.key == pygame.K_UP:
                player.changespeed(0, -3)
            elif event.key == pygame.K_DOWN:
                player.changespeed(0, 3)

        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT:
                player.changespeed(3, 0)
            elif event.key == pygame.K_RIGHT:
                player.changespeed(-3, 0)
            elif event.key == pygame.K_UP:
                player.changespeed(0, 3)
            elif event.key == pygame.K_DOWN:
                player.changespeed(0, -3)

    all_sprite_list.update()

    screen.fill(BLACK)

    all_sprite_list.draw(screen)

    pygame.display.flip()

    clock.tick(100)

pygame.quit()

How to find out prime number in javaScript

Html part:
 <!doctype html>  
 <html lang="en">  
 <head>  
   <meta charset="UTF-8">  
   <title>Document</title>  
 </head>  
 <body>  
 <script src="script.js"></script>  
 </body>  
 </html>  

 JavaScript Part: save as script.js
function is_prime ( number ) {  
   var check = true;  
   if(number > 1 ) {  
     if ( number > 2 ) {  
       var range = parseInt(number / 2) + 2;  
       for ( var i = 2; i < range; i++){  
        if( (number % i) == 0 ){  
          check = false;  
          break;  
         }  
       }  
     }  
   } else {  
     check = false;  
   }  
   return check;  
 }  
 number = 100;  
 for (var i = 1; i <= number; i++ ) {  
   if(is_prime(i)) {  
     console.log(i);  
   }  
 }  

How to calculate Tax by Excel using custom functions


##Instruction of the tax calculation

If the salary is less than 50k your tax will be 5%;
If the salary is more than and equal 50k and less than 120k tax will be 20%;
If the salary is more than and equal to 120k tax will be 25%;


###for excel with space
IF (A1 < 50000, A1 * .05,
IF( AND(A1 >= 50000, A1 < 120000), A1 * .20,
IF( A1 >= 120000, A1 * .25

) ) )

###for excel without space so that I can use directly 
=IF(A1<50000,A1*0.05,IF(AND(A1>=50000,A1<120000),A1*0.20,IF(A1>=120000,A1*0.25)))

###for vb script function in excel 

Function GP(Salary as Double)
If Salary < 50000 Then
GP = Format((Salary * .05) , "0.00");
ElseIf Salary >= 50000 AND Salary < 120000 Then
GP = Format((Salary * 20) , "0.00");
ElseIf 
GP = Format((Salary * .05) , "0.00");
End If
End Function

fibonacci number or lucas sequence using python

###fibonacci number or lucas sequence
num=int(input("Enter your number"))
a = 0
b = 1
print(a)
print(b)
for count in range (0, 10):
    s = a + b
    a = b
    b = s
    print (s)

counting leap year using python

year = int(input('Enter the year: '))
if year % 4 == 0:
    if year % 100 == 0:
            if year % 400 == 0:
                print ('This is leap year')
            else:
                print('This is not leap year')
    else:
        print('This is leap year')
else:
    print('This is not leap year')

positive and negative number determination using python

positive and negative number determination using python


x = float(input("Enter Your Number :"))
if x > 0:
    print('positive number')
elif x == 0:
    print('zero')
else:
    print('negative number')