Just a simple dictionary based on the food! Imagine there is a battle in your kitchen...
- #create dictionaries
for the weapons (such as tomato,cheese,garlic...)
-
- tomato = {
- "name": "tomato",
- "color": "red",
- "health": 120,
- "speed": 35
- }
-
- cheese = {
- "name": "cheese",
- "color": "blue",
- "health": 50,
- "speed": 25
- }
-
- garlic = {
- "name": "garlic",
- "color": "white",
- "health": 80,
- "speed": 70
- }
-
- #create a dictionary for the enemy
- enemy = {
- "name": "visiting_cook",
- "health": 80,
- "speed": 40
- }
-
- #create a dictionary for our player.
- player = {
- "name":None,
- "weapon": None,
- "health": None
- }
-
- #assign the value to player by adding them
to the dictionary.
- #player["weapon"] =
"garlic"
- #player["health"] =
garlic["health"]
- #player["name"] = "Yoji"
-
- #assign different value...
- #player["weapon"] =
"tomato"
- #player["health"] =
tomato["health"]
- #player["name"] = "Yoji"
-
- player["weapon"] = "cheese"
- player["health"] =
cheese["health"]
- player["name"] = "Yoji"
-
-
- pname = player["name"]
- ename = enemy["name"]
-
-
- #define the function
- def
kitchen_battle(pname,ename):
- if
player["health"] >
enemy["health"]:
- print
"%s defeated your %s!" % (pname,ename)
- elif
player["health"] ==
enemy["health"]:
- print
"WOW! %s and your %s are
strong opponents!" % (pname,ename)
- else:
- print
"%s lost to your %s!" % (pname,ename)
-
-
- # call the function
- kitchen_battle(pname,ename)
- # end of the code
Yoji lost to your visiting_cook!
If the player chose different weapon, then the result of your "kitchen battle" based on the comparison between two health points would be different as well...i.e. if we go with ''garlic", the final output would be:
WOW! Yoji and your visiting_cook are strong opponents!
if we chose "tomato", the result would be:
Yoji defeated your visiting_cook!
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Back to CodeCombat. Screenshot of Level "Lowly Kithmen":
Goals:
- Your hero must survive
- Defeat the ogres(2/2)
- Collect the gems
- Bonus: no code problems
Code:
enemy1 = self.findNearestEnemy()
self.attack(enemy1)
self.attack(enemy1)
enemy2 = self.findNearestEnemy()
self.attack(enemy2)
self.attack(enemy2)
self.moveRight(2)
self.moveDown()
self.moveLeft()
No comments:
Post a Comment