public Net(Func <String, bool> logger, Controller c1, Controller c2, int nodeCount, int lineCount, int firstFishkaCount, int secondFishkaCount, int width, int height) { mGameOver = false; mLogger = logger; mNode = new List <Node>(); mLine = new List <Line>(); mPairCounter = new Counter <OrderedPair <Node> >(); mPlayer1 = new Player(Color.Blue, c1, this); mPlayer2 = new Player(Color.Red, c2, this); mPlayer1.setEnemy(mPlayer2); mPlayer2.setEnemy(mPlayer1); c1.init(mPlayer1); c2.init(mPlayer2); mCurPlayer = mPlayer1; Random r = new Random(); for (int i = 0; i < firstFishkaCount; i++) { mPlayer1.add(new Fishka(mPlayer1, 50 + 50 * i, height - 80)); } for (int i = 0; i < secondFishkaCount; i++) { mPlayer2.add(new Fishka(mPlayer2, width - 50 - 50 * i, 50)); } for (int i = 0; i < nodeCount; i++) { mNode.Add(new Node(75 + r.Next(width - 150), 75 + r.Next(height - 150))); } for (int i = 0; i < nodeCount; i++) { for (int o = 0; o < lineCount; o++) { int nodeIndex = r.Next(nodeCount); SwapPair <Node> swapPair = genSwapPair(i, nodeIndex); OrderedPair <Node> orderedPair = swapPair.getOrderedPair(); int shift = mPairCounter.get(orderedPair); mPairCounter.increase(orderedPair); mLine.Add(new Line(swapPair, shift)); } } }
internal void calcPos(Counter <OrderedPair <Node> > pairCounter) { if (!isCycle()) { mVecPair = mPair.map <Vec>(delegate(OrderedPair <Node> pair) { Vec delta = pair.mSecond.mPos - pair.mFirst.mPos; Vec vec = delta.norm(); double shift = (mShift - (pairCounter.get(mPair.getOrderedPair()) - 1) * 0.5f) * W; Vec pFirst = pair.mFirst.mPos + vec.rotate() * shift + vec * Node.mSize / 2; Vec pSecond = pair.mSecond.mPos + vec.rotate() * shift - vec * Node.mSize / 2; return(new OrderedPair <Vec>(pFirst, pSecond)); }); } else { Vec pos = mPair.mFirst.mPos + Vec.getDir(mShift, 3, W); mVecPair = new SwapPair <Vec>(pos, pos, false); } }