0% found this document useful (0 votes)
32 views3 pages

Matchsticks Project C Programming

The document describes the rules of a matchstick game between two players or against the computer. It contains the C++ code to implement the various features of the game.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views3 pages

Matchsticks Project C Programming

The document describes the rules of a matchstick game between two players or against the computer. It contains the C++ code to implement the various features of the game.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <stdio.

h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>

static int NUMBER_MATCHSTICKS = 30;

void emptyBuffer()
{
int c = 0;
while (c != '\n' && c != EOF) // As long as the char is not EndOfFile or \n,
we retrieve it in a temporary variable destined to disappear
c = getchar();
}

void JvsJ() {
int matches = NBR_MATCHES, matchesRemoved;
bool player = true;
while(matches > 0) {

for(int i = 0; i < matches; i++){


|
}
It's player 1's turn to play It's player 2's turn
to play
There are %d matches left, how many matches
do you want to take?", matches) : printf("\nThere are %d matches left, how many
How many matches do you want to take?
scanf("%d", &matchesRemoved);
emptyBuffer();
while(allumettesRetire > 3 || allumettesRetire < 1) {
Your choice is not correct, please choose a number
between 1 and 3
scanf("%d", &matchesRemoved);
emptyBuffer();
}
matches -= removedMatches;
player=!player;
}
Congratulations Player 1!
Player 2!
}

void printRules(){
The goal of the game is simple:
printf("This game is played by two. You have a number n of matches.\n");
In turn, each of the two players removes between 1 and 3 matches.
according to what he wishes. The loser is the one who has to remove the last one.
matchstick.
printf("Attention, there are 2 levels of difficulty in human vs
computer.
The first one is rather easy to beat, so it's for beginners. But the
last.....

void printCredit(){
This program was created by Paul Marande and Nicolas Shultz
}
void printHeader() {
************************
* MATCHSTICK GAME *
************************
}

void difficulty() {
int choice=0;
In order to start, we invite you to choose whether you want to play
against a player or a computer.
1 - Another player 2 - A slightly dumb AI 3 - A more difficult AI
to beat 4 - Exit
Your choice:
scanf("%d", &choice);
emptyBuffer();
while(choice<1&&choice>4){
It seems that you did not enter a valid value
What to do ?
1 - Another player 2 - A somewhat dumb AI 3 - A more
difficult to beat 4 - Exit
Your choice:
scanf("%d", &choice);
emptyBuffer();
}
switch (choice)
{
case 1:
JvsJ();
break;
case 2:
IA NULL
break;
case 3:
STRONG AI
break;
case 4:
return;
break;
default:
break;
}
choice=0;
}

void main() {
int choice;
int end=1;
while(end){
printHeader();
Hello and welcome to the game of matches
What to do?
1 - Play 2 - See the game rules 3 - See the credits 4 -
Quitter
Your choice:
scanf("%d", &choice);
emptyBuffer();
while(choice<1&&choice>4){
It seems that you did not enter a value
valid
What to do ?
1 - Play 2 - View the rules of the game 3 - View the credits 4
- Quitter
Your choice:
scanf("%d", &choice);
emptyBuffer();
}
switch (choice)
{
case 1:
difficulty();
break;
case 2:
printRules();
break;
case 3:
printCredit();
break;
case 4:
end=0;
break;
default
break;
}
choice=0;
}

You might also like