<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Snake Spielfeld größenunabhängig drucken]]></title><description><![CDATA[<p>Guten Tag,</p>
<p>ich versuche mich nach längerer Pause momentan an einem Snake Spiel in der Konsole.<br />
Mein bisheriger Code sieht so aus (Ist im Moment noch viel unnötiges drin für Funktionen die ich erst noch schreiben will:</p>
<p>Zum Problem :</p>
<p>Mein Problem ist ,dass die Funktion InitField noch nicht so funktioniert wie gewollt.<br />
Ich hätte gerne,dass ich die Spielfeldgröße jederzeit ändern kann und diese Funktion immer den Spielfeldrand initialisiert.<br />
Allerdings ist der rechte Spielfeld Rand immer um 1 Feld des Arrays zu weit links und der unterste Rechte Rand (|) fehlt einfach.<br />
Ich finde einfach nicht heraus, was ich falsch gemacht habe.<br />
Hat jemand eine Idee, was falsch sein könnte, oder wie ich das ganze anders lösen könnte?</p>
<pre><code>#include &lt;math.h&gt;
#include &lt;iostream&gt;
#include &quot;Windows.h&quot;
using namespace std;
void InitField(char * Field, const short field_size, short wight){

	short row = 0;
	short next_row = 9;
	for (int i = 0; i &lt;= (field_size - 1); i++){
		if (i &lt;= wight || i + wight &gt;= (field_size-1) )
			Field[i] = '-';

		else if ( row == (next_row + 1) || row == (next_row + wight ))
			Field[i] = '|';
		else
			Field[i] = ' ';

		if (next_row + wight == row)
			next_row += wight;
		row++;
	}

}
void PrintField(char * field, const short field_size, short wight) {
	short row = 0;
	short next_row = 0;
	for (int i = 0; i &lt;= (field_size - 1); i++){
		if (next_row + wight + 1 == row){
			cout &lt;&lt; &quot;\n&quot;;
			next_row += wight;
		}
		cout &lt;&lt; field[i];
		row++;
	}

}
string KeyPressed(){
	string ret;
	if (GetKeyState(VK_UP))
		return ret = &quot;UP&quot;;
	else if (GetKeyState(VK_DOWN))
		return ret = &quot;DOWN&quot;;
	else if (GetKeyState(VK_LEFT))
		return ret = &quot;LEFT&quot;;
	else if (GetKeyState(VK_RIGHT))
		return ret = &quot;RIGHT&quot;;

}
bool CheckLoose(char *field, short snake_pos){
	if (field[snake_pos] == '-' || field[snake_pos] == '|' || field[snake_pos] == 'o')
		return true;
	else
		return false;
}

void CreateFruit(){
	//random frucht auf Spielfelder 1-8 in jeder zeile
}

void EatenFruit() {

}
void NewPos(short field_size, short hight, short * snake_pos) {
	if (KeyPressed() == &quot;UP&quot;)
		snake_pos -= hight;
	else if (KeyPressed() == &quot;DOWN&quot;)
		snake_pos += hight;
	else if (KeyPressed() == &quot;LEFT&quot;)
		snake_pos -= 1;
	else if (KeyPressed() == &quot;RIGHT&quot;)
		snake_pos += 1;
}

bool snake[50];
int main() {
	HANDLE outcon = GetStdHandle(STD_OUTPUT_HANDLE);

	CONSOLE_FONT_INFOEX font;
	font.cbSize = sizeof(CONSOLE_FONT_INFOEX);
	GetCurrentConsoleFontEx(outcon, false, &amp;font);
	font.dwFontSize.X = 80;
	font.dwFontSize.Y = 80;
	SetCurrentConsoleFontEx(outcon, false, &amp;font);
	short snake_pos = 0;
	short snake_end = 0;
	const short tfield_size = 100;
	//short thight = (short)(sqrt(field_size) -1);
	//short twight = hight;
	short thight = 9;
	short twight = 9;
	char tfield[tfield_size];
	InitField(tfield, tfield_size,twight);
	PrintField(tfield, tfield_size, twight);
	std::cin.get();
	//string current_direction = KeyPressed();

	//string last_direction = current_direction;  //Muss immer die Richtung der Schlange vom letzten Spielzug zeigen,falls der Spieler mal keine Taste drückt

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/334014/snake-spielfeld-größenunabhängig-drucken</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Apr 2026 02:37:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/334014.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 16 Aug 2015 15:47:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Snake Spielfeld größenunabhängig drucken on Sun, 16 Aug 2015 16:31:15 GMT]]></title><description><![CDATA[<p>Guten Tag,</p>
<p>ich versuche mich nach längerer Pause momentan an einem Snake Spiel in der Konsole.<br />
Mein bisheriger Code sieht so aus (Ist im Moment noch viel unnötiges drin für Funktionen die ich erst noch schreiben will:</p>
<p>Zum Problem :</p>
<p>Mein Problem ist ,dass die Funktion InitField noch nicht so funktioniert wie gewollt.<br />
Ich hätte gerne,dass ich die Spielfeldgröße jederzeit ändern kann und diese Funktion immer den Spielfeldrand initialisiert.<br />
Allerdings ist der rechte Spielfeld Rand immer um 1 Feld des Arrays zu weit links und der unterste Rechte Rand (|) fehlt einfach.<br />
Ich finde einfach nicht heraus, was ich falsch gemacht habe.<br />
Hat jemand eine Idee, was falsch sein könnte, oder wie ich das ganze anders lösen könnte?</p>
<pre><code>#include &lt;math.h&gt;
#include &lt;iostream&gt;
#include &quot;Windows.h&quot;
using namespace std;
void InitField(char * Field, const short field_size, short wight){

	short row = 0;
	short next_row = 9;
	for (int i = 0; i &lt;= (field_size - 1); i++){
		if (i &lt;= wight || i + wight &gt;= (field_size-1) )
			Field[i] = '-';

		else if ( row == (next_row + 1) || row == (next_row + wight ))
			Field[i] = '|';
		else
			Field[i] = ' ';

		if (next_row + wight == row)
			next_row += wight;
		row++;
	}

}
void PrintField(char * field, const short field_size, short wight) {
	short row = 0;
	short next_row = 0;
	for (int i = 0; i &lt;= (field_size - 1); i++){
		if (next_row + wight + 1 == row){
			cout &lt;&lt; &quot;\n&quot;;
			next_row += wight;
		}
		cout &lt;&lt; field[i];
		row++;
	}

}
string KeyPressed(){
	string ret;
	if (GetKeyState(VK_UP))
		return ret = &quot;UP&quot;;
	else if (GetKeyState(VK_DOWN))
		return ret = &quot;DOWN&quot;;
	else if (GetKeyState(VK_LEFT))
		return ret = &quot;LEFT&quot;;
	else if (GetKeyState(VK_RIGHT))
		return ret = &quot;RIGHT&quot;;

}
bool CheckLoose(char *field, short snake_pos){
	if (field[snake_pos] == '-' || field[snake_pos] == '|' || field[snake_pos] == 'o')
		return true;
	else
		return false;
}

void CreateFruit(){
	//random frucht auf Spielfelder 1-8 in jeder zeile
}

void EatenFruit() {

}
void NewPos(short field_size, short hight, short * snake_pos) {
	if (KeyPressed() == &quot;UP&quot;)
		snake_pos -= hight;
	else if (KeyPressed() == &quot;DOWN&quot;)
		snake_pos += hight;
	else if (KeyPressed() == &quot;LEFT&quot;)
		snake_pos -= 1;
	else if (KeyPressed() == &quot;RIGHT&quot;)
		snake_pos += 1;
}

bool snake[50];
int main() {
	HANDLE outcon = GetStdHandle(STD_OUTPUT_HANDLE);

	CONSOLE_FONT_INFOEX font;
	font.cbSize = sizeof(CONSOLE_FONT_INFOEX);
	GetCurrentConsoleFontEx(outcon, false, &amp;font);
	font.dwFontSize.X = 80;
	font.dwFontSize.Y = 80;
	SetCurrentConsoleFontEx(outcon, false, &amp;font);
	short snake_pos = 0;
	short snake_end = 0;
	const short tfield_size = 100;
	//short thight = (short)(sqrt(field_size) -1);
	//short twight = hight;
	short thight = 9;
	short twight = 9;
	char tfield[tfield_size];
	InitField(tfield, tfield_size,twight);
	PrintField(tfield, tfield_size, twight);
	std::cin.get();
	//string current_direction = KeyPressed();

	//string last_direction = current_direction;  //Muss immer die Richtung der Schlange vom letzten Spielzug zeigen,falls der Spieler mal keine Taste drückt

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2464107</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2464107</guid><dc:creator><![CDATA[GreeN19]]></dc:creator><pubDate>Sun, 16 Aug 2015 16:31:15 GMT</pubDate></item><item><title><![CDATA[Reply to Snake Spielfeld größenunabhängig drucken on Sun, 16 Aug 2015 19:00:31 GMT]]></title><description><![CDATA[<p>Wie waere es, wenn du die dein Array fuer einen simplen Fall (z.b. 4x5) auf Papier notierst und dann einen Debugger benutzt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2464148</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2464148</guid><dc:creator><![CDATA[TGGC]]></dc:creator><pubDate>Sun, 16 Aug 2015 19:00:31 GMT</pubDate></item></channel></rss>