-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ArkadySK/board_display
Board display
- Loading branch information
Showing
5 changed files
with
117 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.vscode/ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "board.h" | ||
|
||
void board_init(board* b, int size) | ||
{ | ||
b->board_ = malloc(size * sizeof(char*)); | ||
for (int i = 0; i < size; i++) | ||
{ | ||
b->board_[i] = calloc(size, sizeof(char)); | ||
for (int j = 0; j < size; j++) | ||
{ | ||
b->board_[i][j] = NOT_HIT; | ||
} | ||
} | ||
|
||
b->size_ = size; | ||
b->destroyed_ = 0; | ||
} | ||
|
||
void board_destroy(board* b) | ||
{ | ||
for (int i = 0; i < b->size_; i++) | ||
{ | ||
free(b->board_[i]); | ||
} | ||
free(b->board_); | ||
} | ||
|
||
void board_display(board* b_own, board* b_enemy) | ||
{ | ||
printf(" Your board | Enemy board\n"); | ||
printf(" A B C D E F G H I J | A B C D E F G H I J\n"); | ||
for (int i = 0; i < b_own->size_; i++) | ||
{ | ||
printf("%2d ", i + 1); | ||
for (int j = 0; j < b_own->size_; j++) | ||
{ | ||
printf("%c ", b_own->board_[i][j]); | ||
} | ||
printf("|%2d ", i + 1); | ||
for (int j = 0; j < b_enemy->size_; j++) | ||
{ | ||
if (b_enemy->board_[i][j] = SHIP) | ||
{ | ||
printf("%c ", NOT_HIT); | ||
} | ||
else | ||
{ | ||
printf("%c ", b_enemy->board_[i][j]); | ||
} | ||
} | ||
printf("\n"); | ||
} | ||
} | ||
|
||
void place_ships(board* b) | ||
{ | ||
printf("Ship coordinates are given as: \"2Ad\" "); | ||
printf("where 2A are the coordinates of the ship, "); | ||
printf("and the last letter is either \"d\" or \"r\" for down or right\n"); | ||
printf("Where do you want to place the 5 tile ship?"); | ||
// TODO: Waffle | ||
} | ||
|
||
int shoot(board* b, int x, int y) | ||
{ | ||
// TODO: Waffle | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
#include <stdlib.h> | ||
|
||
#define NOT_HIT '.' | ||
#define HIT_WATER 'o' | ||
#define HIT_SHIP 'X' | ||
#define SHIP '#' | ||
|
||
typedef struct board board; | ||
|
||
struct board { | ||
char** board_; | ||
int size_; | ||
int destroyed_; | ||
}; | ||
|
||
void board_init(board* b, int size); | ||
|
||
void board_destroy(board* b); | ||
|
||
void place_ships(board* b); | ||
|
||
void board_display(board* b_own, board* b_enemy); | ||
|
||
int shoot(board* b, int x, int y); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "board.h" | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
board b_own; | ||
board_init(&b_own, 10); | ||
board b_enemy; | ||
board_init(&b_enemy, 10); | ||
board_display(&b_own, &b_enemy); | ||
board_destroy(&b_own); | ||
board_destroy(&b_enemy); | ||
return 0; | ||
} |