⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 squirmcell.h

📁 本程序模拟细胞的自我繁殖
💻 H
字号:
// SquirmCell.h

#pragma once

#include "SquirmCellProperties.h"
#include "SquirmError.h"
#include "C2dVector.h"

#define SquirmCellList CTypedPtrList<CPtrList,SquirmCell*>

const float RADIUS = 6.0F; // nm?
const float MAX_VELOCITY=RADIUS*0.4F;

class SquirmCell : public SquirmCellProperties
{
protected:

    SquirmCellList bonded_cells;

public:

    C2dVector location;

	C2dVector velocity;

    SquirmCell(C2dVector loc,char type,int state);

    SquirmCellList& GetBondedCells() { return this->bonded_cells; }

    SquirmCell* BondTo(SquirmCell* cell) 
    {
        // only bond if not already bonded (and not us!)
        if(cell!=this && this->bonded_cells.Find(cell)==NULL)
        {
			this->MakeBondWith(cell);
			cell->MakeBondWith(this);
        }
        else 
			SquirmError("BondTo : already bonded with this cell!");
        
        return this;
    }

    void Debond(SquirmCell* cell)
    {
        POSITION pos;

        pos = this->bonded_cells.Find(cell);
        if(pos) this->bonded_cells.RemoveAt(pos);
        else SquirmError("Debond : not bonded to this cell!");

        pos = cell->bonded_cells.Find(this);
        if(pos) cell->bonded_cells.RemoveAt(pos);
        else SquirmError("Debond : cell not bonded to us!");
    }

    bool HasBondWith(SquirmCell *cell)
    {
        return (this->bonded_cells.Find(cell)!=NULL);
    }

    void BreakAllBonds()
    {
        while(bonded_cells.GetCount()>0)
        {
            SquirmCell *cell=bonded_cells.GetHead();
            // break bond with this cell (deletes from bonded_cells list)
            Debond(cell);
        }
    }

    void AssignRandomVelocity();

protected:

    void MakeBondWith(SquirmCell *cell) { 
		this->bonded_cells.AddTail(cell); 
	}

    /*void AddToMolecule(SquirmCellList &m)
    {
        // early return if we're already in this list
        if(m.Find(this)!=NULL) return;
        // else add us and all our bonded cells to the list
        m.AddHead(this);
        POSITION pos = this->GetBondedCells().GetHeadPosition();
        while(pos)
        {
            this->GetBondedCells().GetNext(pos)->AddToMolecule(m);
        }
    }*/
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -