public void UpdateStatus(Player bombardier, Player bombarded, int x, int y, IBoardEntry hit) { PlayerBoards[bombarded.ID].MarkBombarded(x, y); bool success = !(hit is EmptyBoardCell); _statusBar.text = string.Format ( "<i>{0}</i> BOMBARDED <i>{1}</i> at <b>{2}{3}</b>. <color={4}>{5}</color>.", bombardier.Name, bombarded.Name, (char)('A' + x), y + 1, success ? "red" : "blue", success ? "HIT" : "MISS" ); if (hit is IShip) { _statusBar.text += string.Format(" {0}'s {1} has been destroyed!", bombarded.Name, (hit as IShip).Name); } if (!bombarded.IsAlive) { _statusBar.text += string.Format(" <b>GAME OVER!</b> <color=green>{0}</color> won after {1} attempts!", bombardier.Name, bombardier.Attempts); } }
public void Bombard(Player opponent, out int x, out int y, out IBoardEntry hit) { Attempts++; BombardmentStrategy.Bombard(KnownOpponentBoard, out x, out y); hit = opponent.PlayerBoard.Bombard(x, y); KnownOpponentBoard.SetInfo(x, y, hit); if (hit is IShip) { KnownOpponentBoard.ReplaceInformation(hit as IShip); } }
/* * Return a list of board full paths, in the Arcweave hierarchy context. */ public static void GetBoardsFullPaths(Project project, List <string> IDs, List <string> paths) { BoardFolder root = project.GetRootBoardFolder(); if (root == null) { Debug.LogWarning("[Arcweave] Cannot find root board. Maybe the exported json is corrupted, or the format has changed."); return; } // Do first depth iteration here to skip appending "Root" to all paths for (int i = 0; i < root.childIds.Length; i++) { IBoardEntry child = project.GetBoardEntry(root.childIds[i]); BoardHierarchyWalker(project, child, "", IDs, paths); } }
private Color GetShipColor(IBoardEntry entry) { if (!(entry is IShip)) { return(Color.white); } switch ((entry as IShip).Name) { case "Battleship": return(Color.yellow); case "Carrier": return(Color.magenta); case "Cruiser": return(Color.green); case "Destroyer": return(Color.cyan); } return(Color.black); }
/* * Recursive static function to iterate over the Board Folder hierarchy and build two lists. * IDs list contains the Hash IDs of the resulting boards, while paths contain the computed Hierachy paths, as they were in Arcweave. */ public static void BoardHierarchyWalker(Project project, IBoardEntry entry, string prefix, List <string> IDs, List <string> paths) { if (entry is Board) { Board b = entry as Board; IDs.Add(b.id); paths.Add(prefix + b.realName); } else if (entry is BoardFolder) { BoardFolder bf = entry as BoardFolder; string newPrefix = prefix + bf.realName + "/"; for (int i = 0; i < bf.childIds.Length; i++) { IBoardEntry child = project.GetBoardEntry(bf.childIds[i]); BoardHierarchyWalker(project, child, newPrefix, IDs, paths); } } else { Debug.LogWarning("[Arcweave] Unexpected type of board entry: " + entry); } }
public void SetInfo(int x, int y, IBoardEntry hit) { _grid[x, y] = hit; }