示例#1
0
//  Take a 'turn' (throw three darts)
void Player::TakeTurn(int cursoractual[], int cursorpos[], int BGPos[], bool playertothrow) {
	int throws = 3;
	int wait = 0;
	p_turnthrows = 0;
	p_turnstartpoints = p_points;
	SetTile(27, 23+5*playertothrow, 1, 5);
	SetTile(27, 23+5*playertothrow-1, 1, 5);
	SetTile(27, 23+5*playertothrow-2, 1, 5);
	
	while ((throws > 0 && p_points > 0) || wait < 40) {
		UpdateObjects();
		
		if (throws > 0 && p_points > 0) {	
			WaitVSync();
			UpdateObjects();
			TakeAShot(cursoractual, cursorpos, BGPos);
			DrawPoints(20+5*playertothrow, 4 + p_throws);
			
			SetTile(27, 23+5*playertothrow-p_turnthrows, 1, 4);
			
			p_throws++;
			p_turnthrows++;
			throws--;
		} else {
			wait++;
		}
		
		for (int i = 0; i < p_turnthrows; i++) {
			darts[i].UpdateDart(BGPos);			
		}
	}
	SetTile(27, 23+5*playertothrow, 1, 4);
	SetTile(27, 23+5*playertothrow-1, 1, 4);
	SetTile(27, 23+5*playertothrow-2, 1, 4);
	ClearObjects();
}
void test1(void)
{
    // Initialize the pseudo-random number generator
  CS170::Utils::srand(0, 0);

    // Setup the ocean
  int num_boats = 3;
  int xsize = 8;
  int ysize = 8;
  CS170::WarBoats::Ocean *theOcean;
  theOcean = CS170::WarBoats::CreateOcean(num_boats, xsize, ysize);
  CS170::WarBoats::Ocean &ocean = *theOcean;

  std::cout << "The empty board" << std::endl;
  CS170::WarBoats::DumpOcean(ocean);
  std::cout << std::endl;

  CS170::WarBoats::Boat boat;
  CS170::WarBoats::Point location;

    // Boat #1
  boat.ID = 1;
  location.x = 1;
  location.y = 3;
  boat.position = location;
  boat.orientation = CS170::WarBoats::oHORIZONTAL;
  CS170::WarBoats::PlaceBoat(ocean, boat);

    // Boat #2
  boat.ID = 2;
  location.x = 5;
  location.y = 1;
  boat.position = location;
  boat.orientation = CS170::WarBoats::oVERTICAL;
  CS170::WarBoats::PlaceBoat(ocean, boat);

    // Boat #3
  boat.ID = 3;
  location.x = 0;
  location.y = 5;
  boat.position = location;
  boat.orientation = CS170::WarBoats::oHORIZONTAL;
  CS170::WarBoats::PlaceBoat(ocean, boat);

  std::cout << "The board with " << num_boats << " boats" << std::endl;
  CS170::WarBoats::DumpOcean(ocean);
  std::cout << std::endl;

  CS170::WarBoats::Point coordinate;

    // Illegal coordinate
  coordinate.x = 10;
  coordinate.y = 5;
  TakeAShot(ocean, coordinate);

    // HIT
  coordinate.x = 1;
  coordinate.y = 3;
  TakeAShot(ocean, coordinate);

    // MISS
  coordinate.x = 5;
  coordinate.y = 7;
  TakeAShot(ocean, coordinate);

    // DUPLICATE
  coordinate.x = 1;
  coordinate.y = 3;
  TakeAShot(ocean, coordinate);

    // HIT
  coordinate.x = 2;
  coordinate.y = 3;
  TakeAShot(ocean, coordinate);

    // HIT
  coordinate.x = 3;
  coordinate.y = 3;
  TakeAShot(ocean, coordinate);

    // SUNK
  coordinate.x = 4;
  coordinate.y = 3;
  TakeAShot(ocean, coordinate);
  CS170::WarBoats::DestroyOcean(theOcean);
}