Draft
Pacman
21 of 134ogryzek
Description:
Pacman
Create a class Pacman:
- New Pacman objects are instantiated without any parameters
- New Pacman objects should have the following attributes:
- lives
- points
- level
- ball count
- ghost count
- state
- super time
- Pacman objects should have an "eat ball" method that takes a ball as an argument, and adds 1 to the point attribute when eating a ball
# check ball type: ball.ball_type
- each time a ball is eaten, points and ball count should each increase by 1
- if the ball count reaches 40, level should be increased by 1 and ball count should be reset to 0
- if the ball is of ball type "super", the Pacman object's state should change to "super" and set "super time" to 10
- if the Pacman's state is super, "super time" should be decreased by 1 each time a ball of ball type "regular" is eaten
- Pacman objects should have an "eat ghost" method that takes a ghost as an argument.
- If the Pacman object's state is "super" eating a ghost should increase points by 10.
- If the Pacman object's state is not super, eating a ghost should decrease lives by 1
- If the Pacman object has zero lives left, eating a ghost should reset points to zero.
- Eating a ghost should increase the total "ghost count" by 1
- We should be able to access the following attributes, which should increment accordingly when eating ghosts (e.g. eating a purple ghost should increase the 'ghost count total' by one and the 'ghost count purple' by one):
player1.ghost_count["total"] # default value is 0 player1.ghost_count["white"] # default value is 0 player1.ghost_count["yellow"] # default value is 0 player1.ghost_count["purple"] # default value is 0 player1.ghost_count["red"] # default value is 0
# check ball_type: ball.ball_type
player1 = Pacman.new
player1.lives #=> 3
player1.points #=> 0
player1.level #=> 1
player1.ball_count #=> 0
player1.state #=> "regular"
player1.super_time #=> 0
player1.eat_ball(regular_ball)
player1.points #=> 1
player1.eat_ghost(ghost)
player1.lives #=> 2
player1.eat_ball(super_ball)
player1.state #=> "super"
player1.eat_ghost(ghost)
player1.lives #=> 2
player1.points #=> 12
Object-oriented Programming
Similar Kata:
Stats:
Created | Aug 7, 2014 |
Warriors Trained | 919 |
Total Skips | 454 |
Total Code Submissions | 4430 |
Total Times Completed | 134 |
Ruby Completions | 21 |
JavaScript Completions | 52 |
CoffeeScript Completions | 8 |
Python Completions | 63 |
Total Stars | 17 |
% of votes with a positive feedback rating | 0% of 0 |
Total "Very Satisfied" Votes | 11 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 29 |