Amazing-Python-Scripts

Форк
0
78 строк · 1.5 Кб
1
# 2048.py
2

3
# importing the logic.py file
4
# where we have written all the
5
# logic functions used.
6
import logic
7

8
# Driver code
9
if __name__ == '__main__':
10
	
11
# calling start_game function
12
# to initialize the matrix
13
	mat = logic.start_game()
14

15
while(True):
16

17
	# taking the user input
18
	# for next step
19
	x = input("Press the command : ")
20

21
	# we have to move up
22
	if(x == 'W' or x == 'w'):
23

24
		# call the move_up function
25
		mat, flag = logic.move_up(mat)
26

27
		# get the current state and print it
28
		status = logic.get_current_state(mat)
29
		print(status)
30

31
		# if game not over then continue
32
		# and add a new two
33
		if(status == 'GAME NOT OVER'):
34
			logic.add_new_2(mat)
35

36
		# else break the loop
37
		else:
38
			break
39

40
	# the above process will be followed
41
	# in case of each type of move
42
	# below
43

44
	# to move down
45
	elif(x == 'S' or x == 's'):
46
		mat, flag = logic.move_down(mat)
47
		status = logic.get_current_state(mat)
48
		print(status)
49
		if(status == 'GAME NOT OVER'):
50
			logic.add_new_2(mat)
51
		else:
52
			break
53

54
	# to move left
55
	elif(x == 'A' or x == 'a'):
56
		mat, flag = logic.move_left(mat)
57
		status = logic.get_current_state(mat)
58
		print(status)
59
		if(status == 'GAME NOT OVER'):
60
			logic.add_new_2(mat)
61
		else:
62
			break
63

64
	# to move right
65
	elif(x == 'D' or x == 'd'):
66
		mat, flag = logic.move_right(mat)
67
		status = logic.get_current_state(mat)
68
		print(status)
69
		if(status == 'GAME NOT OVER'):
70
			logic.add_new_2(mat)
71
		else:
72
			break
73
	else:
74
		print("Invalid Key Pressed")
75

76
	# print the matrix after each
77
	# move.
78
	print(mat)
79

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.