Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snake game.py #100

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions auto_Name_genarator/Name_Genarator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@

# Use python to genaate the random names...

import random
import string

FirstNames = './Names/FirstNames.txt'
MiddleNames = './Names/MiddleNames.txt'
LastNames = './Names/LastNames.txt'
StateNames = './Names/StateNames.txt'
CountryNames = './Names/CountryNames.txt'
CountyNames = './Names/CountyNames.txt'
PlaceNames = './Names/PlaceNames.txt'
CompanyNames = './Names/CompanyNames.txt'


#genarate the charectors.....

def Number(start=0, end=100000):
"""
Returns random integer between range of numbers
"""
return random.randint(start, end)


def UpperChars(NoOfChars=2):
"""
UpperChars(NoOfChars=2) Returns 2 random CAPITAL letters.
"""
_char = ''
for num in range(NoOfChars):
_char += random.choice(string.ascii_uppercase)
return _char


def rawCount(filename):
"""
Function to get Line Count in txt files.
rawcount('C:\A.txt') outputs integer value of count of lines.
"""
with open(filename, 'rb') as f:
lines = 1
buf_size = 1024 * 1024
read_f = f.raw.read

buf = read_f(buf_size)
while buf:
lines += buf.count(b'\n')
buf = read_f(buf_size)
return lines


def randomLine(filename):
num = int(random.uniform(0, rawCount(filename)))
with open(filename, 'r', encoding="UTF-8") as f:
for i, line in enumerate(f, 1):
if i == num:
break
return line.strip('\n')

# assing names---->

def First():
return randomLine(FirstNames)


def Last():
return randomLine(LastNames)


def Middle():
return randomLine(MiddleNames)


def States():
return randomLine(StateNames)


def Places():
return randomLine(PlaceNames)


def County():
return randomLine(CountyNames)


def Company():
return randomLine(CompanyNames)


def Country():
_Cc = randomLine(CountryNames)
_Cc = _Cc.split('|')
return _Cc[1]


def CountryCode():
_Cc = randomLine(CountryNames)
_Cc = _Cc.split('|')
return _Cc[0]


def StateCode():
return States().split(', ')[1]


def Full():
"""
Returns a random First Name and Last Name combination
"""
return ' '.join([First(), Last()])


def Address():
"""
Returns a Random address in the Format:
54F - Sauk, Middle, New Mexico, NM, 4292.

"""
_door = str(Number(11, 99))
_zip = str(Number(1000, 9999))
_adrs = ', '.join([Places(), County(), States(), _zip])
_adrs = _door + UpperChars(1) + ' - ' + _adrs + '.'
return _adrs


def ShortAddress():

"""
Returns a Short Random address in the Format:
31 Outagamie, Wisconsin, WI, 8281
"""
_door = str(Number(11, 99))
_zip = str(Number(1000, 9999))
_adrs = ', '.join([County(), States(), _zip])
_adrs = _door + ' ' + _adrs
return _adrs


if __name__ == '__main__':
print(Full(), ' works at ', Company(), ' lives at ', Address(), StateCode(), Country())


#Done_------->
27 changes: 27 additions & 0 deletions create a clock/crate a clock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function currentTime() {
let date = new Date();
let hh = date.getHours();
let mm = date.getMinutes();
let ss = date.getSeconds();
let session = "AM";


if(hh > 12){
session = "PM";
}
//calculating hours mins seconds

hh = (hh < 10) ? "0" + hh : hh;
mm = (mm < 10) ? "0" + mm : mm;
ss = (ss < 10) ? "0" + ss : ss;

let time = hh + ":" + mm + ":" + ss + " " + session;

document.getElementById("clock").innerText = time;
var t = setTimeout(function(){ currentTime() }, 1000);

}

currentTime();


133 changes: 133 additions & 0 deletions snake game_py/snake game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import pygame
import time
import random

pygame.init()

white = (255, 255, 255)
yellow = (255, 255, 102)
black = (0, 0, 0)
red = (213, 50, 80)
green = (0, 255, 0)
blue = (50, 153, 213)

dis_width = 600
dis_height = 400

dis = pygame.display.set_mode((dis_width, dis_height))
pygame.display.set_caption('Snake Game by Edureka')

clock = pygame.time.Clock()

snake_block = 10
snake_speed = 15

#changing style and Font

font_style = pygame.font.SysFont("bahnschrift", 25)
score_font = pygame.font.SysFont("comicsansms", 35)


def Your_score(score):
value = score_font.render("Your Score: " + str(score), True, yellow)
dis.blit(value, [0, 0])



def our_snake(snake_block, snake_list):
for x in snake_list:
pygame.draw.rect(dis, black, [x[0], x[1], snake_block, snake_block])


def message(msg, color):
mesg = font_style.render(msg, True, color)
dis.blit(mesg, [dis_width / 6, dis_height / 3])


def gameLoop():

game_over = False
game_close = False

x1 = dis_width / 2
y1 = dis_height / 2

x1_change = 0
y1_change = 0

snake_List = []
Length_of_snake = 1

foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0
foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0


while not game_over:

while game_close == True:
dis.fill(blue)
message("You Lost! Press C-Play Again or Q-Quit", red)
Your_score(Length_of_snake - 1)
pygame.display.update()

for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
game_over = True
game_close = False
if event.key == pygame.K_c:
gameLoop()

for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x1_change = -snake_block
y1_change = 0
elif event.key == pygame.K_RIGHT:
x1_change = snake_block
y1_change = 0
elif event.key == pygame.K_UP:
y1_change = -snake_block
x1_change = 0
elif event.key == pygame.K_DOWN:
y1_change = snake_block
x1_change = 0


if x1 >= dis_width or x1 < 0 or y1 >= dis_height or y1 < 0:
game_close = True
x1 += x1_change
y1 += y1_change
dis.fill(blue)
pygame.draw.rect(dis, green, [foodx, foody, snake_block, snake_block])
snake_Head = []
snake_Head.append(x1)
snake_Head.append(y1)
snake_List.append(snake_Head)
if len(snake_List) > Length_of_snake:
del snake_List[0]

for x in snake_List[:-1]:
if x == snake_Head:
game_close = True

our_snake(snake_block, snake_List)
Your_score(Length_of_snake - 1)

pygame.display.update()

if x1 == foodx and y1 == foody:
foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0
foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0
Length_of_snake += 1

clock.tick(snake_speed)

pygame.quit()
quit()


gameLoop()
#End game