Hello everyone, I am trying to understand Arrays and how to apply them with programming and code. I have been trying to complete an assignment and I just can't figure out how to do some of the steps. Could you help me?
Here is my assignment:
The Game
The game is played on a 15 by 15 board. Each player takes turns placing their pieces anywhere on the board not already occupied by another piece. A player wins by getting 5 pieces in a row horizontally, vertically, or diagonally. The game is over without a winner if there are no open places to go.
Requirements
You must create a playable version of the game for two human players. The minimal features your game must have are:
Graphical display of the board itself
Graphical display of the pieces on the board using different shapes, colors, or something else for the two players
Indication of whose turn (player 1 or 2) it is
Method for each player to select which position they want to go
Checks to make sure the chosen position is available, with an appropriate error indication
Checks to determine if a player won and indication of that
Checks to determine if the game is over when nobody won (board is full) and indication of that
I would suggest starting with having NumericUpDown or buttons to select row and column. More complex, interesting, and user friendly methods are possible but start with a simple approach.
Bonus
For extra credit you may add extra features to the game or improve the aesthetics of the existing features. Some examples of things you could add are:
Using the mouse to click on the board itself for player to choose their position
Making the board and pieces look particularly good
Ability to play again when the game is complete
Keeping track of wins and losses when playing multiple games
More elaborate graphics for winning
Allow a computer player
Here is what I have so far:
I am stuck on the part where it assigns each player with a certain character (X and O) and how to make them appear on the grid after you click on a square. Could any of you please help me? Any input or tips would be greatly appreciated.
Thanks!
Here is my assignment:
The Game
The game is played on a 15 by 15 board. Each player takes turns placing their pieces anywhere on the board not already occupied by another piece. A player wins by getting 5 pieces in a row horizontally, vertically, or diagonally. The game is over without a winner if there are no open places to go.
Requirements
You must create a playable version of the game for two human players. The minimal features your game must have are:
Graphical display of the board itself
Graphical display of the pieces on the board using different shapes, colors, or something else for the two players
Indication of whose turn (player 1 or 2) it is
Method for each player to select which position they want to go
Checks to make sure the chosen position is available, with an appropriate error indication
Checks to determine if a player won and indication of that
Checks to determine if the game is over when nobody won (board is full) and indication of that
I would suggest starting with having NumericUpDown or buttons to select row and column. More complex, interesting, and user friendly methods are possible but start with a simple approach.
Bonus
For extra credit you may add extra features to the game or improve the aesthetics of the existing features. Some examples of things you could add are:
Using the mouse to click on the board itself for player to choose their position
Making the board and pieces look particularly good
Ability to play again when the game is complete
Keeping track of wins and losses when playing multiple games
More elaborate graphics for winning
Allow a computer player
Here is what I have so far:
Game Code:
Public Class Form1 Dim leftEdge, topEdge, sqSize, gridCount As Integer Dim counter As Integer = 0 Dim grid(14, 14) As Integer Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint For Y As Integer = topEdge To leftEdge + sqSize * gridCount Step sqSize e.Graphics.DrawLine(Pens.Black, leftEdge, Y, leftEdge + sqSize * gridCount, Y) Next For i As Integer = 0 To gridCount e.Graphics.DrawLine(Pens.Black, leftEdge + i * sqSize, topEdge, leftEdge + i * sqSize, topEdge + sqSize * gridCount) Next End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load leftEdge = 20 topEdge = 20 sqSize = 40 gridCount = 15 Label1.Visible = True Label2.Visible = False End Sub Private Sub playersTurncheck() If counter Mod 2 = 0 Then Label1.Visible = True Label2.Visible = False Else Label1.Visible = False Label2.Visible = True End If End Sub Private Sub winnerCheck() End Sub End Class
I am stuck on the part where it assigns each player with a certain character (X and O) and how to make them appear on the grid after you click on a square. Could any of you please help me? Any input or tips would be greatly appreciated.
Thanks!