Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "sdl/sdl.h"
- #include "surfaces.h"
- #include <ctime>
- #include <stdlib.h>
- //Variabler
- int xbot;
- bool placement[9];
- //Funktioner
- void apply_surface(int x, int y, SDL_Surface *source, SDL_Surface *destination) {
- SDL_Rect rect;
- rect.x = x;
- rect.y = y;
- SDL_BlitSurface(source, NULL, destination, &rect);
- }
- void keyinput();
- void exit();
- int place(int choose);
- void bot();
- int main(int argc, char *args[]) {
- SDL_Init(SDL_INIT_EVERYTHING);
- apply_surface(0, 0, background, screen);
- SDL_Flip(screen);
- for(int i = 0; i<10; i++) {
- placement[i] = true;
- }
- keyinput();
- SDL_Delay(2000);
- SDL_Quit();
- }
- void keyinput() {
- SDL_Event event;
- while(true) {
- if( SDL_PollEvent (&event)) {
- if(event.type == SDL_KEYDOWN) {
- switch(event.key.keysym.sym) {
- case SDLK_1:
- if(placement[1] == true) {
- place(1);
- }
- break;
- case SDLK_2:
- place(2);
- break;
- case SDLK_3:
- place(3);
- break;
- case SDLK_4:
- place(4);
- break;
- case SDLK_5:
- place(5);
- break;
- case SDLK_6:
- place(6);
- break;
- case SDLK_7:
- place(7);
- break;
- case SDLK_8:
- place(8);
- break;
- case SDLK_9:
- place(9);
- break;
- case SDLK_ESCAPE:
- exit();
- break;
- }
- }
- }
- bot();
- }
- }
- int place(int choose) {
- switch(choose) {
- case 1:
- if(placement[1] == true) {
- apply_surface(20, 20, X, screen);
- placement[1] = false;
- }
- break;
- case 2:
- if(placement[2] == true) {
- apply_surface(235, 20, X, screen);
- placement[2] = false;
- }
- break;
- case 3:
- if(placement[3] == true) {
- apply_surface(470, 20, X, screen);
- placement[3] = false;
- }
- break;
- case 4:
- if(placement[4] == true) {
- apply_surface(20, 170, X, screen);
- placement[4] = false;
- }
- break;
- case 5:
- if(placement[5] == true) {
- apply_surface(235, 170, X, screen);
- placement[5] = false;
- }
- break;
- case 6:
- if(placement[6] == true) {
- apply_surface(470, 170, X, screen);
- placement[6] = false;
- }
- break;
- case 7:
- if(placement[7] == true) {
- apply_surface(20, 360, X, screen);
- placement[7] = false;
- }
- break;
- case 8:
- if(placement[8] == true) {
- apply_surface(235, 360, X, screen);
- placement[8] = false;
- }
- break;
- case 9:
- if(placement[9] == true) {
- apply_surface(470, 360, X, screen);
- placement[9] = false;
- }
- break;
- }
- SDL_Flip(screen);
- }
- void bot() {
- srand(time(NULL));
- xbot = rand() % 9 + 1;
- switch(xbot) {
- case 1:
- if(placement[1] == true) {
- apply_surface(20, 20, O, screen);
- placement[1] = false;
- }
- break;
- case 2:
- if(placement[2] == true) {
- apply_surface(235, 20, O, screen);
- placement[2] = false;
- }
- break;
- case 3:
- if(placement[3] == true) {
- apply_surface(470, 20, O, screen);
- placement[3] = false;
- }
- break;
- case 4:
- if(placement[4] == true) {
- apply_surface(20, 170, O, screen);
- placement[4] = false;
- }
- break;
- case 5:
- if(placement[5] == true) {
- apply_surface(235, 170, O, screen);
- placement[5] = false;
- }
- break;
- case 6:
- if(placement[6] == true) {
- apply_surface(470, 170, O, screen);
- placement[6] = false;
- }
- break;
- case 7:
- if(placement[7] == true) {
- apply_surface(20, 360, O, screen);
- placement[7] = false;
- }
- break;
- case 8:
- if(placement[8] == true) {
- apply_surface(235, 360, O, screen);
- placement[8] = false;
- }
- break;
- case 9:
- if(placement[9] == true) {
- apply_surface(470, 360, O, screen);
- placement[9] = false;
- }
- break;
- }
- }
- void exit() {
- SDL_FreeSurface(background);
- SDL_FreeSurface(X);
- SDL_FreeSurface(O);
- SDL_Quit();
- }
Advertisement
Add Comment
Please, Sign In to add comment