예제 #1
0
		// Transforms one or more given pieces to a certain type, on a certain Square or Intersection
		public void TransformPiece(PieceType type, GameModel.Intersection toIntr, GameModel.Square toSqr, params GameModel.Piece[] piece)
		{
			// Transforming one piece
			if(piece.Length == 1 && toSqr != null)
			{
				int index = m_pieces.IndexOf(GetPieceState(piece[0]));
				
				m_pieces[index].GetComponent<PieceScript>().Type = type;
				m_pieces[index].GetComponent<PieceScript>().Square = toSqr;
				m_pieces[index].GetComponent<PieceScript>().Piece = new GameModel.Piece(type, piece[0].Color);
				m_pieces[index].GetComponent<PieceScript>().InitSprites();
				m_pieces[index].GetComponent<PieceScript>().CheckSprite();
			}

			// Transforming Globules
			else if(piece.Length > 1 && toIntr != null)
			{
				int index = m_pieces.IndexOf(GetPieceState(piece[0]));
				
				foreach (GameModel.Piece item in piece)
				{
					if(item != piece[0])
						m_pieces.Remove(GetPieceState(item));
				}

				m_pieces[index].GetComponent<PieceScript>().Type = type;
				m_pieces[index].transform.position = type != PieceType.Tetraglobe ? ToUnityCoord(toSqr) : ToUnityCoord(toIntr);
				m_pieces[index].GetComponent<PieceScript>().Piece = new GameModel.Piece(type, piece[0].Color);
				m_pieces[index].GetComponent<PieceScript>().InitSprites();
				m_pieces[index].GetComponent<PieceScript>().CheckSprite();
				
			}
		}
예제 #2
0
		public static GameModel.Intersection ToModelIntr(Vector3 pos)
		{
			GameModel.Intersection intersection = new GameModel.Intersection();

			intersection.A = (int)((pos.y - 0.3) / 0.6);
			intersection.B = (int)((pos.x + 3.9) / 0.6);
			
			return intersection;
		}
예제 #3
0
		public GameObject GetPieceState(GameModel.Intersection intersection)
		{
			foreach(GameObject item in m_pieces)
			{
				if(item.GetComponent<PieceScript>().Intersection == intersection)
					return item;
			}

			return null;
		}
예제 #4
0
		// Removes a piece on a given intersection
		public void RemovePiece(GameModel.Intersection intr)
		{
			GameObject removedPiece = GetPieceState(intr);

			if (!m_pieces.Contains(removedPiece))
				return;
			
			removedPiece.SetActive(false);
			m_pieces.Remove(removedPiece);
			Destroy(removedPiece);
		}
예제 #5
0
		public static Vector3 ToUnityCoord(GameModel.Intersection intr)
		{
			Vector3 position = new Vector3();

			// same as for the squares here, adding a 0.3 since it is where the INTR(0,0) is, "physically"
			position.x = (float) (0.3 + intr.B * 0.6);

			// same as for the squares, the Y INTR starts just a bit higher
			position.y = (float) (-3.9 + intr.A * 0.6);

			return position;
		}
예제 #6
0
        public PieceScript(PieceType type, Color color, GameModel.Intersection intersection)
        {
            m_type  = type;
            m_color = color;

            gameObject.transform.position = Board.ToUnityCoord(intersection);

            if (!InitSprites())
            {
                Debug.LogError("Error initializating sprites for " + m_type);
                return;
            }

            SpriteRenderer.sprite = (intersection.A + intersection.B) % 2 == 0 ? m_sprite1 : m_sprite2;

            gameObject.SetActive(true);
        }
예제 #7
0
		public void PlacePiece(GameModel.Piece piece, GameModel.Intersection intersection)
		{
			if(piece.Type != PieceType.Tetraglobe)
				return;

			GameObject newPiece = new GameObject(GameModel.GetString.GetStr(piece.Type));

			newPiece.AddComponent<SpriteRenderer>();
			newPiece.AddComponent<BoxCollider2D>();
			newPiece.AddComponent<PieceScript>();

			newPiece.GetComponent<BoxCollider2D>().isTrigger = true;
			newPiece.GetComponent<PieceScript>().Collider = newPiece.GetComponent<BoxCollider2D>();
			newPiece.GetComponent<PieceScript>().Type = piece.Type;
			newPiece.GetComponent<PieceScript>().Color = piece.Color;
			newPiece.GetComponent<PieceScript>().Intersection = intersection;
			newPiece.GetComponent<PieceScript>().Piece = piece;
			newPiece.GetComponent<PieceScript>().InitSprites();
			newPiece.GetComponent<PieceScript>().CheckSprite();
			
			m_pieces.Add(newPiece);

			Instantiate(newPiece, newPiece.transform.position, Quaternion.identity);
		}
예제 #8
0
		public void MovePiece(GameModel.Piece piece, GameModel.Intersection toIntr)
		{
			GetPieceState(piece).transform.position = ToUnityCoord(toIntr);
		}
예제 #9
0
		public void SwapPiece(GameModel.Piece piece1, GameModel.Piece piece2, GameModel.Square toSqr, GameModel.Intersection toIntr)
		{	
			MovePiece(piece1, toSqr);
			MovePiece(piece2, toIntr);
			
			GetPieceState(piece1).GetComponent<PieceScript>().CheckSprite();
			GetPieceState(piece2).GetComponent<PieceScript>().CheckSprite();
		}