private PlayObject buildNewConstructionRails(int tileIndex, PlayColor color) { var newBlockItem = (RailsTemplate)constructionRailsRes[color].Instance(); rotateNewRails((Spatial)newBlockItem, selected.Value, tileIndex); updateLastRail(selected.Value, tileIndex, color); tiles[tileIndex].placeItem((Spatial)newBlockItem); return(newBlockItem); }
private TrainTemplate getTrain(PlayColor color) { foreach (TrainTemplate train in GetNode("Trains").GetChildren()) { if (train.color == color) { return(train); } } return(null); }
private void updateLastRail(int updateI, int nextI, PlayColor color) { if (!tiles[updateI].hasDepot) { paths[color].cutPathIncluding(updateI); var fromI = paths[color].last().index; var newBlockItem = determineLastBlock(fromI, updateI, nextI, color); rotateNewRails((Spatial)newBlockItem, fromI, updateI); tiles[updateI].placeItem((Spatial)newBlockItem); paths[color].add(fromI, updateI, newBlockItem); } }
private void makeLastBlockConstruction(PlayColor color) { var lastElementIndex = paths[color].last().index; paths[color].cutPathIncluding(lastElementIndex); var newBlockItem = (RailsTemplate)constructionRailsRes[color].Instance(); rotateNewRails((Spatial)newBlockItem, paths[color].last().index, lastElementIndex); tiles[lastElementIndex].placeItem((Spatial)newBlockItem); paths[color].add(paths[color].last().index, lastElementIndex, newBlockItem); }
private void pathCompleteChanged(bool complete, PlayColor color) { if (complete) { getTrain(color).chooChoo(); if (checkAllPathsCompeted()) { levelComplete(); } } else { getTrain(color).chooChoo(false); } }
private RailsTemplate determineLastBlock(int fromI, int currentI, int nextI, PlayColor color) { // we're not building next block, so the last block should be construction if (currentI == nextI) { return((RailsTemplate)constructionRailsRes[color].Instance()); } var diff = nextI - fromI; var diffAbs = Math.Abs(diff); // straight if (diff == 2 || -diff == 2 || diff == 2 * cols || -diff == 2 * cols) { return((RailsTemplate)straightRailsRes[color].Instance()); } // right if (diffAbs == cols - 1) { if (Math.Abs(currentI - fromI) == cols) { return((RailsTemplate)rightRailsRes[color].Instance()); } else if (Math.Abs(currentI - fromI) == 1) { return((RailsTemplate)leftRailsRes[color].Instance()); } } if (diffAbs == cols + 1) { if (Math.Abs(currentI - fromI) == cols) { return((RailsTemplate)leftRailsRes[color].Instance()); } else if (Math.Abs(currentI - fromI) == 1) { return((RailsTemplate)rightRailsRes[color].Instance()); } } throw new Exception(string.Format(@"This should not happen. We didn't detect correct shape of rails when updating last path. (fromI: '{0}', currentI: '{1}', nextI: '{2}', color: '{3}'", fromI, currentI, nextI, color)); }
public Path(PlayColor color) { this.color = color; }