Giter Club home page Giter Club logo

noughts_and_crosses's Introduction

C++ London University Session 6 Group Exercise

Noughts and Crosses

Your task for this evening is to write a console-based, two player noughts-and-crosses (AKA tic-tac-toe) game.

Requirements

The game should proceed as follows:

  1. Ask player 1 for their name, followed by player 2. These names should then be used to address the players for the remainder of the game.

  2. Ask player 1 to choose a token (nought or cross). Player 2 will use the opposite token.

  3. Ask player 1 to choose a cell. How you read the input is up to you. Redraw the board with player 1's token drawn in the appropriate cell.

  4. Ask player 2 to choose a cell. If this cell is already taken, inform the player and ask them to choose again. Redraw the board showing all the tokens placed so far.

  5. Repeat steps 3 and 4 until a player has won, or the game as ended in a draw. If there is a winner, that player has 2 points added to their total score, and the other player receives 0 points. If the game is a draw, both players receive 1 point.

  6. Print the current total scores for both players.

  7. Ask whether the players wish to play another game, or quit. If they wish to play again, restart the game, but alternate the starting player. For example, if player 1 started the last game then player 2 starts this game, and vice versa.

  8. If the players choose not to start a new game, announce the overall winner (if any).

Getting started

The file tictactoe.hpp contains the interface for a simple library to help you build the game. It consists of a board class, an enumeration entry representing the state of each cell of the grid (empty, nought or cross), and an output steaming function to print the grid.

The file game.cpp contains an empty main() routine for you to fill in with your game code

Also declared in tictactoe.hpp are two helper functions check_winner() and check_draw(), which can be used to check whether a player has won, or if the game has ended in a draw respectively. However, these are NOT IMPLEMENTED correctly: if you want to use them in your game, you will need to provide a correct implementation in tictactoe.cpp.

You are free to change or add to any of the given files in any way you like, or add new files to the project. The provided functions are merely intended to help you get started -- you are not required to use them.

Hints

  • Before writing any code, think about how to break down the game into individual functions, like check_winner() and check_draw(). Perhaps have one or two team members work on (and test) each function before bringing them together.

  • Concentrate on implementing the main game logic first. Add score tracking, multiple games etc later if you have time.

Have fun!

noughts_and_crosses's People

Contributors

tcbrindle avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.