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.ballType;
    
    # check ball type:
    ball.ballType
    
    # check ball type:
    ball.ball_type
    
    # 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.ghostCount["total"]           // default value is 0
          player1.ghostCount["white"]           // default value is 0
          player1.ghostCount["yellow"]          // default value is 0
          player1.ghostCount["purple"]          // default value is 0
          player1.ghostCount["red"]             // default value is 0
        
          player1.ghostCount["total"]           # default value is 0
          player1.ghostCount["white"]           # default value is 0
          player1.ghostCount["yellow"]          # default value is 0
          player1.ghostCount["purple"]          # default value is 0
          player1.ghostCount["red"]             # default value is 0
        
          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
        
          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 ballType: ball.ballType;
player1 = new Pacman();
player1.lives  //=> 3
player1.points //=> 0
player1.level  //=> 1
player1.ballCount //=> 0
player1.state  //=> "regular"
player1.superTime //=> 0

player1.eatBall(regularBall)
player1.points  //=> 1
player1.eatGhost(ghost)
player1.lives  //=> 2
player1.eatBall(superBall)
player1.state  //=> "super"
player1.eatGhost(ghost)
player1.lives  //=> 2
player1.points //=> 12
# check ballType: ball.ballType
player1 = new Pacman()
player1.lives #=> 3
player1.points #=> 0
player1.level #=> 1
player1.ballCount #=> 0
player1.state #=> "regular"
player1.superTime #=> 0
player1.eatBall regularBall
player1.points #=> 1
player1.eatGhost ghost
player1.lives #=> 2
player1.eatBall superBall
player1.state #=> "super"
player1.eatGhost ghost
player1.lives #=> 2
player1.points #=> 12
# 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
# check ball_type: ball.ball_type
player1 = Pacman()
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

Stats:

CreatedAug 7, 2014
Warriors Trained919
Total Skips454
Total Code Submissions4430
Total Times Completed134
Ruby Completions21
JavaScript Completions52
CoffeeScript Completions8
Python Completions63
Total Stars17
% of votes with a positive feedback rating0% of 0
Total "Very Satisfied" Votes11
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes29
Ad
Contributors
  • ogryzek Avatar
  • user578387 Avatar
Ad