![]() |
4-gewinnt
1.0.0
Klassiker "4-gewinnt" als Konsolenanwendung
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
gehe zum Quellcode dieser Datei
Funktionen | |
void | gameFunction () |
void | clearAll () |
void | playerAction () |
void | throwCoin (int pos, char player) |
void | drawCoin (int pos, char CoinType) |
void | startGame () |
char | checkForWinner (int x, int y, char player) |
int | neighbourRow (int x, int y, int xMovement, int yMovement, char player) |
int | checkDraw () |
int | irand (int a, int e) |
void | animateFalling (struct board *currBoard, unsigned int xPos, char CoinType) |
Variablen | |
char | player1 [20] |
char | player2 [20] |
struct board | gameField |
int | gameFieldWidth = 7 |
int | gameFieldHeigth = 6 |
int | gameFieldCreated = 0 |
int | coinPosition = 1 |
int | playersTurn |
char | playersCoin |
char | victor |
int | moves |
int | end = 0 |
void animateFalling | ( | struct board * | currBoard, |
unsigned int | xPos, | ||
char | CoinType | ||
) |
this Method animates a falling Coin by moving the coin one field lower than wait and repeat this until there's another coin or it reaches the end of the board This Method fully cleans the board up after finishing–>means: after execution the board will look like nothing ever happened. The animated coin is not saved permanetly saved on the board
xPos | the row in which the coin is going to fall |
currBoard | the board with the current game state |
CoinType | variable to determine if the current Player has 'X' or '0' as Coin |
final clean up deleting the last coin if this last part of the code will be deleted the last position of the coin will be permantely saved on the supplied board
Definiert in Zeile 446 der Datei gamefunction.c.
Benutzt calcFieldAddress(), drawBoard(), FIELD_EMPTY, FIELD_PLAYER1 und board::height.
int checkDraw | ( | ) |
Checks if the board is full. Only possible if nobody has won earlier.
Definiert in Zeile 419 der Datei gamefunction.c.
Benutzt FIELD_EMPTY, gameField, gameFieldHeigth, gameFieldWidth und getField().
Wird benutzt von gameFunction().
char checkForWinner | ( | int | x, |
int | y, | ||
char | player | ||
) |
Look for a winner of the current game. First vertically, then horizontally and then the 2 diagonal rows. lineCount is the number of Coins which are neighbours.
x | X-Position of last dropped coin. |
y | Y-Position of last dropped coin. |
player | The last coin which was dropped to the game, as the starting point of this algorithm. |
Definiert in Zeile 356 der Datei gamefunction.c.
Benutzt FIELD_EMPTY und neighbourRow().
Wird benutzt von throwCoin().
void clearAll | ( | ) |
Clears all elements which are used within the gameflow Board, loop condition, positions
Definiert in Zeile 171 der Datei gamefunction.c.
Benutzt clearBoard(), coinPosition, end, freeBoard(), gameField, gameFieldCreated, playersTurn und victor.
Wird benutzt von gameFunction().
void drawCoin | ( | int | pos, |
char | CoinType | ||
) |
Draws the Coin above the board
pos | which position should the coin be drawn to. |
coinType | which coin should be drawn. |
Definiert in Zeile 291 der Datei gamefunction.c.
Benutzt EXITCODE_OUTOFMEMORY, FIELD_PLAYER1, FONT_COIN_PLAYER1, FONT_COIN_PLAYER2, gameFieldWidth und output().
Wird benutzt von playerAction().
void gameFunction | ( | ) |
gameFunction first forces users to enter their names and checks them for different mistakes after that startGame() is called within the gameloop, which processes the main game flow last but not least we check for a winner or check for draw and continue to Hall of Shame.
Definiert in Zeile 28 der Datei gamefunction.c.
Benutzt checkDraw(), clearAll(), consoleClear(), drawBoard(), end, FIELD_PLAYER1, FIELD_PLAYER2, flushBuffer(), gameField, irand(), lower_to_upper(), moves, NO_HIGHLIGHT, output(), player1, player2, playersTurn, showHallOfShame(), startBuffer(), startGame(), updateSaveHoS() und victor.
Wird benutzt von mainMenuReactToEnter().
int irand | ( | int | a, |
int | e | ||
) |
Get random integer a<=x<=e
a | Lowest value for x. |
e | Highest value for x. |
Definiert in Zeile 433 der Datei gamefunction.c.
Wird benutzt von gameFunction().
int neighbourRow | ( | int | x, |
int | y, | ||
int | xMovement, | ||
int | yMovement, | ||
char | player | ||
) |
Recursive function to sum up the coins which are connected in a row.
x | X-Position of last dropped coin. |
y | Y-Position of last dropped coin. |
xMovement | This is used to build a "vector" |
yMovement | This is used to build a "vector" |
player | The cointype to count in a row. |
Definiert in Zeile 406 der Datei gamefunction.c.
Benutzt gameField, getField() und neighbourRow().
Wird benutzt von checkForWinner() und neighbourRow().
void playerAction | ( | ) |
Definiert in Zeile 194 der Datei gamefunction.c.
Benutzt coinPosition, drawBoard(), drawCoin(), end, EXITCODE_OUTOFMEMORY, FIELD_PLAYER1, FIELD_PLAYER2, flushBuffer(), gameField, gameFieldWidth, moves, output(), player1, player2, playersCoin, playersTurn, setLineAlign(), startBuffer(), throwCoin() und userInput.
Wird benutzt von startGame().
void startGame | ( | ) |
Function will create a new Board, clears it and calls playerAction()
Definiert in Zeile 333 der Datei gamefunction.c.
Benutzt gameField, gameFieldCreated, gameFieldHeigth, gameFieldWidth, newBoard() und playerAction().
Wird benutzt von gameFunction().
void throwCoin | ( | int | pos, |
char | player | ||
) |
Checks if a row is full, otherwise throw coin
pos | position of where coin should be placed (board begins at 0 and coinpos at 1!) |
player | Char which contains X oder O according to the player |
Definiert in Zeile 252 der Datei gamefunction.c.
Benutzt checkForWinner(), FIELD_EMPTY, FIELD_PLAYER1, FIELD_PLAYER2, gameField, gameFieldHeigth, getField(), playersTurn, setField() und victor.
Wird benutzt von playerAction().
int coinPosition = 1 |
Definiert in Zeile 15 der Datei gamefunction.c.
Wird benutzt von clearAll() und playerAction().
int end = 0 |
Definiert in Zeile 20 der Datei gamefunction.c.
Wird benutzt von clearAll(), gameFunction() und playerAction().
struct board gameField |
Definiert in Zeile 11 der Datei gamefunction.c.
Wird benutzt von checkDraw(), clearAll(), gameFunction(), neighbourRow(), playerAction(), startGame() und throwCoin().
int gameFieldCreated = 0 |
Definiert in Zeile 14 der Datei gamefunction.c.
Wird benutzt von clearAll() und startGame().
int gameFieldHeigth = 6 |
Definiert in Zeile 13 der Datei gamefunction.c.
Wird benutzt von checkDraw(), startGame() und throwCoin().
int gameFieldWidth = 7 |
Definiert in Zeile 12 der Datei gamefunction.c.
Wird benutzt von checkDraw(), drawCoin(), playerAction() und startGame().
int moves |
Definiert in Zeile 19 der Datei gamefunction.c.
Wird benutzt von extractMoves(), gameFunction(), playerAction() und showHallOfShame().
char player1[20] |
Definiert in Zeile 8 der Datei gamefunction.c.
Wird benutzt von gameFunction() und playerAction().
char player2[20] |
Definiert in Zeile 9 der Datei gamefunction.c.
Wird benutzt von gameFunction() und playerAction().
char playersCoin |
Definiert in Zeile 17 der Datei gamefunction.c.
Wird benutzt von playerAction().
int playersTurn |
Definiert in Zeile 16 der Datei gamefunction.c.
Wird benutzt von clearAll(), gameFunction(), playerAction() und throwCoin().
char victor |
Definiert in Zeile 18 der Datei gamefunction.c.
Wird benutzt von clearAll(), gameFunction(), showHallOfShame() und throwCoin().