-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
98 lines (82 loc) · 2.77 KB
/
player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import sys
from alarmexception import *
from random import *
import time
import os
class Player():
# playerPos=[1,1]
def __init__(self):
# Board=Board
self.playerPos=[1,1]
def drawPlayer(self,x,y,Board): # Drawing the player at (X,Y)
if(Board[2*x][4*y]!="X" and Board[2*x][4*y]!="/"):
Board[2*x][4*y] = "B"
Board[2*x][4*y+1] = "B"
Board[2*x][4*y+2] = "B"
Board[2*x][4*y+3] = "B"
Board[2*x+1][4*y] = "B"
Board[2*x+1][4*y+1] = "B"
Board[2*x+1][4*y+2] = "B"
Board[2*x+1][4*y+3] = "B"
return [x,y]
def erasePlayer(self,x,y,Board): # Erasing the player at (X,Y)
if(Board[2*x][4*y]!="X" and Board[2*x][4*y]!="/"):
Board[2*x][4*y] = " "
Board[2*x][4*y+1] = " "
Board[2*x][4*y+2] = " "
Board[2*x][4*y+3] = " "
Board[2*x+1][4*y] = " "
Board[2*x+1][4*y+1] = " "
Board[2*x+1][4*y+2] = " "
Board[2*x+1][4*y+3] = " "
def checkPosition(self,x,y,Board): # Checking whether the wall bricks are there at (X,Y)
if(Board[2*x][4*y]=="X" or Board[2*x][4*y]=="/"):
return -1
return 1
def updatePlayer(self,Board): #updating the position of players
x = self.playerPos[0]
y = self.playerPos[1]
self.drawPlayer(x,y,Board) #calling drawPlayer to draw the Bomberman
return
def playerInit(self): # Initializing the player
playerPos = (1,1)
x = self.playerPos[0]
y = self.playerPos[1]
self.drawPlayer(x,y,Board)
return
def moveDown(self,Board): # When user called Bomberman to move down
x = self.playerPos[0]
y = self.playerPos[1]
if(self.checkPosition(x+1,y,Board)>0): # checking if there is no wall bricks
self.erasePlayer(self.playerPos[0],self.playerPos[1],Board)
self.playerPos[0] += 1 # changing player position
# self.erasePlayer(self.playerPos[0],self.playerPos[1])
self.drawPlayer(self.playerPos[0],self.playerPos[1],Board)
return
def moveUp(self,Board):
x = self.playerPos[0]
y = self.playerPos[1]
if(self.checkPosition(x-1,y,Board)>0):
self.erasePlayer(self.playerPos[0],self.playerPos[1],Board)
self.playerPos[0] -= 1
# self.erasePlayer(self.playerPos[0],self.playerPos[1])
self.drawPlayer(self.playerPos[0],self.playerPos[1],Board)
return
def moveLeft(self,Board):
x = self.playerPos[0]
y = self.playerPos[1]
if(self.checkPosition(x,y-1,Board)>0):
self.erasePlayer(self.playerPos[0],self.playerPos[1],Board)
self.playerPos[1] -= 1
self.drawPlayer(self.playerPos[0],self.playerPos[1],Board)
return
def moveRight(self,Board):
x = self.playerPos[0]
y = self.playerPos[1]
if(self.checkPosition(x,y+1,Board)>0):
self.erasePlayer(self.playerPos[0],self.playerPos[1],Board)
self.playerPos[1] += 1
self.drawPlayer(self.playerPos[0],self.playerPos[1],Board)
return
def playerpos(self): # Returning player's position
return self.playerPos