Coding in python Please!!I need help please help me in the easiest way to do this coding question. Please do not post it's answer from chegg just use your own skills to write code in easyiest way possible. I will really appriciate your help. Coding language PYTHON : The purpose of this assignment is to help you get comfortable creating and using simple classes and objects. In this assignment, we wish to model a 2-D video game character’s movements. In particular, suppose we are creating a tiny game, where the character can occupy one of 25 squares, like so: The first thing we need to keep track of is the character’s name, so we can differentiate this character from other characters or enemies. The other thing we need to keep track of is the character’s position, i.e., which square they are in. In order to do this, we’ll use an X-Y coordinate system with the origin in the top left corner (the 0,0 square in the picture). So, in the picture, the character occupies square 3, 2; that is, x=3 and y=2. Your task is to create a class representing the Character. Your class should have three attributes: name, x, and y. Your class should have an __init__ method. The __init__method should accept a name (required) as an argument, and should accept optional arguments for x and y. If x and y are not supplied, they should default to 0, 0. For the time being, we will not require any error checking to prevent invalid x and y values. Your class should also have a __str__ method, which should return a string that looks like the following: Bob, x: 2, y: 3 Where Bob is whatever the Character’s name is. Lastly, your class should have four methods: move_up(), move_left(), move_down(), move_right(). The methods should each check to make sure the move is possible, and if so, update the x or y value appropriately. If the move isn’t legal, you should just print an error message (i.e., “cannot move up, already at the top!”), and not update any values. An example of the program running is provided here: >>> bob = Character (“Bob”, 0, 1) >>> print(bob) Bob, x: 0, y: 1 >>> bob.move_up() >>> print(bob) Bob, x: 0, y: 0 >>> bob.move_right() >>> print(bob) Bob, x: 1, y: 0 >>> bob.move_up() Error: can’t move up, already at the top! >>> bob.move_down() >>> bob.move_down() >>> bob.move_down() >>> print(bob)
Coding in python
Please!!I need help please help me in the easiest way to do this coding question. Please do not post it's answer from chegg just use your own skills to write code in easyiest way possible. I will really appriciate your help.
Coding language PYTHON :
The purpose of this assignment is to help you get comfortable creating and using simple classes and objects.
In this assignment, we wish to model a 2-D video game character’s movements. In particular, suppose we are creating a tiny game, where the character can occupy one of 25 squares, like so:
The first thing we need to keep track of is the character’s name, so we can differentiate this character from other characters or enemies. The other thing we need to keep track of is the character’s position, i.e., which square they are in. In order to do this, we’ll use an X-Y coordinate system with the origin in the top left corner (the 0,0 square in the picture). So, in the picture, the character occupies square 3, 2; that is, x=3 and y=2.
Your task is to create a class representing the Character. Your class should have three attributes: name, x, and y. Your class should have an __init__ method. The __init__method should accept a name (required) as an argument, and should accept optional arguments for x and y. If x and y are not supplied, they should default to 0, 0. For the time being, we will not require any error checking to prevent invalid x and y values.
Your class should also have a __str__ method, which should return a string that looks like the following:
Bob, x: 2, y: 3
Where Bob is whatever the Character’s name is.
Lastly, your class should have four methods: move_up(), move_left(), move_down(), move_right(). The methods should each check to make sure the move is possible, and if so, update the x or y value appropriately. If the move isn’t legal, you should just print an error message (i.e., “cannot move up, already at the top!”), and not update any values.
An example of the program running is provided here:
>>> bob = Character (“Bob”, 0, 1)
>>> print(bob)
Bob, x: 0, y: 1
>>> bob.move_up()
>>> print(bob)
Bob, x: 0, y: 0
>>> bob.move_right()
>>> print(bob)
Bob, x: 1, y: 0
>>> bob.move_up()
Error: can’t move up, already at the top!
>>> bob.move_down()
>>> bob.move_down()
>>> bob.move_down()
>>> print(bob)
Bob, x: 1, y: 3
Step by step
Solved in 4 steps with 2 images