Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
Cong Le Ba committed Apr 26, 2018
1 parent 8ba006f commit 6987d33
Show file tree
Hide file tree
Showing 34 changed files with 1,018 additions and 574 deletions.
10 changes: 6 additions & 4 deletions Cong.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="Graphics.cpp" />
<Unit filename="graphics.h" />
<Unit filename="Game.cpp" />
<Unit filename="Game.h" />
<Unit filename="Painter.cpp" />
<Unit filename="Painter.h" />
<Unit filename="Window.cpp" />
<Unit filename="Window.h" />
<Unit filename="main.cpp" />
<Unit filename="painter.cpp" />
<Unit filename="painter.h" />
<Extensions>
<code_completion />
<envvars />
Expand Down
45 changes: 34 additions & 11 deletions Cong.depend
Original file line number Diff line number Diff line change
@@ -1,31 +1,54 @@
# depslib dependency file v1.0
1521101881 source:e:\workplace\cong\main.cpp
1524555855 source:e:\workplace\cong\main.cpp
<iostream>
<cstdlib>
<ctime>
<cstring>
<SDL.h>
"graphics.h"
"painter.h"
"Window.h"
"Painter.h"
"Game.h"
"SDL_mixer.h"

1521101941 source:e:\workplace\cong\graphics.cpp
1523591454 source:e:\workplace\cong\graphics.cpp
"graphics.h"
<iostream>

1520474533 e:\workplace\cong\graphics.h
1523274691 e:\workplace\cong\graphics.h
<iostream>
<SDL.h>

1521101662 source:e:\workplace\cong\painter.cpp
1524495293 source:e:\workplace\cong\painter.cpp
<cmath>
<cstdlib>
<iostream>
<SDL.h>
<SDL_image.h>
"painter.h"
"Painter.h"

1521096980 e:\workplace\cong\painter.h
1524489429 e:\workplace\cong\painter.h
<string>
<SDL.h>
<SDL_image.h>

1524488751 e:\workplace\cong\window.h
<iostream>
<SDL.h>

1524488478 source:e:\workplace\cong\window.cpp
"Window.h"
<iostream>

1524643213 source:e:\workplace\cong\game.cpp
<cstring>
<cstdlib>
<ctime>
<SDL.h>
<SDL_image.h>
"Game.h"
"Painter.h"
<SDL_mixer.h>

1524494135 e:\workplace\cong\game.h
<SDL.h>
<SDL_image.h>
"Painter.h"
"Window.h"

30 changes: 20 additions & 10 deletions Cong.layout
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<ActiveTarget name="Debug" />
<File name="painter.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="8" zoom_2="0">
<File name="Painter.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="8" zoom_2="0">
<Cursor>
<Cursor1 position="780" topLine="24" />
<Cursor1 position="873" topLine="29" />
</Cursor>
</File>
<File name="painter.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="10" zoom_2="0">
<File name="Window.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="9" zoom_2="0">
<Cursor>
<Cursor1 position="153" topLine="9" />
<Cursor1 position="2078" topLine="45" />
</Cursor>
</File>
<File name="graphics.cpp" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="13" zoom_2="0">
<File name="Painter.cpp" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="7" zoom_2="0">
<Cursor>
<Cursor1 position="1984" topLine="56" />
<Cursor1 position="101" topLine="93" />
</Cursor>
</File>
<File name="graphics.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="10" zoom_2="0">
<File name="Game.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="13" zoom_2="0">
<Cursor>
<Cursor1 position="583" topLine="0" />
<Cursor1 position="89" topLine="0" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="10" zoom_2="0">
<File name="Window.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="10" zoom_2="0">
<Cursor>
<Cursor1 position="1517" topLine="54" />
<Cursor1 position="290" topLine="3" />
</Cursor>
</File>
<File name="Game.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="13" zoom_2="0">
<Cursor>
<Cursor1 position="1033" topLine="82" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="10" zoom_2="0">
<Cursor>
<Cursor1 position="698" topLine="25" />
</Cursor>
</File>
</CodeBlocks_layout_file>
93 changes: 93 additions & 0 deletions Game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <SDL.h>
#include <SDL_image.h>
#include "Game.h"
#include "Painter.h"
#include <SDL_mixer.h>

using namespace std;

