public static bool DistributeNewCars(ExtendendList <Structure> tmpLst, Game currentGame) { if (Structure.CanDistributeCards(tmpLst)) { if (currentGame.OtherCards.Count != 0 && currentGame.OtherCards.Count > 9) { int count = 0; ExtendendList <Cart> saved = new ExtendendList <Cart>(); foreach (Structure str in tmpLst) { Cart toAdd = currentGame.OtherCards[count]; saved.Add(toAdd); toAdd.Active = true; str.lstCards.Add(toAdd); count++; } for (int i = 0; i <= count - 1; i++) { currentGame.OtherCards.Remove(saved[i]); } Structure.SetState(tmpLst, false); } return(true); } else { return(false); } }
public static void setSelectedState(ExtendendList <Cart> lstCarts, bool state) { foreach (Cart tmp in lstCarts) { tmp.Selection = state; } }
public static ExtendendList <Cart> CreateNewCarts(Game.Mode gameMode) { ExtendendList <Class.Cart> lstCarts = new ExtendendList <Class.Cart>(); if (gameMode == Game.Mode.OneSuit) { for (int i = 0; i <= 7; i++) { for (int y = 1; y <= 13; y++) { lstCarts.Add(new Class.Cart((Class.Cart.cType)y, GameMode.Black)); } } } else { for (int i = 0; i <= 7; i++) { bool addFlag = false; for (int y = 1; y <= 13; y++) { lstCarts.Add(new Class.Cart((Class.Cart.cType)y, (addFlag ? GameMode.Black : GameMode.Red))); addFlag = !addFlag; } } } // List is filled now. Cart.Shuffle <Cart>(lstCarts); return(lstCarts); }
public static void setState(ExtendendList <Cart> lstCarts, bool state) { foreach (Cart tmp in lstCarts) { tmp.Active = state; } }
public ExtendendList <T> Clone() { ExtendendList <T> tmpLst = new ExtendendList <T>(); foreach (T tmp in base.ToArray()) { tmpLst.Add(tmp); } return(tmpLst); }
public static Info FindByLocation(ExtendendList <Structure> lst, Point p) { int i = 0, c = 0; Info toReturn = new Info(); foreach (Class.Structure mStr in lst) { c = 0; int cCard = 0; Rectangle actCard; if (mStr.lstCards.Count == 0) { if (new Rectangle(i * (test.Width + test.Distance), test.Y + 10, test.Width, test.Height).Contains(p)) { toReturn.SelectedCart = null; toReturn.CurrentStructure = mStr; return(toReturn); } i++; continue; } foreach (Class.Cart mCart in mStr.lstCards) { int x = i * (test.Width + test.Distance); int y = test.Y + (c * 10); if (!mCart.Active) { actCard = new Rectangle(x, y, test.Width, 5); } else { if (mStr.lstCards.IndexOf(mCart) == mStr.lstCards.Count - 1) { actCard = new Rectangle(i * (test.Width + test.Distance), y + cCard * test.Distance2, test.Width, test.Height); } else { actCard = new Rectangle(i * (test.Width + test.Distance), y + (cCard * test.Distance2), test.Width, test.Distance2 * 2); } cCard++; } c++; if (actCard.Contains(p)) { toReturn.SelectedCart = mCart; toReturn.CurrentStructure = mStr; return(toReturn); } } i++; } return(toReturn); }
public static void SetState(ExtendendList <Structure> lst, bool state) { lst.ForEach(delegate(Structure tmp) { foreach (Cart c in tmp.lstCards) { c.Selection = state; c.IsTipp = state; } }); }
public static void Shuffle <T>(ExtendendList <T> ilist) { int iIndex; T tTmp; for (int i = 1; i < ilist.Count; ++i) { iIndex = rand.Next(i + 1); tTmp = ilist[i]; ilist[i] = ilist[iIndex]; ilist[iIndex] = tTmp; } }
public static ExtendendList <Cart> GetActiveCards(ExtendendList <Cart> lstCart) { ExtendendList <Cart> cd = new ExtendendList <Cart>(); foreach (Cart tmp in lstCart) { if (tmp.Active) { cd.Add(tmp); } } return(cd); }
public static ExtendendList <Cart> FindActiveCars(ExtendendList <Cart> lst) { ExtendendList <Cart> tmp = new ExtendendList <Cart>(); foreach (Cart ctr in lst) { if (ctr.Active) { tmp.Add(ctr); } } return(tmp); }
public static bool GetState(ExtendendList <Structure> lst) { foreach (Structure tmp in lst) { foreach (Cart tmpC in tmp.lstCards) { if (tmpC.Selection) { return(true); } } } return(false); }
public static int CalculateDifference(cType one, cType two) { ExtendendList <cType> cTmp = new ExtendendList <cType>(); foreach (string item in Enum.GetNames(typeof(cType))) { cType tmp = cType.Default; if (Enum.TryParse <cType>(item, out tmp)) { cTmp.Add(tmp); } } return(Structure.Abs(cTmp.IndexOf(one) - cTmp.IndexOf(two))); }
public static bool CanDistributeCards(ExtendendList <Structure> lst) { if (lst == null) { return(false); } foreach (Structure str in lst) { if (str.lstCards.Count == 0) { return(false); } } return(true); }
public static ExtendendList <Structure> GetSelectedStructures(ExtendendList <Structure> lst) { ExtendendList <Structure> tmpLst = new ExtendendList <Structure>(); foreach (Structure tmp in lst) { foreach (Cart tmpC in tmp.lstCards) { if (tmpC.Selection) { tmpLst.Add(tmp); } } } return(tmpLst); }
public static bool CompareLists(ExtendendList <Cart.cType> one, ExtendendList <Cart> two) { if (one.Count == two.Count) { for (int i = 0; i <= one.Count - 1; i++) { if (one[i] != two[i].ccType) { return(false); } } return(true); } else { return(false); } }
public static bool CanMoveAllCards(ExtendendList <Cart> lst) { ExtendendList <Cart> activeCards = Cart.GetActiveCards(lst); if (lst.Count == 1) { return(true); } int diff = 0; for (int s = 0; s <= lst.Count - 1; s++) { if (s + 1 > lst.Count - 1) { // Check if all cards are the same color, otherwise it isn't possible to move. GameMode mdr = GameMode.Black; for (int y = 0; y <= lst.Count - 1; y++) { if (y == 0) { mdr = lst[y].GameMode_; } else { if (mdr != lst[y].GameMode_) { return(false); } } } return(true); } diff = Cart.CalculateDifference(lst[s].ccType, lst[s + 1].ccType); if (Structure.Abs(diff) != 1) { return(false); } } return(false); }
public static bool CanMoveCards(ExtendendList <Cart> ct) { List <Cart.cType> cmrList = new List <Cart.cType>(); foreach (string tmp in Enum.GetNames(typeof(Cart.cType))) { Cart.cType d = Cart.cType.Default; if (Enum.TryParse <Cart.cType>(tmp, out d)) { cmrList.Add(d); } } cmrList.Reverse(); for (int i = 0; i <= ct.Count - 2; i++) // Not - 1, but - 2. Last item won't needed. { int diff = Structure.Abs(cmrList.IndexOf(ct[i].ccType) - cmrList.IndexOf(ct[i + 1].ccType)); // It works within three cards. if (diff != 1) { return(false); } } return(true); }
public static ExtendendList <Structure> CreateStructureList(Game currentGame) { ExtendendList <Cart> mCarts = Class.Cart.CreateNewCarts(currentGame.GameMode); ExtendendList <Structure> mStructures = new ExtendendList <Class.Structure>(); ExtendendList <Class.Cart> tmpLst = new ExtendendList <Class.Cart>(); int index = 0, ct = 0; for (int i = 0; i <= 9; i++) { Structure.SType cType = (i >= 4) ? Structure.SType.Five : SType.Six; Structure str = new Structure(null, cType); int cCards = (i >= 4) ? 5 : 6; for (int c = 0; c <= cCards - 1; c++) { Cart curCart = mCarts[index]; // curCart.owner = str; if (c == cCards - 1) { curCart.Active = true; } tmpLst.Add(curCart); index++; ct++; } str.lstCards = tmpLst.Clone(); tmpLst.Clear(); mStructures.Add(str); } currentGame.OtherCards.Clear(); for (int c = ct; c <= mCarts.Count - 1; c++) { currentGame.OtherCards.Add(mCarts[c]); } return(mStructures); }
public static Info CheckWinning(ExtendendList <Structure> lst) { // Idea: Create a structure for the first to last, then for the second to the last and ... // If a structure fits to the here created structure then returns the structure. Info toRetrun = new Info(); // Create mainList: ExtendendList <Cart.cType> mainList = new ExtendendList <Cart.cType>(); foreach (string cmr in Enum.GetNames(typeof(Class.Cart.cType))) { mainList.Add((Class.Cart.cType)Enum.Parse(typeof(Class.Cart.cType), cmr)); } mainList.Reverse(); mainList.Remove(Cart.cType.Default); foreach (Structure curStr in lst) { // Filter active cars. ExtendendList <Cart> active = new ExtendendList <Cart>(); foreach (Cart mCart in curStr.lstCards) { if (mCart.Active) { active.Add(mCart); } } for (int i = 0; i <= active.Count - 1; i++) { ExtendendList <Cart> compare = new ExtendendList <Cart>(); for (int j = i; j <= active.Count - 1; j++) { compare.Add(active[j]); } // Compare these lists if (Structure.CompareLists(mainList, compare)) { toRetrun.CurrentStructure = curStr; Cart.GameMode currentState = Cart.GameMode.Black; for (int k = 0; k <= compare.Count - 1; k++) { if (k == 0) { currentState = compare[k].GameMode_; } else { if (currentState != compare[k].GameMode_) { toRetrun.OK = false; break; } else { toRetrun.OK = true; } } } if (compare.Count > 0) { toRetrun.SelectedCart = compare[0]; } return(toRetrun); // We don't go on in the loop, we want to leave here and break leaves only one loop, but there are another, so it is easier. } } } return(toRetrun); }
private void CurrentRenderer_MouseDown(MouseEventArgs e) { Class.Structure.Info strM = Class.Structure.FindByLocation(this.currentGame.MStructures, e.Location); if (strM.CurrentStructure != null) { if (Class.Structure.GetState(this.currentGame.MStructures)) { if (oldOne == strM.CurrentStructure) { Class.Structure.SetState(this.currentGame.MStructures, false); this.Invalidate(); return; } Class.Structure oldStructure = Class.Structure.GetSelectedStructures(this.currentGame.MStructures)[0]; // -------------------------------------------------------------------------------------- Class.ExtendendList <Class.Cart> items = new Class.ExtendendList <Class.Cart>(); foreach (Class.Cart cC in oldStructure.lstCards) { if (cC.Active && cC.Selection) { items.Add(cC); } } bool canMoveStructureWithMoreThanThreeCards = Class.Structure.CanMoveCards(items); bool canGoOn = false; if (strM.CurrentStructure.lstCards.Count == 0) { canGoOn = canMoveStructureWithMoreThanThreeCards; } else if (items.Count < 2) { Class.Cart fCardOldOne = items[0]; Class.Cart fCardNewOne = strM.CurrentStructure.lstCards[strM.CurrentStructure.lstCards.Count - 1]; // Calculate the difference now! int diff = Class.Cart.CalculateDifference(fCardOldOne.ccType, fCardNewOne.ccType); canGoOn = (diff == 1); } else { if (canMoveStructureWithMoreThanThreeCards) { // Proove: First card of the new structure have to be a difference from 1 to the first card in the structrue(oldone) Class.Cart fCardOldOne = items[0]; Class.Cart fCardNewOne = strM.CurrentStructure.lstCards[strM.CurrentStructure.lstCards.Count - 1]; // Calculate the difference now! int diff = Class.Cart.CalculateDifference(fCardOldOne.ccType, fCardNewOne.ccType); canGoOn = (diff == 1); } } if (!canGoOn) { System.Console.Beep(); foreach (Class.Cart c in items) { c.Selection = false; } this.Invalidate(); return; } oldOne = null; Class.ExtendendList <Class.Cart> tmp = new Class.ExtendendList <Class.Cart>(); foreach (Class.Cart cC in oldStructure.lstCards) { if (cC.Active && cC.Selection) { tmp.Add(cC); strM.CurrentStructure.lstCards.Add(cC); } } Class.Structure.SetState(oldStructure, false); Class.Structure.SetLastCartActiveIfPossible(oldStructure); foreach (Class.Cart curCart in tmp) { oldStructure.lstCards.Remove(curCart); } if (oldStructure.lstCards.Count != 0) { oldStructure.lstCards[oldStructure.lstCards.Count - 1].Active = true; } this.Invalidate(); this.currentGame.CheckForWin(); } else { Class.Structure.SetState(this.currentGame.MStructures, false); if (strM.SelectedCart == null) { return; } strM.SelectedCart.Selection = true; oldOne = strM.CurrentStructure; bool tryFinding = Class.Cart.CanMoveAllCards(this.currentGame.GetShouldSelectedCards(strM)); if (!tryFinding && this.currentGame.GetShouldSelectedCards(strM).Count == 0) { Class.ExtendendList <Class.Cart> lstCards = new Class.ExtendendList <Class.Cart>(); lstCards.Add(strM.SelectedCart); tryFinding = Class.Cart.CanMoveAllCards(lstCards); } if (tryFinding) { Class.ExtendendList <Class.Cart> shouldSelected = new Class.ExtendendList <Class.Cart>(); // Select carts, which are under this cart int index = strM.CurrentStructure.lstCards.IndexOf(strM.SelectedCart); if (index != -1) { for (int i = index + 1; i <= strM.CurrentStructure.lstCards.Count - 1; i++) { Class.Cart current = strM.CurrentStructure.lstCards[i]; current.Selection = true; } } } else { strM.SelectedCart.Selection = false; Console.Beep(); } this.currentGame.CheckForWin(); this.Invalidate(); } } }
public static ExtendendList <Tipp> ShowsAllTipps(ExtendendList <Structure> lst) { ExtendendList <Tipp> toReturn = new ExtendendList <Tipp>(); foreach (Structure ms in lst) { ExtendendList <Cart> active = new ExtendendList <Cart>(); foreach (Cart cmr in ms.lstCards) { if (cmr.Active) { active.Add(cmr); } } ExtendendList <Cart> proove = new ExtendendList <Cart>(); ExtendendList <Cart> testLst = new ExtendendList <Cart>(); bool okay = false; for (int i = 0; i <= active.Count - 1; i++) { proove.Clear(); for (int j = i; j <= active.Count - 1; j++) { proove.Add(active[j]); } okay = Structure.CanMoveCards(proove); if (proove.Count != 1 && okay) { // If you try to switch more than one card, all cards have to be the same color. Cart.GameMode currentMode = Cart.GameMode.Black; bool ok = false; for (int y = 0; y <= proove.Count - 1; y++) { if (y == 0) { currentMode = proove[y].GameMode_; } else { if (currentMode != proove[y].GameMode_) { ok = false; break; } } } okay = ok; } if (okay) { // At first, we have have to check out, whether the structure fits to the last cart from another structure! bool goOn = false; foreach (Structure d1 in lst) { if (d1.lstCards.Count == 0) { goOn = true; } else { testLst.Clear(); testLst.Add(d1.lstCards[d1.lstCards.Count - 1]); testLst.AddRange(proove); goOn = Structure.CanMoveCards(testLst); if (goOn) { foreach (Cart cs1 in testLst) { cs1.IsTipp = true; } } } if (goOn) { if (testLst.Count != 0) { foreach (Cart cs1 in proove) { cs1.IsTipp = true; } } } } } } } return(toReturn); }
public Structure(ExtendendList <Cart> lstCards, SType Type) { this.lstCards = lstCards; this.Type = Type; }
public Tipp(ExtendendList <Cart> SelectedCards) { this.SelectedCards = SelectedCards; }