Connect 4 in C++

Topics: Referee, Stanley Rous, Column Pages: 15 (4604 words) Published: March 10, 2011

Module Code…CO1451.

Module Title… Programming in C++
Module Tutor Harvey Long

Assignment Title/Number……No.1…

Student Name……Stephen Allen

Student ID No… All09109979

I confirm that this piece of work which I have submitted is all my own work and that all references and quotations from both primary and secondary sources have been fully identified and properly acknowledged in footnotes and bibliography.

Signature of student.........ste allen..............................................................

The game of connect 4 consists of two players that take alternate turns to drop counters into a grid. There are two styles of counter so that each player has their own. The grid is a 7 by 7 table making a total of 49 elements. The object of the game is for the first player to make a straight line of 4 matching counters in any direction. The game is played by players choosing which column to drop their counter and that counter falling to the lowest empty row in that column. As more turns are taken, more opportunities arise where lines of 4 matching counters can be achieved in horizontal, vertical and diagonal directions. The game goes on with each player attempting to match a line of 4 of their own counters whilst simultaneously sabotaging any matching lines of their opponent. If no matches are found throughout the game then the game ends after 49 turns have been taken and all the elements are filled. Design

Upon running the desired program the users would be presented with a menu offering 3 options. These options can translate into a switch:case:break function within the program and the typical menu will be:- Case1: (option 1) Play Connect 4

Case2 : (option 2) View League Table
Case3 : (option 3) Quit
Key in option number and press enter!
Upon choosing case1 users will be asked to key in player1 and player2 names. A grid with seven rows and seven columns will be displayed. The squares in the grid will all start off empty. Underneath the grid the instruction for whose turn it is will ask that player to choose a column to place their counter in. They will also be reminded of what symbol is their counter. A tally will be defined as equal to zero before each set of four squares are checked. The players will place alternate counters into the grid and after 7 counters have been placed the computer will start to check the whole grid for a matching line of 4 similar counters in horizontal, vertical and diagonal directions, after each subsequent turn. The computer makes the checks by comparing adjacent squares and increasing the tally by 1 each time they match. For the horizontal check the first 4 adjacent squares will be compared and the x co-ordinate will increase by 1 each time the check has been made. This only needs to be done for the first three x co-ordinates of each row as after the forth x co-ordinate there are not enough squares to make a 4 counter match. The vertical check will increase the y co-ordinate by 1 after each check and do so for the first three squares of each column. The diagonal checks will have combinations of increase/decrease x & y co-ordinates after each check. When the grid is full of counters and 49 turns have been taken and no lines of 4 matching counters have been found the computer will display “DRAW” and the case will break back to the options menu. The leaderboard score table will be automatically updated after each game ends. This will be done by use of the fstream command and opening a pre-saved text file which can be edited to record players/games played/games won If case2 is chosen then the text file will be opened in a read only fashion and displayed for the users The program will be exited if case3 is chosen.

The main concern in designing this program is creating a gameplay area and defining each square so that it can be assigned values that are...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Cases Study 4 C Essay
  • Will C Essay
  • C Essay
  • truman 1984 c&c Essay
  • 4 Essay
  • 4 Essay
  • Francis C ArnaisLot 3 Blk 4 Essay
  • Chapter 4 6 Comprehension Questions C Essay

Become a StudyMode Member

Sign Up - It's Free