public void Start() { BallCost_Out.text = BallCost.ToString(); PointKeeper_Out.text = CoinScore.ToString(); GameObject[] Pegs = GameObject.FindGameObjectsWithTag("QPeg"); GameObject[] WasteBins = GameObject.FindGameObjectsWithTag("WasteBins"); foreach (var p in Pegs) { if (p.gameObject.GetComponent <PegCollision>() == null) { bool registered = false; foreach (var _peg in RegisteredPegs) { if (_peg._instantiatedObject != null && _peg._instantiatedObject == p) { registered = true; } } if (!registered) { Peg _newPeg = new Peg(this, p.gameObject); RegisteredPegs.Add(_newPeg); } } } foreach (var wb in WasteBins) { WasteBinBarrier wbr = wb.GetComponent <WasteBinBarrier>(); wbr.Controller = this; } }
public PegControl(Peg peg) { Peg = peg; InitializeComponent(); DataContext = this; }
public void OnPuckPegCollision(PuckPegCollisionEvent puckPegCollisionEvent) { if (IsActive && pegBreakCount < maxPegBreaks) { Puck puck = puckPegCollisionEvent.puck; Rigidbody2D puckBody = puck.GetComponent <Rigidbody2D>(); Collider2D pegCollider = puckPegCollisionEvent.collision.collider; Peg peg = pegCollider.GetComponent <Peg>(); // Ignore collision with this peg Collider2D puckCollider = puck.GetComponent <Collider2D>(); Physics2D.IgnoreCollision(pegCollider, puckCollider); // Smash Peg SmashPeg(pegCollider, puckBody); pegBreakCount++; // Dampen momentum of Puck after it smashes the Peg DampenPuckMomentum(peg, puck); StartCoroutine(StutterPuckMovement(puckBody)); if (pegBreakCount >= maxPegBreaks) { Deactivate(); } } }
void Start() { healthBar = GetComponentInChildren <HealthBar>(); peg = GetComponent <Peg>(); crate = GetComponent <Crate>(); health = maxHealth; }
public void ShouldSupportGenericPassthroughResult() { // Arrange var peg = Peg.GenericPassthroughTest(); peg.DefaultSemanticActions.SetDefaultGenericPassthroughAction <GenericPassthroughAst>(); string inputString = string.Empty; var op = peg.Operators; var tokenizer = peg.Tokenizer(TokenDefinitions.AB); var rules = peg.ParserGenerator.GetParsingRules("Start => []"); var parser = peg.Parser(ParsingRuleNames.Start, rules); // Act var tokensResult = tokenizer.Tokenize(inputString); var parseResult = parser.Parse(tokensResult.MatchedRanges); // Assert var result = (GenericPassthroughAst)parseResult.SemanticActionResult; var subResults = result.SubResults.Cast <GenericPassthroughAst>().First().SubResults.Cast <GenericPassthroughAst>().ToList(); Assert.Equal(string.Empty, result.MatchedTokens.GetMatchedString()); Assert.Empty(subResults); Assert.Equal(MatchedPegOperator.NonTerminal, result.MatchedOperator); Assert.Equal(MatchedPegOperator.EmptyString, result.SubResults.Cast <GenericPassthroughAst>().Single().MatchedOperator); }
/*private void DampenPuckMomentum(Peg peg, Puck puck) { * Debug.Log($"Attempting to Dampen Puck Momentum after {pegBreakCount} broken Pegs."); * * Rigidbody2D puckBody = puck.GetComponent<Rigidbody2D>(); * * Vector2 collisionNormal = puck.transform.position - peg.transform.position; * collisionNormal.Normalize(); * Debug.Log($"Normal Vector={collisionNormal}"); * * Vector2 puckVelocity = puckBody.velocity; * Debug.Log($"Current Puck Velocity={puckVelocity}"); * * Vector2 projVOnN = puckVelocity * (float) (Math.Abs(Vector2.Dot(puckVelocity, collisionNormal)) / Math.Pow(puckVelocity.magnitude, 2)); * Debug.Log($"Projection of Vel onto Normal={projVOnN}"); * * float pegBreakCountMod = (float) Math.Pow((double) pegBreakCount / maxPegBreaks, 2.0); * Debug.Log($"pegBreakCountMod={pegBreakCountMod}"); * * Vector2 newPuckVelocity = puckVelocity + pegBreakCountMod * projVOnN; * Debug.Log($"New Puck Velocity={newPuckVelocity}"); * * puckBody.velocity = newPuckVelocity; * }*/ private void DampenPuckMomentum(Peg peg, Puck puck) { Debug.Log($"Attempting to Dampen Puck Momentum after {pegBreakCount} broken Pegs."); Rigidbody2D puckBody = puck.GetComponent <Rigidbody2D>(); Vector2 v = puckBody.velocity; Debug.Log($"Current Velocity of the Puck is: {v}"); Vector2 n = puck.transform.position - peg.transform.position; n.Normalize(); Debug.Log($"The normalized collision vector is {n}"); float scalarProjVOnN = Vector2.Dot(n, v) / n.magnitude; Debug.Log($"The scalar projection of V onto N is {scalarProjVOnN}"); Vector2 pegsForceOnPuck = scalarProjVOnN * n; Debug.Log($"The full force on the Puck from the Peg is: {pegsForceOnPuck}"); float pegBreakCountMod = (float)Math.Pow((double)pegBreakCount / maxPegBreaks, 2.0); Debug.Log($"Based on pegBreakCount:{pegBreakCount}, multiplying our force by {pegBreakCountMod}"); Vector2 puckDampeningForce = pegBreakCountMod * pegsForceOnPuck; Debug.Log($"Final force acting on the Puck: {puckDampeningForce}"); puckBody.velocity = v + puckDampeningForce; Debug.Log($"Puck's new velocity is: {puckBody.velocity}"); }
public void ShouldSupportGenericPassthroughResult() { // Arrange var peg = Peg.GenericPassthroughTest(); peg.DefaultSemanticActions.SetDefaultGenericPassthroughAction <GenericPassthroughAst>(); string testInput = "aaaabbbb"; var tokenizer = peg.Tokenizer(TokenDefinitions.AB); var rules = peg.ParserGenerator.GetParsingRules("Start => &([A]) [A] [B]"); var parser = peg.Parser(ParsingRuleNames.Start, rules); // Act var tokenizationResult = tokenizer.Tokenize(testInput); var parseResult = parser.Parse(tokenizationResult.MatchedRanges); // Assert var result = (GenericPassthroughAst)parseResult.SemanticActionResult; var subResults = result.SubResults.Cast <GenericPassthroughAst>().First().SubResults.Cast <GenericPassthroughAst>().ToList(); Assert.Null(subResults[0]); // predicate does not consume tokens var seqResults = subResults[1].SubResults.Cast <GenericPassthroughAst>().ToList(); Assert.Equal("aaaa", seqResults[0].MatchedTokens.GetMatchedString()); Assert.Equal("bbbb", seqResults[1].MatchedTokens.GetMatchedString()); Assert.Equal(MatchedPegOperator.NonTerminal, result.MatchedOperator); }
public async Task <Peg> CreatePeg(Peg peg) { var added = _context.Add(peg); await _context.SaveChangesAsync().ConfigureAwait(false); return(added.Entity); }
private void MakePeg(Vector3 newPos) { //create a new Peg object GameObject newPeg = (GameObject)Instantiate(Resources.Load("Prefabs/" + "Peg_Prefab"), newPos, Quaternion.Euler(270, 0, 0)); string cTurn = turn; //Set Peg's parent object, name, and color based on turn if (turn == "red") { newPeg.transform.parent = redPegs.transform; newPeg.name = ("redPeg ") + (newPeg.transform.position.x / 3) + (",") + (newPeg.transform.position.z / 3).ToString(); newPeg.GetComponent <Renderer> ().material.color = Color.red; } else if (turn == "black") { newPeg.transform.parent = blackPegs.transform; newPeg.name = ("blackPeg ") + (newPeg.transform.position.x / 3) + (",") + (newPeg.transform.position.z / 3).ToString(); newPeg.GetComponent <Renderer> ().material.color = Color.black; } //add new Peg to list of Pegs pegs[(int)newPeg.transform.position.z / 3, (int)newPeg.transform.position.x / 3] = newPeg; //set peg owner Peg ps = newPeg.GetComponent <Peg>(); ps.setOwner(turn); //checkNeighbors (newPeg.transform.position); checkNeighbors(newPeg); isInEndzone(); }
public void ClearPeg() { if (_peg != null) { _peg.SetSlot(null); _peg.SetPosition(new Vector3(OFF_SCREEN, OFF_SCREEN, OFF_SCREEN)); _peg = null; } }
public void SetPeg(int PegRowIndex, Peg Peg) { if (Pegs[PegRowIndex] != null) { DestroyPeg(PegRowIndex); } Pegs[PegRowIndex] = Peg; }
// //copy costructor //to create the state of the new successor function // //input: //destinationPegIndex: to check if we reach the destination peg public State(State toClone, int diskToMove, Peg destinationPeg, bool isEmptyDestination) : this() { // //index source and destination peg which sets at the same location for (int i = 0; i < Pegs.Length; i++) { //hold the current peg //reverse discs on currunt peg i to copy from the parent's largest disc at bottom to smallest disc at peek //because foreach loops on stacks from peek to bottom var peg_i = toClone.Pegs[i].Reverse(); // //are we reach the destination peg //copy each disc from the destination peg to the source peg // int destinationPeg_pos = (int)destinationPeg; if (i == destinationPeg_pos && //if destination peg is empty isEmptyDestination ) { //put the new disc this.Pegs[i].Push(diskToMove); } // // foreach (var disc in peg_i) { // //if the current disk is not the disc which will be moved from the source //avoid copying the disc which will be moved from the source if (disc != diskToMove) { this.Pegs[i].Push(disc); } // //if the current peg is the destination peg, //put the the new arrived disc from the source to the top destination if (i == destinationPeg_pos && ( //if destination peg is empty //emptyDestination //|| //or if we reachs the top of the destination peg disc == toClone.PeekPeg(destinationPeg) ) ) { //put the new disc this.Pegs[i].Push(diskToMove); } } } }
public static TestBoardSource CreateDefault() { return(new TestBoardSource(5, 5, 0, new[] { Peg.CreateMissingPeg(1, 1), Peg.CreateMissingPeg(2, 1), Peg.CreateMissingPeg(3, 2), })); }
override public void Render() { Grid gridView = new Grid(); // Clear board gridView.RowDefinitions.Clear(); gridView.ColumnDefinitions.Clear(); gridView.Children.Clear(); // Get Properties int Height = _pegBoard.GameState.GetLength(0); int Width = _pegBoard.GameState.GetLength(1); // Add Rows for (int i = 0; i < Height; i++) { gridView.RowDefinitions.Add(new RowDefinition()); } // Add Columns for (int i = 0; i < Width; i++) { gridView.ColumnDefinitions.Add(new ColumnDefinition()); } // Add Pegs for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { switch (_pegBoard.GetPeg(new IntPoint(x, y))) { case PegState.Invalid: break; case PegState.Peg: Peg peg = new Peg(new IntPoint(x, y)); Grid.SetRow(peg, y); Grid.SetColumn(peg, x); gridView.Children.Add(peg); break; case PegState.NoPeg: PegDropZone dropZone = new PegDropZone(new IntPoint(x, y)); Grid.SetRow(dropZone, y); Grid.SetColumn(dropZone, x); gridView.Children.Add(dropZone); dropZone.PegSwapped += DropZone_PegSwapped; break; } } } // Finally, set the view to the rendered grid _view.Content = gridView; }
public Peg[] GenerateSolution(Colour[] colours) { var peg1 = new Peg(Colour.Red); var peg2 = new Peg(Colour.Blue); var peg3 = new Peg(Colour.Green); var peg4 = new Peg(Colour.Orange); var solution = new[] { peg1, peg2, peg3, peg4 }; return(solution); }
public void LoadPegs(List <PegData> pegLocs) { Pegs = new List <Peg>(); foreach (var pegData in pegLocs) { Peg peg = createPeg(pegData.X, pegData.Y, pegData.PegType); Pegs.Add(peg); peg.Init(); } }
private void hanoi(int n, Peg source_peg, Peg goal_peg, Peg dev_peg, Peg axiul_peg, Dictionary <int, int> dict, ref int count) { if (n != 0) { int m = dict[n]; hanoi(m, source_peg, dev_peg, goal_peg, axiul_peg, dict, ref count); FS3(n - m, m + 1, source_peg, goal_peg, axiul_peg, ref count); hanoi(m, dev_peg, goal_peg, source_peg, axiul_peg, dict, ref count); } }
public void SpawnPeg(int color, Vector2 spawnPos, Vector2 targetPos) { GameObject pegGo = Instantiate(pegPrefab, spawnPos.ToVector3() + Vector3.up * 0.25f, Quaternion.identity); Peg peg = pegGo.GetComponent <Peg>(); peg.color = color; peg.transform.DOMove(targetPos.ToVector3() + Vector3.up * 0.25f, 1); }
/// <summary> /// Returns a boolean indicating whether a peg has a neighbor in a given direction /// </summary> /// <param name="pegIndex"></param> /// <param name="dir"></param> /// <returns></returns> public bool PegHasNeighbor(int pegIndex, Directions dir) { int ro = pegLayout[pegIndex].row; if (dir == Directions.UP_RIGHT) { if (pegLayout[(pegIndex - ro) + 1] != null) { jumpedPeg = pegLayout[(pegIndex - ro) + 1]; return(true); } } if (dir == Directions.UP_LEFT) { if (pegLayout[pegIndex - (ro)] != null) { jumpedPeg = pegLayout[pegIndex - (ro)]; return(true); } } if (dir == Directions.DOWN_LEFT) { if (pegLayout[pegIndex + (ro)] != null) { jumpedPeg = pegLayout[pegIndex + (ro)]; return(true); } } if (dir == Directions.DOWN_RIGHT) { if (pegLayout[pegIndex + (ro + 1)] != null) { jumpedPeg = pegLayout[pegIndex + (ro + 1)]; return(true); } } if (dir == Directions.LEFT) { if (pegLayout[pegIndex - 1] != null && pegLayout[pegIndex - 1].row == ro) { jumpedPeg = pegLayout[pegIndex - 1]; return(true); } } if (dir == Directions.RIGHT) { if (pegLayout[pegIndex + 1] != null && pegLayout[pegIndex + 1].row == ro) { jumpedPeg = pegLayout[pegIndex + 1]; return(true); } } return(false); }
void PegClicked(Peg peg) { if (_currentPeg != null) { _currentPeg.SetInactive(); } _currentPeg = peg; _currentPeg.SetActive(); }
private void DisplayShot(PlayerShot shot) { Transform tilePos; if ((tilePos = currentBoard.transform.Find(shot.coords)) != null) { Debug.Log("Shot -" + tilePos); Peg curPeg = Instantiate(pegObject, Vector3.zero, Quaternion.identity) as Peg; curPeg.transform.position = tilePos.position; } }
public Peg[] GenerateSolution(Colour[] colours) { var solution = new Peg[4]; for (int i = 0; i < 4; i++) { solution[i] = new Peg(colours[i]); } return(solution); }
public void PegBoardGetGoalPegTest() { // Arrange var pegBoard = PegBoard.FromSource(_mockPegBoardSource.Object); // Act var actual = pegBoard.GoalPeg; // Assert Assert.AreEqual(Peg.Create(5, 1), actual); }
public void PegsFactoryCreateTest() { // Arrange var pegsFactory = new Peg.Factory(5, 9); // Act var actual = pegsFactory.CreatePeg(5, 1); // Assert Assert.AreEqual(Peg.Create(5, 1), actual); }
// Recursive function that will replace values from last to first private void ReplaceNode(Peg.Base.PegNode node, int id, string oldName, string newName, StringBuilder text) { if (node.next_ != null) ReplaceNode(node.next_, id, oldName, newName, text); if (node.id_ == id && parser.GetSource().Substring(node.match_.posBeg_, node.match_.Length) == oldName) { text.Remove(node.match_.posBeg_, node.match_.Length); text.Insert(node.match_.posBeg_, newName); } else if (node.child_ != null) ReplaceNode(node.child_, id, oldName, newName, text); }
public void PegsFactoryCreatePegUpFromTest() { // Arrange var pegsFactory = new Peg.Factory(5, 9); var currentPeg = pegsFactory.CreatePeg(5, 1); // Act var actual = pegsFactory.CreatePegUpFrom(currentPeg); // Assert Assert.AreEqual(Peg.Create(3, 1), actual); }
public Board(int _players) { Length = 18 * _players; PlayersPegs = new Peg[_players, 5]; for(int i = 0; i < _players; i++){ PlayersPegs[i,0] = new Peg(0, 1, i, LOCATION.HOME, 0); PlayersPegs[i,1] = new Peg(1, 1, i, LOCATION.HOME, 1); PlayersPegs[i,2] = new Peg(2, 1, i, LOCATION.HOME, 2); PlayersPegs[i,3] = new Peg(3, 1, i, LOCATION.HOME, 3); PlayersPegs[i,4] = new Peg(4, 1, i, LOCATION.HOME, 4); } }
void Awake() { peg = GetComponent <Peg>(); if (playerID == 0) { playerID = 1; } peg.isPlayer = true; peg.playerNum = playerID; }
public GameBoard() { Pegs = new Peg[5, 5]; for (int y = 0; y < 5; y++) { for (int x = 0; x < 5 - y; x++) { Pegs[x, y] = new Peg(x, y); Pegs[x, y].Empty = false; } } }
void insertIntoHole() { if (canInsertPeg) { if (Input.GetButtonDown("Fire1")) { Debug.Log("Peg is inserted"); pegToBeInserted.transform.position = transform.position; Peg peg = pegToBeInserted.GetComponent <Peg>(); jumpAPeg(peg); } } }
public void CreateHintBasedOnPlayerSolutionShould_CreateHintWith4KeyPegs_BasedOnPlayerSolution() { var secretSolutionGenerator = new SecretSolutionGenerator(); var mastermind = new Mastermind(secretSolutionGenerator); var peg1 = new Peg(Colour.Red); var peg2 = new Peg(Colour.Blue); var peg3 = new Peg(Colour.Green); var peg4 = new Peg(Colour.Orange); var solution = new[] { peg1, peg2, peg3, peg4 }; var hint = mastermind.CreateHintBasedOnPlayerSolution(solution); Assert.Equal(4, hint.Length); }
private void TbxPegCName_TextChanged(object sender, TextChangedEventArgs e) { Peg tempStart = CmbStart.SelectedItem as Peg; Peg tempEnd = CmbEnd.SelectedItem as Peg; ViewModelLocator.MainViewModel.ListPeg.Clear(); ViewModelLocator.MainViewModel.ListPeg.Add(ViewModelLocator.MainViewModel.A); ViewModelLocator.MainViewModel.ListPeg.Add(ViewModelLocator.MainViewModel.B); ViewModelLocator.MainViewModel.ListPeg.Add(ViewModelLocator.MainViewModel.C); CmbStart.SelectedItem = tempStart; CmbEnd.SelectedItem = tempEnd; }
private static Peg ParseFromString(string line) { var size = line.Split(',').Select(part => part.Trim()); if (size.Count() == 2 && int.TryParse(size.ElementAt(1), out var columns) && int.TryParse(size.ElementAt(0), out var rows)) { return(Peg.Create(rows, columns)); } throw new ArgumentException("invalid board size line"); }
public void MovePeg(Peg p, int x, int y) { try { // validate the move is even possible. // new location must be empty if (Pegs[x, y].Empty == false) { throw new System.Exception("Cannot Move Peg, space is not empty."); } // Must be on a valid spot on the board. if (IsValidSpace(x, y) == false) { throw new System.Exception("Cannot Move Peg, invalid location."); } var other = new Vector2(x, y); // must be 2 spots away if (p.Location.x == x && Mathf.Abs((int)p.Location.y - y) != 1) { var d = Vector2.Distance(p.Location, other); var msg = string.Format("Cannot move peg, Distance:{0} A=({1}, {2}) B=({3}, {4})", d, p.Location.x, p.Location.y, x, y); throw new System.Exception(msg); } if (p.Location.y == y && Mathf.Abs((int)p.Location.x - x) != 1) { var d = Vector2.Distance(p.Location, other); var msg = string.Format("Cannot move peg, Distance:{0} A=({1}, {2}) B=({3}, {4})", d, p.Location.x, p.Location.y, x, y); throw new System.Exception(msg); } var tower = other - p.Location; tower.x = tower.x / 2; tower.y = tower.y / 2; var midPeglocation = p.Location + tower; // must have a peg in between if (Pegs[(int)midPeglocation.x, (int)midPeglocation.y].Empty) { throw new System.Exception("Cannot move peg, must leap over another peg."); } Pegs[x, y].Empty = false; DestroyPeg((int)midPeglocation.x, (int)midPeglocation.y); Pegs[(int)p.Location.x, (int)p.Location.y].Empty = true; } catch (System.Exception e) { Debug.LogError(e); } }
// Recursive function that will adjust relative cells from last to first private void ReplaceRelativeCell(Peg.Base.PegNode node, int rowOffset, int colOffset, StringBuilder text) { if (node.next_ != null) ReplaceRelativeCell(node.next_, rowOffset, colOffset, text); if (node.id_ == (int)EExcelFormula.A1Row && parser.GetSource().Substring(node.match_.posBeg_, 1) != "$") { int rowNumber = Convert.ToInt32(parser.GetSource().Substring(node.match_.posBeg_, node.match_.Length)); text.Remove(node.match_.posBeg_, node.match_.Length); text.Insert(node.match_.posBeg_, Convert.ToString(rowNumber + rowOffset)); } else if (node.id_ == (int)EExcelFormula.A1Column && parser.GetSource().Substring(node.match_.posBeg_, 1) != "$") { int colNumber = GetColumnNumber(parser.GetSource().Substring(node.match_.posBeg_, node.match_.Length)); text.Remove(node.match_.posBeg_, node.match_.Length); text.Insert(node.match_.posBeg_, GetColumnId(colNumber + colOffset)); } else if (node.child_ != null) ReplaceRelativeCell(node.child_, rowOffset, colOffset, text); }
public AstProgram(Peg.PegAstNode node) : base(node) { foreach (Peg.PegAstNode child in node.GetChildren()) { CatAstNode statement = CatAstNode.Create(child); mStatements.Add(statement); } }
public void EndPhase(Player _player) { if(TurnCounter != Players.IndexOf(_player) && PhaseCounter != PHASE.END){ return; } _player.SelectedCard = -1; LastPlayed = null; FirstPeg = null; SecondPeg = null; MoveToDistanceFirst = -1; MoveToDistanceSecond = -1; //roll PhaseCounter PhaseCounter = PHASE.DRAW; //roll TurnCounter TurnCounter = (TurnCounter + 1) % Players.Count; }
public Board(int size, int x, int y, string dir) { this.size = size; this.peg = new Peg(x, y, dir); }
public void Back(Player _player) { switch(PhaseCounter){ case PHASE.PEG: //go back to play phase PhaseCounter = PHASE.PLAY; //return the last played card back into the palyers hand _player.Discard.Remove(_player.LastDiscarded); _player.Hand.Add(_player.LastDiscarded); _player.LastDiscarded = null;//may need more logic to retain the last last discarded LastPlayed = null; FirstPeg = null; SecondPeg = null; break; case PHASE.MOVE: FirstPeg = null; SecondPeg = null; PhaseCounter = PHASE.PEG; break; case PHASE.END: //having a stack of peg states would make this easy break; } }
public void PegToPlayerHome(Peg _peg) { _peg.Location = LOCATION.HOME; _peg.Distance = _peg.Number; }
public bool TestPegLand(Peg _peg, LOCATION _location, int _distance) { LOCATION beginningLocation = _peg.Location; int beginningDistance = _peg.Distance; //need to check moving distances for valid position if((_location == LOCATION.MAINTRACK && _distance > TableBoard.Length) || (_location == LOCATION.CASTLE && _distance > 4)){ //this is outside the play area //should pop and error message Debug.Log("Move to: " + _location + " " + _distance + " is outside the play area, invalid move."); return false; } //need to check the landing location of any pegs that was landed on //check maintrack distance for any other peg for(int i = 0; i < Players.Count; i++){ for(int j = 0; j < 5 /*the number of pegs a player has*/; j++){ //test each peg to see if its in that spot. if(TableBoard.PlayersPegs[i,j].Location == _location && TableBoard.PlayersPegs[i,j].Distance == _distance){ if(_peg.Player == TableBoard.PlayersPegs[i,j].Player){ return false; }else{//not same player's pegs if(_peg.Team == TableBoard.PlayersPegs[i,j].Team){//same team return TestPegLand(TableBoard.PlayersPegs[i,j], LOCATION.MAINTRACK, TableBoard.GetPlayerCastleEntrance(i)); }else{//not same team //PegToPlayerHome(TableBoard.PlayersPegs[i,j]); return true; } } } } } return true; }
public bool TestPegMove(Peg _peg, LOCATION _location, int _distance) { LOCATION beginningLocation = _peg.Location; int beginningDistance = _peg.Distance; //need to check moving distances for valid position if((_location == LOCATION.MAINTRACK && _distance > TableBoard.Length) || (_location == LOCATION.CASTLE && _distance > 4)){ //this is outside the play area //should pop and error message Debug.Log("Move to: " + _location + " " + _distance + " is outside the play area, invalid move."); return false; } //need to check that we are not moving over any of our own pegs. for(int i = 0; i < 5 /**/; i++){ if(TableBoard.PlayersPegs[_peg.Player,i].Location == _location){ } } return true; } private void DisplayPegs(List<Peg> _pegs) { foreach(Peg _peg in _pegs){ //Peg GUI if(GUI.Button( new Rect((CARDBUFFER + CARDWIDTH) * _pegs.IndexOf(_peg), CARDHEIGHT + CARDBUFFER + CARDBUFFER, CARDWIDTH, CARDHEIGHT), _peg.Name())){ //Select Peg if(LastPlayed.Rank == RANK.Ten || LastPlayed.Rank == RANK.Nine || LastPlayed.Rank == RANK.Seven){ SecondPeg = FirstPeg; } FirstPeg = _peg; } } } void OnGUI() { if(Players.Count > 0){ if(Players[TurnCounter].Hand.Count > 0){ foreach(Card _card in Players[TurnCounter].Hand){ if(GUI.Button(new Rect((CARDWIDTH + CARDBUFFER)* Players[TurnCounter].Hand.IndexOf(_card), CARDBUFFER,CARDWIDTH,CARDHEIGHT),_card.FaceValue())){ Players[TurnCounter].SelectedCard = Players[TurnCounter].Hand.IndexOf(_card); } } } switch(PhaseCounter){ case PHASE.DRAW: if(GUI.Button(new Rect((Camera.main.pixelWidth / 2) - CARDWIDTH / 2, Camera.main.pixelHeight / 2,CARDWIDTH,CARDHEIGHT),"Draw")){ DrawPhase(Players[TurnCounter]); } break; case PHASE.PLAY: if(GUI.Button(new Rect((Camera.main.pixelWidth / 2) - CARDWIDTH - (CARDBUFFER / 2), Camera.main.pixelHeight / 2,CARDWIDTH,CARDHEIGHT),"Play")){ PlayPhase(Players[TurnCounter]); } if(GUI.Button(new Rect((Camera.main.pixelWidth / 2) + (CARDBUFFER / 2), Camera.main.pixelHeight / 2,CARDWIDTH,CARDHEIGHT),"Discard")){ DiscardPhase(Players[TurnCounter]); } break; case PHASE.PEG: List<Peg> tempPegs = GetAvailablePegs(TurnCounter, LastPlayed); //display the available pegs DisplayPegs(tempPegs); //check the selected card for available pegs //Ace Maintrack Pegs of the player, Castle Pegs, and Home Pegs //2-9 Maintrack Pegs of the player, Castle Pegs (needs logic for 7's and 9's upon moving the last Peg into the castle) //10 All Main Track Pegs + logic for a selected Peg filtering out any Peg from that Player //Jack, Queen, KingMaintrack Pegs of the player and Home Pegs //Joker all Player's Pegs. /* GUI.Button(new Rect((CARDWIDTH + CARDBUFFER)* 0, (CARDBUFFER * 2) + CARDHEIGHT,CARDWIDTH,CARDHEIGHT),TableBoard.PlayersPegs[TurnCounter,0].Name()); GUI.Button(new Rect((CARDWIDTH + CARDBUFFER)* 1, (CARDBUFFER * 2) + CARDHEIGHT,CARDWIDTH,CARDHEIGHT),TableBoard.PlayersPegs[TurnCounter,1].Name()); GUI.Button(new Rect((CARDWIDTH + CARDBUFFER)* 2, (CARDBUFFER * 2) + CARDHEIGHT,CARDWIDTH,CARDHEIGHT),TableBoard.PlayersPegs[TurnCounter,2].Name()); GUI.Button(new Rect((CARDWIDTH + CARDBUFFER)* 3, (CARDBUFFER * 2) + CARDHEIGHT,CARDWIDTH,CARDHEIGHT),TableBoard.PlayersPegs[TurnCounter,3].Name()); GUI.Button(new Rect((CARDWIDTH + CARDBUFFER)* 4, (CARDBUFFER * 2) + CARDHEIGHT,CARDWIDTH,CARDHEIGHT),TableBoard.PlayersPegs[TurnCounter,4].Name()); */ if(GUI.Button(new Rect((Camera.main.pixelWidth / 2) + (CARDBUFFER / 2), Camera.main.pixelHeight / 2,CARDWIDTH,CARDHEIGHT),"Select Peg")){ if(LastPlayed .Rank == RANK.Seven || LastPlayed .Rank == RANK.Nine || LastPlayed .Rank == RANK.Ten){ if(FirstPeg != null && SecondPeg != null && FirstPeg != SecondPeg){ PegPhase(Players[TurnCounter]); }else{ Debug.Log("You must select 2 different Pegs"); } }else{ if(FirstPeg != null){ PegPhase(Players[TurnCounter]); } } } if(GUI.Button(new Rect(Camera.main.pixelWidth - (CARDWIDTH + CARDBUFFER), Camera.main.pixelHeight - (CARDHEIGHT + CARDBUFFER), CARDWIDTH, CARDHEIGHT), "Back")){ Back(Players[TurnCounter]); } break; case PHASE.MOVE: //display the move that will happen DisplayMove(); if(GUI.Button(new Rect((Camera.main.pixelWidth / 2) - CARDWIDTH / 2, Camera.main.pixelHeight / 2,CARDWIDTH,CARDHEIGHT),"Move")){ MovePhase(Players[TurnCounter]); } if(GUI.Button(new Rect(Camera.main.pixelWidth - (CARDWIDTH + CARDBUFFER), Camera.main.pixelHeight - (CARDHEIGHT + CARDBUFFER), CARDWIDTH, CARDHEIGHT), "Back")){ Back(Players[TurnCounter]); } break; case PHASE.END: if(GUI.Button(new Rect((Camera.main.pixelWidth / 2) - CARDWIDTH / 2, Camera.main.pixelHeight / 2,CARDWIDTH,CARDHEIGHT),"End Turn")){ EndPhase(Players[TurnCounter]); } if(GUI.Button(new Rect(Camera.main.pixelWidth - (CARDWIDTH + CARDBUFFER), Camera.main.pixelHeight - (CARDHEIGHT + CARDBUFFER), CARDWIDTH, CARDHEIGHT), "Back")){ Back(Players[TurnCounter]); } break; }