From 0a66dce53bead8d3d3f20156ef17579621a3af0d Mon Sep 17 00:00:00 2001 From: Daniel M Date: Thu, 8 Feb 2024 12:15:51 +0100 Subject: [PATCH] =?UTF-8?q?refactoring=20:=20Zeillen=20abstandverbessert?= =?UTF-8?q?=20um=20Code=20=C3=BCbersichtlicher=20zumachen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../out/c/duellist-spielesammlung-projekt.o | Bin 13912 -> 13908 bytes .../test_duellist_spielesammlung_projekt.out | Bin 102734 -> 102734 bytes .../test_duellist_spielesammlung_projekt.pass | 2 +- src/main/duellist-spielesammlung-projekt.c | 11 ++++------- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/build/test/out/c/duellist-spielesammlung-projekt.o b/build/test/out/c/duellist-spielesammlung-projekt.o index c4f8ca157d31be18a2193977aae32e3aa6ada235..ba37b1f72e617bda3092fa706a2069a2a7983c5d 100644 GIT binary patch delta 433 zcmcbSb0vqb=K+X3=GdU?`7;2XSAK{Eh$-V$M_Fu3e&^{K~^Bm2;;^G73G&BxDi6h z`8lPzc?gjZK^c&G52*GWL6CD8eHpJaf=tU0R0DDSpxhJ&;k2UE)cD-YywtSJ)SMIs zMq|bnJ_ZI)9gwm)M}Y1X0UKZp)xjVl3X(B~8qXq>$-rnbnO{mYNewK-1Jqmr)@u!P zH$<-*Trb#i7?%ZN6ht4>L=F+KM`2tZkjd&$Yf6N&fSk>3Qa9NdpDa#LVrKN-oTzHZ z$RZMHkTH3hnhImriD={!UnC!}^%;-5e zlTn?qbn-+-b=H~c3=FR}?`7;2XLOwGEh$;=#P|aVhL6CD8{TZ(_f=tU0R0DAXpxhJ&;k2UE)cD-YywtSJ)SMIs zMsvm%J_ZI)9gwm)M}Y1X0UKZr)xjVl3X(C08qXq>$-rnanO{mYNdqjz1Jqmr)@u!P zH$<-nTrb#i7?%ZN6ht4>L=F+KM`2tZkja`*Yf6N&fSk>3Qa9NdpDj*MVrKN&oTzHZ z$RZkPkU4ppnhG;BXVc`}YVwTwlW(g@@)>aK2EymNIj-+sIC1i1CUrg5NRB3E?#-s^ TpP4qRX-RN0zS?YWEXoW3dgxyC diff --git a/build/test/out/test_duellist_spielesammlung_projekt.out b/build/test/out/test_duellist_spielesammlung_projekt.out index 931e9533b13fed55867dd3ccbd4ae50de5e97395..5169aa3c025e69a26e96cd5219c936f28fa1122a 100644 GIT binary patch delta 478 zcmX@Ni0#}Wwh0|f%eGJK@?%mE*?23CiSf*4OXhPg>TMbSF)%RjMmR8BVParloKw!i zz#w=MD8y(7mSLKhAh;8m8zWSdUyhKC5K7L^Db3A8h=d4U0IBzYYR?he590bVUT0)r zV49dAcnie!gK{Ugy%DZAW;_z^z~BiIpK}CgzX(`|F;oeI2-rEsQ1e)XG8q_6V1_e@ zrsk!@CugK4XEQLWfkl0QW>tXAvSx*ur3N<(Y&(q00ybJ3s*!0ThX~lK5ObI&@_?*T zhgwx4lm+B$c7E%~#^fn5dFKh!&AUI>a4@oLw)oS;$XL30_upm4j8B#)88R|6dT&oQ zVKii95s5U&m_EalQH8N<`hHVJc}9cj_e~ik`3yOBbL`=GzMJFv?gbMkO=mM>)MJh2 zXkzBvZfVANoO$~{OGX<}rWY*JA2>3KY!C2f>|tW`+D&%P>t$5ZsB(jS(u!FGt8m2qov|l;-9kL_!2FfYf_KwdV-#2XXxwuQM_* zFip%5yanP0K)I9K-U!#5Gad$qh&fCXc|cZa zLaizh$^vpWJHK^gWAYZ5yz_+V=G~ubI2hSBTl{HaWGvsj`|mPij%PsUGcn9ym>y`x zD7?MKkntH4qtEta6GlTu7STw9%;_^s8C95>Ih&^MHD#1%)SrIWlu?q;fMYihKHtr8 zefPqNlc%$oG3v2Kax^h>Z#Oq%JkGq$iqT4x=@rZL2ab#)+XMU=dzcu#x8Dt9tY=|l S+a4Rnco}H_cEbopSxW$k(|u|H diff --git a/build/test/results/test_duellist_spielesammlung_projekt.pass b/build/test/results/test_duellist_spielesammlung_projekt.pass index 03dadd2..c0b331f 100644 --- a/build/test/results/test_duellist_spielesammlung_projekt.pass +++ b/build/test/results/test_duellist_spielesammlung_projekt.pass @@ -115,4 +115,4 @@ :failed: 0 :ignored: 0 :stdout: [] -:time: 0.0499390999998468 +:time: 0.05679710000003979 diff --git a/src/main/duellist-spielesammlung-projekt.c b/src/main/duellist-spielesammlung-projekt.c index d0a7c8b..df02795 100644 --- a/src/main/duellist-spielesammlung-projekt.c +++ b/src/main/duellist-spielesammlung-projekt.c @@ -216,7 +216,6 @@ void show_minefield(char** minefield, int height, int width) { int field_check(char** minefield, char** mines, int height, int width, int row, int column) { char counter = 0; - if ((row < 0) || (row >= height) || (column < 0) || (column >= width)) { printf("Exception: Outside the minefield!\n"); return -1; @@ -289,13 +288,11 @@ int field_check(char** minefield, char** mines, int height, int width, int row, if ((row - 1 >= 0) && (column - 1 >= 0) && (minefield[row - 1][column - 1] == unknown_character) && (mines[row - 1][column - 1] == 0)) { field_check(minefield, mines, height, width, row - 1, column - 1); } - return 1; } int end_check(char** minefield, char** mines, int height, int width) { int i, j; - for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { // If a field is not uncovered and does not contain a mine, the game is not over @@ -304,7 +301,6 @@ int end_check(char** minefield, char** mines, int height, int width) { } } } - return 1; } @@ -324,6 +320,7 @@ int minesweeper() { scanf("%d", &height); printf("Enter the width of the game field:\n"); scanf("%d", &width); + if (height <= 0 || width <= 0 || height > max_height || width > max_width) { printf("Invalid field dimensions.\n"); return 1; @@ -331,21 +328,21 @@ int minesweeper() { int num_mines = calculate_mines(height, width); printf("The game field is >%d< in height and >%d< in width.\n", height, width); printf("There are %d mines on the game field.\n", num_mines); + // Matrix for the game field char** minefield = create_minefield(height, width, unknown_character); char** mines = create_minefield(height, width, 0); + distribute_mines(mines, height, width, num_mines); - while (1) { + while (1) { printf("Enter 'row column' to uncover (to quit enter '0 0'):\n"); if (scanf("%d %d", &row, &column) != 2) { printf("Incorrect input!\n"); return 1; } - row--; column--; - // Quit if ((row == -1) && (column == -1)) { break;