SlideShare a Scribd company logo
1 of 3
#include <allegro.h>

BITMAP *xSprite;
BITMAP *oSprite;

int board[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0}; //This will be used to keep
                                             //track of the Xs and Os
int curSquare = 0; //This will keep track of the current square
                    //the selector is on

int turn = 1; //This will keep track of whose turn it is
              //1 Will be for X and 2 for O

int x = 0; //X and Y position of selector
int y = 0;

int tempX = 0; //holds temporary values used to clear selector
int tempY = 0;

void setupBoard(){ //This function will draw in the grid

       acquire_screen();

       line(   screen,   200, 0,   200,   480,   makecol(   255,   255,   255));
       line(   screen,   400, 0,   400,   480,   makecol(   255,   255,   255));
       line(   screen,   0, 150,   680,   150,   makecol(   255,   255,   255));
       line(   screen,   0, 300,   680,   300,   makecol(   255,   255,   255));

       rect( screen, x+1, y+1, x + 199, y + 149, makecol( 255, 255, 0));

       release_screen();

}

void updateBoard(){ //draws in selector

       rect( screen, tempX+1, tempY+1, tempX + 199, tempY + 149, makecol( 0, 0,
0));
       rect( screen, x+1, y+1, x + 199, y + 149, makecol( 255, 255, 0));
       rest(100);
}

void announceWinner(){ //Announces the winner


         if( turn == 1){
                   textout_ex( screen, font, "X Wins!!!!", 300, 240,
makecol( 255, 0, 0), makecol(0, 0, 0));
         } else {
                  textout_ex( screen, font, "O Wins!!!!", 300, 240, makecol(
255, 0, 0), makecol(0, 0, 0));
         }


}

void checkWin(){ //checks for a winner
if( board[0] == turn && board[1] == turn   &&   board[2] == turn){
             announceWinner();
         } else if( board[0] == turn && board[3]    == turn   && board[6] == turn){
             announceWinner();
         } else if( board[0] == turn && board[4]    == turn   && board[8] == turn){
             announceWinner();
         } else if( board[1] == turn && board[4]    == turn   && board[7] == turn){
             announceWinner();
         } else if( board[2] == turn && board[4]    == turn   && board[6] == turn){
             announceWinner();
         } else if( board[2] == turn && board[5]    == turn   && board[8] == turn){
             announceWinner();
         } else if( board[3] == turn && board[4]    == turn   && board[5] == turn){
             announceWinner();
         } else if( board[6] == turn && board[7]    == turn   && board[8] == turn){
             announceWinner();
         }

}



void drawXO(){ //draws in the X and O

        acquire_screen();

      if(turn == 1){
       draw_sprite( screen, xSprite, x, y);
       board[curSquare] = 1;
       checkWin();
       ++turn;
    } else if( turn == 2){
       draw_sprite( screen, oSprite, x, y);
       board[curSquare] = 2;
       checkWin();
       --turn;
    }

    release_screen();

    rest(100);

    }

void moveBox(){ //takes input

         clear_keybuf();
         tempX = x;
         tempY = y;

         if( key[KEY_UP] && y != 0){

             y -= 150;
             curSquare -=3;
             updateBoard();
} else if( key[KEY_DOWN] && y != 300){

         y += 150;
         curSquare +=3;
         updateBoard();

    }   else if( key[KEY_RIGHT] && x != 400){

         x += 200;
         ++curSquare;
         updateBoard();

    } else if( key[KEY_LEFT] && x != 0){

         x -= 200;
         --curSquare;
         updateBoard();

    } else if( key[KEY_ENTER] && board[curSquare] == 0){

         drawXO();

    }

}

int main(){

    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);

    xSprite = load_bitmap( "x.bmp", NULL);

    oSprite = load_bitmap( "o.bmp", NULL);

    setupBoard();

    while( !key[KEY_ESC]){
        moveBox();

    }

    destroy_bitmap( xSprite);
    destroy_bitmap( oSprite);

    return 0;

}
END_OF_MAIN();


www.cppgameprogramming.com/cgi/nav.cgi?page=alleganimation

More Related Content

What's hot

Better performance through Superscalarity
Better performance through SuperscalarityBetter performance through Superscalarity
Better performance through SuperscalarityMårten Rånge
 
Making Games in JavaScript
Making Games in JavaScriptMaking Games in JavaScript
Making Games in JavaScriptSam Cartwright
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureanishgoel
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Svet Ivantchev
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++Ankit Kumar
 
