///<summary> /// Move the domino to the closest position next to the Mouse Pointer ///</summary> /// <param name="domino"></param> /// <param name="mousePositionX"></param> /// <param name="mousePosittionY"></param> void MoveDominoToPoint(Domino domino, Vector2 mousePoint) { //Debug.Log("Move domino to point " + mousePoint.ToString()); int row; int column; //find row column from point if (mBoard.Controller.Size % 2 == 1) { row = (int)Math.Round((mousePoint.y - 0.5f * Square.kPixelSize) / Square.kPixelSize + 0.5f * mBoard.Controller.Size); column = (int)Math.Round((mousePoint.x - 0.5f * Square.kPixelSize) / Square.kPixelSize + 0.5f * mBoard.Controller.Size); } else { row = (int)Math.Round(mousePoint.y / Square.kPixelSize + 0.5f * mBoard.Controller.Size); column = (int)Math.Round(mousePoint.x / Square.kPixelSize + 0.5f * mBoard.Controller.Size); } // Note ACL there was some layer logic here. // this will move on the board if (LocationIsInBoard(row, column, domino.Controller.IsHorizontal())) { domino.Controller.Row = row; domino.Controller.Column = column; domino.UpdateDominoLocation(mBoard.Controller.Size); } // if p1, allow move out top to bag else if (GamePlayManager.Instance.Player1Playing && LocationIsInUpperBag(row, column, domino.Controller.IsHorizontal())) { domino.Controller.Row = row; domino.Controller.Column = column; domino.UpdateDominoLocation(mBoard.Controller.Size); } // if p1, allow move out left to bag else if ((!GamePlayManager.Instance.Player1Playing) && LocationIsInLeftBag(row, column, domino.Controller.IsHorizontal())) { domino.Controller.Row = row; domino.Controller.Column = column; domino.UpdateDominoLocation(mBoard.Controller.Size); } }
public void BuildChainTest() { var domino = new Domino(); string chain; Assert.IsTrue(domino.BuildChain("01 12 23 34 45", out chain)); Assert.IsFalse(domino.BuildChain("01 12 23 34 45 66", out chain)); Assert.IsFalse(domino.BuildChain("01 12 23 44 45 56", out chain)); }
public void BuildBonePairsTets2() { var domino = new Domino(); List<Bone> singleBones; var pairs = domino.BuildBonePairs(domino.ConvertStringToBones("11 22 34 45 56"), out singleBones); Assert.AreEqual(2, pairs.Count); Assert.AreEqual(2, singleBones.Count); }
public void Add(Node end, Domino d, IPlayer player) { if (_root == null) throw new InvalidOperationException("Graph has not been started"); var possibleEnds = Ends(player); if (!possibleEnds.Contains(end)) { throw new ArgumentException("Must use a valid end!"); } end.AddChild(d); }
public void AddChild(Domino child) { if (Available <= 0) throw new InvalidOperationException("No open plays on this domino:" + Value.ToString()); Children.Add(new Node(child, this)); }
//used by King of fools otherwise it would be private. internal Node(Domino v, Node parent) { Value = v; Children = new List<Node>(); if (parent.End == Value.First) End = Value.Second; else if (parent.End == Value.Second) End = Value.First; else throw new ArgumentException("Dominoes don't match"); Owner = parent.Owner; }
public Track LoadFrom(SavedGame.SavedTrack savedTrack) { track.Clear(); savedTrack.track.ForEach(sd => Place(Domino.LoadFrom(sd))); return(this); }
private void RemoveDominoInHand(Player player, Domino domino) { player.Dominoes.Remove(domino); }
private void LoadDomino(PictureBox pb, Domino d) { pb.Image = Image.FromFile(System.Environment.CurrentDirectory + "\\..\\..\\Dominos\\" + d.Filename); }
public static void MoveToAccurate(Domino d, float x, float y, float z, float time) { // ACL // TODO animate this ACL d.gameObject.transform.position = new Vector3(x, y, z); }
/// <summary> /// THe domino can be played if the right or left match the last domino /// </summary> public virtual bool CanPlayDomino(Domino domino) { return(_train.Last.Value.CanAttachRight(domino)); }
protected bool TryPlaceDomino(int x1, int y1, Constants.Direction d) { if ((x1 == 0) && (d == Constants.Direction.Left)) { return(false); } if ((x1 == MaxWidth - 1) && (d == Constants.Direction.Right)) { return(false); } if ((y1 == 0) && (d == Constants.Direction.Above)) { return(false); } if ((y1 == MaxHeight - 1) && (d == Constants.Direction.Below)) { return(false); } var x2 = x1; var y2 = y1; Domino domino = null; switch (d) { case Constants.Direction.Left: x2--; domino = new Domino(Input[y2][x2], Input[y1][x1]); break; case Constants.Direction.Right: x2++; domino = new Domino(Input[y1][x1], Input[y2][x2]); break; case Constants.Direction.Above: y2--; domino = new Domino(Input[y2][x2], Input[y1][x1]); break; case Constants.Direction.Below: y2++; domino = new Domino(Input[y1][x1], Input[y2][x2]); break; } if (Input[y1][x1] == 0) { return(false); } if (Input[y2][x2] == 0) { return(false); } var c1 = Board.CellAt(x1, y1); var c2 = Board.CellAt(x2, y2); if (c1.IsOccupied || c2.IsOccupied) { return(false); } var canPlacePip1 = CanPlacePip(c1, domino.Pips[0]); var canPlacePip2 = CanPlacePip(c2, domino.Pips[1]); var canPlace = (canPlacePip1 && canPlacePip2); if (canPlace) { Board.PlaceDomino(c1, c2, domino); } return(canPlace); }
void Update() { var center = new Vector2(Screen.width * ScreenPosition.x, Screen.height * ScreenPosition.y); Ray mRay = Camera.main.ScreenPointToRay(center); RaycastHit hit; if (Physics.Raycast(mRay, out hit)) { if (hit.transform.CompareTag("DetectedPlane") /*|| hit.transform.CompareTag("Domino")*/) { if (PlayerPrefs.GetInt("isStickyMode") == 0) { reticle.transform.position = hit.point; Vector3 targetPostition = new Vector3(target.position.x, this.transform.position.y, target.position.z); this.transform.LookAt(targetPostition); } else if (PlayerPrefs.GetInt("isStickyMode") == 1) { //reticle.transform.SetPositionAndRotation(hit.transform.position, hit.transform.rotation); //reticle.transform.position = hit.point; // transform.rotation = Quaternion.identity; Vector3 right = Vector3.right; if (hit.normal != Vector3.up) { right = Vector3.Cross(hit.normal, Vector3.up); } Vector3 forward = Vector3.Cross(hit.normal, right); Quaternion orientation = Quaternion.identity; orientation.SetLookRotation(forward, hit.normal); transform.rotation = Quaternion.Slerp(orientation, transform.rotation, 0.75f); transform.position = hit.point + (hit.normal * 0.01f); Distance = hit.distance; } if (RectTransformUtility.RectangleContainsScreenPoint(btn.GetComponent <RectTransform>(), Input.mousePosition)) { return; } if (RectTransformUtility.RectangleContainsScreenPoint(swipe_panel.GetComponent <RectTransform>(), Input.mousePosition)) { return; } if ((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended) || Input.GetMouseButtonUp(0)) { if (IsPointerOverUIObject()) { return; } if (pointSpwaner.isDefault) { onPlacedObject?.Invoke(); holdDominos.Clear(); GameObject dominoSpawned = Instantiate(prefab, reticle.transform.position, reticle.transform.rotation); dominoSpawned.GetComponent <SwitchOnRandomDomino>().colorID = PlayerPrefs.GetInt("isRandomColoring") == 1 ? Random.Range(1, 7) : colorID; if (PlayerPrefs.GetInt("isStickyMode") == 0) { dominoSpawned.GetComponent <SwitchOnRandomDomino>().Dominos[0].GetComponent <Rigidbody>().useGravity = true; print(dominoSpawned.GetComponent <SwitchOnRandomDomino>().Dominos[0].name); } else if (PlayerPrefs.GetInt("isStickyMode") == 1) { dominoSpawned.transform.GetChild(0).GetComponent <Rigidbody>().useGravity = false; dominoSpawned.transform.GetChild(0).GetComponent <Rigidbody>().isKinematic = true; print(dominoSpawned.transform.GetChild(0).name); } mainController.AddDomino(dominoSpawned); Domino domino = new Domino(); domino._dominoObj = dominoSpawned; domino._dominoPosition = dominoSpawned.transform.position; domino._dominoRotation = dominoSpawned.transform.rotation; domino._dominoScale = dominoSpawned.transform.localScale; holdDominos.Add(domino); _undoRedoManager.LoadData(TransactionData.States.spawned, holdDominos); } } } } }
public void PruebaElegirPrimerJugador() { List <Jugador> jugadores = new List <Jugador>(); jugadores.Add(new Jugador() { Nombre = "Jugador 1", FichasDisponibles = new List <Ficha> { new Ficha { primerNumero = 0, segundoNumero = 1 }, new Ficha { primerNumero = 1, segundoNumero = 2 }, new Ficha { primerNumero = 2, segundoNumero = 5 } } }); jugadores.Add(new Jugador() { Nombre = "Jugador 2", FichasDisponibles = new List <Ficha> { new Ficha { primerNumero = 3, segundoNumero = 1 }, new Ficha { primerNumero = 3, segundoNumero = 0 }, new Ficha { primerNumero = 4, segundoNumero = 3 } } }); jugadores.Add(new Jugador() { Nombre = "Jugador 3", FichasDisponibles = new List <Ficha> { new Ficha { primerNumero = 1, segundoNumero = 4 }, new Ficha { primerNumero = 2, segundoNumero = 3 }, new Ficha { primerNumero = 1, segundoNumero = 6 } } }); Domino domino = new Domino { Jugadores = jugadores }; Jugador jugadorInicial = domino.ElegirJugadorInicial(); Assert.IsNotNull(jugadorInicial); Assert.IsTrue(jugadorInicial.Nombre == "Jugador 3"); jugadores.Clear(); jugadores.Add(new Jugador() { Nombre = "Jugador 1", FichasDisponibles = new List <Ficha> { new Ficha { primerNumero = 0, segundoNumero = 1 }, new Ficha { primerNumero = 2, segundoNumero = 2, esDoble = true }, new Ficha { primerNumero = 2, segundoNumero = 5 } } }); jugadores.Add(new Jugador() { Nombre = "Jugador 2", FichasDisponibles = new List <Ficha> { new Ficha { primerNumero = 3, segundoNumero = 1 }, new Ficha { primerNumero = 3, segundoNumero = 0 }, new Ficha { primerNumero = 4, segundoNumero = 4, esDoble = true } } }); jugadores.Add(new Jugador() { Nombre = "Jugador 3", FichasDisponibles = new List <Ficha> { new Ficha { primerNumero = 1, segundoNumero = 4 }, new Ficha { primerNumero = 2, segundoNumero = 3 }, new Ficha { primerNumero = 6, segundoNumero = 6, esDoble = true } } }); jugadores.Add(new Jugador() { Nombre = "Jugador 4", FichasDisponibles = new List <Ficha> { new Ficha { primerNumero = 0, segundoNumero = 4 }, new Ficha { primerNumero = 3, segundoNumero = 5 }, new Ficha { primerNumero = 5, segundoNumero = 6 } } }); domino = new Domino { Jugadores = jugadores }; jugadorInicial = domino.ElegirJugadorInicial(); Assert.IsNotNull(jugadorInicial); Assert.IsTrue(jugadorInicial.Nombre == "Jugador 3"); }
/// <summary> /// Private - Play the highest double /// </summary> private void playHighestDouble() { Domino highest = null; int foundHighestIn = 0; // 0 - noboy , 1 computer, 2, player // Determine highest for (int i = 0; i < computerHand.Count; i++) { if (computerHand[i].IsDouble()) { if ((highest == null) || (highest.Score < computerHand[i].Score)) { highest = computerHand[i]; foundHighestIn = 1; } } } // Look in the uer hand for (int i = 0; i < tableDominos.Count; i++) { if (tableDominos[i].domino.IsDouble()) { if ((highest == null) || (highest.Score < tableDominos[i].domino.Score)) { highest = tableDominos[i].domino; foundHighestIn = 2; } } } // Found in computer if (foundHighestIn == 1) { int toRemove = computerHand.IndexOfDomino(highest.Side1); Domino dom = computerHand.GetDomino(highest.Side1); computerHand.RemoveAt(toRemove); // Computer goes first this.whosTurn = 0; } // Found in player else if (foundHighestIn == 2) { for (int i = 0; i < tableDominos.Count; i++) { if (tableDominos[i].domino == highest) { Domino dom = tableDominos[i].domino; tableDominos.RemoveAt(i); // Player goes first this.whosTurn = 1; break; } } } else { throw new System.ArgumentException("Not implemented - should redo teardown / setup - but this is academic..."); } // Now that highest domino has been found and removed from either a player or computer - lets put it where it goes and set the trains enginePB.ImageLocation = "Images/" + highest.Filename; // Now lets set the trains up this.userTrain.EngineValue = highest.Side1; this.computerTrain.EngineValue = highest.Side1; this.mexicanTrain.EngineValue = highest.Side1; }
private void ScoreByPlaying(Player player) { int score = 0; if (History.HorizontalDominoes.Count == 1) { Domino domino = History.HorizontalDominoes.First.Value; score += domino.Value1 + domino.Value2; if (score % 5 == 0) { AddScore(player, score); } return; } Domino firstHorizontalDomino = History.HorizontalDominoes.First.Value; if (firstHorizontalDomino.Placement.Direction == DominoDirection.Vertical) { score += firstHorizontalDomino.Placement.UpValue + firstHorizontalDomino.Placement.DownValue; } else if (firstHorizontalDomino.Placement.Direction == DominoDirection.Vertical) { score += firstHorizontalDomino.Placement.LeftValue; } else { throw new Exception("Error: Domino not specified"); } Domino lastHorizontalDomino = History.HorizontalDominoes.Last.Value; if (lastHorizontalDomino.Placement.Direction == DominoDirection.Vertical) { score += lastHorizontalDomino.Placement.UpValue + lastHorizontalDomino.Placement.DownValue; } else if (lastHorizontalDomino.Placement.Direction == DominoDirection.Vertical) { score += lastHorizontalDomino.Placement.RightValue; } else { throw new Exception("Error: Domino not specified"); } if (History.VerticalDominoes.Count == 0) { if (score % 5 == 0) { AddScore(player, score); } return; } else { Domino firstVerticalDomino = History.VerticalDominoes.First.Value; if (firstVerticalDomino != History.Spinner) { if (firstVerticalDomino.Placement.Direction == DominoDirection.Vertical) { score += firstVerticalDomino.Placement.UpValue; } else if (firstVerticalDomino.Placement.Direction == DominoDirection.Horizontal) { score += firstVerticalDomino.Placement.LeftValue + firstVerticalDomino.Placement.RightValue; } else { throw new Exception("Error: Domino not specified"); } } Domino lastVerticalDomino = History.VerticalDominoes.First.Value; if (lastVerticalDomino != History.Spinner) { if (lastVerticalDomino.Placement.Direction == DominoDirection.Vertical) { score += lastVerticalDomino.Placement.UpValue; } else if (lastVerticalDomino.Placement.Direction == DominoDirection.Horizontal) { score += lastVerticalDomino.Placement.LeftValue + lastVerticalDomino.Placement.RightValue; } else { throw new Exception("Error: Domino not specified"); } } if (score % 5 == 0) { AddScore(player, score); } } }
internal void Pick(Domino domino) { _myDominoes.Add(domino); }
/// <summary> /// Tries to parse the second line of input. /// </summary> /// <param name="text"></param> /// <returns></returns> private bool TryParseSecond(string text) { const string zero = "0"; // This one could be a long runner. var parts = PrepareText(text).Split(' '); if (parts.Length != _expectedCount) { var message = string.Format("Expected {{{0}}} domino heights: {{{1}}}", _expectedCount, text); throw new ArgumentException(message, "text"); } /* Aggregate only the Dominoes corresponding to the non-zero height i's. Besides * game play itself, this is by far the longest runner in the whole process. */ (from i in Enumerable.Range(0, _expectedCount) where !parts[i].Equals(zero) select i) .Aggregate(_dominoes, (g, i) => { g[i] = new Domino(i, parts[i]); //g[i].Knocked += Domino_Knocked; return g; }); return true; }
public void TestBoneYardDraw() { Domino domino = boneYard.Draw(); Assert.IsInstanceOf <Domino>(domino); }
public void ExceptionIllegalPlay() { this.d1n1 = new Domino(1, 1); Assert.Throws <ArgumentException>(delegate { this.trainWithEngine.Play(d1n1); }); }
public static int Encode(Domino domino) { return(domino.Number * 10000 + domino.Head * 100 + domino.Tail); }
public void TestGetDoubleDomino() { Domino d = count2.GetDoubleDomino(2); Assert.AreEqual(d, d22); }
private void RaiseFXEventsAfterPlacedDomino(Domino domino) { // TODO }
public void TestBoneYardThisGetter() { Domino domino = boneYard[0]; Assert.IsInstanceOf <Domino>(domino); }
public bool PlayDomino(GameRole role, Domino dominoInHand, Domino dominoOnBoard) { if (IsGameEnded || !role.Equals(CurrentGameRole) || !IsDominoInHand(role, dominoInHand)) { return(false); } Player currentPlayer = GetCurrentPlayer(); if (dominoOnBoard == null && History.HorizontalDominoes.Count == 0) { RemoveDominoInHand(currentPlayer, dominoInHand); History.HorizontalDominoes.AddLast(dominoInHand); if (dominoInHand.Value1 == dominoInHand.Value2) { dominoInHand.Placement.Direction = DominoDirection.Vertical; dominoInHand.Placement.UpValue = dominoInHand.Value1; dominoInHand.Placement.DownValue = dominoInHand.Value2; History.Spinner = dominoInHand; History.VerticalDominoes.AddLast(dominoInHand); } else { dominoInHand.Placement.Direction = DominoDirection.Horizontal; dominoInHand.Placement.LeftValue = dominoInHand.Value1; dominoInHand.Placement.RightValue = dominoInHand.Value2; } ScoreByPlaying(currentPlayer); NextTurn(); return(true); } if (dominoOnBoard.Equals(History.HorizontalDominoes.First)) { if (dominoInHand.Value1 == dominoInHand.Value2) { if (dominoInHand.Value1 == dominoOnBoard.Placement.LeftValue) { RemoveDominoInHand(currentPlayer, dominoInHand); History.HorizontalDominoes.AddFirst(dominoInHand); dominoInHand.Placement.Direction = DominoDirection.Vertical; dominoInHand.Placement.UpValue = dominoInHand.Value1; dominoInHand.Placement.DownValue = dominoInHand.Value2; if (History.Spinner == null) { History.Spinner = dominoInHand; History.VerticalDominoes.AddLast(dominoInHand); } ScoreByPlaying(currentPlayer); if (currentPlayer.Dominoes.Count == 0) { ScoreByEndingHand(currentPlayer); } NextTurn(); return(true); } return(false); } else { if (dominoInHand.Value1 == dominoOnBoard.Placement.LeftValue) { RemoveDominoInHand(currentPlayer, dominoInHand); History.HorizontalDominoes.AddFirst(dominoInHand); dominoInHand.Placement.Direction = DominoDirection.Horizontal; dominoInHand.Placement.LeftValue = dominoInHand.Value2; dominoInHand.Placement.RightValue = dominoInHand.Value1; ScoreByPlaying(currentPlayer); if (currentPlayer.Dominoes.Count == 0) { ScoreByEndingHand(currentPlayer); } NextTurn(); return(true); } else if (dominoInHand.Value2 == dominoOnBoard.Placement.LeftValue) { RemoveDominoInHand(currentPlayer, dominoInHand); History.HorizontalDominoes.AddFirst(dominoInHand); dominoInHand.Placement.Direction = DominoDirection.Horizontal; dominoInHand.Placement.LeftValue = dominoInHand.Value1; dominoInHand.Placement.RightValue = dominoInHand.Value2; ScoreByPlaying(currentPlayer); if (currentPlayer.Dominoes.Count == 0) { ScoreByEndingHand(currentPlayer); } NextTurn(); return(true); } return(false); } } else if (dominoOnBoard.Equals(History.HorizontalDominoes.Last)) { if (dominoInHand.Value1 == dominoInHand.Value2) { if (dominoInHand.Value1 == dominoOnBoard.Placement.RightValue) { RemoveDominoInHand(currentPlayer, dominoInHand); History.HorizontalDominoes.AddLast(dominoInHand); dominoInHand.Placement.Direction = DominoDirection.Vertical; dominoInHand.Placement.UpValue = dominoInHand.Value1; dominoInHand.Placement.DownValue = dominoInHand.Value2; if (History.Spinner == null) { History.Spinner = dominoInHand; History.VerticalDominoes.AddLast(dominoInHand); } ScoreByPlaying(currentPlayer); if (currentPlayer.Dominoes.Count == 0) { ScoreByEndingHand(currentPlayer); } NextTurn(); return(true); } return(false); } else { if (dominoInHand.Value1 == dominoOnBoard.Placement.RightValue) { RemoveDominoInHand(currentPlayer, dominoInHand); History.HorizontalDominoes.AddLast(dominoInHand); dominoInHand.Placement.Direction = DominoDirection.Horizontal; dominoInHand.Placement.LeftValue = dominoInHand.Value1; dominoInHand.Placement.RightValue = dominoInHand.Value2; ScoreByPlaying(currentPlayer); if (currentPlayer.Dominoes.Count == 0) { ScoreByEndingHand(currentPlayer); } NextTurn(); return(true); } else if (dominoInHand.Value2 == dominoOnBoard.Placement.RightValue) { RemoveDominoInHand(currentPlayer, dominoInHand); History.HorizontalDominoes.AddLast(dominoInHand); dominoInHand.Placement.Direction = DominoDirection.Horizontal; dominoInHand.Placement.LeftValue = dominoInHand.Value2; dominoInHand.Placement.RightValue = dominoInHand.Value1; ScoreByPlaying(currentPlayer); if (currentPlayer.Dominoes.Count == 0) { ScoreByEndingHand(currentPlayer); } NextTurn(); return(true); } return(false); } } else if (dominoOnBoard.Equals(History.VerticalDominoes.First)) { if (dominoInHand.Value1 == dominoInHand.Value2) { if (dominoInHand.Value1 == dominoOnBoard.Placement.UpValue) { RemoveDominoInHand(currentPlayer, dominoInHand); History.HorizontalDominoes.AddFirst(dominoInHand); dominoInHand.Placement.Direction = DominoDirection.Horizontal; dominoInHand.Placement.LeftValue = dominoInHand.Value1; dominoInHand.Placement.RightValue = dominoInHand.Value2; ScoreByPlaying(currentPlayer); if (currentPlayer.Dominoes.Count == 0) { ScoreByEndingHand(currentPlayer); } NextTurn(); return(true); } return(false); } else { if (dominoInHand.Value1 == dominoOnBoard.Placement.UpValue) { RemoveDominoInHand(currentPlayer, dominoInHand); History.HorizontalDominoes.AddFirst(dominoInHand); dominoInHand.Placement.Direction = DominoDirection.Vertical; dominoInHand.Placement.UpValue = dominoInHand.Value2; dominoInHand.Placement.DownValue = dominoInHand.Value1; ScoreByPlaying(currentPlayer); if (currentPlayer.Dominoes.Count == 0) { ScoreByEndingHand(currentPlayer); } NextTurn(); return(true); } else if (dominoInHand.Value2 == dominoOnBoard.Placement.UpValue) { RemoveDominoInHand(currentPlayer, dominoInHand); History.HorizontalDominoes.AddFirst(dominoInHand); dominoInHand.Placement.Direction = DominoDirection.Vertical; dominoInHand.Placement.UpValue = dominoInHand.Value1; dominoInHand.Placement.DownValue = dominoInHand.Value2; ScoreByPlaying(currentPlayer); if (currentPlayer.Dominoes.Count == 0) { ScoreByEndingHand(currentPlayer); } NextTurn(); return(true); } return(false); } } else if (dominoOnBoard.Equals(History.VerticalDominoes.Last)) { if (dominoInHand.Value1 == dominoInHand.Value2) { if (dominoInHand.Value1 == dominoOnBoard.Placement.DownValue) { RemoveDominoInHand(currentPlayer, dominoInHand); History.HorizontalDominoes.AddLast(dominoInHand); dominoInHand.Placement.Direction = DominoDirection.Horizontal; dominoInHand.Placement.LeftValue = dominoInHand.Value1; dominoInHand.Placement.RightValue = dominoInHand.Value2; ScoreByPlaying(currentPlayer); if (currentPlayer.Dominoes.Count == 0) { ScoreByEndingHand(currentPlayer); } NextTurn(); return(true); } return(false); } else { if (dominoInHand.Value1 == dominoOnBoard.Placement.DownValue) { RemoveDominoInHand(currentPlayer, dominoInHand); History.HorizontalDominoes.AddLast(dominoInHand); dominoInHand.Placement.Direction = DominoDirection.Vertical; dominoInHand.Placement.UpValue = dominoInHand.Value1; dominoInHand.Placement.DownValue = dominoInHand.Value2; ScoreByPlaying(currentPlayer); if (currentPlayer.Dominoes.Count == 0) { ScoreByEndingHand(currentPlayer); } NextTurn(); return(true); } else if (dominoInHand.Value2 == dominoOnBoard.Placement.DownValue) { RemoveDominoInHand(currentPlayer, dominoInHand); History.HorizontalDominoes.AddLast(dominoInHand); dominoInHand.Placement.Direction = DominoDirection.Vertical; dominoInHand.Placement.UpValue = dominoInHand.Value2; dominoInHand.Placement.DownValue = dominoInHand.Value1; ScoreByPlaying(currentPlayer); if (currentPlayer.Dominoes.Count == 0) { ScoreByEndingHand(currentPlayer); } NextTurn(); return(true); } return(false); } } return(false); }
// Update is called once per frame void Update() { if (GameProperties.gameType == GameType.kGameTypeGod) { if ((GameProperties.editMode != EditMode.kEditModeDominos) || GameProperties.paused || LevelPropertiesScript.sharedInstance().wasPaused()) { return; } if (Input.GetMouseButton(0) || (Input.GetMouseButtonUp(0))) { Vector3 screenCoordinates = Input.mousePosition; if (CreateDominos.sharedInstance().positionIsOnGUI(screenCoordinates) || LevelPropertiesScript.sharedInstance().positionIsOnGUI(screenCoordinates) || EditModeScript.sharedInstance().positionIsOnGUI(screenCoordinates)) { return; } GameObject floor = LevelPropertiesScript.sharedInstance().floor; Vector3 floorPosition = floor.transform.position; floorPosition.y = (floor.transform.position.y + floor.transform.localScale.y * 0.5f); Vector3 position = CreateDominos.sharedInstance().worldCoordinatesFromScreenCoordinates(screenCoordinates, floorPosition); if (!this.positionIsValid(position)) { return; } if (Input.GetMouseButtonDown(0)) { this.mouseLastDominoPosition = position; this.mouseNDominosCurrentMotion = 0; this.mouseLastDomino = null; } Vector3 diffVector = (position - this.mouseLastDominoPosition); diffVector.y = 0.0f; float distanceWithLastDominoSqr = diffVector.sqrMagnitude; if (distanceWithLastDominoSqr >= (CreateDominos.dominosSeparation * CreateDominos.dominosSeparation)) { float distanceWithLastDomino = Mathf.Sqrt(distanceWithLastDominoSqr); Vector3 nextPosition = this.mouseLastDominoPosition; Vector3 moveVector = (diffVector.normalized * CreateDominos.dominosSeparation); this.mouseLastDominoAngle = Quaternion.LookRotation(diffVector); this.mouseLastDominoAngle.x = 0.0f; this.mouseLastDominoAngle.z = 0.0f; int nDominos = (int)(distanceWithLastDomino / CreateDominos.dominosSeparation); Quaternion rotation = this.mouseLastDominoAngle; for (int i = 0; i < nDominos; i++) { if (i == 0) { if (this.mouseLastDomino != null) { Domino mouseLastDominoAttributes = this.mouseLastDomino.GetComponent <Domino>(); rotation = mouseLastDominoAttributes.originalRotation; if (this.mouseNDominosCurrentMotion == 1) { rotation = this.mouseLastDominoAngle; } else { rotation = Quaternion.Lerp(rotation, this.mouseLastDominoAngle, 0.5f); } this.mouseLastDomino.transform.rotation = rotation; mouseLastDominoAttributes.originalRotation = rotation; } } nextPosition += moveVector; Vector3 p = new Vector3(nextPosition.x, nextPosition.y, nextPosition.z); float f = (0.5f + (0.5f * i / nDominos)); Quaternion nextRotation = Quaternion.Lerp(rotation, this.mouseLastDominoAngle, f); GameObject domino = CreateDominos.sharedInstance().instantiateDomino(ref nextPosition, nextRotation); nextPosition.x = p.x; nextPosition.y = p.y; nextPosition.z = p.z; if (domino != null) { this.mouseNDominosCurrentMotion++; this.mouseLastDomino = domino; } } this.mouseLastDominoPosition = nextPosition; } if (Input.GetMouseButtonUp(0)) { if (this.mouseNDominosCurrentMotion == 0) { Ray ray = Camera.main.ScreenPointToRay(screenCoordinates); Vector3 pos; GameObject selectedDomino = CreateDominos.rayCastWithDominos(ray, out pos); if (selectedDomino != null) { CreateDominos.sharedInstance().removeDomino(selectedDomino); } else { CreateDominos.sharedInstance().instantiateDomino(ref position, this.mouseLastDominoAngle); } } this.mouseNDominosCurrentMotion = 0; this.mouseLastDomino = null; } } } }
// adds a domino picture to a train public void ComputerPlayOnTrain(Domino d, Train train, List <PictureBox> trainPBs, int pbIndex) { PictureBox trainPB = trainPBs[pbIndex]; LoadDomino(trainPB, d); }
public void Remove(Domino toRemove) { toRemove.DestroyGameObject(); track.Remove(toRemove); }
private static bool CanAppend(Domino domino, List <Domino> chain) { return(chain == null || chain.Count == 0 || chain.Last().B == domino?.A); }
public void Initialize(Domino domino) { mController = new DominoController(domino.Controller); mController.Parent = this; }
//should only be used to start lines. internal Node(Domino v, string owner) { if (!v.IsDouble()) throw new ArgumentException("Must start game graph with double"); Value = v; Children = new List<Node>(); End = Value.First; Owner = owner; }
public static void RotateToAccurate(Domino d, float rx, float ry, float rz, float time) { // TODO animate this ACL. UnityEngine.Debug.Log("Rotate to accurate " + rz.ToString()); d.gameObject.transform.Rotate(rx, ry, rz); }
public void RemoveChild(Domino child) { var c = Children.Find(n => n.Value.Equals(child)); if (c == null) throw new ArgumentOutOfRangeException("child"); Children.Remove(c); }
private static void TestMTConstructorProperties() { Console.WriteLine("Test MexicanTrain constructor"); Console.WriteLine(); Random rndGen = new Random(); int engVal = rndGen.Next(1, 7); MexicanTrain test = new MexicanTrain(engVal); const int MAXDOTS = 6; BoneYard b = new BoneYard(MAXDOTS); b.Shuffle(); // IsEmpty (True) Console.WriteLine("Expect: IsEmpty True"); Console.WriteLine("Result: IsEmpty " + test.IsEmpty.ToString()); Console.WriteLine(); int handSize = rndGen.Next(1, 7); Domino last = new Domino(); for (int i = 0; i < handSize; i++) { Domino dom = b.Draw(); if (i == handSize - 1) { last = dom; } test.Add(dom); } // Dominos Drawn Console.WriteLine("Dominos: \n" + test.ToString()); // Count Console.WriteLine("Expect: Count " + handSize.ToString()); Console.WriteLine("Result: Count " + test.Count.ToString()); Console.WriteLine(); // EngineValue Console.WriteLine("Expect: Engine Value " + engVal.ToString()); Console.WriteLine("Result: Engine Value " + test.EngineValue.ToString()); Console.WriteLine(); // IsEmpty (False) Console.WriteLine("Expect: IsEmpty False"); Console.WriteLine("Result: IsEmpty " + test.IsEmpty.ToString()); Console.WriteLine(); // LastDomino Console.WriteLine("Expect: LastDomino is " + last.ToString()); Console.WriteLine("Result: LastDomino is " + test.LastDomino.ToString()); Console.WriteLine(); // PlayableValue Console.WriteLine("Expect: PlayableValue is " + last.Side2.ToString()); Console.WriteLine("Result: PlayableValue is " + test.PlayableValue.ToString()); Console.WriteLine(); // Index Console.WriteLine("Expect: last domino by index is " + last.ToString()); Console.WriteLine("Result: last domino by index is " + test[test.Count - 1].ToString()); Console.WriteLine(); }
public void Start(Domino starter) { if (!starter.IsDouble()) throw new ArgumentException("Must start game graph with double"); if (_root != null) throw new InvalidOperationException("Graph already started"); _root = starter; _lines = Players.Select(p => new Node(starter, p.Name())).ToList(); }
// plays a domino on a train. Loads the appropriate train pb, // removes the domino pb from the hand, updates the train status label , // disables the hand pbs and disables appropriate buttons public void UserPlayOnTrain(Domino d, Train train, List <PictureBox> trainPBs) { }
// adds a domino picture to a train public void ComputerPlayOnTrain(Domino d, Train train, List <PictureBox> trainPBs, int pbIndex) { }
// instantiate boneyard and hands // find the highest double in each hand // determine who should go first, remove the highest double from the appropriate hand // and display the highest double in the UI // instantiate trains now that you know the engine value // create all of the picture boxes for the user's hand and load the dominos for the hand // Add the picture boxes for each train to the appropriate list of picture boxes // update the labels on the UI // if it's the computer's turn, let her play // if it's the user's turn, enable the pbs so she can play public void SetUp() { boneyard = new BoneYard(9); playersHand = new Hand(boneyard, 2); computersHand = new Hand(boneyard, 2); int pDIndex = playersHand.IndexOfHighDouble(); int cDIndex = computersHand.IndexOfHighDouble(); Domino highestDouble = null; bool playerGoesFirst = true; // player must have positive index value AND computer must either have negative index OR lower value on the domino, in order for player to go first. if (pDIndex >= 0 && (cDIndex == -1 || (playersHand[pDIndex].Side1 > computersHand[cDIndex].Side1))) { //player goes first highestDouble = playersHand[pDIndex]; playersHand.RemoveAt(pDIndex); LoadDomino(enginePB, highestDouble);//the highest double picture box } else if (cDIndex >= 0 && (pDIndex == -1 || (playersHand[pDIndex].Side1 < computersHand[cDIndex].Side1))) { playerGoesFirst = false; highestDouble = computersHand[cDIndex]; computersHand.RemoveAt(cDIndex); LoadDomino(enginePB, highestDouble); } playersTrain = new PlayerTrain(playersHand, highestDouble.Side1); computersTrain = new PlayerTrain(computersHand, highestDouble.Side1); mexicanTrain = new MexicanTrain(highestDouble.Side1); playersHandPbs = new List <PictureBox>(); for (int i = 0; i < playersHand.Count; i++) { playersHandPbs.Add(CreateUserHandPB(i)); } LoadHand(playersHandPbs, playersHand); computersTrainPbs = new List <PictureBox>(5); computersTrainPbs.Add(compTrainPB1); computersTrainPbs.Add(compTrainPB2); computersTrainPbs.Add(compTrainPB3); computersTrainPbs.Add(compTrainPB4); computersTrainPbs.Add(compTrainPB5); playersTrainPbs = new List <PictureBox>(5); playersTrainPbs.Add(userTrainPB1); playersTrainPbs.Add(userTrainPB2); playersTrainPbs.Add(userTrainPB3); playersTrainPbs.Add(userTrainPB4); playersTrainPbs.Add(userTrainPB5); mexicanTrainPbs = new List <PictureBox>(5); mexicanTrainPbs.Add(mexTrainPB1); mexicanTrainPbs.Add(mexTrainPB2); mexicanTrainPbs.Add(mexTrainPB3); mexicanTrainPbs.Add(mexTrainPB4); mexicanTrainPbs.Add(mexTrainPB5); UpdateTrainStatusLabels(); if (playerGoesFirst == true) { EnableUserHandPBs(); } else { CompleteComputerMove(); } }