public Player(Texture2D pieceTex, Player otherplayer) { texture = pieceTex; pieceSize = texture.Width / 6; isPlayerVisible = false; CreateGamePieces(otherplayer); }
Vector2 GetRandPos(int x, int x2, int y, int y2, Player otherplayer) { bool keeprandomnize = true; int posX = 0; int posY = 0; Vector2 pos = Vector2.Zero; while (keeprandomnize) { keeprandomnize = false; int X = GetRandX(x, x2); int Y = GetRandY(y, y2); posX = (int)(X / 32) * 32; posY = (int)(Y / 32) * 32; pos = new Vector2(posX, posY); for (int i = 0; i < positionsOccupied.Count; i++) { if (positionsOccupied[i] == pos) { keeprandomnize = true; } } if(otherplayer != null) { for (int i = 0; i < otherplayer.positionsOccupied.Count; i++) { if (otherplayer.positionsOccupied[i] == pos) { keeprandomnize = true; } } } } positionsOccupied.Add(pos); return new Vector2(posX, posY); }
public void UsePieces(int x, int y, Player p1, Player p2) { if(pickedUpPieces == -1) { for (int i = 0; i < numberOfPieces; i++) { if (gamePieces[i].PickUpPiece(x,y)) { pickedUpPieces = i; int idx = p1.positionsOccupied.FindIndex(0, (Vector2 v) => { return v == gamePieces[i].pos; }); p1.positionsOccupied.RemoveAt(idx); break; } } } else { bool placefree = true; for (int i = 0; i < p1.positionsOccupied.Count; i++) { if (p1.positionsOccupied[i] == gamePieces[pickedUpPieces].pos) { placefree = false; } } for (int i = 0; i < p2.positionsOccupied.Count; i++) { if (p2.positionsOccupied[i] == gamePieces[pickedUpPieces].pos) { placefree = false; } } if (placefree) { p1.positionsOccupied.Add(gamePieces[pickedUpPieces].pos); pickedUpPieces = -1; } } }
void CreateGamePieces(Player otherplayer) { gamePieces = new GamePieces[numberOfPieces]; for (int i = 0; i < numberOfPieces; i++) { gamePieces[i] = new GamePieces(GetRandPos(0, 384, 0, 384, otherplayer), 0, 5, pieceSize); } pickedUpPieces = -1; }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); player1Pieces = Content.Load<Texture2D>("chess_white"); player2Pieces = Content.Load<Texture2D>("chess_black"); gridTex = Content.Load<Texture2D>("chess_tiles"); startmenu = Content.Load<Texture2D>("Start"); font = Content.Load<SpriteFont>("SpriteFont1"); //redT = Content.Load<Texture2D>("red"); grid = new Grid(gridTex); IsMouseVisible = true; players = new Player[2]; players[0] = new Player(player1Pieces, null); players[1] = new Player(player2Pieces, players[0]); players[0].SetPiecesVisibilty(true); players[1].SetPiecesVisibilty(true); currentPlayer = 0; }