Compare commits
No commits in common. "4e1b5e0deaf9c05dabe9fb7a8bb5437a8b60b55b" and "d44c824b92f15c345e8d5c1a40a45450ca97615f" have entirely different histories.
4e1b5e0dea
...
d44c824b92
457
TTT/.gitignore
vendored
457
TTT/.gitignore
vendored
@ -1,457 +0,0 @@
|
|||||||
## Ignore Visual Studio temporary files, build results, and
|
|
||||||
## files generated by popular Visual Studio add-ons.
|
|
||||||
##
|
|
||||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
|
||||||
|
|
||||||
# User-specific files
|
|
||||||
*.rsuser
|
|
||||||
*.suo
|
|
||||||
*.user
|
|
||||||
*.userosscache
|
|
||||||
*.sln.docstates
|
|
||||||
|
|
||||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
|
||||||
*.userprefs
|
|
||||||
|
|
||||||
# Mono auto generated files
|
|
||||||
mono_crash.*
|
|
||||||
|
|
||||||
# Build results
|
|
||||||
[Dd]ebug/
|
|
||||||
[Dd]ebugPublic/
|
|
||||||
[Rr]elease/
|
|
||||||
[Rr]eleases/
|
|
||||||
x64/
|
|
||||||
x86/
|
|
||||||
[Ww][Ii][Nn]32/
|
|
||||||
[Aa][Rr][Mm]/
|
|
||||||
[Aa][Rr][Mm]64/
|
|
||||||
bld/
|
|
||||||
[Bb]in/
|
|
||||||
[Oo]bj/
|
|
||||||
[Ll]og/
|
|
||||||
[Ll]ogs/
|
|
||||||
|
|
||||||
# Visual Studio 2015/2017 cache/options directory
|
|
||||||
.vs/
|
|
||||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
|
||||||
#wwwroot/
|
|
||||||
|
|
||||||
# Visual Studio 2017 auto generated files
|
|
||||||
Generated\ Files/
|
|
||||||
|
|
||||||
# MSTest test Results
|
|
||||||
[Tt]est[Rr]esult*/
|
|
||||||
[Bb]uild[Ll]og.*
|
|
||||||
|
|
||||||
# NUnit
|
|
||||||
*.VisualState.xml
|
|
||||||
TestResult.xml
|
|
||||||
nunit-*.xml
|
|
||||||
|
|
||||||
# Build Results of an ATL Project
|
|
||||||
[Dd]ebugPS/
|
|
||||||
[Rr]eleasePS/
|
|
||||||
dlldata.c
|
|
||||||
|
|
||||||
# Benchmark Results
|
|
||||||
BenchmarkDotNet.Artifacts/
|
|
||||||
|
|
||||||
# .NET
|
|
||||||
project.lock.json
|
|
||||||
project.fragment.lock.json
|
|
||||||
artifacts/
|
|
||||||
|
|
||||||
# Tye
|
|
||||||
.tye/
|
|
||||||
|
|
||||||
# ASP.NET Scaffolding
|
|
||||||
ScaffoldingReadMe.txt
|
|
||||||
|
|
||||||
# StyleCop
|
|
||||||
StyleCopReport.xml
|
|
||||||
|
|
||||||
# Files built by Visual Studio
|
|
||||||
*_i.c
|
|
||||||
*_p.c
|
|
||||||
*_h.h
|
|
||||||
*.ilk
|
|
||||||
*.meta
|
|
||||||
*.obj
|
|
||||||
*.iobj
|
|
||||||
*.pch
|
|
||||||
*.pdb
|
|
||||||
*.ipdb
|
|
||||||
*.pgc
|
|
||||||
*.pgd
|
|
||||||
*.rsp
|
|
||||||
*.sbr
|
|
||||||
*.tlb
|
|
||||||
*.tli
|
|
||||||
*.tlh
|
|
||||||
*.tmp
|
|
||||||
*.tmp_proj
|
|
||||||
*_wpftmp.csproj
|
|
||||||
*.log
|
|
||||||
*.vspscc
|
|
||||||
*.vssscc
|
|
||||||
.builds
|
|
||||||
*.pidb
|
|
||||||
*.svclog
|
|
||||||
*.scc
|
|
||||||
|
|
||||||
# Chutzpah Test files
|
|
||||||
_Chutzpah*
|
|
||||||
|
|
||||||
# Visual C++ cache files
|
|
||||||
ipch/
|
|
||||||
*.aps
|
|
||||||
*.ncb
|
|
||||||
*.opendb
|
|
||||||
*.opensdf
|
|
||||||
*.sdf
|
|
||||||
*.cachefile
|
|
||||||
*.VC.db
|
|
||||||
*.VC.VC.opendb
|
|
||||||
|
|
||||||
# Visual Studio profiler
|
|
||||||
*.psess
|
|
||||||
*.vsp
|
|
||||||
*.vspx
|
|
||||||
*.sap
|
|
||||||
|
|
||||||
# Visual Studio Trace Files
|
|
||||||
*.e2e
|
|
||||||
|
|
||||||
# TFS 2012 Local Workspace
|
|
||||||
$tf/
|
|
||||||
|
|
||||||
# Guidance Automation Toolkit
|
|
||||||
*.gpState
|
|
||||||
|
|
||||||
# ReSharper is a .NET coding add-in
|
|
||||||
_ReSharper*/
|
|
||||||
*.[Rr]e[Ss]harper
|
|
||||||
*.DotSettings.user
|
|
||||||
|
|
||||||
# TeamCity is a build add-in
|
|
||||||
_TeamCity*
|
|
||||||
|
|
||||||
# DotCover is a Code Coverage Tool
|
|
||||||
*.dotCover
|
|
||||||
|
|
||||||
# AxoCover is a Code Coverage Tool
|
|
||||||
.axoCover/*
|
|
||||||
!.axoCover/settings.json
|
|
||||||
|
|
||||||
# Coverlet is a free, cross platform Code Coverage Tool
|
|
||||||
coverage*.json
|
|
||||||
coverage*.xml
|
|
||||||
coverage*.info
|
|
||||||
|
|
||||||
# Visual Studio code coverage results
|
|
||||||
*.coverage
|
|
||||||
*.coveragexml
|
|
||||||
|
|
||||||
# NCrunch
|
|
||||||
_NCrunch_*
|
|
||||||
.*crunch*.local.xml
|
|
||||||
nCrunchTemp_*
|
|
||||||
|
|
||||||
# MightyMoose
|
|
||||||
*.mm.*
|
|
||||||
AutoTest.Net/
|
|
||||||
|
|
||||||
# Web workbench (sass)
|
|
||||||
.sass-cache/
|
|
||||||
|
|
||||||
# Installshield output folder
|
|
||||||
[Ee]xpress/
|
|
||||||
|
|
||||||
# DocProject is a documentation generator add-in
|
|
||||||
DocProject/buildhelp/
|
|
||||||
DocProject/Help/*.HxT
|
|
||||||
DocProject/Help/*.HxC
|
|
||||||
DocProject/Help/*.hhc
|
|
||||||
DocProject/Help/*.hhk
|
|
||||||
DocProject/Help/*.hhp
|
|
||||||
DocProject/Help/Html2
|
|
||||||
DocProject/Help/html
|
|
||||||
|
|
||||||
# Click-Once directory
|
|
||||||
publish/
|
|
||||||
|
|
||||||
# Publish Web Output
|
|
||||||
*.[Pp]ublish.xml
|
|
||||||
*.azurePubxml
|
|
||||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
|
||||||
# but database connection strings (with potential passwords) will be unencrypted
|
|
||||||
*.pubxml
|
|
||||||
*.publishproj
|
|
||||||
|
|
||||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
|
||||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
|
||||||
# in these scripts will be unencrypted
|
|
||||||
PublishScripts/
|
|
||||||
|
|
||||||
# NuGet Packages
|
|
||||||
*.nupkg
|
|
||||||
# NuGet Symbol Packages
|
|
||||||
*.snupkg
|
|
||||||
# The packages folder can be ignored because of Package Restore
|
|
||||||
**/[Pp]ackages/*
|
|
||||||
# except build/, which is used as an MSBuild target.
|
|
||||||
!**/[Pp]ackages/build/
|
|
||||||
# Uncomment if necessary however generally it will be regenerated when needed
|
|
||||||
#!**/[Pp]ackages/repositories.config
|
|
||||||
# NuGet v3's project.json files produces more ignorable files
|
|
||||||
*.nuget.props
|
|
||||||
*.nuget.targets
|
|
||||||
|
|
||||||
# Microsoft Azure Build Output
|
|
||||||
csx/
|
|
||||||
*.build.csdef
|
|
||||||
|
|
||||||
# Microsoft Azure Emulator
|
|
||||||
ecf/
|
|
||||||
rcf/
|
|
||||||
|
|
||||||
# Windows Store app package directories and files
|
|
||||||
AppPackages/
|
|
||||||
BundleArtifacts/
|
|
||||||
Package.StoreAssociation.xml
|
|
||||||
_pkginfo.txt
|
|
||||||
*.appx
|
|
||||||
*.appxbundle
|
|
||||||
*.appxupload
|
|
||||||
|
|
||||||
# Visual Studio cache files
|
|
||||||
# files ending in .cache can be ignored
|
|
||||||
*.[Cc]ache
|
|
||||||
# but keep track of directories ending in .cache
|
|
||||||
!?*.[Cc]ache/
|
|
||||||
|
|
||||||
# Others
|
|
||||||
ClientBin/
|
|
||||||
~$*
|
|
||||||
*~
|
|
||||||
*.dbmdl
|
|
||||||
*.dbproj.schemaview
|
|
||||||
*.jfm
|
|
||||||
*.pfx
|
|
||||||
*.publishsettings
|
|
||||||
orleans.codegen.cs
|
|
||||||
|
|
||||||
# Including strong name files can present a security risk
|
|
||||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
|
||||||
#*.snk
|
|
||||||
|
|
||||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
|
||||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
|
||||||
#bower_components/
|
|
||||||
|
|
||||||
# RIA/Silverlight projects
|
|
||||||
Generated_Code/
|
|
||||||
|
|
||||||
# Backup & report files from converting an old project file
|
|
||||||
# to a newer Visual Studio version. Backup files are not needed,
|
|
||||||
# because we have git ;-)
|
|
||||||
_UpgradeReport_Files/
|
|
||||||
Backup*/
|
|
||||||
UpgradeLog*.XML
|
|
||||||
UpgradeLog*.htm
|
|
||||||
ServiceFabricBackup/
|
|
||||||
*.rptproj.bak
|
|
||||||
|
|
||||||
# SQL Server files
|
|
||||||
*.mdf
|
|
||||||
*.ldf
|
|
||||||
*.ndf
|
|
||||||
|
|
||||||
# Business Intelligence projects
|
|
||||||
*.rdl.data
|
|
||||||
*.bim.layout
|
|
||||||
*.bim_*.settings
|
|
||||||
*.rptproj.rsuser
|
|
||||||
*- [Bb]ackup.rdl
|
|
||||||
*- [Bb]ackup ([0-9]).rdl
|
|
||||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
|
||||||
|
|
||||||
# Microsoft Fakes
|
|
||||||
FakesAssemblies/
|
|
||||||
|
|
||||||
# GhostDoc plugin setting file
|
|
||||||
*.GhostDoc.xml
|
|
||||||
|
|
||||||
# Node.js Tools for Visual Studio
|
|
||||||
.ntvs_analysis.dat
|
|
||||||
node_modules/
|
|
||||||
|
|
||||||
# Visual Studio 6 build log
|
|
||||||
*.plg
|
|
||||||
|
|
||||||
# Visual Studio 6 workspace options file
|
|
||||||
*.opt
|
|
||||||
|
|
||||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
|
||||||
*.vbw
|
|
||||||
|
|
||||||
# Visual Studio LightSwitch build output
|
|
||||||
**/*.HTMLClient/GeneratedArtifacts
|
|
||||||
**/*.DesktopClient/GeneratedArtifacts
|
|
||||||
**/*.DesktopClient/ModelManifest.xml
|
|
||||||
**/*.Server/GeneratedArtifacts
|
|
||||||
**/*.Server/ModelManifest.xml
|
|
||||||
_Pvt_Extensions
|
|
||||||
|
|
||||||
# Paket dependency manager
|
|
||||||
.paket/paket.exe
|
|
||||||
paket-files/
|
|
||||||
|
|
||||||
# FAKE - F# Make
|
|
||||||
.fake/
|
|
||||||
|
|
||||||
# CodeRush personal settings
|
|
||||||
.cr/personal
|
|
||||||
|
|
||||||
# Python Tools for Visual Studio (PTVS)
|
|
||||||
__pycache__/
|
|
||||||
*.pyc
|
|
||||||
|
|
||||||
# Cake - Uncomment if you are using it
|
|
||||||
# tools/**
|
|
||||||
# !tools/packages.config
|
|
||||||
|
|
||||||
# Tabs Studio
|
|
||||||
*.tss
|
|
||||||
|
|
||||||
# Telerik's JustMock configuration file
|
|
||||||
*.jmconfig
|
|
||||||
|
|
||||||
# BizTalk build output
|
|
||||||
*.btp.cs
|
|
||||||
*.btm.cs
|
|
||||||
*.odx.cs
|
|
||||||
*.xsd.cs
|
|
||||||
|
|
||||||
# OpenCover UI analysis results
|
|
||||||
OpenCover/
|
|
||||||
|
|
||||||
# Azure Stream Analytics local run output
|
|
||||||
ASALocalRun/
|
|
||||||
|
|
||||||
# MSBuild Binary and Structured Log
|
|
||||||
*.binlog
|
|
||||||
|
|
||||||
# NVidia Nsight GPU debugger configuration file
|
|
||||||
*.nvuser
|
|
||||||
|
|
||||||
# MFractors (Xamarin productivity tool) working folder
|
|
||||||
.mfractor/
|
|
||||||
|
|
||||||
# Local History for Visual Studio
|
|
||||||
.localhistory/
|
|
||||||
|
|
||||||
# BeatPulse healthcheck temp database
|
|
||||||
healthchecksdb
|
|
||||||
|
|
||||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
|
||||||
MigrationBackup/
|
|
||||||
|
|
||||||
# Ionide (cross platform F# VS Code tools) working folder
|
|
||||||
.ionide/
|
|
||||||
|
|
||||||
# Fody - auto-generated XML schema
|
|
||||||
FodyWeavers.xsd
|
|
||||||
|
|
||||||
##
|
|
||||||
## Visual studio for Mac
|
|
||||||
##
|
|
||||||
|
|
||||||
|
|
||||||
# globs
|
|
||||||
Makefile.in
|
|
||||||
*.userprefs
|
|
||||||
*.usertasks
|
|
||||||
config.make
|
|
||||||
config.status
|
|
||||||
aclocal.m4
|
|
||||||
install-sh
|
|
||||||
autom4te.cache/
|
|
||||||
*.tar.gz
|
|
||||||
tarballs/
|
|
||||||
test-results/
|
|
||||||
|
|
||||||
# Mac bundle stuff
|
|
||||||
*.dmg
|
|
||||||
*.app
|
|
||||||
|
|
||||||
# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
|
|
||||||
# General
|
|
||||||
.DS_Store
|
|
||||||
.AppleDouble
|
|
||||||
.LSOverride
|
|
||||||
|
|
||||||
# Icon must end with two \r
|
|
||||||
Icon
|
|
||||||
|
|
||||||
|
|
||||||
# Thumbnails
|
|
||||||
._*
|
|
||||||
|
|
||||||
# Files that might appear in the root of a volume
|
|
||||||
.DocumentRevisions-V100
|
|
||||||
.fseventsd
|
|
||||||
.Spotlight-V100
|
|
||||||
.TemporaryItems
|
|
||||||
.Trashes
|
|
||||||
.VolumeIcon.icns
|
|
||||||
.com.apple.timemachine.donotpresent
|
|
||||||
|
|
||||||
# Directories potentially created on remote AFP share
|
|
||||||
.AppleDB
|
|
||||||
.AppleDesktop
|
|
||||||
Network Trash Folder
|
|
||||||
Temporary Items
|
|
||||||
.apdisk
|
|
||||||
|
|
||||||
# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
|
|
||||||
# Windows thumbnail cache files
|
|
||||||
Thumbs.db
|
|
||||||
ehthumbs.db
|
|
||||||
ehthumbs_vista.db
|
|
||||||
|
|
||||||
# Dump file
|
|
||||||
*.stackdump
|
|
||||||
|
|
||||||
# Folder config file
|
|
||||||
[Dd]esktop.ini
|
|
||||||
|
|
||||||
# Recycle Bin used on file shares
|
|
||||||
$RECYCLE.BIN/
|
|
||||||
|
|
||||||
# Windows Installer files
|
|
||||||
*.cab
|
|
||||||
*.msi
|
|
||||||
*.msix
|
|
||||||
*.msm
|
|
||||||
*.msp
|
|
||||||
|
|
||||||
# Windows shortcuts
|
|
||||||
*.lnk
|
|
||||||
|
|
||||||
# JetBrains Rider
|
|
||||||
.idea/
|
|
||||||
*.sln.iml
|
|
||||||
|
|
||||||
##
|
|
||||||
## Visual Studio Code
|
|
||||||
##
|
|
||||||
.vscode/*
|
|
||||||
!.vscode/settings.json
|
|
||||||
!.vscode/tasks.json
|
|
||||||
!.vscode/launch.json
|
|
||||||
!.vscode/extensions.json
|
|
||||||
|
|
||||||
# CMAKE
|
|
||||||
build/
|
|
||||||
8
TTT/.vscode/settings.json
vendored
8
TTT/.vscode/settings.json
vendored
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"files.associations": {
|
|
||||||
"xstring": "cpp",
|
|
||||||
"xutility": "cpp",
|
|
||||||
"map": "cpp",
|
|
||||||
"vector": "cpp"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
28
TTT/.vscode/tasks.json
vendored
28
TTT/.vscode/tasks.json
vendored
@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"type": "cppbuild",
|
|
||||||
"label": "C/C++: cl.exe build active file",
|
|
||||||
"command": "cl.exe",
|
|
||||||
"args": [
|
|
||||||
"/Zi",
|
|
||||||
"/EHsc",
|
|
||||||
"/nologo",
|
|
||||||
"/Fe${fileDirname}\\${fileBasenameNoExtension}.exe",
|
|
||||||
"${file}"
|
|
||||||
],
|
|
||||||
"options": {
|
|
||||||
"cwd": "${fileDirname}"
|
|
||||||
},
|
|
||||||
"problemMatcher": [
|
|
||||||
"$msCompile"
|
|
||||||
],
|
|
||||||
"group": {
|
|
||||||
"kind": "build",
|
|
||||||
"isDefault": true
|
|
||||||
},
|
|
||||||
"detail": "Task generated by Debugger."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": "2.0.0"
|
|
||||||
}
|
|
||||||
221
TTT/App.cpp
221
TTT/App.cpp
@ -1,221 +0,0 @@
|
|||||||
#include "App.hh"
|
|
||||||
|
|
||||||
namespace TTT
|
|
||||||
{
|
|
||||||
|
|
||||||
App::App(int width, int height) :
|
|
||||||
m_WindowHeight(height), m_WindowWidth(width), m_Close(0), m_GridHeight(5), m_GridWidth(5)
|
|
||||||
{
|
|
||||||
// returns zero on success else non-zero
|
|
||||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
|
|
||||||
SDL_LogCritical(0,"error initializing SDL: %s\n", SDL_GetError());
|
|
||||||
}
|
|
||||||
m_Window = SDL_CreateWindow("Tic-Tac-Toe", // creates a window
|
|
||||||
SDL_WINDOWPOS_CENTERED,
|
|
||||||
SDL_WINDOWPOS_CENTERED,
|
|
||||||
m_WindowHeight, m_WindowHeight, 0);
|
|
||||||
|
|
||||||
// Initialize grid. Look at this transposed.
|
|
||||||
auto pair = std::pair<SDL_Rect, TEXTURE>();
|
|
||||||
pair.second = WALL;
|
|
||||||
m_Grid = {
|
|
||||||
{ pair, pair, pair, pair, pair },
|
|
||||||
{ pair, pair, pair, pair, pair },
|
|
||||||
{ pair, pair, pair, pair, pair },
|
|
||||||
{ pair, pair, pair, pair, pair },
|
|
||||||
{ pair, pair, pair, pair, pair }
|
|
||||||
};
|
|
||||||
|
|
||||||
m_Grid[0][0].second = NONE;
|
|
||||||
|
|
||||||
|
|
||||||
// triggers the program that controls
|
|
||||||
// your graphics hardware and sets flags
|
|
||||||
Uint32 render_flags = SDL_RENDERER_ACCELERATED;
|
|
||||||
|
|
||||||
// creates a renderer to render our images
|
|
||||||
m_Renderer = SDL_CreateRenderer(m_Window, -1, render_flags);
|
|
||||||
|
|
||||||
// please provide a path for your image
|
|
||||||
SDL_Surface* wall_surface = IMG_Load("./res/TTT_WALL.png");
|
|
||||||
SDL_Surface* symbol_x_surface = IMG_Load("./res/SYMBOL_X.png");
|
|
||||||
SDL_Surface* symbol_o_surface = IMG_Load("./res/SYMBOL_O.png");
|
|
||||||
|
|
||||||
// loads image to our graphics hardware memory.
|
|
||||||
m_Textures[TTT::WALL] = SDL_CreateTextureFromSurface(m_Renderer, wall_surface);
|
|
||||||
m_Textures[TTT::SYMBOL_X] = SDL_CreateTextureFromSurface(m_Renderer, symbol_x_surface);
|
|
||||||
m_Textures[TTT::SYMBOL_O] = SDL_CreateTextureFromSurface(m_Renderer, symbol_o_surface);
|
|
||||||
|
|
||||||
// clears surfaces from main-memory.
|
|
||||||
SDL_FreeSurface(wall_surface);
|
|
||||||
SDL_FreeSurface(symbol_x_surface);
|
|
||||||
SDL_FreeSurface(symbol_o_surface);
|
|
||||||
|
|
||||||
// let us control our image position
|
|
||||||
// so that we can move it with our keyboard.
|
|
||||||
SDL_Rect dest;
|
|
||||||
SDL_Rect dest2;
|
|
||||||
// connects our texture with dest to control position
|
|
||||||
SDL_QueryTexture(m_Textures[TTT::WALL], NULL, NULL, &dest.w, &dest.h);
|
|
||||||
SDL_QueryTexture(m_Textures[TTT::SYMBOL_O], NULL, NULL, &dest2.w, &dest2.h);
|
|
||||||
|
|
||||||
// adjust height and width of our image box.
|
|
||||||
// dest.w /= 6;
|
|
||||||
// dest.h /= 6;
|
|
||||||
|
|
||||||
// sets initial x-position of object
|
|
||||||
dest.x = (m_WindowWidth - dest.w) / 2;
|
|
||||||
dest2.x = (m_WindowWidth - dest2.w) / 2;
|
|
||||||
// sets initial y-position of object
|
|
||||||
dest.y = (m_WindowHeight - dest.h) / 2;
|
|
||||||
dest2.y = (m_WindowHeight - dest2.h) / 2;
|
|
||||||
|
|
||||||
DrawGrid();
|
|
||||||
|
|
||||||
// speed of box
|
|
||||||
int speed = 300;
|
|
||||||
|
|
||||||
// animation loop
|
|
||||||
while (!m_Close) {
|
|
||||||
SDL_Event event;
|
|
||||||
|
|
||||||
// Events management
|
|
||||||
while (SDL_PollEvent(&event)) {
|
|
||||||
switch (event.type) {
|
|
||||||
|
|
||||||
case SDL_QUIT:
|
|
||||||
// handling of close button
|
|
||||||
m_Close = 1;
|
|
||||||
break;
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
|
||||||
switch (event.button.button)
|
|
||||||
{
|
|
||||||
case SDL_BUTTON(SDL_BUTTON_LEFT):
|
|
||||||
SDL_LogInfo(0, "LEFT CLICK (%d, %d)\n", event.motion.x, event.motion.y);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_KEYDOWN:
|
|
||||||
// keyboard API for key pressed
|
|
||||||
switch (event.key.keysym.scancode) {
|
|
||||||
case SDL_SCANCODE_ESCAPE:
|
|
||||||
m_Close = 1;
|
|
||||||
break;
|
|
||||||
case SDL_SCANCODE_W:
|
|
||||||
case SDL_SCANCODE_UP:
|
|
||||||
dest.y -= speed / 30;
|
|
||||||
break;
|
|
||||||
case SDL_SCANCODE_A:
|
|
||||||
case SDL_SCANCODE_LEFT:
|
|
||||||
dest.x -= speed / 30;
|
|
||||||
break;
|
|
||||||
case SDL_SCANCODE_S:
|
|
||||||
case SDL_SCANCODE_DOWN:
|
|
||||||
dest.y += speed / 30;
|
|
||||||
break;
|
|
||||||
case SDL_SCANCODE_D:
|
|
||||||
case SDL_SCANCODE_RIGHT:
|
|
||||||
dest.x += speed / 30;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// right boundary
|
|
||||||
if (dest.x + dest.w > 1000)
|
|
||||||
dest.x = 1000 - dest.w;
|
|
||||||
|
|
||||||
// left boundary
|
|
||||||
if (dest.x < 0)
|
|
||||||
dest.x = 0;
|
|
||||||
|
|
||||||
// bottom boundary
|
|
||||||
if (dest.y + dest.h > 1000)
|
|
||||||
dest.y = 1000 - dest.h;
|
|
||||||
|
|
||||||
// upper boundary
|
|
||||||
if (dest.y < 0)
|
|
||||||
dest.y = 0;
|
|
||||||
|
|
||||||
// clears the screen
|
|
||||||
SDL_RenderClear(m_Renderer);
|
|
||||||
SDL_RenderCopy(m_Renderer, m_Textures[TTT::WALL], NULL, &dest);
|
|
||||||
SDL_RenderCopy(m_Renderer, m_Textures[TTT::SYMBOL_O], NULL, &dest2);
|
|
||||||
GridRenderCopy();
|
|
||||||
|
|
||||||
// triggers the double buffers
|
|
||||||
// for multiple rendering
|
|
||||||
SDL_RenderPresent(m_Renderer);
|
|
||||||
|
|
||||||
// calculates to 60 fps
|
|
||||||
SDL_Delay(1000 / 60);
|
|
||||||
}
|
|
||||||
|
|
||||||
// destroy texture
|
|
||||||
SDL_DestroyTexture(m_Textures[TTT::SYMBOL_O]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void App::DrawToGridCell(TEXTURE textureId, int x, int y)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void App::DrawGrid()
|
|
||||||
{
|
|
||||||
int CELL_WIDTH = 64;
|
|
||||||
int CELL_HEIGHT = 64;
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i <= m_GridWidth - 1; ++i)
|
|
||||||
{
|
|
||||||
for (int j = 0; j <= m_GridHeight - 1; ++j)
|
|
||||||
{
|
|
||||||
// connects our texture with dest to control position
|
|
||||||
SDL_QueryTexture(
|
|
||||||
m_Textures[m_Grid[i][j].second], NULL, NULL,
|
|
||||||
&m_Grid[i][j].first.w, &m_Grid[i][j].first.h);
|
|
||||||
|
|
||||||
// m_Grid[i][j].first.x = (m_WindowWidth - m_Grid[i][j].first.w) / 2;
|
|
||||||
// m_Grid[i][j].first.y = (m_WindowHeight - m_Grid[i][j].first.h) / 2;
|
|
||||||
|
|
||||||
m_Grid[i][j].first.w = CELL_WIDTH;
|
|
||||||
m_Grid[i][j].first.h = CELL_HEIGHT;
|
|
||||||
m_Grid[i][j].first.x = m_Grid[i][j].first.w * i;
|
|
||||||
m_Grid[i][j].first.y = m_Grid[i][j].first.h * j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void App::UpdateGridHover(int x, int y)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void App::GridRenderCopy()
|
|
||||||
{
|
|
||||||
for (int i = 0; i <= m_GridWidth - 1; ++i)
|
|
||||||
{
|
|
||||||
for (int j = 0; j <= m_GridHeight - 1; ++j)
|
|
||||||
{
|
|
||||||
SDL_RenderCopy(m_Renderer, m_Textures[m_Grid[i][j].second], NULL, &m_Grid[i][j].first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
App::~App()
|
|
||||||
{
|
|
||||||
|
|
||||||
// destroy renderer
|
|
||||||
SDL_DestroyRenderer(m_Renderer);
|
|
||||||
// destroy window
|
|
||||||
SDL_DestroyWindow(m_Window);
|
|
||||||
// close SDL
|
|
||||||
SDL_Quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace TTT
|
|
||||||
47
TTT/App.hh
47
TTT/App.hh
@ -1,47 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <SDL2/SDL_image.h>
|
|
||||||
#include <SDL2/SDL_timer.h>
|
|
||||||
#include <SDL2/SDL2_gfxPrimitives.h>
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace TTT
|
|
||||||
{
|
|
||||||
|
|
||||||
enum TEXTURE {
|
|
||||||
NONE,
|
|
||||||
WALL,
|
|
||||||
SYMBOL_X,
|
|
||||||
SYMBOL_O
|
|
||||||
};
|
|
||||||
|
|
||||||
class App
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
int m_WindowWidth;
|
|
||||||
int m_WindowHeight;
|
|
||||||
int m_Close;
|
|
||||||
int m_GridHeight;
|
|
||||||
int m_GridWidth;
|
|
||||||
SDL_Window* m_Window;
|
|
||||||
SDL_Renderer* m_Renderer;
|
|
||||||
SDL_Surface* m_Surface;
|
|
||||||
std::map<TEXTURE,SDL_Texture*> m_Textures;
|
|
||||||
std::vector<std::vector<std::pair<SDL_Rect, TEXTURE>>> m_Grid;
|
|
||||||
|
|
||||||
public:
|
|
||||||
App(int width, int height);
|
|
||||||
void DrawToGridCell(TEXTURE textureId, int x, int y);
|
|
||||||
void DrawGrid();
|
|
||||||
void UpdateGridHover(int x, int y);
|
|
||||||
void GridRenderCopy();
|
|
||||||
~App();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace TTT
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 8.4 KiB |
@ -1,23 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.0.0)
|
|
||||||
project(Tic-Tac-Toe VERSION 0.1.0)
|
|
||||||
|
|
||||||
find_package(SDL2 CONFIG REQUIRED)
|
|
||||||
find_package(SDL2_image CONFIG REQUIRED)
|
|
||||||
find_package(sdl2-gfx CONFIG REQUIRED)
|
|
||||||
|
|
||||||
add_executable(Tic-Tac-Toe main.cpp App.cpp App.hh)
|
|
||||||
|
|
||||||
target_link_libraries(Tic-Tac-Toe
|
|
||||||
PRIVATE
|
|
||||||
$<TARGET_NAME_IF_EXISTS:SDL2::SDL2main>
|
|
||||||
$<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>
|
|
||||||
)
|
|
||||||
target_link_libraries(Tic-Tac-Toe
|
|
||||||
PRIVATE
|
|
||||||
$<IF:$<TARGET_EXISTS:SDL2_image::SDL2_image>,SDL2_image::SDL2_image,SDL2_image::SDL2_image-static>
|
|
||||||
)
|
|
||||||
target_link_libraries(Tic-Tac-Toe PRIVATE SDL2::SDL2_gfx)
|
|
||||||
|
|
||||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
|
||||||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
|
||||||
include(CPack)
|
|
||||||
BIN
TTT/SYMBOL_O.png
BIN
TTT/SYMBOL_O.png
Binary file not shown.
|
Before Width: | Height: | Size: 512 B |
BIN
TTT/SYMBOL_X.png
BIN
TTT/SYMBOL_X.png
Binary file not shown.
|
Before Width: | Height: | Size: 498 B |
BIN
TTT/TTT_WALL.png
BIN
TTT/TTT_WALL.png
Binary file not shown.
|
Before Width: | Height: | Size: 618 B |
11
TTT/main.cpp
11
TTT/main.cpp
@ -1,11 +0,0 @@
|
|||||||
#include "App.hh"
|
|
||||||
|
|
||||||
using namespace TTT;
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
|
|
||||||
App app = App(1000, 1000);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user