示例#1
0
 //衝突判定
 static bool collision(Field[,] field, Point putAt, Size cardSize)
 {
     Size fieldSize = new Size(field.GetLength(0), field.GetLength(1));
     if (putAt.X > fieldSize.Width - cardSize.Width || putAt.Y > fieldSize.Height - cardSize.Height) return true;
     
     for (int x = 0; x < cardSize.Width; x++)
     {
         for (int y = 0; y < cardSize.Height; y++)
         {
             if (field[putAt.X + x, putAt.Y + y].group != -1)
             {
                 return true;
             }
         }
     }
     return false;
 }
示例#2
0
        //CPUの再帰用コンストラクタ
        public GameManager(GameManager game, List<Card>[] handCard)
        {
            myConstractor(game.cardNum, game.handCardNum, game.fieldSize, game.cardSize);
            for(int x = 0; x < game.fieldSize.Width; x++)
            {
                for (int y = 0; y < game.fieldSize.Height; y++)
                {
                    field[x, y] = new Field(game.field[x, y]);
                }
            }
            initiation = (bool[])game.initiation.Clone();
            now_Player = game.now_Player;
            for(int i = 0; i < handCard.Count(); i++)
            {
                this.handCard[i] = new List<Card>(handCard[i]);
            }

        }
示例#3
0
        //初期化処理群
        void myConstractor(int cardNum, int handCardNum, Size fieldSize, Size cardSize, string[] deckIndexes = null)
        {
            this.fieldSize = fieldSize;
            this.cardSize = cardSize;
            this.cardNum = cardNum;
            this.handCardNum = handCardNum;
            messageList = new List<string>();
            //フィールド初期化
            field = new Field[fieldSize.Width, fieldSize.Height];
            for (int x = 0; x < fieldSize.Width; x++)
            {
                for (int y = 0; y < fieldSize.Height; y++)
                {
                    field[x, y] = new Field();
                }
            }
            //カード初期化
            deck = new List<Card>[max_Player];
            handCard = new List<Card>[max_Player];
            //山札を作成
            if (deckIndexes == null) deckIndexes = new string[max_Player];
            foreach (var deckIndex in deckIndexes.Select((v, i) => new { v, i }))
            {
                if (deckIndex.v == "" || deckIndex.v == null)
                {
                    deck[deckIndex.i] = Enumerable.Range(0, cardNum).Select(t => Card.RandomCardGenerator()).ToList();
                }
                else
                {
                    deck[deckIndex.i] = new List<Card>(Card.deckList[deckIndex.v].Select(t => new Card(((int[])t.elems.ToArray().Clone()).ToList(), t.imgPath)));
                }

                //山札をシャッフル
                Card.suffleCards(ref deck[deckIndex.i]);
            }
            initiation = new bool[max_Player];
            for(int i = 0; i < max_Player; i++)
            {
                //手札を作成
                handCard[i] = new List<Card>();
                //イニシエーション
                initiation[i] = true;
            }
            //Card.SerializeCards(card_1p);

            //ドロー
            for (int i = 0; i < handCardNum; i++)
            {
                for (int j = 0; j < max_Player; j++)
                {
                    draw();
                    next();
                }
            }
        }
示例#4
0
 //フィールドのクリア
 public void clearField()
 {
     field = new Field[fieldSize.Width, fieldSize.Height];
     for (int x = 0; x < fieldSize.Width; x++)
     {
         for (int y = 0; y < fieldSize.Height; y++)
         {
             field[x, y] = new Field();
         }
     }
     initiation = new bool[2] { true, true };
 }
示例#5
0
        /// <summary>
        /// コネクターに連結可能か判定
        /// card.TestCard==trueの場合はコネクターの属性を無視
        /// </summary>
        /// <param name="field"></param>
        /// <param name="putAt"></param>
        /// <param name="card"></param>
        /// <param name="mycardSize">回転に合わせたカードサイズ</param>
        /// <returns></returns>
        static bool canConnect(Field[,] field, Point putAt, Card card, Size mycardSize)
        {
            Size fieldSize = new Size(field.GetLength(0), field.GetLength(1));

            List<int> elems = card.elems;
            int turn = card.turn;
            for (int i = 0; i < 4; i++)
            {
                if (elems[i] == -1 && card.testCard == -1) continue;
                int sx, sy;
                switch ((i + turn) % 4)
                {
                    case 0:
                        sx = putAt.X + mycardSize.Width / 2 - 1;
                        sy = putAt.Y - 1;
                        if (sy < 0) continue;
                        connector_group = field[sx, sy].group;
                        if (card.testCard == -1 &&
                            field[sx, sy].connector == elems[i] &&
                            field[sx + 1, sy].connector == elems[i] ||
                            card.testCard != -1 &&
                            field[sx, sy].group == card.testCard &&//テストカード
                            field[sx + 1, sy].group == card.testCard &&
                            field[sx, sy].connector != -1 &&
                            field[sx + 1, sy].connector != -1)
                            return true;
                        break;
                    case 1:
                        sx = putAt.X + mycardSize.Width;
                        sy = putAt.Y + mycardSize.Height / 2;
                        if (sx >= fieldSize.Width) continue;
                        connector_group = field[sx, sy].group;
                        if (card.testCard == -1 &&
                            field[sx, sy].connector == elems[i] &&
                            field[sx, sy - 1].connector == elems[i] ||
                            card.testCard != -1 &&
                            field[sx, sy].group == card.testCard &&//テストカード
                            field[sx, sy - 1].group == card.testCard &&
                            field[sx, sy].connector != -1 &&
                            field[sx, sy - 1].connector != -1)
                            return true;
                        break;
                    case 2:
                        sx = putAt.X + mycardSize.Width / 2 - 1;
                        sy = putAt.Y + mycardSize.Height;
                        if (sy >= fieldSize.Height) continue;
                        connector_group = field[sx, sy].group;
                        if (card.testCard == -1 &&
                            field[sx, sy].connector == elems[i] &&
                            field[sx + 1, sy].connector == elems[i] ||
                            card.testCard != -1 &&
                            field[sx, sy].group == card.testCard &&//テストカード
                            field[sx + 1, sy].group == card.testCard &&
                            field[sx, sy].connector != -1 &&
                            field[sx + 1, sy].connector != -1)
                            return true;
                        break;
                    case 3:
                        sx = putAt.X - 1;
                        sy = putAt.Y + mycardSize.Height / 2 - 1;
                        if (sx < 0) continue;
                        connector_group = field[sx, sy].group;
                        if (card.testCard == -1 &&
                            field[sx, sy].connector == elems[i] &&
                            field[sx, sy + 1].connector == elems[i] ||
                            card.testCard != -1 &&
                            field[sx, sy].group == card.testCard &&//テストカード
                            field[sx, sy + 1].group == card.testCard &&
                            field[sx, sy].connector != -1 &&
                            field[sx, sy + 1].connector != -1)
                            return true;
                        break;
                }
            }
            return false;
        }
