Matchsticks Project C Programming
Matchsticks Project C Programming
h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
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) {
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;
}