[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노Chiwon Song
 
Wap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithmWap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithmKapil Pandit
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changeshayato
 
10CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 1010CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 10Vanishree Arun
 
An Introduction to Tinkerpop
An Introduction to TinkerpopAn Introduction to Tinkerpop
An Introduction to TinkerpopTakahiro Inoue
 
10CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 810CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 8Vanishree Arun
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicalsManoj Chauhan
 

What's hot (20)

Better performance through Superscalarity
Better performance through SuperscalarityBetter performance through Superscalarity
Better performance through Superscalarity
 
Proga 0706
Proga 0706Proga 0706
Proga 0706
 
Making Games in JavaScript
Making Games in JavaScriptMaking Games in JavaScript
Making Games in JavaScript
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lecture
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016
 
Linux tips
Linux tipsLinux tips
Linux tips
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 
[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노
 
Wap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithmWap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithm
 
Teste
TesteTeste
Teste
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changes
 
201707 CSE110 Lecture 13
201707 CSE110 Lecture 13   201707 CSE110 Lecture 13
201707 CSE110 Lecture 13
 
10CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 1010CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 10
 
Vcs9
Vcs9Vcs9
Vcs9
 
An Introduction to Tinkerpop
An Introduction to TinkerpopAn Introduction to Tinkerpop
An Introduction to Tinkerpop
 
OOXX
OOXXOOXX
OOXX
 
Ssaw08 0624
Ssaw08 0624Ssaw08 0624
Ssaw08 0624
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautiful
 
10CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 810CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 8
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicals
 

Viewers also liked

Your Smartphone Your Safeguard (YS2)
Your Smartphone Your Safeguard (YS2)Your Smartphone Your Safeguard (YS2)
Your Smartphone Your Safeguard (YS2)readoneitz
 
Gayatrimantra
GayatrimantraGayatrimantra
Gayatrimantrakrishavg
 
Cooking storyboard
Cooking storyboardCooking storyboard
Cooking storyboardTyler Tilton
 
SliderocketTest
SliderocketTestSliderocketTest
SliderocketTestArnedavid
 
Sliderocket(Test)
Sliderocket(Test)Sliderocket(Test)
Sliderocket(Test)Arnedavid
 
iEnglish workshop 4
 iEnglish workshop 4 iEnglish workshop 4
iEnglish workshop 4dearjili
 
Frog and taod dissection
Frog and taod dissectionFrog and taod dissection
Frog and taod dissectionannde
 
Wego Zakelijk
Wego ZakelijkWego Zakelijk
Wego ZakelijkRob Baas
 
Продвижение в социальных медиа
Продвижение в социальных медиаПродвижение в социальных медиа
Продвижение в социальных медиаTrisCenter
 
Pengenalan Kabupaten Bandung Barat
Pengenalan Kabupaten Bandung BaratPengenalan Kabupaten Bandung Barat
Pengenalan Kabupaten Bandung Baratreadoneitz
 

Viewers also liked (14)

2975 ftp
2975 ftp2975 ftp
2975 ftp
 
Your Smartphone Your Safeguard (YS2)
Your Smartphone Your Safeguard (YS2)Your Smartphone Your Safeguard (YS2)
Your Smartphone Your Safeguard (YS2)
 
Gayatrimantra
GayatrimantraGayatrimantra
Gayatrimantra
 
Cooking storyboard
Cooking storyboardCooking storyboard
Cooking storyboard
 
Sliderocket
SliderocketSliderocket
Sliderocket
 
SliderocketTest
SliderocketTestSliderocketTest
SliderocketTest
 
Sliderocket(Test)
Sliderocket(Test)Sliderocket(Test)
Sliderocket(Test)
 
Sliderocket
SliderocketSliderocket
Sliderocket
 
Sliderocket
SliderocketSliderocket
Sliderocket
 
iEnglish workshop 4
 iEnglish workshop 4 iEnglish workshop 4
iEnglish workshop 4
 
Frog and taod dissection
Frog and taod dissectionFrog and taod dissection
Frog and taod dissection
 
Wego Zakelijk
Wego ZakelijkWego Zakelijk
Wego Zakelijk
 
Продвижение в социальных медиа
Продвижение в социальных медиаПродвижение в социальных медиа
Продвижение в социальных медиа
 
Pengenalan Kabupaten Bandung Barat
Pengenalan Kabupaten Bandung BaratPengenalan Kabupaten Bandung Barat
Pengenalan Kabupaten Bandung Barat
 

Similar to Include

AI CHALLENGE ADMIN
AI CHALLENGE ADMINAI CHALLENGE ADMIN
AI CHALLENGE ADMINAnkit Gupta
 
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docxPiersRCoThomsonw
 
#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdf#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdfsinghanubhav1234
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfanjandavid
 
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docxNewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docxcurwenmichaela
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfpoblettesedanoree498
 
i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfarmcomputers
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdffonecomp
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfcontact32
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfasif1401
 
This is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfThis is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfcalderoncasto9163
 
Know more processing
Know more processingKnow more processing
Know more processingYukiAizawa1
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
Im trying again -Okay, Im in need of some help - this is the c.pdf
Im trying again -Okay, Im in need of some help - this is the c.pdfIm trying again -Okay, Im in need of some help - this is the c.pdf
Im trying again -Okay, Im in need of some help - this is the c.pdfeyeonsecuritysystems
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfanwarsadath111
 
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdfNeed to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdfflashfashioncasualwe
 
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
 draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdfaquacosmossystems
 

Similar to Include (20)

AI CHALLENGE ADMIN
AI CHALLENGE ADMINAI CHALLENGE ADMIN
AI CHALLENGE ADMIN
 
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
 
#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdf#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdf
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
 
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docxNewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
 
Proga 090525
Proga 090525Proga 090525
Proga 090525
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdf
 
i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdf
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
 
Proga 0622
Proga 0622Proga 0622
Proga 0622
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdf
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
 
This is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfThis is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdf
 
Know more processing
Know more processingKnow more processing
Know more processing
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Im trying again -Okay, Im in need of some help - this is the c.pdf
Im trying again -Okay, Im in need of some help - this is the c.pdfIm trying again -Okay, Im in need of some help - this is the c.pdf
Im trying again -Okay, Im in need of some help - this is the c.pdf
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdf
 
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdfNeed to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf
 
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
 draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
 
Proga 0601
Proga 0601Proga 0601
Proga 0601
 

Recently uploaded

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Recently uploaded (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Include

  • 1. #include <allegro.h> BITMAP *xSprite; BITMAP *oSprite; int board[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0}; //This will be used to keep //track of the Xs and Os int curSquare = 0; //This will keep track of the current square //the selector is on int turn = 1; //This will keep track of whose turn it is //1 Will be for X and 2 for O int x = 0; //X and Y position of selector int y = 0; int tempX = 0; //holds temporary values used to clear selector int tempY = 0; void setupBoard(){ //This function will draw in the grid acquire_screen(); line( screen, 200, 0, 200, 480, makecol( 255, 255, 255)); line( screen, 400, 0, 400, 480, makecol( 255, 255, 255)); line( screen, 0, 150, 680, 150, makecol( 255, 255, 255)); line( screen, 0, 300, 680, 300, makecol( 255, 255, 255)); rect( screen, x+1, y+1, x + 199, y + 149, makecol( 255, 255, 0)); release_screen(); } void updateBoard(){ //draws in selector rect( screen, tempX+1, tempY+1, tempX + 199, tempY + 149, makecol( 0, 0, 0)); rect( screen, x+1, y+1, x + 199, y + 149, makecol( 255, 255, 0)); rest(100); } void announceWinner(){ //Announces the winner if( turn == 1){ textout_ex( screen, font, "X Wins!!!!", 300, 240, makecol( 255, 0, 0), makecol(0, 0, 0)); } else { textout_ex( screen, font, "O Wins!!!!", 300, 240, makecol( 255, 0, 0), makecol(0, 0, 0)); } } void checkWin(){ //checks for a winner
  • 2. if( board[0] == turn && board[1] == turn && board[2] == turn){ announceWinner(); } else if( board[0] == turn && board[3] == turn && board[6] == turn){ announceWinner(); } else if( board[0] == turn && board[4] == turn && board[8] == turn){ announceWinner(); } else if( board[1] == turn && board[4] == turn && board[7] == turn){ announceWinner(); } else if( board[2] == turn && board[4] == turn && board[6] == turn){ announceWinner(); } else if( board[2] == turn && board[5] == turn && board[8] == turn){ announceWinner(); } else if( board[3] == turn && board[4] == turn && board[5] == turn){ announceWinner(); } else if( board[6] == turn && board[7] == turn && board[8] == turn){ announceWinner(); } } void drawXO(){ //draws in the X and O acquire_screen(); if(turn == 1){ draw_sprite( screen, xSprite, x, y); board[curSquare] = 1; checkWin(); ++turn; } else if( turn == 2){ draw_sprite( screen, oSprite, x, y); board[curSquare] = 2; checkWin(); --turn; } release_screen(); rest(100); } void moveBox(){ //takes input clear_keybuf(); tempX = x; tempY = y; if( key[KEY_UP] && y != 0){ y -= 150; curSquare -=3; updateBoard();
  • 3. } else if( key[KEY_DOWN] && y != 300){ y += 150; curSquare +=3; updateBoard(); } else if( key[KEY_RIGHT] && x != 400){ x += 200; ++curSquare; updateBoard(); } else if( key[KEY_LEFT] && x != 0){ x -= 200; --curSquare; updateBoard(); } else if( key[KEY_ENTER] && board[curSquare] == 0){ drawXO(); } } int main(){ allegro_init(); install_keyboard(); set_color_depth(16); set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0); xSprite = load_bitmap( "x.bmp", NULL); oSprite = load_bitmap( "o.bmp", NULL); setupBoard(); while( !key[KEY_ESC]){ moveBox(); } destroy_bitmap( xSprite); destroy_bitmap( oSprite); return 0; } END_OF_MAIN(); www.cppgameprogramming.com/cgi/nav.cgi?page=alleganimation