gold-getter.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # GoldGetter.py
  4. #
  5. # Copyright 2018 Stephen Stengel <stephen.stengel@cwu.edu>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20. # MA 02110-1301, USA.
  21. #STEPHEN STENGEL
  22. #CS565 project 2
  23. #This is a small game where the player gets the gold and avoids the bomb.
  24. #Controls: Move player with WASD.
  25. #TODO:
  26. # 19 oct 2020: Rewrite to use classes because I know this stuff now.
  27. #
  28. # Use copyright-free art! So I can put it on github
  29. #
  30. # More bombs. Read array for all, move each one at a time.
  31. #
  32. # Add proximity to chase mechanic. Only chase when within two squares?
  33. #
  34. # Just figured out how to add bombs. Make the detection functions put
  35. # coordinates into a tuple and pass that. Obviously change things to look
  36. # for more bombs. Best would be a variable amount of bombs.
  37. #
  38. # Add intellegence to bomb movements. STARTED
  39. #
  40. # Add more bombs/difficulties.
  41. #
  42. # Make it so bombs cannot kill before player moves.
  43. #
  44. # Czech spellingz
  45. #
  46. # Prevent user from making the board too small or too big
  47. #
  48. # Figure out what I meant by some of these comments...
  49. #
  50. # If I ever need to change the function createDataArray(), give it better
  51. # variable names.
  52. #
  53. # Also I could simplify createDataArray() by just using the isPlayerHere,
  54. # isBombHere, and isgoldhere functions etc. instead of checking
  55. # coordinates manually.
  56. #
  57. #DONE:
  58. # Fix the bug where an endless loop is started if the bomb starts the game
  59. # boxxed in a corner by two golds. DONE
  60. #
  61. # Add ability to control player. DONE
  62. #
  63. # Find a way to prevent the jumpy graphics glitch. DONE
  64. #
  65. # Make it so that it doesn't exit on win/loss. Instead go into loop using
  66. # input and print. DONE
  67. #IDEAS:
  68. # Keep player from moving more than two squares away from the bomb.
  69. #
  70. # If bomb finds gold, it should puppyguard the gold.
  71. #
  72. # Add obsticals (if no path between player and gold retry. same for bomb)
  73. import random
  74. import readchar
  75. import math
  76. import pygame
  77. pygame.init()
  78. #Global variables because I'm literally just slapping this together in like an hour.
  79. SCREEN_SIZE = 400
  80. WINDOW_BOARD_DIMENSION = 5
  81. WINDOW = pygame.display.set_mode((SCREEN_SIZE, SCREEN_SIZE))
  82. pygame.display.set_caption("Gold Getter")
  83. # Colors
  84. WHITE = (255, 255, 255)
  85. BLACK = (0, 0, 0)
  86. GRAY = (200, 200, 200)
  87. RED = (255, 0, 0)
  88. BLUE = (0, 0, 255)
  89. GREEN = (0, 255, 0)
  90. #need to get image sizes before I put them in the screen.
  91. # Images
  92. # ~ PLAYER_IMAGE = pygame.transform.scale(pygame.image.load("images/robot.png").convert(), (80, 80))
  93. # ~ BOMB_IMAGE = pygame.transform.scale(pygame.image.load("images/bomb.png").convert(), (80, 80))
  94. # ~ GOLD_IMAGE = pygame.transform.scale(pygame.image.load("images/gold.png").convert(), (80, 80))
  95. PLAYER_IMAGE = None
  96. BOMB_IMAGE = None
  97. GOLD_IMAGE = None
  98. class SquareStatus(object):
  99. def __init__(self, isBombHere, isPlayerHere, \
  100. wasBombHere, wasPlayerHere, isGoldHere):
  101. self.isBombHere = isBombHere
  102. self.isPlayerHere = isPlayerHere
  103. self.wasBombHere = wasBombHere
  104. self.wasPlayerHere = wasPlayerHere
  105. self.isGoldHere = isGoldHere
  106. class Engine(object):
  107. def __init__(self):
  108. pass
  109. def API(self):
  110. DIMENSION = self.BOARD_DIMENSION()
  111. theBoardYo = self.createDataArray(DIMENSION)
  112. self.playGame(theBoardYo, DIMENSION)
  113. #Use this to pass the value of the size of the board to functions
  114. #Call the created variable DIMENSION inside of the function
  115. #Don't make the board 1x1, lol
  116. #We can change the size of the board by changing the number that is returned
  117. def BOARD_DIMENSION(self):
  118. size = input(\
  119. "What size should the square board be?\n"\
  120. "Enter an integer from 3 to 9.\n"\
  121. "(If you are in fullscreen try 3 to 19): ")
  122. return int(size)
  123. #This creates the data array that holds the places of the characters and
  124. #generates the initial positions of the caracters
  125. def createDataArray(self, DIMENSION):
  126. #print("Creating the game board array that stores the data...")
  127. boardArray = \
  128. [[SquareStatus( False, \
  129. False, \
  130. False, \
  131. False, \
  132. False) for x in range(DIMENSION)] \
  133. for y in range(DIMENSION)]
  134. #print("boardArray created!")
  135. #sets player's initial position
  136. (a, b) = self.randomStart(DIMENSION)
  137. boardArray[a][b].isPlayerHere = True
  138. #sets bomb's initial position. Repeats if spot is taken.
  139. (c, d) = self.randomStart(DIMENSION)
  140. while(c == a and d == b):
  141. (c, d) = self.randomStart(DIMENSION)
  142. boardArray[c][d].isBombHere = True
  143. #sets golds initial position.
  144. (e, f) = self.randomStart(DIMENSION)
  145. while((e == c and f == d) or (e == a and f == b)):
  146. (e, f) = self.randomStart(DIMENSION)
  147. boardArray[e][f].isGoldHere = True
  148. #sets another gold.
  149. (g, h) = self.randomStart(DIMENSION)
  150. while( (g == e and h == f) \
  151. or (g == c and h == d) \
  152. or (g == a and h == b) ):
  153. (g, h) = self.randomStart(DIMENSION)
  154. boardArray[g][h].isGoldHere = True
  155. return boardArray
  156. #This function contains the loop that runs the game.
  157. def playGame(self, boardArray, DIMENSION):
  158. updatedBoardArray = boardArray
  159. print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
  160. isStillGold = self.isThereStillGold(updatedBoardArray, DIMENSION)
  161. self.displayBoard(updatedBoardArray, DIMENSION)
  162. throwAwayVariable = ""
  163. throwAwayVariable = print(input("press enter key to continue!"))
  164. while(isStillGold):
  165. #make bomb walk once#doing this after player
  166. updatedBoardArray = self.moveBomb(updatedBoardArray, DIMENSION)
  167. print( "\n\n\n\n\n\n\n\n\n\n\n\n\n" \
  168. "\n\n\n\n\n\n\n\n\n\n\n\n\n" \
  169. "Avoid the bomb!")
  170. self.displayBoard(updatedBoardArray, DIMENSION)
  171. #throwAwayVariable = print(input("press enter key to continue!"))
  172. #check if bomb is on player
  173. #tested working
  174. if(self.isBombOnPlayer(updatedBoardArray, DIMENSION)):
  175. print( "OWCH!\n" + \
  176. "The bomb got you!\n" + \
  177. "I don't care what universe you're from-- that's gotta hurt!\n" +\
  178. "GAME OVER!\n")
  179. exit(0)
  180. #make player walk
  181. # print("\n\n\n\n\n\n\n\n\n\n\n\n\nPlayer's turn...")
  182. updatedBoardArray = \
  183. self.movePlayerManual(updatedBoardArray, DIMENSION)
  184. #playerongold?
  185. if(self.isPlayerOnGold(updatedBoardArray, DIMENSION)):
  186. (a, b) = self.getPlayerPosition(updatedBoardArray, DIMENSION)
  187. self.deleteGold(updatedBoardArray, DIMENSION, a, b)
  188. print( "\n\n\n\n\n\n\n\n\n\n\n\n\n" \
  189. "\n\n\n\n\n\n\n\n\n\n\n\n\n" \
  190. "Avoid the bomb!")
  191. self.displayBoard(updatedBoardArray, DIMENSION)
  192. #throwAwayVariable = print(input("press enter key to continue!"))
  193. #check if bomb is on player
  194. #tested working
  195. if(self.isBombOnPlayer(updatedBoardArray, DIMENSION)):
  196. print( "OWCH!\n" + \
  197. "The bomb got you!\n" + \
  198. "I don't care what universe you're from-- that's gotta hurt!\n" +\
  199. "GAME OVER!\n")
  200. exit(0)
  201. #check if there is any gold left
  202. isStillGold = self.isThereStillGold(updatedBoardArray, DIMENSION)
  203. if(isStillGold != True):
  204. break
  205. #make player walk again
  206. updatedBoardArray = \
  207. self.movePlayerManual(updatedBoardArray, DIMENSION)
  208. #playerongold?
  209. if(self.isPlayerOnGold(updatedBoardArray, DIMENSION)):
  210. (a, b) = self.getPlayerPosition(updatedBoardArray, DIMENSION)
  211. self.deleteGold(updatedBoardArray, DIMENSION, a, b)
  212. print( "\n\n\n\n\n\n\n\n\n\n\n\n\n" \
  213. "\n\n\n\n\n\n\n\n\n\n\n\n\n" \
  214. "Player's turn...")
  215. self.displayBoard(updatedBoardArray, DIMENSION)
  216. #throwAwayVariable = print(input("press enter key to continue!"))
  217. #check if bomb is on player
  218. #tested working
  219. if(self.isBombOnPlayer(updatedBoardArray, DIMENSION)):
  220. print( "OWCH!\n" + \
  221. "The bomb got you!\n" + \
  222. "I don't care what universe you're from-- that's gotta hurt!\n" +\
  223. "GAME OVER!\n")
  224. WINDOW.fill(RED)
  225. end_text = pygame.font.SysFont('courier', 20).render("GAME OVER!", 1, BLACK)
  226. WINDOW.blit(end_text, ((SCREEN_SIZE - end_text.get_width()) // 2, (SCREEN_SIZE - end_text.get_height()) // 2))
  227. pygame.display.update()
  228. pygame.time.delay(5000)
  229. exit(0)
  230. #check if there is any gold left
  231. isStillGold = self.isThereStillGold(updatedBoardArray, DIMENSION)
  232. if(isStillGold != True):
  233. break
  234. # Player wins
  235. print("You got all the gold! YAAAAAAAAAY!")
  236. WINDOW.fill(GREEN)
  237. end_text = pygame.font.SysFont('courier', 20).render("YOU WIN!", 1, BLACK)
  238. WINDOW.blit(end_text, ((SCREEN_SIZE - end_text.get_width()) // 2, (SCREEN_SIZE - end_text.get_height()) // 2))
  239. pygame.display.update()
  240. pygame.time.delay(5000)
  241. def displayBoard(self, boardArray, DIMENSION):
  242. #print("Displaying board...")
  243. print("##################")
  244. the_underscores = "_"
  245. print(" " + \
  246. str(the_underscores * ( (DIMENSION * 3) + (DIMENSION - 1) ) ))
  247. for i in range(DIMENSION):
  248. for j in range(DIMENSION):
  249. print("| " \
  250. + self.displayCharacters(boardArray, i, j) \
  251. + " ", end = '')
  252. print("|\n ", end = "")
  253. print(the_underscores * ( (DIMENSION * 3) + (DIMENSION - 1) ) )
  254. #for underscores we need DIMENSION*3 + (DIMENSION - 1) underscores
  255. #print("Done!")
  256. ## New bit to display the board with pygame. I'm going to just
  257. ## read the array every time that this is called and use a
  258. ## couple for loops to fill the screen.
  259. WINDOW_BOARD_DIMENSION = DIMENSION
  260. WINDOW.fill(WHITE)
  261. print("window board dimension: " + str(WINDOW_BOARD_DIMENSION))
  262. unitSize = SCREEN_SIZE // WINDOW_BOARD_DIMENSION
  263. PLAYER_IMAGE = pygame.transform.scale(pygame.image.load("images/robot.png").convert(), (unitSize, unitSize))
  264. BOMB_IMAGE = pygame.transform.scale(pygame.image.load("images/bomb.png").convert(), (unitSize, unitSize))
  265. GOLD_IMAGE = pygame.transform.scale(pygame.image.load("images/gold.png").convert(), (unitSize, unitSize))
  266. #Start points for drawing lines
  267. x = 0
  268. for i in range(WINDOW_BOARD_DIMENSION):
  269. x = i * unitSize
  270. pygame.draw.line(WINDOW, BLACK, (x, 0), (x, SCREEN_SIZE), 1)
  271. pygame.draw.line(WINDOW, BLACK, (0, x), (SCREEN_SIZE, x), 1)
  272. # I need to get the position in which to place each image.
  273. x = y = 0
  274. for i in range(len(boardArray)):
  275. for j in range(len(boardArray[i])):
  276. if boardArray[i][j].isPlayerHere:
  277. y = i * unitSize
  278. x = j * unitSize
  279. WINDOW.blit(PLAYER_IMAGE, (x,y) )
  280. if boardArray[i][j].isBombHere:
  281. y = i * unitSize
  282. x = j * unitSize
  283. WINDOW.blit(BOMB_IMAGE, (x,y) )
  284. if boardArray[i][j].isGoldHere:
  285. y = i * unitSize
  286. x = j * unitSize
  287. WINDOW.blit(GOLD_IMAGE, (x,y) )
  288. pygame.display.update()
  289. #This function needs to return characters with a priority of:
  290. #bomb, player, gold, bombtrail, playertrail
  291. def displayCharacters(self, boardArray, i, j):
  292. if(boardArray[i][j].isBombHere):
  293. return "B"
  294. elif(boardArray[i][j].isPlayerHere):
  295. return "P"
  296. elif(boardArray[i][j].isGoldHere):
  297. return "G"
  298. elif(boardArray[i][j].wasBombHere):
  299. return ","
  300. elif(boardArray[i][j].wasPlayerHere):
  301. return "."
  302. else:
  303. return " "
  304. def randomStart(self, DIMENSION):
  305. i = -1.0
  306. j = -1.0
  307. i = random.randint(0, DIMENSION - 1)
  308. j = random.randint(0, DIMENSION - 1)
  309. #print("This is i:" + str(i))
  310. #print("This is j:" + str(j))
  311. return (i, j)
  312. #Checks the boardArray for gold
  313. def isThereStillGold(self, boardArray, DIMENSION):
  314. #print("isThereStillGold has been called")
  315. for i in range(DIMENSION):
  316. for j in range(DIMENSION):
  317. if(boardArray[i][j].isGoldHere):
  318. return True
  319. return False
  320. #checks if bomb is on the player
  321. def isBombOnPlayer(self, boardArray, DIMENSION):
  322. if(self.getPlayerPosition(boardArray, DIMENSION) \
  323. == self.getBombPosition(boardArray, DIMENSION)):
  324. return True
  325. return False
  326. #returns the cell that the player is in as a tuple
  327. def getPlayerPosition(self, boardArray, DIMENSION):
  328. i = -1
  329. j = -1
  330. for i in range(DIMENSION):
  331. for j in range(DIMENSION):
  332. if(boardArray[i][j].isPlayerHere):
  333. return (i, j)
  334. return (i, j)
  335. #returns the cell that the bomb is in as a tuple
  336. def getBombPosition(self, boardArray, DIMENSION):
  337. i = -1
  338. j = -1
  339. for i in range(DIMENSION):
  340. for j in range(DIMENSION):
  341. if(boardArray[i][j].isBombHere):
  342. return (i, j)
  343. return (i, j)
  344. #Why is it called IF?
  345. def checkIfGoldPosition(self, boardArray, DIMENSION):
  346. i = -1
  347. j = -1
  348. for i in range(DIMENSION):
  349. for j in range(DIMENSION):
  350. if(boardArray[i][j].isBombHere):
  351. return (i, j)
  352. return (i, j)
  353. #Move the player! Manually!
  354. def movePlayerManual(self, boardArray, DIMENSION):
  355. (currentY, currentX) = self.getPlayerPosition(boardArray, DIMENSION)
  356. (finalY, finalX) = (currentY, currentX)
  357. #this section ayy
  358. while( (finalY, finalX) == (currentY, currentX) ):
  359. #print("Which way do you want to go?!")
  360. wayToGo = "q"
  361. while( (wayToGo != "w") \
  362. and (wayToGo != "a") \
  363. and (wayToGo != "s") \
  364. and (wayToGo != "d") ):
  365. wayToGo = readchar.readchar()
  366. if(wayToGo == "w"):#up
  367. #print("up")
  368. (y, x) = ((currentY - 1), currentX)
  369. # print("y of proposed position " + str(y))
  370. # print("x of proposed position " + str(x))
  371. elif(wayToGo == "a"):#left
  372. #print("left")
  373. (y, x) = (currentY,(currentX - 1))
  374. # print("y of proposed position " + str(y))
  375. # print("x of proposed position " + str(x))
  376. elif(wayToGo == "d"):#right
  377. #print("right")
  378. (y, x) = (currentY, (currentX + 1))
  379. # print("y of proposed position " + str(y))
  380. # print("x of proposed position " + str(x))
  381. elif(wayToGo == "s"):#down
  382. #print("down")
  383. (y, x) = ((currentY + 1), currentX)
  384. # print("y of proposed position " + str(y))
  385. # print("x of proposed position " + str(x))
  386. #wait! just return the one thing that you want changed and
  387. #change/set it in the game function?
  388. #Not sure what that comment was supposed to mean.
  389. if(self.checkIfCanMovePlayer(boardArray, DIMENSION, y, x)):
  390. boardArray[currentY][currentX].isPlayerHere = False
  391. boardArray[currentY][currentX].wasPlayerHere = True
  392. # print("boardArray[currY][currX].isPlayerHere: " \
  393. # + str(boardArray[currentY][currentX].isPlayerHere))
  394. boardArray[y][x].isPlayerHere = True
  395. # print("boardArray[y][x].isPlayerHere: " \
  396. # + str(boardArray[y][x].isPlayerHere))
  397. (finalY, finalX) = (y, x)
  398. # print("returnning boardArray")
  399. return boardArray
  400. #Checks proposed movement for validity.
  401. def checkIfCanMovePlayer(self, boardArray, DIMENSION, y, x):
  402. if(y < 0):
  403. return False
  404. elif(y > DIMENSION - 1):
  405. return False
  406. elif(x < 0):
  407. return False
  408. elif(x > DIMENSION - 1):
  409. return False
  410. #this would be too easy
  411. #~ elif((y, x) == self.getBombPosition(boardArray, DIMENSION)):
  412. #~ return False
  413. else:
  414. return True
  415. #I need to make the bomb smarter.
  416. #Add a thing to check bomb's y,x position compared to player position
  417. #Make bomb only able to reduce distance between it and player.
  418. #Maybe just put this in the canBombMove function? Then don't need to change
  419. #anything here and it will just get sent back here to roll again.
  420. # Might need to add a counter loop to prevent getting stuck behind an
  421. # obstical. Or just add a don't move condition?
  422. #Need a new function to check the distance between the bomb and the player
  423. # Could just use standard distance formula from algebra?
  424. def moveBomb(self, boardArray, DIMENSION):
  425. (currentY, currentX) = self.getBombPosition(boardArray, DIMENSION)
  426. (finalY, finalX) = (currentY, currentX)
  427. (playerY, playerX) = self.getPlayerPosition(boardArray, DIMENSION)
  428. #print("Player is at..." + str(playerY) + ", " + str(playerX))
  429. print("bomb distance: " \
  430. + str(self.bombDistance(playerY, playerX, currentY, currentX)) )
  431. #stuckCounter is how many times the bomb has tried and failed to move.
  432. #The bomb will not move if it hits 50.
  433. stuckCounter = 0
  434. while( ((finalY, finalX) == (currentY, currentX)) \
  435. and (stuckCounter < 50) ):
  436. num = random.uniform(0.0, 1.0)
  437. if(num < 0.25):#up
  438. # print("up")
  439. (y, x) = ((currentY - 1), currentX)
  440. # print("y of proposed position " + str(y))
  441. # print("x of proposed position " + str(x))
  442. elif(num < 0.5):#left
  443. # print("left")
  444. (y, x) = (currentY,(currentX - 1))
  445. # print("y of proposed position " + str(y))
  446. # print("x of proposed position " + str(x))
  447. elif(num < 0.75):#right
  448. # print("right")
  449. (y, x) = (currentY, (currentX + 1))
  450. # print("y of proposed position " + str(y))
  451. # print("x of proposed position " + str(x))
  452. else:#down
  453. # print("down")
  454. (y, x) = ((currentY + 1), currentX)
  455. # print("y of proposed position " + str(y))
  456. # print("x of proposed position " + str(x))
  457. #throoooow = print(input("heh"))
  458. #distance checks
  459. currentBombDistance = self.bombDistance(playerY, \
  460. playerX, \
  461. currentY, \
  462. currentX)
  463. proposedBombDistance = self.bombDistance(playerY, playerX, y, x)
  464. if(self.checkIfCanMoveBomb(boardArray, \
  465. DIMENSION, \
  466. y, \
  467. x, \
  468. currentBombDistance, \
  469. proposedBombDistance)):
  470. #print("running the second if in moveBomb...")
  471. boardArray[currentY][currentX].isBombHere = False
  472. boardArray[currentY][currentX].wasBombHere = True
  473. # print("boardArray[currY][currX].isBombHere: " \
  474. # + str(boardArray[currentY][currentX].isBombHere))
  475. boardArray[y][x].isBombHere = True
  476. # print("boardArray[y][x].isBombHere: " \
  477. # + str(boardArray[y][x].isBombHere))
  478. (finalY, finalX) = (y, x)
  479. # print("returnning boardArray")
  480. return boardArray
  481. stuckCounter += 1
  482. return boardArray
  483. def checkIfCanMoveBomb(self, \
  484. boardArray, \
  485. DIMENSION, \
  486. y, \
  487. x, \
  488. currentBombDistance, \
  489. proposedBombDistance):
  490. if(y < 0):
  491. return False
  492. elif(y > DIMENSION - 1):
  493. return False
  494. elif(x < 0):
  495. return False
  496. elif(x > DIMENSION - 1):
  497. return False
  498. elif(boardArray[y][x].isGoldHere):
  499. return False
  500. elif(proposedBombDistance > currentBombDistance):
  501. return False
  502. else:
  503. return True
  504. #Returns the direct distance between the player and bomb.
  505. def bombDistance(self, playerY, playerX, bombY, bombX):
  506. return math.sqrt( (playerX - bombX)**2 + (playerY - bombY)**2 )
  507. def isPlayerOnGold(self, boardArray, DIMENSION):#THIS FIRST HAAHA
  508. (a, b) = self.getPlayerPosition(boardArray, DIMENSION)
  509. if(boardArray[a][b].isGoldHere):
  510. # print("player IS on gold!")
  511. return True
  512. else:
  513. # print("player is NOT on gold")
  514. return False
  515. #Deletes a gold!? Call Greenspan!
  516. def deleteGold(self, boardArray, DIMENSION, a, b):
  517. boardArray[a][b].isGoldHere = False
  518. def main():
  519. e = Engine()
  520. e.API()
  521. pass
  522. if __name__ == '__main__':
  523. main()
  524. ################################################################################
  525. #old movePlayer function
  526. #~ #player will not move onto bomb
  527. #~ #if cannot move in first direction, it must re-roll
  528. #~ #(y, x) is the way it is set up now
  529. #~ #WORKS still need to change old place to False
  530. #~ #also need to fix the weird error that it gives about line 176
  531. #~ #maybe change the recursion to a while loop!
  532. #~ #The player starts at the same place each time the loop is run! NOT GOOD
  533. #~ def movePlayer(self, boardArray, DIMENSION):
  534. #~ (currentY, currentX) = self.getPlayerPosition(boardArray, DIMENSION)
  535. #~ (finalY, finalX) = (currentY, currentX)
  536. #~ #print("y of current position " + str(currentY))
  537. #~ #print("x of current position " + str(currentX))
  538. #~ # ~ (y, x) = ((a -1), b)
  539. #~ # ~ print("y of proposed position" + str(y))
  540. #~ # ~ print("x of proposed position" + str(x))
  541. #~ while( (finalY, finalX) == (currentY, currentX) ):
  542. #~ num = random.uniform(0.0, 1.0)
  543. #~ if(num < 0.25):#up
  544. #~ # print("up")
  545. #~ (y, x) = ((currentY - 1), currentX)
  546. #~ # print("y of proposed position " + str(y))
  547. #~ # print("x of proposed position " + str(x))
  548. #~ elif(num < 0.5):#left
  549. #~ # print("left")
  550. #~ (y, x) = (currentY,(currentX - 1))
  551. #~ # print("y of proposed position " + str(y))
  552. #~ # print("x of proposed position " + str(x))
  553. #~ elif(num < 0.75):#right
  554. #~ # print("right")
  555. #~ (y, x) = (currentY, (currentX + 1))
  556. #~ # print("y of proposed position " + str(y))
  557. #~ # print("x of proposed position " + str(x))
  558. #~ else:#down
  559. #~ # print("down")
  560. #~ (y, x) = ((currentY + 1), currentX)
  561. #~ # print("y of proposed position " + str(y))
  562. #~ # print("x of proposed position " + str(x))
  563. #~ #wait! just return the one thing that you want changed and change/set it in the game function?
  564. #~ if(self.checkIfCanMovePlayer(boardArray, DIMENSION, y, x)):
  565. #~ boardArray[currentY][currentX].isPlayerHere = False
  566. #~ boardArray[currentY][currentX].wasPlayerHere = True
  567. #~ # print("boardArray[currY][currX].isPlayerHere: " + str(boardArray[currentY][currentX].isPlayerHere))
  568. #~ boardArray[y][x].isPlayerHere = True
  569. #~ # print("boardArray[y][x].isPlayerHere: " + str(boardArray[y][x].isPlayerHere))
  570. #~ (finalY, finalX) = (y, x)
  571. #~ # print("returnning boardArray")
  572. #~ return boardArray