1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
#include <allegro.h>
#include <cstdlib>
#include <time.h>
int die1num = 1;
int die2num = 1;
int timer = 1;
BITMAP* Image;
BITMAP* Die1;
BITMAP* Die2;
BITMAP* Die3;
BITMAP* Die4;
BITMAP* Die5;
BITMAP* Die6;
void endgame() {
timer = 0;
}
void diceroll() {
die1num = rand() % 6 + 1;
die2num = rand() % 6 + 1;
timer = 1;
if (die1num == 1) {
acquire_screen();
blit (Die1, screen, 0, 0, 700, 450, 29, 29);
release_screen();
}
if (die1num == 2) {
acquire_screen();
blit (Die2, screen, 0, 0, 700, 450, 29, 29);
release_screen();
}
if (die1num == 3) {
acquire_screen();
blit (Die3, screen, 0, 0, 700, 450, 29, 29);
release_screen();
}
if (die1num == 4) {
acquire_screen();
blit (Die4, screen, 0, 0, 700, 450, 29, 29);
release_screen();
}
if (die1num == 5) {
acquire_screen();
blit (Die5, screen, 0, 0, 700, 450, 29, 29);
release_screen();
}
if (die1num == 6) {
acquire_screen();
blit (Die6, screen, 0, 0, 700, 450, 29, 29);
release_screen();
}
if (die2num == 1) {
acquire_screen();
blit (Die1, screen, 0, 0, 731, 450, 29, 29);
release_screen();
}
if (die2num == 2) {
acquire_screen();
blit (Die2, screen, 0, 0, 731, 450, 29, 29);
release_screen();
}
if (die2num == 3) {
acquire_screen();
blit (Die3, screen, 0, 0, 731, 450, 29, 29);
release_screen();
}
if (die2num == 4) {
acquire_screen();
blit (Die4, screen, 0, 0, 731, 450, 29, 29);
release_screen();
}
if (die2num == 5) {
acquire_screen();
blit (Die5, screen, 0, 0, 731, 450, 29, 29);
release_screen();
}
if (die2num == 6) {
acquire_screen();
blit (Die6, screen, 0, 0, 731, 450, 29, 29);
release_screen();
}
}
int main() {
allegro_init();
install_keyboard();
set_color_depth (16);
set_gfx_mode (GFX_AUTODETECT, 920, 560, 0, 0);
Image = load_bitmap ("Board.bmp", NULL);
Die1 = load_bitmap ("Dice1.bmp", NULL);
Die2 = load_bitmap ("Dice2.bmp", NULL);
Die3 = load_bitmap ("Dice3.bmp", NULL);
Die4 = load_bitmap ("Dice4.bmp", NULL);
Die5 = load_bitmap ("Dice5.bmp", NULL);
Die6 = load_bitmap ("Dice6.bmp", NULL);
srand (time (NULL));
acquire_screen();
clear_to_color (screen, makecol (255, 255, 255));
blit (Image, screen, 0, 0, 5, 20, 521, 521);
blit (Die1, screen, 0, 0, 700, 450, 29, 29);
blit (Die1, screen, 0, 0, 731, 450, 29, 29);
release_screen();
while (timer > 0) {
clear_keybuf();
readkey();
if (key[KEY_ESC]) {
endgame();
}
else if (key[KEY_R]) {
diceroll();
}
}
destroy_bitmap (Image);
return 0;
}
END_OF_MAIN();
|