Question

In: Computer Science

Can someone add comments on this explaining the code and also I could not figure out...

Can someone add comments on this explaining the code and also I could not figure out how to code the finalbattle to make it where if u use a lowercase "a" for the final attack you lose.

from sys import exit

print ("The city needs your help, you must save them!")
print ("What is your name?")
name=input("Enter your name:")
print ("Ok, are you ready to begin?")
def decisions():
decision = input("yes or no?\n")
if decision == "yes":
print ("You made the right decision, may your blade keep you safe.")
elif decision == "no":
print ("You have let the people down and the city will be destroyed.")
exit(0)
decisions()

def choosepath():
print ("You must leave the town in order to save the people.")
print ("You may go either north or south to destroy the enemies raiding the city.")
print ("The paths to the east and west have been destroyed and it is up to you to stop this from happening elsewhere.")
path = ''
while path !='north' and path !='south'and path !='east' and path !='west':
print ("which path would you like to take?")
print ("choose north or south:")
path = input()
if path =="north":
print ("You head north towards the enemy approching the front gates.")
elif path=="south":
print ("You head south to sneak up on the enemy and attack from behind.")
choosepath()

print("You arrive at the battle and start planning your attack!")
print("You spot an enemy and must make a wise decision to start your fight...")
print("Before picking your target you must choose your weapon!")
def weapon():
weapon = ''
while weapon != 'sword' and weapon !='axe':
print("Choose your sword or axe!")
weapon = input ()
if weapon == "sword":
print("You chose sword!")
elif weapon =="axe":
print ("You chose axe!")
weapon()

print("Now that you have chosen your weapon it is time to attack!")
print("You look around for a brief moment...")
print("You start to have doubts, now is your chance to turn around.")
print("Would you like to turn around and let the people die to save your own life?")
final_decision = input ("yes or no?\n")
if final_decision == "yes":
print("You have let the people down...")
exit(0)
elif final_decision =="no":
print("You are a brave knight.")
print("Now is your time to strike!")
print("Quickly! the enemy is approaching, it is now or never!")

enemy = 0
a=50
A=50

enemy_approaches = input ("Press a to attack!")
if enemy_approaches=='a' or enemy_approaches =='A':
enemy = enemy + 50
enemy_approaches = input ("The enemy is getting weaker keep attacking!")
if enemy_approaches=='a' or enemy_approaches =='A':
enemy = enemy + 50
enemy_approaches = input ("Time for the final blow!")
if enemy_approaches=='a' or enemy_approaches =='A':
enemy = enemy+ 50
if enemy >= 150:
print ("Congratulations, you have defeated the enemy!")

def finalbattle():
print("You defeated a soldier now it is time to take out the leader!")
print("You must be careful great knight, he if very powerful!")
print("You will need to use power attacks to defeat him!")
print("Use capital A for a power attack.")
print("Use basic attacks until he is stunned, when the time is right kill him with a powerful blow!")
print("...")
print("NOW! IT IS TIME TO ATTACK!")

finalbattle()

enemy = 0
a=50
A=100

enemy_approaches = input ("Press a to attack!")
if enemy_approaches=='a':
enemy = enemy + 50
enemy_approaches = input ("One more and you will have him stunned!")
if enemy_approaches=='a':
enemy = enemy + 50
enemy_approaches = input ("You stunned him! Use your powerful strike")
if enemy_approaches =='A':
enemy = enemy+ 100
if enemy >= 200:
print("You have defeated the boss and saved the city!")
print("YOU WIN!")

Solutions

Expert Solution

CODE for the above game (PYTHON):

from sys import exit #Importing modules

print ("The city needs your help, you must save them!") #This is the output statement visible on the screen

print ("What is your name?")

name=input("Enter your name:") #Prompting the user to enter his/her name

print ("Ok, are you ready to begin?") #Output statement to the screen

def decisions(): #"Decisions" function for taking the decision from the Player(user)

decision = input("yes or no?\n") #Prompting the player to take a decision (yes or no)

if decision == "yes": #If the decision taken by the player is "yes"

print ("You made the right decision, may your blade keep you safe.") #Output this statement to the screen

elif decision == "no": #If the decision taken by the use is "no"

print ("You have let the people down and the city will be destroyed.") #Output this statement to the screen

exit(0) #Exiting the game (program)

decisions() #Calling the "decisions" function

def choosepath(): #"choosepath" is a function for choosing a path by the use

print ("You must leave the town in order to save the people.") #The below 3 statements are outputted to the screen

print ("You may go either north or south to destroy the enemies raiding the city.")

print ("The paths to the east and west have been destroyed and it is up to you to stop this from happening elsewhere.")

path = '' #Inititalising "path" variable as an empty string

