//metode der styrer den overordnede del af spillet (hvordan spiller bevæger sig fra start til s**t med terningkast) //bruger distToGoal som den primære værdi til at afgøre brikryk public void Move(int diceRoll) { Console.WriteLine(); switch (pos) { //switchcase, der arbejder ud fra brikposition case PiecePos.Spawn: if (diceRoll == 6) { lm.BreakLine(); Console.WriteLine("Piece#" + pieceId + " has left spawn!"); pos = PiecePos.Moving; } Console.WriteLine(); break; case PiecePos.Moving: lm.BreakLine(); Console.WriteLine("Piece#" + pieceId + " Has been moved."); distToGoal = distToGoal - diceRoll; if (distToGoal < 0) { distToGoal = distToGoal * (-1); } else if (distToGoal == 0) { pos = PiecePos.Goal; } Console.WriteLine("Distance to goal: " + (distToGoal)); lm.BreakLine(); break; case PiecePos.Goal: lm.BreakLine(); Console.WriteLine("Piece#" + pieceId + " has reached the goal!"); break; } Console.ReadKey(); }
//=================================================== /*! @brief ピースがそろっているか判定 @date 2013/02/13 @author Daichi Horio */ //=================================================== public List<PiecePos> Judge(PiecePos pos) { List<PiecePos> list = new List<PiecePos>(); List<PiecePos> tempList = new List<PiecePos>(); if (mRoot.PiecesList[pos.x, pos.y] == null) { return list; } list = SeekX(list, pos); list = ListAdd(list, tempList); tempList.Clear(); list = SeekY(list, pos); list = ListAdd(list, tempList); tempList.Clear(); return list; }
//=================================================== /*! @brief 全体のピースがそろっているか判定 @date 2013/02/13 @author Daichi Horio */ //=================================================== public List<PiecePos> AllJudge() { List<PiecePos> list = new List<PiecePos>(); PiecePos nowPos; for (int j = 0; j < Height; j++) { for (int i = 0; i < Width; i++) { if (mRoot.PiecesList[i, j] != null) { nowPos = new PiecePos(i, j); list = Judge(nowPos); if (list.Count != 0) { return list; } list.Clear(); } } } return null; }
public PieceDeathData(PiecePos pos, PieceDirction dir, int count) { Pos = pos; Dir = dir; Count = count; }
//=================================================== /*! @brief 下が何個空いてるか探索 @date 2013/01/29 @author Daichi Horio */ //=================================================== private int SeekDown(PiecePos pos, int count) { if (pos.y == 0) return count; if (mPieces[pos.x, pos.y - 1] != null) return count; count++; count = SeekDown(new PiecePos(pos.x, pos.y - 1), count); return count; }
//=================================================== /*! @brief ピースの生成 @date 2013/01/20 @author Daichi Horio */ //=================================================== private PieceObject PieceGenerate(PiecePos initPos) { PieceObject p; Vector2 pos = new Vector2(initPos.x * PieceSize, PieceSize * initPos.y); GameObject obj = Instantiate(PiecePrefab, pos, Quaternion.identity) as GameObject; obj.transform.parent = transform; p = obj.GetComponent<PieceObject>(); p.Color = (PieceColor)Random.Range(1, 7); return p; }
/*! 初期化 */ private void Init() { for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { PiecePos pos = new PiecePos(i, j + Height); mPieces[i, j] = PieceGenerate(pos); mPieces[i, j].SetPosition(new PiecePos(i, j), InitMoveSpeed); mActivList.Add(mPieces[i, j]); } } }
//=================================================== /*! @brief y軸探索 @date 2014/03/19 @author Daichi Horio */ //=================================================== private List<PiecePos> SeekY(List<PiecePos> origin, PiecePos pos) { List<PiecePos> tempList = new List<PiecePos>(); // 上方向に探索 tempList = SeekProcessY(tempList, pos, true); // 下方向に探索 tempList = SeekProcessY(tempList, pos, false); if (tempList.Count >= DeleteCount) { origin = ListAdd(origin, tempList); tempList.Remove(pos); foreach (var obj in tempList) { origin = SeekX(origin, obj); } } return origin; }
//=================================================== /*! @brief y軸方向にそろっているか判定 @param pos 判定する座標 @param dir どっち方向に判定する @return 揃っているピース @date 2014/03/19 @author Daichi Horio */ //=================================================== private List<PiecePos> SeekProcessY( List<PiecePos> list, PiecePos pos, bool dir) { if (mRoot.PiecesList[pos.x, pos.y] == null) return list; // 一番最初に自分自身の座標をリストに追加 if (list.Count == 0) { list = ListAdd(list, pos); } PieceColor color = mRoot.PiecesList[pos.x, pos.y].Color; PiecePos temp; // 方向によってどっちを探索するか if (dir) temp = new PiecePos(pos.x, pos.y + 1); else temp = new PiecePos(pos.x, pos.y - 1); if (pos.y < Height - 1 && pos.y > 0) { if (mRoot.PiecesList[temp.x, temp.y] == null) { return list; } else if (mRoot.PiecesList[temp.x, temp.y].Color == color) { list = ListAdd(list, temp); list = SeekProcessY(list, temp, dir); } } return list; }
//=================================================== /*! @brief まだリスト無いか確認してに加える @date 2014/03/19 @author Daichi Horio */ //=================================================== private List<PiecePos> ListAdd(List<PiecePos> list, PiecePos pos) { if(!list.Contains(pos)) { list.Add(pos); } return list; }
/*! ピースに指定の座標をセット @param x x軸 @param y y軸 @param speed 移動速度 */ public void SetPosition(PiecePos pos, float speed) { mState = PieceState.MOVE; mMoveSpeed = speed; mPos = pos; mTargetPos = new Vector2(mPos.x * 1.05f, mPos.y * 1.05f); }