示例#1
0
int Server::step(int x, int y, char direction)
{
	char name = grid[cellValue(x, y)];
	std::map<char, coordinates> directions;
	directions['N'].y = -1;
	directions['N'].x = 0;
	directions['S'].y = 1;
	directions['S'].x = 0;
	directions['W'].y = 0;
	directions['W'].x = -1;
	directions['E'].y = 0;
	directions['E'].x = 1;

	if (x + directions[direction].x < 0 || y + directions[direction].y < 0 || x + directions[direction].x >= width || y + directions[direction].y >= height) {
		removeVehicle(name);
		return 0;
	}
	grid[cellValue(x, y)] = ' ';

	char tmp_field;
	int destinationX = x + directions[direction].x;
	int destinationY = y + directions[direction].y;

	if ((tmp_field = grid[cellValue(destinationX, destinationY)]) == ' ') {
		grid[cellValue(destinationX, destinationY)] = name;
	} else {
		removeVehicle(name);
		removeVehicle(tmp_field);
		return 0;
	}
	return 0;
}
示例#2
0
void Server::removeVehicle(char name)
{
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			if (grid[cellValue(x, y)] == name) {
				grid[cellValue(x, y)] = ' ';
			}
		}
	}
	kill(registeredVehicles[name], SIGTERM);
	registeredVehicles.erase(name);
	return;
}
示例#3
0
QString TableEditor::tableToString()
{
    QString tableStr;
    for (int i = 0; i < m_dataTable->numRows(); i++) {
      tableStr += indent(4);
      Node *node = (*m_tableRows)[i].node;
      Tag *tag = 0L;
      if (node)
          tag = node->tag;
      if (tag)
        tableStr += tag->toString();
      else
        tableStr += QuantaCommon::tagCase("<tr>");
      for (int j = 0; j < m_dataTable->numCols(); j++)  {
        if ((*m_tableTags)[i][j].node && !(*m_tableTags)[i][j].merged)
        {
          tableStr += indent(6);
          tableStr += cellValue(i, j);
        }
      }
      tableStr += indent(4);
      if (tag)
        tableStr += "</" + QuantaCommon::tagCase(tag->name) +">";
      else
        tableStr += QuantaCommon::tagCase("</tr>");
    }
  return tableStr;
}
示例#4
0
std::string Server::gridToString(std::vector<char> grid)
{
	std::string s;
	//Erste Reihe mit # füllen 1 mehr als Feld Breit
	for (int i = 0; i <= width + 1; i++) {
		s.push_back('#');
	}
	s.push_back('\n');

	for (int y = 0; y < height; y++) {
		s.push_back('#');
		for (int x = 0; x < width; x++) {
			s.push_back(grid[cellValue(x, y)]);
		}
		s.push_back('#');
		s.push_back('\n');
	}

	//Letzte Reihe mit # füllen
	for (int i = 0; i <= width + 1; i++) {
		s.push_back('#');
	}
	s.push_back('\n');

	return s;
}
示例#5
0
int Server::placeVehicle(char name, int pid)
{
	if (registeredVehicles.count(name) == 0) {
		registeredVehicles[name] = pid;
		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {

				if (grid[cellValue(x, y)] == ' ') {
					grid[cellValue(x, y)] = name;
					int encoded = (1000 * x + y);
					return encoded;
				}
			}
		}
	}
	return -1;
}
示例#6
0
int Server::moveVehicle(char name, char direction)
{
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			if (grid[cellValue(x, y)] == name) {

				step(x, y, direction);
				return 0;
			}
		}
	}
	return 0;
}
示例#7
0
void RKMatrixInput::copy () {
	RK_TRACE (PLUGIN);

	QItemSelectionRange range = display->getSelectionBoundaries ();
	if (!range.isValid ()) return;

	RKTextMatrix ret;
	for (int col = range.left (); col <= range.right (); ++col) {
		for (int row = range.top (); row <= range.bottom (); ++row) {
			ret.setText (row - range.top (), col - range.left (), cellValue (row, col));
		}
	}
	ret.copyToClipboard ();
}
示例#8
0
//__________________________________________________________
_HYObjectInspector::_HYObjectInspector(void):_HYTWindow (objectInspectorTitle, false)
{
    _HYRect         canvasSettings = {30,50,30,50,HY_COMPONENT_NO_SCROLL};
    _HYLabel*       l1 = new _HYLabel (canvasSettings,GetOSWindowData());
    canvasSettings.left  = 110;
    canvasSettings.right = 10000;
    _HYPullDown*    p1 = new _HYPullDown (canvasSettings,GetOSWindowData());
    p1->EnableMenu(true);
    canvasSettings.left = canvasSettings.right = 90;
    _HYButtonBar*   b1 = new _HYButtonBar(canvasSettings,GetOSWindowData());

    canvasSettings.top = 20;
    canvasSettings.left = 250;
    canvasSettings.bottom = 10000;
    canvasSettings.width = HY_COMPONENT_V_SCROLL;
    _HYTable*   ot  = new _HYTable (canvasSettings,GetOSWindowData(),1,2,125,100,HY_TABLE_STATIC_TEXT);
    canvasSettings.width = HY_COMPONENT_NO_SCROLL|HY_COMPONENT_BORDER_B|HY_COMPONENT_BORDER_T;
    _HYTable*   ot2 = new _HYTable (canvasSettings,GetOSWindowData(),1,2,125,20,HY_TABLE_STATIC_TEXT);


    ot->SetMessageRecipient (this);
    ot2->SetMessageRecipient (this);
    b1->SetMessageRecipient (this);
    p1->SetMessageRecipient (this);

    _String toolTipText ("Open window with the object");
    b1->AddButton (ProcureIconResource(HY_DATAPANEL_ICON_ID+7),&toolTipText);
    toolTipText = "Delete selected object";
    b1->AddButton (ProcureIconResource(HY_DATAPANEL_ICON_ID+3),&toolTipText);
    toolTipText = "Read object from file";
    b1->AddButton (ProcureIconResource(HY_DATAPANEL_ICON_ID+8),&toolTipText);
    toolTipText = "Create new object";
    b1->AddButton (ProcureIconResource(HY_DATAPANEL_ICON_ID+9),&toolTipText);

    b1->EnableButton(0,false);
    b1->EnableButton(1,false);
    b1->EnableButton(2,false);
    b1->EnableButton(3,false);
    b1->SetButtonDim(16);

    AddObject (l1);
    AddObject (ot);
    AddObject (ot2);
    AddObject (p1);
    AddObject (b1);
    SetTableDimensions (3,3);
    SetCell (0,0,b1);
    SetCell (0,1,p1);
    SetCell (0,2,p1);
    SetCell (1,0,ot2);
    SetCell (1,1,ot2);
    SetCell (1,2,ot2);
    SetCell (2,0,ot);
    SetCell (2,1,ot);
    SetCell (2,2,ot);

    _HYFont  labelFont;
#ifdef __WINDOZE__
    labelFont.face = "MS Sans Serif";
    labelFont.size = 10;
#else
#ifdef __HYPHY_GTK__
    labelFont.face = _HY_SANS_FONT;
    labelFont.size = 12;
#else
    labelFont.face = "Geneva";
    labelFont.size = 14;
#endif
#endif
    labelFont.style = HY_FONT_PLAIN;
    l1->SetFont (labelFont);
#ifdef __MAC__
    labelFont.face = "Times";
    labelFont.size = 12;
#endif
    ot->SetFont (labelFont);
    ot2->SetFont (labelFont);
    l1->SetBackColor (boxBColor);
    p1->SetBackColor (boxBColor);
    b1->SetBackColor (boxBColor);
    l1->SetForeColor (boxFColor);
    l1->SetAlignFlags (HY_ALIGN_LEFT);
    l1->SetShadow(true);
    p1->SetAlignFlags (HY_ALIGN_LEFT);
    b1->SetAlignFlags (HY_ALIGN_LEFT);
    ot->selectionType = HY_TABLE_SEL_ROWS|HY_TABLE_DONT_SIZE|HY_TABLE_FOCUSABLE ;
    ot2->selectionType = HY_TABLE_SEL_ROWS|HY_TABLE_DONT_SIZE;

    _String cellValue ("Object ID");
    ot2->SetCellData (&cellValue,0,0,HY_TABLE_BOLD|HY_TABLE_STATIC_TEXT|HY_TABLE_BEVELED|HY_TABLE_CANTSELECT|HY_TABLE_PULLDOWN,true);
    cellValue = "Object Info";
    ot2->SetCellData (&cellValue,0,1,HY_TABLE_STATIC_TEXT|HY_TABLE_BEVELED|HY_TABLE_CANTSELECT|HY_TABLE_BOLD,true);

    l1->SetText (_String(" Class"));
    p1->AddMenuItem ("Trees",-1);
    p1->AddMenuItem ("Data Sets",-1);
    p1->AddMenuItem ("Models",-1);
    p1->AddMenuItem ("Likelihood Functions",-1);
    p1->ChangeSelection (objectInspectorObjClass,false);

    if (objectInspectorRect.width<0) {
        _HYRect  screenRect = GetScreenDimensions();
        SetWindowRectangle (0,0,screenRect.bottom-50,screenRect.right-20);
        SetPosition (screenRect.right-260,60);
        objectInspectorRect = GetWindowRect ();
    }

    firstTime = true;

    //p1->EnableItem  (2,false);

    DeleteObject (l1);
    DeleteObject (p1);
    DeleteObject (ot);
    DeleteObject (b1);

    lastKillID = 0;
}