Simple (Very Easy to Make) RPG Game Simulation in Python and Turtle
The code creates a very simple/easy RPG game, with 2 classes Jedi
and Orc
. The data is visualized using turtle
. Each class has a method of attack
(lightsaber_attack
for Jedi
), which has an argument that must be either a Jedi
or Orc
instance, the .health
attribute of the attacked one will be reduced by .power
of the attacker. If .health
is not positive, then the image of the character will disappear. By the design, each character can attack own self.
Simulation:
luke.lightsaber_attack( orc_1 )
luke.lightsaber_attack( orc_2 )
orc_1.attack( luke )
orc_2.attack( orc_2 )
Questions:
- How can I make the code to be easily understood by teenagers? (in a tutoring)
- How to make it more compact?
- Are there any missing important features of Python's OOP that is quite important to be explained to students? (except for super
and inheritance)
Links and full code:
The link for jedi_gif
: LINK
The link for orc_gif
: LINK
The link for darkorc_gif
: LINK
The link for damaged_gif
: LINK
import turtle
import time
jedi_gif = "/home/asus/Arief_tempo/images/random/jedi.gif"
orc_gif = "orc.gif"
darkorc_gif = "darkorc.gif"
damaged_gif = "damaged.gif"
turtle.register_shape( jedi_gif )
turtle.register_shape( orc_gif )
turtle.register_shape( darkorc_gif )
turtle.register_shape( damaged_gif )
class JediLuke:
def __init__(self):
self.power = 300
self.health = 300
self.img = turtle.Turtle( shape = jedi_gif )
self.damaged_img = turtle.Turtle( shape = damaged_gif, visible = False )
self.img.penup()
self.damaged_img.penup()
def lightsaber_attack(self, enemy):
self.img.setpos(enemy.img.pos()[0], enemy.img.pos()[1])
enemy.damaged_img.showturtle()
enemy.health += - self.power
time.sleep(1)
enemy.damaged_img.hideturtle()
if enemy.health < 0:
enemy.img.hideturtle()
self.img.setpos(200, 0)
def change_pos(self, pos):
self.img.setpos(pos[0], pos[1])
self.damaged_img.setpos(pos[0], pos[1] + 150)
class Orc:
def __init__(self, health, gif_image):
self.power = 100
self.health = health
self.img = turtle.Turtle( shape = gif_image )
self.damaged_img = turtle.Turtle( shape = damaged_gif, visible = False )
self.img.penup()
self.damaged_img.penup()
def attack(self, enemy):
current_pos = self.img.pos()
self.img.setpos(enemy.img.pos()[0], enemy.img.pos()[1])
enemy.damaged_img.showturtle()
enemy.health += - self.power
time.sleep(1)
enemy.damaged_img.hideturtle()
if enemy.health < 0:
enemy.img.hideturtle()
self.img.setpos(current_pos[0], current_pos[1])
def change_pos(self, pos):
self.img.setpos(pos[0], pos[1])
self.damaged_img.setpos(pos[0], pos[1] + 150)
luke = JediLuke()
luke.change_pos( [200, 0] )
orc_1 = Orc( health = 400 , gif_image = orc_gif)
orc_1.change_pos( [-200, 100] )
orc_2 = Orc( health = 200, gif_image = darkorc_gif )
orc_2.change_pos( [-200, -100] )
python object-oriented game role-playing-game turtle-graphics
add a comment |
The code creates a very simple/easy RPG game, with 2 classes Jedi
and Orc
. The data is visualized using turtle
. Each class has a method of attack
(lightsaber_attack
for Jedi
), which has an argument that must be either a Jedi
or Orc
instance, the .health
attribute of the attacked one will be reduced by .power
of the attacker. If .health
is not positive, then the image of the character will disappear. By the design, each character can attack own self.
Simulation:
luke.lightsaber_attack( orc_1 )
luke.lightsaber_attack( orc_2 )
orc_1.attack( luke )
orc_2.attack( orc_2 )
Questions:
- How can I make the code to be easily understood by teenagers? (in a tutoring)
- How to make it more compact?
- Are there any missing important features of Python's OOP that is quite important to be explained to students? (except for super
and inheritance)
Links and full code:
The link for jedi_gif
: LINK
The link for orc_gif
: LINK
The link for darkorc_gif
: LINK
The link for damaged_gif
: LINK
import turtle
import time
jedi_gif = "/home/asus/Arief_tempo/images/random/jedi.gif"
orc_gif = "orc.gif"
darkorc_gif = "darkorc.gif"
damaged_gif = "damaged.gif"
turtle.register_shape( jedi_gif )
turtle.register_shape( orc_gif )
turtle.register_shape( darkorc_gif )
turtle.register_shape( damaged_gif )
class JediLuke:
def __init__(self):
self.power = 300
self.health = 300
self.img = turtle.Turtle( shape = jedi_gif )
self.damaged_img = turtle.Turtle( shape = damaged_gif, visible = False )
self.img.penup()
self.damaged_img.penup()
def lightsaber_attack(self, enemy):
self.img.setpos(enemy.img.pos()[0], enemy.img.pos()[1])
enemy.damaged_img.showturtle()
enemy.health += - self.power
time.sleep(1)
enemy.damaged_img.hideturtle()
if enemy.health < 0:
enemy.img.hideturtle()
self.img.setpos(200, 0)
def change_pos(self, pos):
self.img.setpos(pos[0], pos[1])
self.damaged_img.setpos(pos[0], pos[1] + 150)
class Orc:
def __init__(self, health, gif_image):
self.power = 100
self.health = health
self.img = turtle.Turtle( shape = gif_image )
self.damaged_img = turtle.Turtle( shape = damaged_gif, visible = False )
self.img.penup()
self.damaged_img.penup()
def attack(self, enemy):
current_pos = self.img.pos()
self.img.setpos(enemy.img.pos()[0], enemy.img.pos()[1])
enemy.damaged_img.showturtle()
enemy.health += - self.power
time.sleep(1)
enemy.damaged_img.hideturtle()
if enemy.health < 0:
enemy.img.hideturtle()
self.img.setpos(current_pos[0], current_pos[1])
def change_pos(self, pos):
self.img.setpos(pos[0], pos[1])
self.damaged_img.setpos(pos[0], pos[1] + 150)
luke = JediLuke()
luke.change_pos( [200, 0] )
orc_1 = Orc( health = 400 , gif_image = orc_gif)
orc_1.change_pos( [-200, 100] )
orc_2 = Orc( health = 200, gif_image = darkorc_gif )
orc_2.change_pos( [-200, -100] )
python object-oriented game role-playing-game turtle-graphics
add a comment |
The code creates a very simple/easy RPG game, with 2 classes Jedi
and Orc
. The data is visualized using turtle
. Each class has a method of attack
(lightsaber_attack
for Jedi
), which has an argument that must be either a Jedi
or Orc
instance, the .health
attribute of the attacked one will be reduced by .power
of the attacker. If .health
is not positive, then the image of the character will disappear. By the design, each character can attack own self.
Simulation:
luke.lightsaber_attack( orc_1 )
luke.lightsaber_attack( orc_2 )
orc_1.attack( luke )
orc_2.attack( orc_2 )
Questions:
- How can I make the code to be easily understood by teenagers? (in a tutoring)
- How to make it more compact?
- Are there any missing important features of Python's OOP that is quite important to be explained to students? (except for super
and inheritance)
Links and full code:
The link for jedi_gif
: LINK
The link for orc_gif
: LINK
The link for darkorc_gif
: LINK
The link for damaged_gif
: LINK
import turtle
import time
jedi_gif = "/home/asus/Arief_tempo/images/random/jedi.gif"
orc_gif = "orc.gif"
darkorc_gif = "darkorc.gif"
damaged_gif = "damaged.gif"
turtle.register_shape( jedi_gif )
turtle.register_shape( orc_gif )
turtle.register_shape( darkorc_gif )
turtle.register_shape( damaged_gif )
class JediLuke:
def __init__(self):
self.power = 300
self.health = 300
self.img = turtle.Turtle( shape = jedi_gif )
self.damaged_img = turtle.Turtle( shape = damaged_gif, visible = False )
self.img.penup()
self.damaged_img.penup()
def lightsaber_attack(self, enemy):
self.img.setpos(enemy.img.pos()[0], enemy.img.pos()[1])
enemy.damaged_img.showturtle()
enemy.health += - self.power
time.sleep(1)
enemy.damaged_img.hideturtle()
if enemy.health < 0:
enemy.img.hideturtle()
self.img.setpos(200, 0)
def change_pos(self, pos):
self.img.setpos(pos[0], pos[1])
self.damaged_img.setpos(pos[0], pos[1] + 150)
class Orc:
def __init__(self, health, gif_image):
self.power = 100
self.health = health
self.img = turtle.Turtle( shape = gif_image )
self.damaged_img = turtle.Turtle( shape = damaged_gif, visible = False )
self.img.penup()
self.damaged_img.penup()
def attack(self, enemy):
current_pos = self.img.pos()
self.img.setpos(enemy.img.pos()[0], enemy.img.pos()[1])
enemy.damaged_img.showturtle()
enemy.health += - self.power
time.sleep(1)
enemy.damaged_img.hideturtle()
if enemy.health < 0:
enemy.img.hideturtle()
self.img.setpos(current_pos[0], current_pos[1])
def change_pos(self, pos):
self.img.setpos(pos[0], pos[1])
self.damaged_img.setpos(pos[0], pos[1] + 150)
luke = JediLuke()
luke.change_pos( [200, 0] )
orc_1 = Orc( health = 400 , gif_image = orc_gif)
orc_1.change_pos( [-200, 100] )
orc_2 = Orc( health = 200, gif_image = darkorc_gif )
orc_2.change_pos( [-200, -100] )
python object-oriented game role-playing-game turtle-graphics
The code creates a very simple/easy RPG game, with 2 classes Jedi
and Orc
. The data is visualized using turtle
. Each class has a method of attack
(lightsaber_attack
for Jedi
), which has an argument that must be either a Jedi
or Orc
instance, the .health
attribute of the attacked one will be reduced by .power
of the attacker. If .health
is not positive, then the image of the character will disappear. By the design, each character can attack own self.
Simulation:
luke.lightsaber_attack( orc_1 )
luke.lightsaber_attack( orc_2 )
orc_1.attack( luke )
orc_2.attack( orc_2 )
Questions:
- How can I make the code to be easily understood by teenagers? (in a tutoring)
- How to make it more compact?
- Are there any missing important features of Python's OOP that is quite important to be explained to students? (except for super
and inheritance)
Links and full code:
The link for jedi_gif
: LINK
The link for orc_gif
: LINK
The link for darkorc_gif
: LINK
The link for damaged_gif
: LINK
import turtle
import time
jedi_gif = "/home/asus/Arief_tempo/images/random/jedi.gif"
orc_gif = "orc.gif"
darkorc_gif = "darkorc.gif"
damaged_gif = "damaged.gif"
turtle.register_shape( jedi_gif )
turtle.register_shape( orc_gif )
turtle.register_shape( darkorc_gif )
turtle.register_shape( damaged_gif )
class JediLuke:
def __init__(self):
self.power = 300
self.health = 300
self.img = turtle.Turtle( shape = jedi_gif )
self.damaged_img = turtle.Turtle( shape = damaged_gif, visible = False )
self.img.penup()
self.damaged_img.penup()
def lightsaber_attack(self, enemy):
self.img.setpos(enemy.img.pos()[0], enemy.img.pos()[1])
enemy.damaged_img.showturtle()
enemy.health += - self.power
time.sleep(1)
enemy.damaged_img.hideturtle()
if enemy.health < 0:
enemy.img.hideturtle()
self.img.setpos(200, 0)
def change_pos(self, pos):
self.img.setpos(pos[0], pos[1])
self.damaged_img.setpos(pos[0], pos[1] + 150)
class Orc:
def __init__(self, health, gif_image):
self.power = 100
self.health = health
self.img = turtle.Turtle( shape = gif_image )
self.damaged_img = turtle.Turtle( shape = damaged_gif, visible = False )
self.img.penup()
self.damaged_img.penup()
def attack(self, enemy):
current_pos = self.img.pos()
self.img.setpos(enemy.img.pos()[0], enemy.img.pos()[1])
enemy.damaged_img.showturtle()
enemy.health += - self.power
time.sleep(1)
enemy.damaged_img.hideturtle()
if enemy.health < 0:
enemy.img.hideturtle()
self.img.setpos(current_pos[0], current_pos[1])
def change_pos(self, pos):
self.img.setpos(pos[0], pos[1])
self.damaged_img.setpos(pos[0], pos[1] + 150)
luke = JediLuke()
luke.change_pos( [200, 0] )
orc_1 = Orc( health = 400 , gif_image = orc_gif)
orc_1.change_pos( [-200, 100] )
orc_2 = Orc( health = 200, gif_image = darkorc_gif )
orc_2.change_pos( [-200, -100] )
python object-oriented game role-playing-game turtle-graphics
python object-oriented game role-playing-game turtle-graphics
asked 54 mins ago
Arief Anbiya
467214
467214
add a comment |
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210494%2fsimple-very-easy-to-make-rpg-game-simulation-in-python-and-turtle%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210494%2fsimple-very-easy-to-make-rpg-game-simulation-in-python-and-turtle%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown