public Unit(int id, int hp, int picture, GameObject gUnit, unitClass Class) { this.id = id; this.hp = hp; this.picture = picture; this.gUnit = gUnit; this.Class = Class; }
public void createPiece(unitClass cls, Vector2Int coords) { Vector3 loc = new Vector3(); loc = grid.GetCellCenterWorld(new Vector3Int(coords.x, coords.y, 1)); transform.position = loc; switch (cls) { case unitClass.pawn: { sr.sprite = pawnSprite; currentClass = unitClass.pawn; pawnFirstMove = true; str = 2; spd = 1; lck = 5; skl = 3; con = 3; break; } case unitClass.rook: { sr.sprite = rookSprite; currentClass = unitClass.rook; str = 8; spd = 4; lck = 2; skl = 8; con = 8; break; } case unitClass.bishop: { sr.sprite = bishopSprite; currentClass = unitClass.bishop; str = 7; spd = 4; lck = 2; skl = 10; con = 6; break; } case unitClass.knight: { sr.sprite = knightSprite; currentClass = unitClass.knight; str = 10; spd = 3; lck = 2; skl = 6; con = 10; break; } case unitClass.queen: { sr.sprite = queenSprite; currentClass = unitClass.queen; str = 12; spd = 10; lck = 8; skl = 9; con = 4; break; } case unitClass.king: { sr.sprite = kingSprite; currentClass = unitClass.king; str = 12; spd = 1; lck = 1; skl = 12; con = 9; break; } } board.placePieceOnCell(coords, this); }
void setUpPiece(unitClass cls) { }
void Battle(int sx, int sy, unitClass atkClass, unitClass defClass) { GameObject[] units = GameObject.FindObjectsOfType<GameObject>(); GameObject atkUnit = null; GameObject defUnit = null; foreach (GameObject go in units) { if (go.transform.position == new Vector3((float)ShellPositionX(sx), (float)ShellPositionY(sy), -25.4f)) { if(go.GetComponent<Unit>().unitClassId == (int)atkClass) atkUnit = go; if(go.GetComponent<Unit>().unitClassId == (int)defClass) defUnit = go; } } // Animation if (defClass == unitClass.EnemyFlag) { Destroy(defUnit); map[sx, sy] = atkClass; Debug.Log ("You Win!!!!"); GameFinished(); } if (defClass == unitClass.MyFlag) { Destroy(defUnit); map[sx, sy] = atkClass; Debug.Log ("You Lose..."); GameFinished(); } if (((int)atkClass + (int)defClass) == 0) { Destroy(atkUnit); Destroy(defUnit); map[sx, sy] = unitClass.NoUnit; } if (Mathf.Abs((int)atkClass) == 2) { if (Mathf.Abs((int)defClass) == 3) { Destroy (atkUnit); map [sx, sy] = defClass; } else { Destroy (defUnit); map [sx, sy] = atkClass; } } if (Mathf.Abs((int)defClass) == 2) { if(Mathf.Abs((int)atkClass) == 3) { Destroy(defUnit); map[sx, sy] = atkClass; } else { Destroy(atkUnit); map[sx, sy] = defClass; } } if (((int)atkClass + (int)defClass) > 0) { if((int)atkClass > 0) { Destroy(defUnit); map[sx, sy] = atkClass; } else { Destroy(atkUnit); map[sx, sy] = defClass; if(atkClass == unitClass.EnemyFlag) { Debug.Log ("You Win!!!!"); GameFinished(); } } } if (((int)atkClass + (int)defClass) < 0) { if((int)atkClass > 0) { Destroy(atkUnit); map[sx, sy] = defClass; if(atkClass == unitClass.MyFlag) { Debug.Log ("You Lose..."); GameFinished(); } } else { Destroy(defUnit); map[sx, sy] = atkClass; } } }
// Update is called once per frame void Update() { int i; placeComplete = true; for (i=0; i<15; i++) { if (myCount [i] > 0) { placeComplete = false; break; } } if(Input.GetMouseButtonUp(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast (ray, out hit)) { if(placing) { if(ShellY(hit.point.y) > 2) Debug.Log("You Cannot Place Your Unit There (Not Your Area)"); else if(map[ShellX(hit.point.x), ShellY(hit.point.y)] != unitClass.NoUnit) Debug.Log("You Cannot Place Your Unit There (There Is Another Unit Already)"); else { GameObject newUnit = GameObject.Find(id.ToString()); Instantiate(newUnit, new Vector3((float)ShellPositionX(ShellX(hit.point.x)), (float)ShellPositionY(ShellY(hit.point.y)), -25.4f), Quaternion.identity); map[ShellX(hit.point.x), ShellY(hit.point.y)] = id; myCount[((int)id - 1)]--; placing = false; } } if(gameStart && myTurn) { turnOver = false; if(!moving) { startX = ShellX(hit.point.x); startY = ShellY(hit.point.y); startClass = map[startX, startY]; if(CanMoveStart(startX, startY)) moving = true; else Debug.Log("Choose Your Unit Which Can Move"); } if(moving) { destX = ShellX(hit.point.x); destY = ShellY(hit.point.y); destClass = map[destX, destY]; if(CanMoveDest(startX, startY, destX, destY)) { MoveUnit(startX, startY, destX, destY); if((int)destClass < 0) Battle(destX, destY, startClass, destClass); turnOver = true; moving = false; } } if(turnOver) { turnCount += 0.5f; enemyTurn = true; myTurn = false; } } } } if(gameStart && enemyTurn) { turnOver = false; if(!moving) { for(i = 9; i < 72; i++) { startX = i % 9; startY = i / 9; startClass = map[startX, startY]; if((int)startClass < 0) { moving = true; break; } } } if(moving) { destX = startX; destY = startY - 1; destClass = map[destX, destY]; MoveUnit(startX, startY, destX, destY); if((int)destClass > 0) Battle(destX, destY, startClass, destClass); turnOver = true; moving = false; } if(turnOver) { turnCount += 0.5f; myTurn = true; enemyTurn = false; } } }
void OnGUI() { string[] classes = new string[15]; int i, j; for(i = 0; i < 15; i++) classes[i] = ((unitClass)(i + 1)).ToString() + " : " + myCount[i]; for(j = 0; j < 8; j++) for(i = 0; i < 9; i++) GUI.Label (new Rect(1500 + i * 30, 300 - j * 30, 30, 30), ((map[i, j] < 0) ? "?" : map[i, j].ToString("d"))); GUI.Label (new Rect (1500, 330, 300, 30), "Mouse Point Ray Hit On " + hit.point.ToString ()); GUI.Label (new Rect (1500, 360, 300, 30), "Shell Position Of Ray Hit : (" + ShellX(hit.point.x) + ", " + ShellY(hit.point.y) + ")"); if (gameStart) { GUI.Label (new Rect (1500, 390, 300, 30), "Turn No. " + (int)turnCount); GUI.Label (new Rect (1500, 420, 300, 30), ((myTurn) ? "Your Turn." : "Enemy's Turn.")); } if (!gameStart) { GUI.Box (new Rect (135, 90, 240, 360), "Place Your Units Manually"); int sg = GUI.SelectionGrid (new Rect (150, 135, 210, 300), -1, classes, 2); if (sg >= 0) { if (myCount [sg] <= 0) Debug.Log ("You Can't Place It Any More"); else { id = (unitClass)sg + 1; placing = true; } } if (!placeComplete) { if (GUI.Button (new Rect (150, 465, 150, 30), "Place Randomly")) { placeRandomly(); placeComplete = true; } } if (placeComplete) { if (GUI.Button (new Rect (150, 500, 150, 30), "Game Start")) { placeEnemyUnits(); if(Random.Range(0,2) == 1) { myTurn = true; enemyTurn = false; } else { enemyTurn = true; myTurn = false; } turnCount = 1; gameStart = true; } } } }