public void createButton() { this.Anchor = AnchorStyles.Top | AnchorStyles.Left; this.BackColor = System.Drawing.Color.Transparent; getCorrespondentImg(); //rotate the image if the player is the enemy if (this.player.playerEnum == PlayerEnum.Second) { cpImage.RotateFlip(RotateFlipType.Rotate180FlipNone); } this.BackgroundImage = cpImage; this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.FlatAppearance.BorderColor = System.Drawing.Color.Black; this.FlatAppearance.BorderSize = 0; this.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Transparent; this.FlatAppearance.MouseOverBackColor = Color.FromArgb(100, Color.LightGray); this.FlatStyle = FlatStyle.Flat; this.ForeColor = System.Drawing.Color.Transparent; this.Location = Board.BoardToWorld(this.board_point); this.Name = currentType.ToString() + Board.cpNum; this.Size = Board.sizeOfCP; this.Margin = new System.Windows.Forms.Padding(3, 3, 3, 3); this.TabIndex = Board.cpNum; Board.cpNum++; this.UseVisualStyleBackColor = false; this.Click += new System.EventHandler(this.Button_Click); }
private static Piece Create(ChessPieceType type, ChessPieceColor color) { var path = $"Prefabs/{type.ToString()}{(color == ChessPieceColor.Black ? "Dark" : "Light")}"; var prefab = Resources.Load(path); var obj = Object.Instantiate(prefab) as GameObject; var piece = obj.GetComponent <Piece>(); piece.SetType(type, color); return(piece); }
void CheckMove(ChessPiece[,] chessboard, Position from, Position to) { if (chessboard[from.row, from.column] == null) { throw new Exception("No chesspiece at from-position"); } else if (chessboard[to.row, to.column] != null) { throw new Exception("There already is a chesspiece at to-position"); } else if (!ValidMove(chessboard[from.row, from.column], from, to)) { ChessPieceType type = chessboard[from.row, from.column].type; throw new Exception("The " + type.ToString() + " can't move in such a way"); } }
private void initItem() { this.BackgroundImageLayout = ImageLayout.Zoom; this.FlatAppearance.BorderColor = Color.Black; this.FlatAppearance.BorderSize = 0; this.FlatAppearance.MouseDownBackColor = Color.Transparent; this.FlatAppearance.MouseOverBackColor = Color.FromArgb(100, Color.LightGray); this.FlatStyle = FlatStyle.Flat; this.ForeColor = Color.Black; this.Anchor = AnchorStyles.Top | AnchorStyles.Left; this.BackColor = Color.Transparent; this.FlatAppearance.BorderSize = 0; this.Location = this.indexToWorld(); this.Name = "GraveYardItem" + '_' + playerindex + '_' + type.ToString(); this.Size = new Size(68, 68); this.TabStop = false; this.UseVisualStyleBackColor = false; this.Click += new System.EventHandler(this.Button_Click); }
public IChessPiece GetChessPiece(ChessPieceType type, ChessPieceColor color) { IChessPiece piece; switch (type) { case ChessPieceType.PAWN: piece = new Pawn(board, color); break; case ChessPieceType.ROOK: piece = new Rook(board, color); break; case ChessPieceType.BISHOP: piece = new Bishop(board, color); break; case ChessPieceType.KING: piece = new King(board, color); break; case ChessPieceType.QUEEN: piece = new Queen(board, color); break; case ChessPieceType.KNIGHT: piece = new Knight(board, color); break; default: throw new ArgumentException("Called with invalid chess piece type", type.ToString()); } return(piece); }
private void Awake() { BattleStatus battleStatus = PlayerManager.self.statusManager.currentStatus as BattleStatus; respGameInit = battleStatus.respGameInit; selfPlayerId = PlayerManager.self.player.role.roleUid; foreach (TeamInfo teamInfo in respGameInit.teamInfos) { foreach (PlayerFighter fighter in teamInfo.fighters) { if (fighter.playerId == selfPlayerId) { selfTeamId = teamInfo.teamId; } } } List <CardSprite> sprites = respGameInit.allSprite; Debug.LogFormat("sprite size is {0}", sprites.Count); foreach (CardSprite cardSprite in sprites) { //开始初始化棋牌数据 int type = cardSprite.type; ChessPieceType c = (ChessPieceType)(type - 1); string sitName = cardSprite.x + "" + cardSprite.z; string name = c.ToString(); //Debug.LogFormat(sitName); GameObject sitObj = GameObject.Find(sitName); GameObject gameObj = Resources.Load("prefabs/cardPfb/" + name) as GameObject; gameObj = Instantiate(gameObj); ChessPieceController cpc = gameObj.GetComponent <ChessPieceController>(); cpc.chessPiece = new ChessPiece((TeamID)(cardSprite.team), c, cardSprite.x, cardSprite.z); gameObj.transform.position = sitObj.transform.position; if (selfTeamId == (int)TeamID.HEI) { Quaternion quaternion = gameObj.transform.rotation; gameObj.transform.rotation = Quaternion.Euler(0, quaternion.x, quaternion.z); } Material material = Resources.Load("wujiang/Materials/" + cardSprite.bg) as Material; Texture2D texture = Resources.Load("wujiang/" + cardSprite.texture) as Texture2D; Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); MeshRenderer meshRenderer = gameObj.GetComponent <MeshRenderer>(); meshRenderer.materials[0] = material; foreach (SpriteRenderer spriteRenderer in gameObj.GetComponentsInChildren <SpriteRenderer>()) { spriteRenderer.sprite = sprite; break; } } GameObject heiGameObject = GameObject.Find("heiqi"); if (heiGameObject != null) { heiGameObject.SetActive(false); Destroy(heiGameObject); } GameObject hongqiGameObject = GameObject.Find("hongqi"); if (hongqiGameObject != null) { hongqiGameObject.SetActive(false); Destroy(hongqiGameObject); } if (selfTeamId == (int)TeamID.HEI) { GameObject team1Camera = GameObject.Find("Team1Camera"); if (team1Camera != null) { team1Camera.SetActive(false); Destroy(team1Camera); } Camera camera = Resources.Load("prefabs/Team2Camera") as Camera; Instantiate(camera); } if (selfTeamId == (int)TeamID.HONG) { GameObject team2Camera = GameObject.Find("Team2Camera"); if (team2Camera != null) { team2Camera.SetActive(false); Destroy(team2Camera); } } MessageDispatcher.RegisterHandler(MessageConst.Battle.TYPE, this); //初始化完成,向服务器发送消息 NetManager.SendGameInitDone(); }
private char chessPeiceTypeToChar(ChessPieceType type) { return(type.ToString()[0]); }