示例#6
0
 /// <summary>
 /// フィールドに配置したカードを除去
 /// </summary>
 /// <param name="field"></param>
 /// <param name="putAt"></param>
 /// <param name="mycardSize"></param>
 static void unfillCard(Field[,] field, Point putAt, Size mycardSize)
 {
     for (int x = 0; x < mycardSize.Width; x++)
     {
         for (int y = 0; y < mycardSize.Height; y++)
         {
             field[putAt.X + x, putAt.Y + y].group = -1;
             field[putAt.X + x, putAt.Y + y].connector = -1;
         }
     }
     field[putAt.X, putAt.Y].card = null;
 }
示例#7
0
        /// <summary>
        /// フィールドにカードを配置し、イニシエーションの由来を記録
        /// </summary>
        /// <param name="field"></param>
        /// <param name="putAt"></param>
        /// <param name="card"></param>
        /// <param name="mycardSize"></param>
        /// <returns></returns>
        public static int fillCard(Field[,] field, Point putAt, Card card, Size mycardSize)
        {
            if (connector_group == -1) throw new Exception("connector group is -1");

            List<int> elems = card.elems;
            int turn = card.turn;
            //コネクター配置
            for (int i = 0; i < elems.Count(); i++)
            {
                if (elems[i] == -1) continue;
                int sx, sy;
                switch ((i + turn) % 4)
                {
                    case 0:
                        sx = putAt.X + mycardSize.Width / 2 - 1;
                        sy = putAt.Y;
                        field[sx, sy].connector = elems[i];
                        field[sx + 1, sy].connector = elems[i];
                        break;
                    case 1:
                        sx = putAt.X + mycardSize.Width - 1;
                        sy = putAt.Y + mycardSize.Height / 2;
                        field[sx, sy].connector = elems[i];
                        field[sx, sy - 1].connector = elems[i];
                        break;
                    case 2:
                        sx = putAt.X + mycardSize.Width / 2 - 1;
                        sy = putAt.Y + mycardSize.Height;
                        field[sx, sy - 1].connector = elems[i];
                        field[sx + 1, sy - 1].connector = elems[i];
                        break;
                    case 3:
                        sx = putAt.X;
                        sy = putAt.Y + mycardSize.Height / 2 - 1;
                        field[sx, sy].connector = elems[i];
                        field[sx, sy + 1].connector = elems[i];
                        break;
                }
            }

            //グループ化
            for (int x = 0; x < mycardSize.Width; x++)
            {
                for (int y = 0; y < mycardSize.Height; y++)
                {
                    field[putAt.X + x, putAt.Y + y].group = connector_group;
                }
            }

            //カード配置
            field[putAt.X, putAt.Y].card = card;

            int tmpConnector = connector_group;
            connector_group = -1;

            return tmpConnector;
        }
示例#8
0
 public Field(Field field)
 {
     card = field.card;
     connector = field.connector;
     group = field.group;
 }
示例#9
0
        //配置可能判定
        public static bool canPut(Field[,] field, Point putAt, Card card, Size mycardSize, int now_Player, bool[] initiation, bool isJudge = false)
        {
            Size fieldSize = new Size(field.GetLength(0), field.GetLength(1));

            //衝突判定
            if (collision(field, putAt, mycardSize)) return false;

            //イニシエーション可能
            if (initiation[now_Player] && (now_Player % 2 == 0 && putAt.Y == fieldSize.Height - mycardSize.Height || now_Player % 2 == 1 && putAt.Y == 0))
            {
                if (!isJudge) initiation[now_Player] = false;
                connector_group = now_Player;
                return true;
            }

            //属性連結可能
            if (canConnect(field, putAt, card, mycardSize)) return true;

            return false;
        }