Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <GL/glut.h>
- #include <SDL/SDL.h>
- int selected_field,
- chosen_colour[4],
- round_number;
- bool enforce_endturn;
- float colour_set[8][3],
- rows[6],
- columns[8],
- rows_interval,
- cols_interval;
- SDL_Event event;
- void init();
- void draw_square(float x1,float y1, float x2, float y2, float c1, float c2, float c3);
- void draw_doneround(int col_no,int hypoth,int resp);
- void display_end_image(int comb, bool won);
- int verify_answer(int proposition , int solution); // odpowiedz gracza i dobre rozwiazanie zapisane jako czterocyfrowe l. naturalne
- void get_keyboard_events(bool additionals);
- int main(int argc,char* argv[])
- {
- printf("dupa");
- selected_field = 0,
- round_number = 0;
- enforce_endturn = false;
- rows_interval = 95.0f/600.0f;
- cols_interval = 95.0f/800.0f;
- int hypothesis,
- combination = 0,
- power = 1000,
- c,
- response=0;
- bool game_is_on = true;
- init();
- glutInit(&argc,argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(800, 600);
- glutCreateWindow(argv[0]);
- glClearColor(0.0f,0.0f,0.0f,0.0f);
- glClearDepth(1.0);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D(0.0f,1.0f,0.0f,1.0f);
- glMatrixMode(GL_MODELVIEW);
- printf("dupa2");
- for (int i = 0 ; i < 4 ; ++i)
- {
- c = (rand() % 6) + 1;
- combination += c*power;
- power /= 10;
- }
- // DO TUTAJ JEST OK
- power = 1000;
- while(game_is_on)
- {
- printf("guwno");
- get_keyboard_events(true); // zrob klawiature
- if (enforce_endturn) // zweryfikuj kombinacje
- {
- /*
- hypothesis = 0;
- for (int i = 0 ; i < 4 ; ++i)
- {
- hypothesis += power * chosen_colour[i];
- power /= 10;
- }
- response = verify_answer(hypothesis,combination);
- */
- if (response == 40 || round_number == 5) game_is_on = false;
- else
- {
- draw_doneround(round_number,hypothesis,response);
- for (int i = 0 ; i < 4 ; ++i) chosen_colour[i] = 1;
- selected_field = 0;
- enforce_endturn = false;
- power = 1000;
- ++round_number;
- }
- }
- // wyswietl obecna hipoteze TODO
- glFlush();
- }
- if(response == 40) display_end_image(combination,true);
- else display_end_image(combination,false);
- while(!game_is_on)
- {
- get_keyboard_events(false);
- glFlush();
- }
- return 0;
- }
- void init()
- {
- // numery komorek w rzedach
- rows[0] = 25.0f/600.0f;
- rows[1] = 120.0f/600.0f;
- rows[2] = 215.0f/600.0f;
- rows[3] = 310.0f/600.0f;
- rows[4] = 405.0f/600.0f;
- rows[5] = 500.0f/600.0f;
- // numery komorek w kolumnach
- columns[0] = 25.0f/800.0f;
- columns[1] = 120.0f/800.0f;
- columns[2] = 215.0f/800.0f;
- columns[3] = 310.0f/800.0f;
- columns[4] = 415.0f/800.0f;
- columns[5] = 510.0f/800.0f;
- columns[6] = 605.0f/800.0f;
- columns[7] = 700.0f/800.0f;
- // czarny
- colour_set[0][0] = 0.0f;
- colour_set[0][1] = 0.0f;
- colour_set[0][2] = 0.0f;
- // czerwony
- colour_set[1][0] = 1.0f;
- colour_set[1][1] = 0.0f;
- colour_set[1][2] = 0.0f;
- // zolty
- colour_set[2][0] = 1.0f;
- colour_set[2][1] = 1.0f;
- colour_set[2][2] = 0.0f;
- // zielony
- colour_set[3][0] = 0.0f;
- colour_set[3][1] = 1.0f;
- colour_set[3][2] = 0.0f;
- // niebieski
- colour_set[4][0] = 0.0f;
- colour_set[4][1] = 0.0f;
- colour_set[4][2] = 1.0f;
- // pomaranczowy
- colour_set[5][0] = 0.98f;
- colour_set[5][1] = 0.625f;
- colour_set[5][2] = 0.12f;
- // cyan
- colour_set[6][0] = 0.0f;
- colour_set[6][1] = 1.0f;
- colour_set[6][2] = 1.0f;
- // bialy
- colour_set[7][0] = 1.0f;
- colour_set[7][1] = 1.0f;
- colour_set[7][2] = 1.0f;
- for (int i = 0 ; i < 4 ; ++i) chosen_colour[i] = 1;
- }
- void display_end_image(int comb, bool won)
- {
- glColor3f(0.0f,0.0f,0.0f);
- glBegin(GL_TRIANGLES);
- glVertex2f(0.0f,0.0f);
- glVertex2f(1.0f,0.0f);
- glVertex2f(0.0f,1.0f);
- glVertex2f(1.0f,0.0f);
- glVertex2f(1.0f,1.0f);
- glVertex2f(0.0f,1.0f);
- glEnd();
- // TODO
- // narysuj bialy prostokat na srodku
- // dostaw trojkat z gory/dolu
- // wyrysuj poprawna kombinacje
- }
- void draw_square(float x1,float y1, float x2, float y2, float c1, float c2, float c3)
- {
- glColor3f(c1,c2,c3);
- glBegin(GL_TRIANGLES);
- glVertex2f(x1,y1);
- glVertex2f(x2,y1);
- glVertex2f(x1,y2);
- glVertex2f(x1,y2);
- glVertex2f(x2,y1);
- glVertex2f(x2,y2);
- glEnd();
- }
- void draw_doneround(int col_no,int hypoth,int resp)
- {
- int hypo[4],
- power = 1000,
- xmin,
- xmax,
- ymin,
- ymax;
- for (int i = 0 ; i < 4 ; ++i)
- {
- hypo[i] = (hypoth - (hypoth % power) ) / hypoth;
- power /= 10;
- }
- for (int i = 0 ; i < 4 ; ++i)
- {
- xmin = rows[i] + (10.0f/95.0f)*rows_interval;
- xmax = rows[i] + (65.0f/95.0f)*rows_interval;
- ymin = columns[col_no] + (10.0f/95.0f)*cols_interval;
- ymax = columns[col_no] + (65.0f/95.0f)*cols_interval;
- draw_square(xmin,ymin,xmax,ymax,colour_set[hypo[i]][0],colour_set[hypo[i]][1],colour_set[hypo[i]][2]);
- }
- // TODO czarne i biale
- }
- int verify_answer(int proposition , int solution) // odpowiedz gracza i dobre rozwiazanie zapisane jako czterocyfrowe l. naturalne
- {
- int prop[4],
- sol[4],
- power = 1000,
- answer = 0;
- for (int i = 0 ; i < 4 ; ++i)
- {
- prop[i] = (proposition - (proposition % power) ) / power;
- sol[i] = (solution - (solution % power) ) / power;
- power /= 10;
- if (prop[i] == sol[i])
- {
- prop[i] = -1;
- sol[i] = -1;
- answer += 10;
- }
- }
- for (int i = 0 ; i < 4 ; ++i) // czas wyznaczyc ilosc bialych kamykow
- {
- if (prop[i] > 0)
- {
- for (int j = 0 ; j < 4 ; ++j)
- {
- if (prop[i] == sol[j])
- {
- prop[i] = -1;
- sol[j] = -1;
- answer += 1;
- j = 5;
- }
- }
- }
- }
- return answer; // dwucyfrowa liczba naturalna, 10*czarne + biale
- }
- void get_keyboard_events(bool additionals)
- {
- if(SDL_PollEvent(&event)) // czy cos sie zdarzylo
- {
- if (event.type == SDL_KEYDOWN && additionals)
- {
- switch(event.key.keysym.sym)
- {
- case SDLK_q: exit(0); break;
- case SDLK_a: selected_field = (selected_field - 1) % 4; break;
- case SDLK_d: selected_field = (selected_field + 1) % 4; break;
- case SDLK_1: chosen_colour[selected_field] = 1; break;
- case SDLK_2: chosen_colour[selected_field] = 2; break;
- case SDLK_3: chosen_colour[selected_field] = 3; break;
- case SDLK_4: chosen_colour[selected_field] = 4; break;
- case SDLK_5: chosen_colour[selected_field] = 5; break;
- case SDLK_6: chosen_colour[selected_field] = 6; break;
- case SDLK_SPACE: enforce_endturn = true; break;
- }
- }
- else if(event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_q) exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement