Beispiel #1
0
//------------------------------------------------------
bool output(sData* data)
{
  std::cout << "\nOutput below:";

  showScalar(data, "scalar 1", data->s1);

  if( !saveGrid(data, "phyGrid") ) 				{ return false; }
  if( !saveScalar(data, "scalar.dat",data->s1) )	{ return false; }

  std::cout << "Success...\n";
  return true;
}
Beispiel #2
0
//---------------------------------------------------------------------------------
// Function:	setships()
// Title:	Set Ships 
// Description:
//		Allows user to put ships in grid
// Programmer:	Paul Bladek
// modified by:	Kyle Graham
//				Hang Nguyen
// 
// Date:	9/12/06
//
// Version:	0.5
// 
// Environment: Hardware: i3 
//              Software: OS: Windows 7; 
//              Compiles under Microsoft Visual C++ 2012
//
// Input:	location and orientation using getCoord from cin
//
// Output:	prompts to cout
//
// Calls:	printGrid()
//		safeChoice()
//		getCoord()
//		saveGrid()
//
// Called By:	main()
//
// Parameters:	players: Player[];	the array of 2 players 
//		size: char;		'S' or 'L'
//		whichPlayer: short;	the player number (0 or 1)
// 
// Returns:	void
//
// History Log: 
//				9/12/06 PB comleted v 0.5
//				1/16/15 KG & HN completed v 0.6
//				1/23/15 KG & HN completed v 0.7
//				1/29/15 KG & HN completed v 0.8
//     
//---------------------------------------------------------------------------------
void setships(Player players[], char size, short whichPlayer)
{
	char input = 'V';
	char ok = 'Y';
	char save = 'N';
	ostringstream outSStream;
	Cell location = {0, 0};

	for(short j = 1; j < SHIP_SIZE_ARRAYSIZE; j++)
	{
		system("cls");
		printGrid(cout, players[whichPlayer].m_gameGrid[0], size);
		outSStream.str("");
		outSStream << "Player " << whichPlayer + 1 << " Enter " 
			<< shipNames[j] << " orientation";
		input = safeChoice(outSStream.str(), 'V', 'H');
		players[whichPlayer].m_ships[j].m_orientation = (input == 'V') 
			? VERTICAL : HORIZONTAL;
		cout << "Player " << whichPlayer + 1 << " Enter " << shipNames[j] 
			<< " bow coordinates <row letter><col #>: ";
		players[whichPlayer].m_ships[j].m_bowLocation = getCoord(cin, size);
		location = players[whichPlayer].m_ships[j].m_bowLocation;
		// if ok
		if(!validLocation(players[whichPlayer], j, size))
		{
			cout << "invalid location. Press <enter>" ;
			cin.get();
			j--; // redo
			continue;
		}
		// our code
		for(int i = 0; i < shipSize[j]; i ++)
		{
			if (input == 'V')
			{
				players[whichPlayer].m_gameGrid[0][location.m_row + i]
					[location.m_col] = static_cast<Ship>(j);
			}
			else
			{
				players[whichPlayer].m_gameGrid[0][location.m_row]
					[location.m_col + i] = static_cast<Ship>(j);
			}
		}
		system("CLS");
		printGrid(cout, players[whichPlayer].m_gameGrid[0], size);
		ok = safeChoice("Position okay? ", 'Y', 'N');
		// choice not ok
		if (ok == 'N')
		{
			for(int i = 0; i < shipSize[j]; i ++)
			{
				if (input == 'V')
				{
					players[whichPlayer].m_gameGrid[0][location.m_row + i]
						[location.m_col] = NOSHIP;
				}
				else
				{
					players[whichPlayer].m_gameGrid[0][location.m_row]
						[location.m_col + i] = NOSHIP;
				}
			}
			system("CLS");
			printGrid(cout, players[whichPlayer].m_gameGrid[0], size);
			j--;
		}
	} // end for j
	save = safeChoice("\nSave starting grid?", 'Y', 'N');
	if(save == 'Y')
	saveGrid(players, whichPlayer, size);
}
Beispiel #3
0
void CPlayer::setships()
{
	char input = 'V';
	char ok = 'Y';
	char save = 'N';
	ostringstream outSStream;
	CCell location;

	for(short j = 1; j < SHIP_SIZE_ARRAYSIZE; j++)
	{
		system("cls");
		printGrid(cout, ZERO);
		outSStream.str("");
		outSStream << "Player " << m_whichPlayer + ONE << " Enter " 
			<< shipNames[j] << " orientation";
		input = safeChoice(outSStream.str(), 'V', 'H');
		if (input == 'V')
			m_ships[j].setOrientation(ONE);
		else
			m_ships[j].setOrientation(ZERO);
		cout << "Player " << m_whichPlayer + ONE << " Enter " << shipNames[j] 
		<< " bow coordinates <row letter><col #>: ";
		location.getCoord(cin, m_gridSize);
		m_ships[j].setBowLocation(location);
		// if ok
		if(!isValidLocation(j))
		{
			cout << "invalid location. Press <enter>" ;
			cin.ignore(BUFFER_SIZE, '\n');
			cin.get();
			j--; // redo
			continue;
		}
		// our code
		location = m_ships[j].getCell();
		for(int i = 0; i < shipSize[j]; i++)
		{
			if (input == 'V')
			{
				setCell(ZERO, location, m_ships[j].getName());
				location.increaseRow();
			}
			else
			{
				setCell(ZERO, location, m_ships[j].getName());
				location.increaseCol();
			}
		}
		system("CLS");
		printGrid(cout, ZERO);
		ok = safeChoice("Position okay? ", 'Y', 'N');
		// choice not ok
		if (ok == 'N')
		{
			location = m_ships[j].getCell(); 
			for(int i = 0; i < shipSize[j]; i++)
			{
				if (input == 'V')
				{
					setCell(ZERO, location, CShip::NOSHIP);
					location.increaseRow();
				}
				else
				{
					setCell(ZERO, location, CShip::NOSHIP);
					location.increaseCol();
				}
			}
			j--;
		}
	} // end for j
	save = safeChoice("\nSave starting grid?", 'Y', 'N');
	if(save == 'Y')
		saveGrid();
}