while path !='north' and path !='south'and path !='east' and path !='west': #while loop continues until the player enters any path (north or south)

print ("which path would you like to take?")

print ("choose north or south:")

path = input() #Prompting the player to take a path (north or south)

if path =="north": #If the chosen path is "north"

print ("You head north towards the enemy approching the front gates.") #Output this statement

elif path=="south": #If the chosen path is "south"

print ("You head south to sneak up on the enemy and attack from behind.") #Output this statement

choosepath() #Calling the "choospath" function

print("You arrive at the battle and start planning your attack!") #Below 3 lines are outputted to the screen.

print("You spot an enemy and must make a wise decision to start your fight...")

print("Before picking your target you must choose your weapon!")

def weapon(): #"weapon" method for letting the player to choose a weapon ("sword" or "axe")

weapon = '' #Initialising the weapon variable as an empty string

while weapon != 'sword' and weapon !='axe': #While loop continues until the player chooses any weapon ("sword" or "axe")

print("Choose your sword or axe!")

weapon = input () #Prompting the player to choose a weapon

if weapon == "sword": #If the player chooses "sword" as the weapon

print("You chose sword!")

elif weapon =="axe": #If the player chooses "axe" as the weapon

print ("You chose axe!")

weapon() #Calling the weapon function

print("Now that you have chosen your weapon it is time to attack!") #Below 4 lines are outputted to the screen.

print("You look around for a brief moment...")

print("You start to have doubts, now is your chance to turn around.")

print("Would you like to turn around and let the people die to save your own life?")

final_decision = input ("yes or no?\n") #Prompting the player to take the final decision

if final_decision == "yes": #If the final decision is "yes"

print("You have let the people down...") #The game is over....:(

exit(0) #Exiting the program

elif final_decision =="no": #If the final decision is "no"

print("You are a brave knight.") #Outputs the below 3 statements to the screen

print("Now is your time to strike!")

print("Quickly! the enemy is approaching, it is now or never!")

enemy = 0 #Initialising enemy variable (amount of scaring) to 0

a=50 #Initialisng variable a to 50

A=50

enemy_approaches = input ("Press a to attack!") #Prompting the player to attack..

if enemy_approaches=='a' or enemy_approaches =='A': #If the player attacks (i.e., when the player enters "a" or "A")

enemy = enemy + 50 #Increasing the amount of scaring of the enemy to 50

enemy_approaches = input ("The enemy is getting weaker keep attacking!") #Prompting the player to attack again

if enemy_approaches=='a' or enemy_approaches =='A': #If the player attacks:

enemy = enemy + 50 #Again increase the amount of scaring of the enemy..

enemy_approaches = input ("Time for the final blow!") #Right time to give the final blow...

if enemy_approaches=='a' or enemy_approaches =='A': #If the player attacks again:

enemy = enemy+ 50 #Increasing the enemy variable again 50 (amount of scaring)

if enemy >= 150: #If the amount of scaring of the enemy is greater than 150 (i.e.,

# the enemy is scared very much so it will be easy for the player to defeat the enemy..)

print ("Congratulations, you have defeated the enemy!") #Outputting this statement to the screen

def finalbattle(): # "finalbattle" function is fighting with the boss

print("You defeated a soldier now it is time to take out the leader!") #The below 7 lines are outputted to the screen

print("You must be careful great knight, he if very powerful!")

print("You will need to use power attacks to defeat him!")

print("Use capital A for a power attack.")

print("Use basic attacks until he is stunned, when the time is right kill him with a powerful blow!")

print("...")

print("NOW! IT IS TIME TO ATTACK!")

finalbattle() #Calling the "finalbattle" function

enemy = 0 #Initialising enemy variable to 0

a=50

A=100

enemy_approaches = input ("Press a to attack!") #Prompting the player to attack..

if enemy_approaches=='a': #If the player enters "a"

enemy = enemy + 50 #Incrementing the enemy variable

enemy_approaches = input ("One more and you will have him stunned!") #Prompting the player to attack again

if enemy_approaches=='a': #If the player again enter "a"

enemy = enemy + 50 #Incrementing the enemy variable again

enemy_approaches = input ("You stunned him! Use your powerful strike") #Prompting the player to take powerfull strike...

if enemy_approaches == 'a': #If the player enters "a" instead of "A":

print("You have let the people down...") #Boss (ENEMY) defeats the Player(player)

print("YOU LOSE") #Player has lost the game

if enemy_approaches =='A': #If the player enters "A"

enemy = enemy+ 100 #Incrementing the enemy variable

if enemy >= 200: #If the enemy variable is greater than 200:

print("You have defeated the boss and saved the city!") #The Player wins...(i.e., Player has defeated the boss)

print("YOU WIN!") #Player "WINS"

#END OF THE CODE

