public void PerformClick() { Activate(); (Forms.Mancala.List[0] as EarningsCell).Canaddto = VirtualId.Item1 == 1; (Forms.Mancala.List[7] as EarningsCell).Canaddto = VirtualId.Item1 == 2; CuurentCell cell = new CuurentCell() { player = this.VirtualId.Item1, virtualId = this.VirtualId.Item2 }; if (VirtualId.Item1 == 2) { Forms.Mancala._game.MakeMove(this.VirtualId.Item2); } Console.WriteLine("It is Player :{0}", Forms.Mancala._game.NextPlayer); Console.WriteLine("{0} played {1}", VirtualId.Item1, id); Console.WriteLine(Forms.Mancala._game); GetOpositCell opositCell = null; Func <int> noopernings = () => { if (VirtualId.Item1 == 2) { return((VirtualId.Item2 + this.ContainerCell.Controls.Count) / 13); } return((5 - VirtualId.Item2 + this.ContainerCell.Controls.Count) / 13); }; Func <int> index = () => (this.ContainerCell.Controls.Count - noopernings() + id) % 14; Func <int> target = () => 14 - index(); if (Forms.Mancala.List[index()] is Cell) { Cell c = Forms.Mancala.List[index()] as Cell; Cell t = Forms.Mancala.List[target()] as Cell; if (VirtualId.Item1 == c.VirtualId.Item1) { if (c.ContainerCell.Controls.Count == 0 && t.ContainerCell.Controls.Count != 0) { opositCell = new GetOpositCell() { //id=index(), Cell = c, target = t, player = VirtualId.Item1 }; } } } if (this.VirtualId.Item1 == 2 && this.ContainerCell.Controls.Count == 7 - id) { cell.ext = true; } if (this.VirtualId.Item1 == 1 && this.ContainerCell.Controls.Count == 14 - id) { cell.ext = true; // Forms.Mancala._game.NextPlayer = 1; } List <Stone> stones = Empty(); if (stones.Count != 0) { Func <int, int> next = (int current) => (current + 1) % 14; //this.AddStone(stones[0]); //stones.RemoveAt(0); if ((Forms.Mancala.List[next(id)]) is Cell) { var nextcell = (Forms.Mancala.List[next(id)]) as Cell; //nextcell.AddStone(stones[0]); //stones.RemoveAt(0); nextcell.CarryStones(stones); } if ((Forms.Mancala.List[next(id)]) is EarningsCell) { var nextcell = (Forms.Mancala.List[next(id)]) as EarningsCell; //nextcell.AddStone(stones[0]); //stones.RemoveAt(0); nextcell.CarryStones(stones); } } if (opositCell != null) { _observers2[0].OnNext(opositCell); } _observers[0].OnNext(cell); DeActivate(); }
public void OnNext(GetOpositCell value) { if (value.player == 1) { (List[0] as EarningsCell).AddStone(value.Cell.ContainerCell.Controls[0] as Stone); //foreach (Stone stone in value.target.ContainerCell.Controls) //{ // (List[0] as EarningsCell).AddStone(stone); //} int count = value.target.ContainerCell.Controls.Count; for (int i = 0; i < count; i++) { Stone stone = value.target.ContainerCell.Controls[0] as Stone; (List[0] as EarningsCell).AddStone(stone); } // value.target.ContainerCell.Controls.Clear(); } else { (List[7] as EarningsCell).AddStone(value.Cell.ContainerCell.Controls[0] as Stone); //foreach (Stone stone in value.target.ContainerCell.Controls) //{ // (List[7] as EarningsCell).AddStone(stone); //} int count = value.target.ContainerCell.Controls.Count; for (int i = 0; i < count; i++) { Stone stone = value.target.ContainerCell.Controls[0] as Stone; (List[7] as EarningsCell).AddStone(stone); } //value.target.ContainerCell.Controls.Clear(); } player.Play(); //int target_index = 14 - value.id; //Console.WriteLine(value.id); //Console.WriteLine((List[value.id] as Cell).ContainerCell.Controls); //Console.WriteLine(target_index); //Console.WriteLine((List[target_index] as Cell).ContainerCell.Controls); //if ((List[target_index] as Cell).ContainerCell.Controls.Count != 0 // && (List[value.id] as Cell).ContainerCell.Controls.Count==1 // ) //{ // if (value.player == 2 && (target_index < 7 && target_index > 0)) // { // (List[0] as EarningsCell).AddStone((List[value.id] as Cell).ContainerCell.Controls[0] as Stone); // Control.ControlCollection stones = (List[target_index] as Cell).ContainerCell.Controls; // int count = stones.Count; // for (int i = 0; i < stones.Count; i++) // { // (List[0] as EarningsCell).AddStone(stones[0] as Stone); // } // (List[value.id] as Cell).ContainerCell.Controls.Clear(); // (List[target_index] as Cell).ContainerCell.Controls.Clear(); // } // else if (value.player == 1 && (target_index > 7 && target_index < 14)) // { // (List[7] as EarningsCell).AddStone((List[value.id] as Cell).ContainerCell.Controls[0] as Stone); // Control.ControlCollection stones = (List[target_index] as Cell).ContainerCell.Controls; // int count = stones.Count; // for (int i = 0; i < stones.Count; i++) // { // (List[7] as EarningsCell).AddStone(stones[0] as Stone); // } // (List[value.id] as Cell).ContainerCell.Controls.Clear(); // (List[target_index] as Cell).ContainerCell.Controls.Clear(); // } //} //(List[3-value.player] as EarningsCell).ContainerCell.Controls.Add(List[(value.id + 7) % 14]); //if (value.player == 1) //{ // Control.ControlCollection Collection = (List[(value.id + 7) % 14] as Cell).ContainerCell.Controls; // Control.ControlCollection targeted = (List[0] as EarningsCell).ContainerCell.Controls; // for (int i = 0; i < Collection.Count; i++) // { // targeted.Add( // Collection[0] // ); // Collection.Remove( // Collection[0] // ); // } // //Control[] stones = (List[value.id] as Cell).ContainerCell.Controls; // //(List[0] as EarningsCell).ContainerCell.Controls.AddRange(stones); //} //else //{ // Control.ControlCollection Collection = (List[(value.id + 7) % 14] as Cell).ContainerCell.Controls; // EarningsCell targeted = (List[7] as EarningsCell); // for (int i = 0; i < Collection.Count; i++) // { // targeted.AddStones( // Collection[0] // ); // Collection.Remove( // Collection[0] // ); // } //} }