Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42225

VS 2010 Please Help! Noob needs help with Arrays and coding

$
0
0
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:

Game Code:
  1. Public Class Form1
  2.     Dim leftEdge, topEdge, sqSize, gridCount As Integer
  3.     Dim counter As Integer = 0
  4.     Dim grid(14, 14) As Integer
  5.  
  6.     Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
  7.         For Y As Integer = topEdge To leftEdge + sqSize * gridCount Step sqSize
  8.             e.Graphics.DrawLine(Pens.Black, leftEdge, Y, leftEdge + sqSize * gridCount, Y)
  9.         Next
  10.         For i As Integer = 0 To gridCount
  11.             e.Graphics.DrawLine(Pens.Black, leftEdge + i * sqSize, topEdge, leftEdge + i * sqSize, topEdge + sqSize * gridCount)
  12.         Next
  13.     End Sub
  14.  
  15. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  16.         leftEdge = 20
  17.         topEdge = 20
  18.         sqSize = 40
  19.         gridCount = 15
  20.  
  21.         Label1.Visible = True
  22.         Label2.Visible = False
  23.     End Sub
  24.  
  25.     Private Sub playersTurncheck()
  26.         If counter Mod 2 = 0 Then
  27.             Label1.Visible = True
  28.             Label2.Visible = False
  29.         Else
  30.             Label1.Visible = False
  31.             Label2.Visible = True
  32.         End If
  33.     End Sub
  34.  
  35.     Private Sub winnerCheck()
  36.  
  37.     End Sub
  38. 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!

Viewing all articles
Browse latest Browse all 42225

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>