Пример #1
0
        /// <summary>
        /// adds all the NewRules to the deck
        /// </summary>
        public void AddNewRule()
        {
            //initialise array off image of each newRule
            Bitmap[] bArray = new Bitmap[]
            {
                Properties.Resources.Draw_2,
                Properties.Resources.Draw_3,
                Properties.Resources.Draw_4,
                Properties.Resources.Draw_5,
                Properties.Resources.Hand_Limit_0,
                Properties.Resources.Hand_Limit_1,
                Properties.Resources.Hand_Limit_2,
                Properties.Resources.Play_2,
                Properties.Resources.Play_3,
                Properties.Resources.Play_4,
                Properties.Resources.Keeper_Limit_2,
                Properties.Resources.Keeper_Limit_3,
                Properties.Resources.Keeper_Limit_4,
            };
            //*add names of all the NewRules from the embedded file so I don't have to add them individually
            Assembly assembly     = Assembly.GetExecutingAssembly();
            string   resourceName = "Fluxx.Resources.New Rules.csv";

            Stream       stream = assembly.GetManifestResourceStream(resourceName);
            StreamReader reader = new StreamReader(stream);
            int          i      = 0;
            int          num    = 0;
            RuleCard     ruleToAdd;

            while (!reader.EndOfStream)
            {
                string   line     = reader.ReadLine();
                string[] csvArray = line.Split(',');
                //parses at index position 1 as index position 0 contains the name of the card which we dont need
                num = int.Parse(csvArray[1]);
                if (csvArray[0] == "Draw")
                {
                    ruleToAdd = new DrawRule(bArray[i], int.Parse(csvArray[1]));
                }
                else if (csvArray[0] == "Hand Limit")
                {
                    ruleToAdd = new HandLimitRule(bArray[i], int.Parse(csvArray[1]));
                }
                else if (csvArray[0] == "Play")
                {
                    ruleToAdd = new PlayRule(bArray[i], int.Parse(csvArray[1]));
                }
                else
                {
                    ruleToAdd = new KeeperLimitRule(bArray[i], int.Parse(csvArray[1]));
                }
                _cardList.Add(ruleToAdd);
                i++;
            }
        }
        /// <summary>
        /// the base method for draws a new rule, adds it to the table list and removes from hand
        /// </summary>
        /// <param name="board"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        public RuleCard PlayNewRuleBase(Board board, int num)
        {
            //the new rule to be added
            RuleCard nR1;

            //converts from card to new rule
            RuleCard nR = (RuleCard)_hand[num];

            //creates new object, not just reference object
            if (nR is DrawRule)
            {
                nR1 = new DrawRule(nR.Bitmap, nR.Num);
            }
            else if (nR is PlayRule)
            {
                nR1 = new PlayRule(nR.Bitmap, nR.Num);
            }
            else if (nR is HandLimitRule)
            {
                nR1 = new HandLimitRule(nR.Bitmap, nR.Num);
            }
            else
            {
                nR1 = new KeeperLimitRule(nR.Bitmap, nR.Num);
            }
            //if the only thing in the list is the basic rule, draw new rule to the side
            if (board.TableList.Count == 1)
            {
                nR1.XPos = board.CumulativeXPosTable;
                board.PaperTable.DrawImage(nR1.Bitmap, nR1.XPos, nR1.YPos);
                board.CumulativeXPosTable += nR1.WIDTH + nR1.GAP;
            }
            //else there is at least already one rule on the table
            else
            {
                //for every new rule in the list not counting the basic rule
                for (int n = 1; n < board.TableList.Count; n++)
                {
                    //if the nR1 is the same rule type as a rule already there, draw over it
                    if (nR1.GetType() == board.TableList[n].GetType())
                    {
                        nR1.XPos = board.TableList[n].XPos;
                        board.PaperTable.DrawImage(nR1.Bitmap, board.TableList[n].XPos, board.TableList[n].YPos);
                        //We Want to remove the rule that we are drawing over but not if it is a DrawRule
                        if (board.TableList[n] is DrawRule)
                        {
                        }
                        else
                        {
                            board.TableList.RemoveAt(n);
                        }
                        break;
                    }
                    //if we've gone passed every new rule and we didn't hit the break above, it is a unique new rule so draw to the side
                    if (n == board.TableList.Count - 1)
                    {
                        nR1.XPos = board.CumulativeXPosTable;
                        board.PaperTable.DrawImage(nR1.Bitmap, nR1.XPos, nR1.YPos);
                        board.CumulativeXPosTable += nR1.WIDTH + nR1.GAP;
                    }
                }
            }
            board.TableList.Add(nR1);
            _hand.RemoveAt(num);
            return(nR1);
        }