Above CODE implementation:

Above CODE output:

#Below is the output When the player hits (enters) " A " for the final strike:

#When the player hits " A " the player "WINS"

# Below is the output when the player hits " a " for the final strike:

# When the player hits (enters) " a " for the final strike the player gets DEFEATED (LOSES )

NOTE:

# Be aware of the indentation while copying the above code into the editor or idle by observing the above uploaded CODE pictures..

#Any questions or clarifications regarding this problem can be asked in the comments section..


Related Solutions

Can someone please add clear and concise comments thoroughly explaining each line of code below. Just...
Can someone please add clear and concise comments thoroughly explaining each line of code below. Just need help understanding the code, don't need to modify it. The purpose of the code is to count the frequency of words in a text file, and return the most frequent word with its count. It uses two algorithms: Algorithm 1 is based on the data structure LinkedList. It maintains a list for word frequencies. The algorithm runs by scanning every token in the...
Can you add more comments explaining what this code does? i commented what I know so...
Can you add more comments explaining what this code does? i commented what I know so far #include<stdio.h> #include<pthread.h> #include<semaphore.h> #include<unistd.h> sem_t mutex,writeblock; int data = 0,rcount = 0; int sleepLength = 2; // used to represent work void *reader(void *arg) { int f; f = ((int)arg); sem_wait(&mutex); // decrement by 1 if rcount = rcount + 1; if(rcount==1) sem_wait(&writeblock); sem_post(&mutex); printf("Data read by the reader%d is %d\n",f,data); //shows current reader and data sleep(sleepLength); // 1 second of "work" is...
Can someone please write clear and concise comments explaining what each line of code is doing...
Can someone please write clear and concise comments explaining what each line of code is doing for this program in C. I just need help tracing the program and understand what its doing. Thanks #include <stdio.h> #include<stdlib.h> #include<unistd.h> #include<sys/wait.h> int join(char *com1[], char *com2[]) {    int p[2], status;    switch (fork()) {        case -1:            perror("1st fork call in join");            exit(3);        case 0:            break;        default:...
Also please add comments on the code and complete in C and also please use your...
Also please add comments on the code and complete in C and also please use your last name as key. The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message. Test...
I would appreciate if someone could work this out and also explain how to find the...
I would appreciate if someone could work this out and also explain how to find the upper and lower limits. Rothamsted Experimental Station (England) has studied wheat production since 1852. Each year, many small plots of equal size but different soil/fertilizer conditions are planted with wheat. At the end of the growing season, the yield (in pounds) of the wheat on the plot is measured. For a random sample of years, one plot gave the following annual wheat production (in...
I can't seem to figure out what the hybridization of PF6(-) is. could someone explain how...
I can't seem to figure out what the hybridization of PF6(-) is. could someone explain how to find it correctly for me?
hi,I have this C++ program,can someone add few comments with explanation what is the logic and...
hi,I have this C++ program,can someone add few comments with explanation what is the logic and what is what?thank you I m total beginner #include <iostream> using namespace std; int ArraySum(int MyArray[], int size){ int* p = MyArray; int sum = 0; while(p<MyArray+size){ sum += *p; p++; } return sum; } int main() { int MyArray[10] = {4, 0, 453, 1029, 44, 67, 111, 887, 4003, 1002}; cout<<ArraySum(MyArray,10); return 0; }
please I don't understand this code. Can you put comments to explain the statements. Also, if...
please I don't understand this code. Can you put comments to explain the statements. Also, if there any way to rewrite this code to make it easier, that gonna help me a lot. import java.io.*; import java.util.*; public class State {    private int citi1x,citi1y; private int pop1; private int citi2x,citi2y; private int pop2; private int citi3x,citi3y; private int pop3; private int citi4x,citi4y; private int pop4; private int plantx,planty; public int getCity1X(){ return citi1x; } public int getCity1Y(){ return citi1y;...
Could someone point out the logical error in this code? The code seems to start at...
Could someone point out the logical error in this code? The code seems to start at the last input. But I want the code to output something like this: Enter name: A Enter time:5 Enter name:B Enter time: 4 Enter name: C Enter time:3 Enter name:D Enter time: 9 Enter name: E Enter time: 11 A process is started and ends in 5 sec. 1 sec passed... 2 sec passed... 3 sec passed... 4 sec passed... 5 sec passed... B...
C# Tip Calculator. I can't figure the code out for this assignment can I get some...
C# Tip Calculator. I can't figure the code out for this assignment can I get some help For this assignment, you'll create a simple tip calculator. Expected program flow: Ask the user for the bill total. Ask the user for the tip percent. Print the final output in the following format when the user enters 10 and 15 for the first two prompts: Total for bill $10.00 with a 15% tip is $11.50 Note that the money values should be...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT