Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ranginang67
GitHub Repository: Ranginang67/DarkFly-Tool
Path: blob/master/lib/_0_.py
202 views
1
# Program= Ular
2
# Mod By= Ambari Channel
3
# Use ARROW KEYS to play, SPACE BAR for pausing/resuming and Esc Key for exiting
4
5
import curses
6
from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN
7
from random import randint
8
9
print" _ _ _"
10
print" / \ _ __ ___ | |__ __ _ _ __ (_)"
11
print" / _ \ | '_ ` _ \ | '_ \ / _` | | '__| | |"
12
print" / ___ \ | | | | | | | |_) | | (_| | | | | |"
13
print"/_/ \_\ |_| |_| |_| |_.__/ \__,_| |_| |_|"
14
print
15
print" ____ _ _"
16
print"/ ___| | |__ __ _ _ __ _ __ ___ | |"
17
print"|| | '_ \ / _` | | '_ \ | '_ \ / _ \ | |"
18
print"||___ | | | | | (_| | | | | | | | | | | __/ | |"
19
print"\____| |_| |_| \__,_| |_| |_| |_| |_| \___| |_|"
20
print
21
print
22
start = raw_input ("#Start Sekarang?[y/n]:")
23
24
curses.initscr()
25
win = curses.newwin(20, 60, 0, 0)
26
win.keypad(1)
27
curses.noecho()
28
curses.curs_set(0)
29
win.border(0)
30
win.nodelay(1)
31
32
key = KEY_RIGHT # Initializing values
33
score = 0
34
35
snake = [[4,10], [4,9], [4,8]] # Initial snake co-ordinates
36
food = [10,20] # First food co-ordinates
37
38
win.addch(food[0], food[1], '*') # Prints the food
39
40
while key != 27: # While Esc key is not pressed
41
win.border(0)
42
win.addstr(0, 2, 'Score : ' + str(score) + ' ') # Printing 'Score' and
43
win.addstr(0, 27, ' Ular ') # 'SNAKE' strings
44
win.timeout(150 - (len(snake)/5 + len(snake)/10)%120) # Increases the speed of Snake as its length increases
45
46
prevKey = key # Previous key pressed
47
event = win.getch()
48
key = key if event == -1 else event
49
50
51
if key == ord(' '): # If SPACE BAR is pressed, wait for another
52
key = -1 # one (Pause/Resume)
53
while key != ord(' '):
54
key = win.getch()
55
key = prevKey
56
continue
57
58
if key not in [KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN, 27]: # If an invalid key is pressed
59
key = prevKey
60
61
# Calculates the new coordinates of the head of the snake. NOTE: len(snake) increases.
62
# This is taken care of later at [1].
63
snake.insert(0, [snake[0][0] + (key == KEY_DOWN and 1) + (key == KEY_UP and -1), snake[0][1] + (key == KEY_LEFT and -1) + (key == KEY_RIGHT and 1)])
64
65
# If snake crosses the boundaries, make it enter from the other side
66
if snake[0][0] == 0: snake[0][0] = 18
67
if snake[0][1] == 0: snake[0][1] = 58
68
if snake[0][0] == 19: snake[0][0] = 1
69
if snake[0][1] == 59: snake[0][1] = 1
70
71
# Exit if snake crosses the boundaries (Uncomment to enable)
72
#if snake[0][0] == 0 or snake[0][0] == 19 or snake[0][1] == 0 or snake[0][1] == 59: break
73
74
# If snake runs over itself
75
if snake[0] in snake[1:]: break
76
77
78
if snake[0] == food: # When snake eats the food
79
food = []
80
score += 1
81
while food == []:
82
food = [randint(1, 18), randint(1, 58)] # Calculating next food's coordinates
83
if food in snake: food = []
84
win.addch(food[0], food[1], '*')
85
else:
86
last = snake.pop() # [1] If it does not eat the food, length decreases
87
win.addch(last[0], last[1], ' ')
88
win.addch(snake[0][0], snake[0][1], '#')
89
90
curses.endwin()
91
print("\nScore - " + str(score))
92
print("MOD By Ambari Channel")
93