Jeg fik det til at spille:
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <list>
#include <time.h>
#include <string>
#include <fstream>
#include <vector>
#include <iostream>
#include <conio.h>
using namespace std;
void gotoxy (int x, int y)
{
COORD cur = {x,y}; // cur er en koordinat
SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), cur); // sætter cursor efter valg
}
int fullscreen ()
{
#define CONSOLE_FULLSCREEN_MODE 1
typedef BOOL (*F)(HANDLE hConsoleOutput,DWORD dwFlags,COORD *lpNewScreenBufferDimensions);
HINSTANCE dll;
F SetConsoleDisplayMode;
HANDLE h;
COORD size = { 80, 25 };
h = GetStdHandle(STD_OUTPUT_HANDLE);
dll = LoadLibrary("kernel32.dll");
SetConsoleDisplayMode = (F)GetProcAddress(dll,"SetConsoleDisplayMode");
SetConsoleDisplayMode(h,CONSOLE_FULLSCREEN_MODE,&size);
return 0;
}
int main()
{
int box_tilstand [100];
int box_x[100];
int box_y[100];
int box_nr = 0;
int bil_x = 23; // bilens startpunkt ved x
int bil_y = 48; // bilens startpunkt ved y
int n1 = 0;
int valg = 0;
int point = 0;
int liv = 0;
fullscreen() ;
for(n1=0; n1 < 100; n1++) // BKB, der er kun 100 box'er 0..99
{ // resetning af variabler
box_tilstand[n1] = 0;
box_x[n1] = 0;
box_y[n1] = 0;
}
while (1==1) // kører så længe 1 lig 1
{
Sleep(100);
system ("CLS");
//--------------vis grafik--------------
for (n1 = 0; n1 < 100; n1++) // BKB, der er kun 100 box'er 0..99
{
if (box_tilstand[n1]== 1)
{
gotoxy (box_x [n1], box_y[n1]);
cout << " ";
//----------Boxe rykkes en ned--------------
box_y[n1]++;
if(box_y[n1] > 50)
{
box_tilstand[n1] = 0;
}
else
{
gotoxy (box_x [n1], box_y[n1]);
cout << "B";
}
}
}
gotoxy (bil_x , bil_y);
cout << " =|="; //tegner bilen
// ----------------tegning af banen---------------------
gotoxy (9,0); cout << "["; gotoxy (41,0); cout << "]";
gotoxy (9,1); cout << "["; gotoxy (41,1); cout << "]";
gotoxy (9,2); cout << "["; gotoxy (41,2); cout << "]";
gotoxy (9,3); cout << "["; gotoxy (41,3); cout << "]";
gotoxy (9,4); cout << "["; gotoxy (41,4); cout << "]";
gotoxy (9,5); cout << "["; gotoxy (41,5); cout << "]";
gotoxy (9,6); cout << "["; gotoxy (41,6); cout << "]";
gotoxy (9,7); cout << "["; gotoxy (41,7); cout << "]";
gotoxy (9,8); cout << "["; gotoxy (41,8); cout << "]";
gotoxy (9,9); cout << "["; gotoxy (41,9); cout << "]";
gotoxy (9,10); cout << "["; gotoxy (41,10); cout << "]";
gotoxy (9,11); cout << "["; gotoxy (41,11); cout << "]";
gotoxy (9,12); cout << "["; gotoxy (41,12); cout << "]";
gotoxy (9,13); cout << "["; gotoxy (41,13); cout << "]";
gotoxy (9,14); cout << "["; gotoxy (41,14); cout << "]";
gotoxy (9,15); cout << "["; gotoxy (41,15); cout << "]";
gotoxy (9,16); cout << "["; gotoxy (41,16); cout << "]";
gotoxy (9,17); cout << "["; gotoxy (41,17); cout << "]";
gotoxy (9,18); cout << "["; gotoxy (41,18); cout << "]";
gotoxy (9,19); cout << "["; gotoxy (41,19); cout << "]";
gotoxy (9,20); cout << "["; gotoxy (41,20); cout << "]";
gotoxy (9,21); cout << "["; gotoxy (41,21); cout << "]";
gotoxy (9,22); cout << "["; gotoxy (41,22); cout << "]";
gotoxy (9,23); cout << "["; gotoxy (41,23); cout << "]";
gotoxy (9,24); cout << "["; gotoxy (41,24); cout << "]";
gotoxy (9,25); cout << "["; gotoxy (41,25); cout << "]";
gotoxy (9,26); cout << "["; gotoxy (41,26); cout << "]";
gotoxy (9,27); cout << "["; gotoxy (41,27); cout << "]";
gotoxy (9,28); cout << "["; gotoxy (41,28); cout << "]";
gotoxy (9,29); cout << "["; gotoxy (41,29); cout << "]";
gotoxy (9,30); cout << "["; gotoxy (41,30); cout << "]";
gotoxy (9,31); cout << "["; gotoxy (41,31); cout << "]";
gotoxy (9,32); cout << "["; gotoxy (41,32); cout << "]";
gotoxy (9,33); cout << "["; gotoxy (41,33); cout << "]";
gotoxy (9,34); cout << "["; gotoxy (41,34); cout << "]";
gotoxy (9,35); cout << "["; gotoxy (41,35); cout << "]";
gotoxy (9,36); cout << "["; gotoxy (41,36); cout << "]";
gotoxy (9,37); cout << "["; gotoxy (41,37); cout << "]";
gotoxy (9,38); cout << "["; gotoxy (41,38); cout << "]";
gotoxy (9,39); cout << "["; gotoxy (41,39); cout << "]";
gotoxy (9,40); cout << "["; gotoxy (41,40); cout << "]";
gotoxy (9,41); cout << "["; gotoxy (41,41); cout << "]";
gotoxy (9,42); cout << "["; gotoxy (41,42); cout << "]";
gotoxy (9,43); cout << "["; gotoxy (41,43); cout << "]";
gotoxy (9,44); cout << "["; gotoxy (41,44); cout << "]";
gotoxy (9,45); cout << "["; gotoxy (41,45); cout << "]";
gotoxy (9,46); cout << "["; gotoxy (41,46); cout << "]";
gotoxy (9,47); cout << "["; gotoxy (41,47); cout << "]";
gotoxy (9,48); cout << "_"; gotoxy (41,48); cout << "_";
gotoxy (10,48); cout << "_"; gotoxy (40,48); cout << "_";
gotoxy (11,48); cout << "_"; gotoxy (39,48); cout << "_";
gotoxy (12,48); cout << "_"; gotoxy (38,48); cout << "_";
gotoxy (13,48); cout << "_"; gotoxy (37,48); cout << "_";
gotoxy (14,48); cout << "_"; gotoxy (36,48); cout << "_";
gotoxy (15,48); cout << "_"; gotoxy (35,48); cout << "_";
gotoxy (16,48); cout << "_"; gotoxy (34,48); cout << "_";
gotoxy (17,48); cout << "_"; gotoxy (33,48); cout << "_";
gotoxy (18,48); cout << "_"; gotoxy (32,48); cout << "_";
gotoxy (19,48); cout << "_"; gotoxy (31,48); cout << "_";
gotoxy (20,48); cout << "_"; gotoxy (30,48); cout << "_";
gotoxy (21,48); cout << "_"; gotoxy (29,48); cout << "_";
gotoxy (22,48); cout << "_"; gotoxy (28,48); cout << "_";
gotoxy (23,48); cout << "_"; gotoxy (27,48); cout << "_";
gotoxy (24,48); cout << "_"; gotoxy (26,48); cout << "_";
gotoxy (25,48); cout << "_";
gotoxy (45, 2); cout << "Point: " << point;
gotoxy (45, 3); cout << "Liv : " << liv;
gotoxy (45, 4); cout << "Tid : "; //<< tid;
//-------------tegn box-------------------------------
// gotoxy (box_x [3], box_y [3]);
// cout << "XxX";
//--------------bruger input - bilen rykkes til højre og venstre--------
valg = 0; // valg er stadig falsk
if (kbhit()) //hvis der er keyboard input. kbhit = keybord hit
{
valg = getche (); //modtag input
}
if (valg == 75) //hvis ventre knap trykkes
{
bil_x--; //bilen rykkes til venstre
gotoxy (42, 28); cout << "<--";
if (bil_x < 10)
{
bil_x = 10; //hvis bil_x bliver mindre end 10, bliver den bare 10
}
}
if (valg == 77) //hvis højre knap trykkes
{
bil_x++; //bilen rykkes til højre
gotoxy (42, 23); cout << "-->";
if (bil_x > 36)
{
bil_x = 36; // hvis bil_x bliver større end 36, bliver den bare 36
}
}
//--------------bruger input - bilen rykkes opad og nedad--------
if (valg == 72) // hvis "op" pilen trykkes
{
bil_y--; // bilen rykkes opad
if (bil_y < 17)
{
bil_y = 17; // hvis bil_y kommer op til 17, forbliver den 17
}
}
if (valg == 80) // hvis "nedad" pilen trykkes
{
bil_y++; // bilen rykkes nedad
if (bil_y > 48)
{
bil_y = 48; // hvis bil_y kommer under 24, forbliver den 24
}
}
//------------opret boxe------------------------------------------
if (rand()%15 == 1)// hver femte gang løkken kører (i snit)
{
//-----Indsæt box-----------
box_nr++;
if (box_nr == 100)
{
box_nr = 0;
}
/*int nr;
nr = 3;*/
box_x[box_nr] = rand()%41;
box_y[box_nr] = 0;
box_tilstand[box_nr] = 1;
}
}
system("PAUSE");
return 0;
}
De vigtigste rettelser var:
Da der er 100 boxe har disse nummer 0..99, så dine for loops skal være:
for(n1=0; n1 < 100; n1++)
Du glemet at sætte box_tilstand[box_nr] til 1 når du tilføjer en box.
Når du flytter boxene skal y tælles op ikke ned.
Jeg har indsat et delay for at få det til at gå lidt langsommere.
Nogle af boxene rammer uden for banen, du skal nok sætte box_x[] til noget i stil med:
box_x[box_nr] = 9 + rand()%32;