Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions games/tetriz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
89 changes: 89 additions & 0 deletions games/tetriz/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"cmake.generator": "Ninja",
"cmake.outputLogEncoding": "auto",
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"files.associations": {
"iostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"span": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeinfo": "cpp",
"variant": "cpp",
"codecvt": "cpp",
"map": "cpp",
"ranges": "cpp",
"fstream": "cpp",
"cstring": "cpp",
"format": "cpp",
"forward_list": "cpp",
"ios": "cpp",
"list": "cpp",
"locale": "cpp",
"queue": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp"
}
}
14 changes: 14 additions & 0 deletions games/tetriz/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.22)
project(tetriz)

set(CMAKE_CXX_STANDARD 20)

configure_file( ${PROJECT_SOURCE_DIR}/tetriz.map ${PROJECT_BINARY_DIR})

aux_source_directory(. src)
add_executable(tetriz ${src})

if(MSVC)
target_compile_options(tetriz PRIVATE "/utf-8")
set_property(TARGET tetriz PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
Binary file added games/tetriz/Tetriz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions games/tetriz/color.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

#pragma once

enum class Color
{
Cyan = 14,
Red = 9,
Orange = 214,
Yellow = 11,
Green = 2,
Blue = 12,
Purple = 5,
White = 15,
Black = 0,
Gray = 8
};
50 changes: 50 additions & 0 deletions games/tetriz/config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#-- ARCADE MACHINE GAME CONFIG FILE --#
#-- For THOTH TECH - Splashkit Crew - Applications Team
#--------------------------------------------------------------------
#-- File: config.txt
#-- Description: Configuration data for Arcade Machine games
#--------------------------------------------------------------------
#-- Maintenance Log --
#--------------------------------------------------------------------
# Task | Who | Date | Comments
#-----------+---------+----------+-----------------------------------
# Sprint 1 | AGEORGE | 20220326 | Created
#-----------+---------+----------+-----------------------------------
# Sprint 2 | AGEORGE | 20220511 | Added Description
#-----------+---------+----------+-----------------------------------
# Sprint 3 | AGEORGE | 20220828 | Added win, linux and macos params
#-----------+---------+----------+-----------------------------------

#--------------------------------------------------------------------
# PLEASE ONLY EDIT CONTENT AFTER THE "=" SIGN FOR EACH CONFIGURATION SETTING
#--------------------------------------------------------------------

# The title of your game (eg. Super Mario)
title=Tetriz

# The name of the author (eg. Jane Doe)
author=WEI ZHANG

# The genre of your game (eg. Platformer)
genre=Puzzle

# A Description of your game
description=A modern terminal-based Tetris game built with C++20. Features classic Tetris gameplay with hold system, next piece preview, pause/resume functionality, and responsive arcade-style controls. Cross-platform support for Linux and Windows.

# A classification rating to advise the nature of the content (eg. MA 15+)
rating=E

# Programming language the game is written in (eg. C++)
language=C++

# Path to your game thumbnail image (eg. images/icon.png)
image=Tetriz.png

# Location of git repo (eg. https://github.com/thoth-tech/arcade-games)
repository=https://github.com/ZGT23/arcade-games

# [Optional] Uncomment to include path to the game executable (game.exe)


# [Optional] Uncomment to include specific compile commands - if you have a specific compile command (eg. 'make', 'skm g++ *.cpp -lstd++')
#compile-command=skm g++ *.cpp
109 changes: 109 additions & 0 deletions games/tetriz/control.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include "control.h"
#include "define.h"
#include "game.h"
namespace gm
{
char command;

std::map<char, std::function<void()>> comm_func{
{KEY_ESCAPE, command_quit},
{KEY_W, command_pause},
{KEY_S, command_down},
{KEY_A, command_left},
{KEY_D, command_right},
{KEY_R, command_reset},
{KEY_F, command_drop},
{KEY_T, command_rotate_L},
{KEY_G, command_rotate_2},
{KEY_Y, command_hold},
{KEY_H, command_help},
};
#ifdef __linux__
char getch()
{
char c;
struct termios old, cur;
tcgetattr(0, &cur);
old = cur;
cfmakeraw(&cur);
tcsetattr(0, 0, &cur);
c = getchar();
tcsetattr(0, 0, &old);
return c;
}
#endif

void key_event()
{
while (running)
{
command = getch();
if (comm_func.find(command) != comm_func.end())
comm_func[command]();
}
}

void start_listener()
{
static std::jthread t(key_event);
}

void command_quit()
{
quit();
}

void command_rotate_R()
{
rotate(1);
}
void command_rotate_L()
{
rotate(3);
}
void command_rotate_2()
{
rotate(2);
}

void command_left()
{
left();
}

void command_right()
{
right();
}

void command_down()
{
down();
}

void command_drop()
{
drop();
}

void command_hold()
{
hold();
}

void command_reset()
{
reset();
}

void command_help()
{
help();
}

void command_pause()
{
pause();
}

} // namespace gm
24 changes: 24 additions & 0 deletions games/tetriz/control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#pragma once

namespace gm
{
extern char command;
void key_event();
void start_listener();

// 键盘命令函数
void command_quit();
void command_rotate_R();
void command_rotate_L();
void command_rotate_2();
void command_left();
void command_right();
void command_down();
void command_drop();
void command_hold();
void command_reset();
void command_help();
void command_pause();

} // namespace gm
64 changes: 64 additions & 0 deletions games/tetriz/define.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

#pragma once
#include <iostream>
#include <chrono>
#include <string>
#include <thread>
#include <map>
#include <functional>
#include <locale>
#include <codecvt>
#include <vector>
#include <memory>
#include <cassert>
#include <ranges>
#include <sstream>
#include <ostream>
#include <queue>
#include <fstream>
#include <cmath>
#include <iomanip>

#ifdef __linux__
#include <termios.h>
#include <sys/ioctl.h>
#elif _WIN32
#include <conio.h>
#include <windows.h>
#endif

using namespace std::chrono_literals;

#define KEY_W 'w'
#define KEY_S 's'
#define KEY_A 'a'
#define KEY_D 'd'
#define KEY_R 'r'
#define KEY_F 'f'
#define KEY_T 't'
#define KEY_G 'g'
#define KEY_Y 'y'
#define KEY_H 'h'


#ifdef __linux__
#define KEY_UP 65
#define KEY_DOWN 66
#define KEY_LEFT 68
#define KEY_RIGHT 67
#elif _WIN32
#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_LEFT 75
#define KEY_RIGHT 77
#endif

#define KEY_ENTER 13
#define KEY_BACKSPACE 127
#define KEY_ESCAPE 27
#define KEY_SPACE 32

using Matrix = std::vector<std::vector<int>>;
using Tetromino = std::vector<std::vector<std::pair<int, int>>>;
using Offset = std::vector<std::vector<std::pair<int, int>>>;
using std::ranges::views::iota;
Loading