Game::Game( SDL_Window* window, SDL_Renderer* renderer, Window& canvas, Painter& painter ) {
srand(time(NULL));

// Sence1 and Sence2's sound
Mix_Chunk* sence2 = NULL;
sence2 = Mix_LoadWAV( "sound/sence2.ogx" );
if (sence2 == NULL)
{
cout << Mix_GetError();
}
if( Mix_PlayChannel( -1, sence2, -1 ) == -1 )
{
return;
}

// Sence1 here
painter.showSence1();
if (canvas.havePressed()) cout << "Click on sence 1"<<endl; else canvas.quitSDL(window, renderer);

// Sence2 here
painter.showSence2();
if (canvas.havePressed()) cout << "Click on sence 2"<<endl; else canvas.quitSDL(window, renderer);

Mix_Pause( -1 );
Mix_Chunk* music = NULL , *winsound = NULL , *losssound = NULL ;
music = Mix_LoadWAV( "sound/show.wav" );
winsound = Mix_LoadWAV( "sound/win.wav" );
losssound = Mix_LoadWAV( "sound/loss.mp3" );
if (music == NULL || winsound == NULL || losssound == NULL)
{
cout << Mix_GetError();
}
// Slideshow here
bool visit[22];
for (int level=1; level<=5; level++) {
memset(visit,0,sizeof(visit));
int res = -1;
for (int i=1; i<=12; i++) {
int image_index = rand() % 15 + 1;
//int image_index = rand() % 15 + 1;
int image_dir = 1;
painter.showImage(image_dir, image_index);
if( Mix_PlayChannel( -1, music, 0 ) == -1 )
{
return;
}
canvas.haveClick(visit , image_index, res);
if (res!=-1) {
if (res)
{
if( Mix_PlayChannel( -1, winsound, 0 ) == -1 )
{
return;
}
}
else
{
if( Mix_PlayChannel( -1, losssound, 0 ) == -1 )
{
return;
}
}
painter.showResult(res);
if (canvas.havePressed()) cout << "Click on sence 3"<<endl; else canvas.quitSDL(window, renderer);
break;
}
else
if (visit[image_index]) {
res = 0;
if( Mix_PlayChannel( -1, losssound, 0 ) == -1 )
{
return;
}
painter.showResult(res);
if (canvas.havePressed()) cout << "Click on sence 3"<<endl; else canvas.quitSDL(window, renderer);
break;
}
else visit[image_index] = 1;
}
}

}
14 changes: 14 additions & 0 deletions Game.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED
#include <SDL.h>
#include <SDL_image.h>
#include "Painter.h"
#include "Window.h"

class Game
{
public:
Game( SDL_Window* window, SDL_Renderer* renderer, Window& canvas, Painter& painter );

};
#endif // GAME_H_INCLUDED
41 changes: 15 additions & 26 deletions Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <iostream>

#define GRID_SIZE 25
#define SCREEN_HEIGHT 600
#define SCREEN_HEIGHT 500
#define SCREEN_WIDTH 800

using namespace std;
Expand Down Expand Up @@ -65,29 +65,18 @@ bool graphics::havePressed() {
else if (e.type == SDL_QUIT) return 0;
}
}
/*
//The button
//class Button {
// private:
//The attributes of the button
Button::SDL_Rect box;
//The part of the button sprite sheet that will be shown
Button::SDL_Rect* clip;
//public:
//Initialize the variables
Button::Button( int x, int y, int w, int h );
//Handles events and set the button's sprite region
Button::void handle_events();
//Shows the button on the screen
Button::void show();
//};
*/

button::button( int x, int y, int w, int h ) {
//Set the button's attributes
box.x = x;
box.y = y;
box.w = w;
box.h = h;
//Set the default sprite
void graphics::haveClick(bool visit[], int image_index, int& res) {
SDL_Event e;
int dem = 0;
while(dem < 1000) {
if ( SDL_PollEvent(&e)!=0 )
if (e.type == SDL_KEYDOWN || e.type == SDL_MOUSEBUTTONDOWN)
{
cout << "PRESSSSS!" << e.type << endl;
if (!visit[image_index]) res = 0; else res = 1;
return;
}
SDL_Delay(1); dem++;
}
}

66 changes: 0 additions & 66 deletions LICENSE.jpeg.txt

This file was deleted.

Loading

0 comments on commit 6987d33

Please sign in to comment.