// File: Car.cpp
//
// Written by Richard Chang for CMSC202 Spring 2007
//

#include <cassert>

#include "proj2.h"
#include "Car.h"
#include "RaceCourse.h"

// ----------------------------------------------------
// --------------------- Constructors -----------------
//

Car::Car() :
   FuelLevel(0), Rptr(NULL), index(0)
{
  //do nothing
}


Car::Car(RaceCourse *ptr, int i, unsigned int fuel)  :
   FuelLevel(fuel), Rptr(ptr), index(i)
{
  // do nothing
}


// ----------------------------------------------------
// -------------- Moving methods ----------------------
// 

void Car::ZoomLeft() {
   unsigned int fuelUsed ;
   
   fuelUsed = Rptr->MoveMe(index, FuelLevel, 0, -1) ;
   assert(fuelUsed <= FuelLevel) ;
   FuelLevel -= fuelUsed ;
}

void Car::ZoomRight() {
   unsigned int fuelUsed ;
   
   fuelUsed = Rptr->MoveMe(index, FuelLevel, 0, 1) ;
   assert(fuelUsed <= FuelLevel) ;
   FuelLevel -= fuelUsed ;
}

void Car::ZoomUp() {
   unsigned int fuelUsed ;
   
   fuelUsed = Rptr->MoveMe(index, FuelLevel, -1, 0) ;
   assert(fuelUsed <= FuelLevel) ;
   FuelLevel -= fuelUsed ;
}

void Car::ZoomDown() {
   unsigned int fuelUsed ;
   
   fuelUsed = Rptr->MoveMe(index, FuelLevel, 1, 0) ;
   assert(fuelUsed <= FuelLevel) ;
   FuelLevel -= fuelUsed ;
}


// ----------------------------------------------------
// --------------- Accessors, etc ---------------------
// 

Position Car::GetPosition() const {
   return Rptr->GetMyPosition(index) ;
}


unsigned int Car::GetFuelLevel() const {
   return FuelLevel ;
}
