Просмотр исходного кода

remove duplicated app (local player only)

app got no updates and no online support
MX 1 год назад
Родитель
Сommit
86b0e95b2f

+ 0 - 1
ReadMe.md

@@ -146,7 +146,6 @@ The Flipper and its community wouldn't be as rich as it is without your contribu
 | T-rex game | ![Games Badge] | [by Rrycbarm](https://github.com/Rrycbarm/t-rex-runner) |  | [![UFW Badge]](https://lab.flipper.net/apps/t_rex_runner) |
 | TAMA P1 | ![Games Badge] | [by GMMan & DroomOne](https://github.com/GMMan/flipperzero-tamagotch-p1) | requires [this rom](https://tinyurl.com/tamap1) IN `tama_p1` folder on SD renamed as `rom.bin` to make it work. - Modified to allow saving game state by [DroomOne](https://github.com/DroomOne/flipperzero-tamagotch-p1) - Mute mode & settings by [Round-Pi](https://github.com/Round-Pi/flipperzero-tamagotch-p1) | ![None Badge] |
 | Tanks Game | ![Games Badge] | [by alexgr13](https://github.com/alexgr13/flipperzero-firmware/tree/fork/dev/applications/tanks-game) | Fixes for latest subghz changes **by @Sil333033** | ![None Badge] |
-| Tic-Tac-Toe Multi | ![Games Badge] | [by RouNNdeL](https://github.com/RouNNdeL/flipper-tictactoe-multi) |  | [![UFW Badge]](https://lab.flipper.net/apps/ttt_multi) |
 | Video Poker | ![Games Badge] | [by PixlEmly](https://github.com/PixlEmly/flipperzero-firmware-testing/blob/420/applications/VideoPoker/poker.c) |  | [![UFW Badge]](https://lab.flipper.net/apps/videopoker) |
 | Yatzee | ![Games Badge] | [by emfleak](https://github.com/emfleak/flipperzero-yatzee) |  | [![UFW Badge]](https://lab.flipper.net/apps/yatzee) |
 | Secret Toggle | ![Games Badge] | [by nostrumuva](https://github.com/nostrumuva/secret_toggle) |  | [![Author Badge]](https://lab.flipper.net/apps/secret_toggle) |

+ 0 - 16
apps_source_code/flipper-tictactoe-multi/application.fam

@@ -1,16 +0,0 @@
-App(
-    appid="ttt_multi",
-    name="Tic-Tac-Toe Multi",
-    apptype=FlipperAppType.EXTERNAL,
-    entry_point="ttt_multi_app",
-    requires=["gui"],
-    stack_size=1 * 1024,
-    order=40,
-    fap_icon="assets/tictactoe_10px.png",
-    fap_category="Games",
-    fap_icon_assets="assets",
-    fap_author="@RouNNdeL",
-    fap_weburl="https://github.com/RouNNdeL/flipper-tictactoe-multi",
-    fap_version="1.1",
-    fap_description="Multiplayer Tic-Tac-Toe game",
-)

BIN
apps_source_code/flipper-tictactoe-multi/assets/tictactoe_10px.png


+ 0 - 208
apps_source_code/flipper-tictactoe-multi/helpers/ttt_multi_game.c

@@ -1,208 +0,0 @@
-#include "ttt_multi_game.h"
-
-struct TttMultiGame {
-    TttMultiGameState state;
-    TttMultiGameResult result;
-
-    uint8_t board[3][3];
-};
-
-void ttt_multi_game_move_reset(TttMultiGameMove* move) {
-    furi_assert(move);
-
-    // make the move invalid
-    move->player = TttMultiGamePlayerNone;
-    move->x = 0xff;
-    move->y = 0xff;
-}
-
-void ttt_multi_game_move_copy(TttMultiGameMove* dst, const TttMultiGameMove* src) {
-    furi_assert(dst);
-    furi_assert(src);
-
-    dst->player = src->player;
-    dst->x = src->x;
-    dst->y = src->y;
-}
-
-TttMultiGameMove* ttt_multi_game_move_alloc() {
-    TttMultiGameMove* move = malloc(sizeof(TttMultiGameMove));
-
-    ttt_multi_game_move_reset(move);
-
-    return move;
-}
-
-void ttt_multi_game_move_free(TttMultiGameMove* move) {
-    furi_assert(move);
-
-    free(move);
-}
-
-void ttt_multi_game_reset(TttMultiGame* game) {
-    furi_assert(game);
-
-    game->state = TttMultiGameStateTurnX;
-    game->result = TttMultiGameResultNone;
-
-    for(uint8_t i = 0; i < 3; i++) {
-        for(uint8_t j = 0; j < 3; j++) {
-            game->board[i][j] = TttMultiGamePlayerNone;
-        }
-    }
-}
-
-TttMultiGameState ttt_multi_game_get_state(TttMultiGame* game) {
-    furi_assert(game);
-    return game->state;
-}
-
-TttMultiGameResult ttt_multi_game_get_result(TttMultiGame* game) {
-    furi_assert(game);
-    if(game->state != TttMultiGameStateFinished) {
-        return TttMultiGameResultNone;
-    }
-
-    return game->result;
-}
-
-bool ttt_multi_game_is_draw(TttMultiGame* game) {
-    furi_assert(game);
-
-    for(uint8_t i = 0; i < 3; i++) {
-        for(uint8_t j = 0; j < 3; j++) {
-            if(game->board[i][j] == TttMultiGamePlayerNone) {
-                return false;
-            }
-        }
-    }
-
-    return true;
-}
-
-TttMultiGamePlayer ttt_multi_game_get_winner(TttMultiGame* game) {
-    furi_assert(game);
-
-    // Check rows
-    for(uint8_t i = 0; i < 3; i++) {
-        if(game->board[i][0] != TttMultiGamePlayerNone && game->board[i][0] == game->board[i][1] &&
-           game->board[i][1] == game->board[i][2]) {
-            return (TttMultiGamePlayer)game->board[i][0];
-        }
-    }
-
-    // Check columns
-    for(uint8_t i = 0; i < 3; i++) {
-        if(game->board[0][i] != TttMultiGamePlayerNone && game->board[0][i] == game->board[1][i] &&
-           game->board[1][i] == game->board[2][i]) {
-            return (TttMultiGamePlayer)game->board[0][i];
-        }
-    }
-
-    // Check diagonals
-    if(game->board[0][0] == game->board[1][1] && game->board[1][1] == game->board[2][2]) {
-        return (TttMultiGamePlayer)game->board[0][0];
-    }
-    if(game->board[0][2] == game->board[1][1] && game->board[1][1] == game->board[2][0]) {
-        return (TttMultiGamePlayer)game->board[0][2];
-    }
-
-    return TttMultiGamePlayerNone;
-}
-
-static void ttt_multi_game_update_result(TttMultiGame* game) {
-    furi_assert(game);
-
-    if(game->state == TttMultiGameStateFinished) {
-        return;
-    }
-
-    TttMultiGamePlayer winner = ttt_multi_game_get_winner(game);
-    if(winner != TttMultiGamePlayerNone) {
-        game->state = TttMultiGameStateFinished;
-        if(winner == TttMultiGamePlayerX) {
-            game->result = TttMultiGameResultXWin;
-        } else if(winner == TttMultiGamePlayerO) {
-            game->result = TttMultiGameResultOWin;
-        }
-
-        return;
-    }
-
-    if(ttt_multi_game_is_draw(game)) {
-        game->result = TttMultiGameResultDraw;
-        game->state = TttMultiGameStateFinished;
-    }
-}
-
-bool ttt_multi_game_is_move_valid(TttMultiGame* game, TttMultiGameMove* move) {
-    furi_assert(game);
-    furi_assert(move);
-
-    if(move->x > 2 || move->y > 2) {
-        return false;
-    }
-
-    if(move->player != ttt_multi_game_current_player(game)) {
-        return false;
-    }
-
-    if(game->board[move->x][move->y] != TttMultiGamePlayerNone) {
-        return false;
-    }
-
-    return true;
-}
-
-TttMultiGamePlayer ttt_multi_game_current_player(TttMultiGame* game) {
-    furi_assert(game);
-
-    if(game->state == TttMultiGameStateTurnX) {
-        return TttMultiGamePlayerX;
-    } else if(game->state == TttMultiGameStateTurnO) {
-        return TttMultiGamePlayerO;
-    }
-
-    return TttMultiGamePlayerNone;
-}
-
-void ttt_multi_game_swap_player(TttMultiGame* game) {
-    furi_assert(game);
-
-    if(game->state == TttMultiGameStateTurnX) {
-        game->state = TttMultiGameStateTurnO;
-    } else if(game->state == TttMultiGameStateTurnO) {
-        game->state = TttMultiGameStateTurnX;
-    }
-}
-
-void ttt_multi_game_make_move(TttMultiGame* game, TttMultiGameMove* move) {
-    furi_assert(game);
-    furi_assert(move);
-    furi_assert(ttt_multi_game_is_move_valid(game, move));
-
-    game->board[move->x][move->y] = (uint8_t)move->player;
-    ttt_multi_game_swap_player(game);
-    ttt_multi_game_update_result(game);
-}
-
-TttMultiGamePlayer ttt_multi_game_player_at(TttMultiGame* game, uint8_t x, uint8_t y) {
-    furi_assert(game);
-    furi_assert(x < 3);
-    furi_assert(y < 3);
-
-    return (TttMultiGamePlayer)game->board[x][y];
-}
-
-TttMultiGame* ttt_multi_game_alloc() {
-    TttMultiGame* game = malloc(sizeof(TttMultiGame));
-    ttt_multi_game_reset(game);
-
-    return game;
-}
-
-void ttt_multi_game_free(TttMultiGame* game) {
-    furi_assert(game);
-
-    free(game);
-}

+ 0 - 55
apps_source_code/flipper-tictactoe-multi/helpers/ttt_multi_game.h

@@ -1,55 +0,0 @@
-#include <furi.h>
-#include <stdint.h>
-
-typedef enum {
-    TttMultiGamePlayerNone = 0,
-    TttMultiGamePlayerX = 1,
-    TttMultiGamePlayerO = 2,
-} TttMultiGamePlayer;
-
-typedef enum {
-    TttMultiGameStateTurnO,
-    TttMultiGameStateTurnX,
-    TttMultiGameStateFinished
-} TttMultiGameState;
-
-typedef enum {
-    TttMultiGameResultXWin,
-    TttMultiGameResultOWin,
-    TttMultiGameResultDraw,
-    TttMultiGameResultNone
-} TttMultiGameResult;
-
-typedef struct TttMultiGame TttMultiGame;
-
-typedef struct {
-    TttMultiGamePlayer player;
-    uint8_t x;
-    uint8_t y;
-} TttMultiGameMove;
-
-TttMultiGameMove* ttt_multi_game_move_alloc();
-
-void ttt_multi_game_move_free(TttMultiGameMove* move);
-
-void ttt_multi_game_move_copy(TttMultiGameMove* dst, const TttMultiGameMove* src);
-
-TttMultiGame* ttt_multi_game_alloc();
-
-void ttt_multi_game_free(TttMultiGame* game);
-
-void ttt_multi_game_reset(TttMultiGame* game);
-
-void ttt_multi_game_swap_player(TttMultiGame* game);
-
-void ttt_multi_game_make_move(TttMultiGame* game, TttMultiGameMove* move);
-
-bool ttt_multi_game_is_move_valid(TttMultiGame* game, TttMultiGameMove* move);
-
-TttMultiGameState ttt_multi_game_get_state(TttMultiGame* game);
-
-TttMultiGameResult ttt_multi_game_get_result(TttMultiGame* game);
-
-TttMultiGamePlayer ttt_multi_game_player_at(TttMultiGame* game, uint8_t x, uint8_t y);
-
-TttMultiGamePlayer ttt_multi_game_current_player(TttMultiGame* game);

BIN
apps_source_code/flipper-tictactoe-multi/img/1.png


BIN
apps_source_code/flipper-tictactoe-multi/img/2.png


+ 0 - 30
apps_source_code/flipper-tictactoe-multi/scenes/ttt_multi_scene.c

@@ -1,30 +0,0 @@
-#include "ttt_multi_scene.h"
-
-// Generate scene on_enter handlers array
-#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
-void (*const ttt_multi_on_enter_handlers[])(void*) = {
-#include "ttt_multi_scene_config.h"
-};
-#undef ADD_SCENE
-
-// Generate scene on_event handlers array
-#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
-bool (*const ttt_multi_on_event_handlers[])(void* context, SceneManagerEvent event) = {
-#include "ttt_multi_scene_config.h"
-};
-#undef ADD_SCENE
-
-// Generate scene on_exit handlers array
-#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
-void (*const ttt_multi_on_exit_handlers[])(void* context) = {
-#include "ttt_multi_scene_config.h"
-};
-#undef ADD_SCENE
-
-// Initialize scene handlers configuration structure
-const SceneManagerHandlers ttt_multi_scene_handlers = {
-    .on_enter_handlers = ttt_multi_on_enter_handlers,
-    .on_event_handlers = ttt_multi_on_event_handlers,
-    .on_exit_handlers = ttt_multi_on_exit_handlers,
-    .scene_num = TttMultiSceneNum,
-};

+ 0 - 29
apps_source_code/flipper-tictactoe-multi/scenes/ttt_multi_scene.h

@@ -1,29 +0,0 @@
-#pragma once
-
-#include <gui/scene_manager.h>
-
-// Generate scene id and total number
-#define ADD_SCENE(prefix, name, id) TttMultiScene##id,
-typedef enum {
-#include "ttt_multi_scene_config.h"
-    TttMultiSceneNum,
-} TttMultiScene;
-#undef ADD_SCENE
-
-extern const SceneManagerHandlers ttt_multi_scene_handlers;
-
-// Generate scene on_enter handlers declaration
-#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
-#include "ttt_multi_scene_config.h"
-#undef ADD_SCENE
-
-// Generate scene on_event handlers declaration
-#define ADD_SCENE(prefix, name, id) \
-    bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
-#include "ttt_multi_scene_config.h"
-#undef ADD_SCENE
-
-// Generate scene on_exit handlers declaration
-#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
-#include "ttt_multi_scene_config.h"
-#undef ADD_SCENE

+ 0 - 2
apps_source_code/flipper-tictactoe-multi/scenes/ttt_multi_scene_config.h

@@ -1,2 +0,0 @@
-ADD_SCENE(ttt_multi, start, Start)
-ADD_SCENE(ttt_multi, local, Local)

+ 0 - 57
apps_source_code/flipper-tictactoe-multi/scenes/ttt_multi_scene_local.c

@@ -1,57 +0,0 @@
-#include "../ttt_multi.h"
-
-static void ttt_multi_scene_local_callback(void* context, TttMultiCustomEvent event) {
-    furi_assert(context);
-
-    TttMultiApp* ttt_multi = context;
-
-    view_dispatcher_send_custom_event(ttt_multi->view_dispatcher, event);
-}
-
-void ttt_multi_scene_local_on_enter(void* context) {
-    furi_assert(context);
-
-    TttMultiApp* ttt_multi = context;
-    TttMultiGameView* view = ttt_multi->game_view;
-
-    ttt_multi_game_view_set_callback(view, ttt_multi_scene_local_callback, ttt_multi);
-    ttt_multi_game_view_set_local_play(view);
-    view_dispatcher_switch_to_view(ttt_multi->view_dispatcher, TttMultiViewGame);
-}
-
-void ttt_multi_scene_local_on_exit(void* context) {
-    furi_assert(context);
-    TttMultiApp* ttt_multi = context;
-
-    ttt_multi_game_view_reset(ttt_multi->game_view);
-}
-
-bool ttt_multi_scene_local_on_event(void* context, SceneManagerEvent event) {
-    furi_assert(context);
-    TttMultiApp* ttt_multi = context;
-
-    if(event.type == SceneManagerEventTypeCustom) {
-        TttMultiCustomEvent custom_event = event.event;
-        switch(custom_event) {
-        case TttMultiCustomEventGameMove: {
-            TttMultiGameMove last_move = {};
-            ttt_multi_game_view_get_last_move(ttt_multi->game_view, &last_move);
-            ttt_multi_game_view_move(ttt_multi->game_view, &last_move);
-            return true;
-        }
-        case TttMultiCustomEventGameFinish: {
-            TttMultiGameResult result = ttt_multi_game_view_get_result(ttt_multi->game_view);
-            if(result == TttMultiGameResultDraw) {
-                notification_message(ttt_multi->notifications, &sequence_error);
-            } else {
-                notification_message(ttt_multi->notifications, &sequence_success);
-            }
-            return true;
-        }
-        default:
-            break;
-        }
-    }
-
-    return false;
-}

+ 0 - 61
apps_source_code/flipper-tictactoe-multi/scenes/ttt_multi_scene_start.c

@@ -1,61 +0,0 @@
-#include "../ttt_multi.h"
-
-enum SubmenuIndex { SubmenuIndexCreate, SubmenuIndexJoin, SubmenuIndexLocal };
-
-void ttt_multi_scene_start_submenu_callback(void* context, uint32_t index) {
-    TttMultiApp* ttt_multi = context;
-    view_dispatcher_send_custom_event(ttt_multi->view_dispatcher, index);
-}
-
-void ttt_multi_scene_start_on_enter(void* context) {
-    TttMultiApp* ttt_multi = context;
-
-    Submenu* submenu = ttt_multi->submenu;
-    submenu_add_item(
-        submenu,
-        "Create game",
-        SubmenuIndexCreate,
-        ttt_multi_scene_start_submenu_callback,
-        ttt_multi);
-    submenu_add_item(
-        submenu, "Join game", SubmenuIndexJoin, ttt_multi_scene_start_submenu_callback, ttt_multi);
-
-    submenu_add_item(
-        submenu,
-        "Local game",
-        SubmenuIndexLocal,
-        ttt_multi_scene_start_submenu_callback,
-        ttt_multi);
-
-    submenu_set_header(submenu, "Tic-Tac-Toe");
-
-    submenu_set_selected_item(
-        submenu, scene_manager_get_scene_state(ttt_multi->scene_manager, TttMultiSceneStart));
-    view_dispatcher_switch_to_view(ttt_multi->view_dispatcher, TttMultiViewMenu);
-}
-
-bool ttt_multi_scene_start_on_event(void* context, SceneManagerEvent event) {
-    TttMultiApp* ttt_multi = context;
-    bool consumed = false;
-
-    if(event.type == SceneManagerEventTypeCustom) {
-        if(event.event == SubmenuIndexCreate) {
-            // TODO: implement
-            consumed = true;
-        } else if(event.event == SubmenuIndexJoin) {
-            // TODO: implement
-            consumed = true;
-        } else if(event.event == SubmenuIndexLocal) {
-            scene_manager_next_scene(ttt_multi->scene_manager, TttMultiSceneLocal);
-            consumed = true;
-        }
-        scene_manager_set_scene_state(ttt_multi->scene_manager, TttMultiSceneStart, event.event);
-    }
-
-    return consumed;
-}
-
-void ttt_multi_scene_start_on_exit(void* context) {
-    TttMultiApp* ttt_multi = context;
-    submenu_reset(ttt_multi->submenu);
-}

+ 0 - 87
apps_source_code/flipper-tictactoe-multi/ttt_multi.c

@@ -1,87 +0,0 @@
-#include "ttt_multi.h"
-
-bool ttt_multi_custom_event_callback(void* context, uint32_t event) {
-    furi_assert(context);
-    TttMultiApp* ttt_multi = context;
-    return scene_manager_handle_custom_event(ttt_multi->scene_manager, event);
-}
-
-bool ttt_multi_back_event_callback(void* context) {
-    furi_assert(context);
-    TttMultiApp* ttt_multi = context;
-    return scene_manager_handle_back_event(ttt_multi->scene_manager);
-}
-
-void ttt_multi_tick_event_callback(void* context) {
-    furi_assert(context);
-    TttMultiApp* ttt_multi = context;
-    scene_manager_handle_tick_event(ttt_multi->scene_manager);
-}
-
-TttMultiApp* ttt_multi_alloc() {
-    TttMultiApp* ttt_multi = malloc(sizeof(TttMultiApp));
-
-    ttt_multi->view_dispatcher = view_dispatcher_alloc();
-    ttt_multi->scene_manager = scene_manager_alloc(&ttt_multi_scene_handlers, ttt_multi);
-
-    view_dispatcher_enable_queue(ttt_multi->view_dispatcher);
-    view_dispatcher_set_event_callback_context(ttt_multi->view_dispatcher, ttt_multi);
-    view_dispatcher_set_custom_event_callback(
-        ttt_multi->view_dispatcher, ttt_multi_custom_event_callback);
-    view_dispatcher_set_navigation_event_callback(
-        ttt_multi->view_dispatcher, ttt_multi_back_event_callback);
-    view_dispatcher_set_tick_event_callback(
-        ttt_multi->view_dispatcher, ttt_multi_tick_event_callback, 100);
-
-    ttt_multi->gui = furi_record_open(RECORD_GUI);
-    view_dispatcher_attach_to_gui(
-        ttt_multi->view_dispatcher, ttt_multi->gui, ViewDispatcherTypeFullscreen);
-
-    ttt_multi->notifications = furi_record_open(RECORD_NOTIFICATION);
-
-    ttt_multi->game_view = ttt_multi_game_view_alloc();
-    view_dispatcher_add_view(
-        ttt_multi->view_dispatcher,
-        TttMultiViewGame,
-        ttt_multi_game_get_view(ttt_multi->game_view));
-
-    ttt_multi->submenu = submenu_alloc();
-    view_dispatcher_add_view(
-        ttt_multi->view_dispatcher, TttMultiViewMenu, submenu_get_view(ttt_multi->submenu));
-
-    return ttt_multi;
-}
-
-void ttt_multi_free(TttMultiApp* ttt_multi) {
-    furi_assert(ttt_multi);
-
-    notification_message(ttt_multi->notifications, &sequence_blink_stop);
-    furi_record_close(RECORD_NOTIFICATION);
-    ttt_multi->notifications = NULL;
-
-    view_dispatcher_remove_view(ttt_multi->view_dispatcher, TttMultiViewGame);
-    ttt_multi_game_view_free(ttt_multi->game_view);
-
-    view_dispatcher_remove_view(ttt_multi->view_dispatcher, TttMultiViewMenu);
-    submenu_free(ttt_multi->submenu);
-
-    scene_manager_free(ttt_multi->scene_manager);
-    view_dispatcher_free(ttt_multi->view_dispatcher);
-
-    furi_record_close(RECORD_GUI);
-    ttt_multi->gui = NULL;
-
-    free(ttt_multi);
-}
-
-int32_t ttt_multi_app(void* p) {
-    UNUSED(p);
-    TttMultiApp* ttt_multi = ttt_multi_alloc();
-
-    scene_manager_next_scene(ttt_multi->scene_manager, TttMultiSceneStart);
-    view_dispatcher_run(ttt_multi->view_dispatcher);
-
-    ttt_multi_free(ttt_multi);
-
-    return 0;
-}

+ 0 - 36
apps_source_code/flipper-tictactoe-multi/ttt_multi.h

@@ -1,36 +0,0 @@
-#pragma once
-
-#include <furi.h>
-#include <gui/gui.h>
-#include <gui/view_dispatcher.h>
-#include <gui/scene_manager.h>
-#include <notification/notification_messages.h>
-
-#include <gui/modules/submenu.h>
-#include <gui/modules/popup.h>
-#include <gui/modules/loading.h>
-#include <gui/modules/text_input.h>
-#include <gui/modules/widget.h>
-
-#include <input/input.h>
-
-#include "scenes/ttt_multi_scene.h"
-#include "views/ttt_multi_game_view.h"
-
-#include "ttt_multi_icons.h"
-
-typedef struct {
-    Gui* gui;
-    NotificationApp* notifications;
-    ViewDispatcher* view_dispatcher;
-    SceneManager* scene_manager;
-
-    // Common views
-    Submenu* submenu;
-    TttMultiGameView* game_view;
-} TttMultiApp;
-
-typedef enum {
-    TttMultiViewMenu,
-    TttMultiViewGame,
-} TttMultiView;

+ 0 - 6
apps_source_code/flipper-tictactoe-multi/ttt_multi_custom_event.h

@@ -1,6 +0,0 @@
-typedef enum {
-    TttMultiCustomEventReserved = 100,
-
-    TttMultiCustomEventGameMove,
-    TttMultiCustomEventGameFinish,
-} TttMultiCustomEvent;

+ 0 - 416
apps_source_code/flipper-tictactoe-multi/views/ttt_multi_game_view.c

@@ -1,416 +0,0 @@
-#include "ttt_multi_game_view.h"
-
-struct TttMultiGameView {
-    View* view;
-};
-
-typedef struct {
-    TttMultiGame* game;
-    uint8_t position_x;
-    uint8_t position_y;
-
-    TttMultiGamePlayer local_player;
-    bool is_local;
-
-    TttMultiGameViewCallback callback;
-    void* context;
-
-    TttMultiGameMove* last_move;
-    TttMultiGameResult result;
-} TttMultiGameViewModel;
-
-void ttt_multi_game_view_draw_callback(Canvas* canvas, void* _model) {
-    TttMultiGameViewModel* model = _model;
-
-    canvas_clear(canvas);
-    const uint8_t top = 2;
-    const uint8_t left = 4;
-    const uint8_t cell_size = 20;
-    const uint8_t padding = 4;
-
-    canvas_draw_frame(canvas, left - 1, top - 1, 3 * cell_size + 2, 3 * cell_size + 2);
-
-    for(uint8_t i = 0; i < 3; i++) {
-        for(uint8_t j = 0; j < 3; j++) {
-            canvas_draw_frame(
-                canvas, left + i * cell_size, top + j * cell_size, cell_size, cell_size);
-        }
-    }
-
-    for(uint8_t i = 0; i < 3; i++) {
-        for(uint8_t j = 0; j < 3; j++) {
-            bool is_selected = model->position_x == i && model->position_y == j &&
-                               ttt_multi_game_get_state(model->game) != TttMultiGameStateFinished;
-
-            if(ttt_multi_game_player_at(model->game, i, j) == TttMultiGamePlayerX) {
-                canvas_draw_line(
-                    canvas,
-                    left + i * cell_size + padding,
-                    top + j * cell_size + padding,
-                    left + i * cell_size + cell_size - padding,
-                    top + j * cell_size + cell_size - padding);
-                canvas_draw_line(
-                    canvas,
-                    left + i * cell_size + cell_size - padding,
-                    top + j * cell_size + padding,
-                    left + i * cell_size + padding,
-                    top + j * cell_size + cell_size - padding);
-            } else if(ttt_multi_game_player_at(model->game, i, j) == TttMultiGamePlayerO) {
-                canvas_draw_circle(
-                    canvas,
-                    left + i * cell_size + cell_size / 2,
-                    top + j * cell_size + cell_size / 2,
-                    cell_size / 2 - padding);
-            }
-
-            if(is_selected) {
-                canvas_draw_frame(
-                    canvas,
-                    left + i * cell_size + 1,
-                    top + j * cell_size + 1,
-                    cell_size - 2,
-                    cell_size - 2);
-            }
-        }
-    }
-
-    char* status_str = "";
-    // TODO: Rewrite this
-    if(model->is_local) {
-        if(ttt_multi_game_get_state(model->game) == TttMultiGameStateFinished) {
-            if(ttt_multi_game_get_result(model->game) == TttMultiGameResultXWin) {
-                status_str = "X win";
-            } else if(ttt_multi_game_get_result(model->game) == TttMultiGameResultOWin) {
-                status_str = "O win";
-            } else if(ttt_multi_game_get_result(model->game) == TttMultiGameResultDraw) {
-                status_str = "Draw";
-            }
-        } else {
-            if(ttt_multi_game_current_player(model->game) == TttMultiGamePlayerX) {
-                status_str = "X turn";
-            } else {
-                status_str = "O turn";
-            }
-        }
-    } else {
-        if(ttt_multi_game_get_state(model->game) == TttMultiGameStateFinished) {
-            if(model->local_player == TttMultiGamePlayerX) {
-                if(ttt_multi_game_get_result(model->game) == TttMultiGameResultXWin) {
-                    status_str = "You win";
-                } else if(ttt_multi_game_get_result(model->game) == TttMultiGameResultOWin) {
-                    status_str = "You lose";
-                } else if(ttt_multi_game_get_result(model->game) == TttMultiGameResultDraw) {
-                    status_str = "Draw";
-                }
-            } else {
-                if(ttt_multi_game_get_result(model->game) == TttMultiGameResultXWin) {
-                    status_str = "You lose";
-                } else if(ttt_multi_game_get_result(model->game) == TttMultiGameResultOWin) {
-                    status_str = "You win";
-                } else if(ttt_multi_game_get_result(model->game) == TttMultiGameResultDraw) {
-                    status_str = "Draw";
-                }
-            }
-        } else {
-            if(model->local_player == TttMultiGamePlayerX) {
-                if(ttt_multi_game_get_state(model->game) == TttMultiGameStateTurnX) {
-                    status_str = "Your turn";
-                } else {
-                    status_str = "Opponent turn";
-                }
-            } else {
-                if(ttt_multi_game_get_state(model->game) == TttMultiGameStateTurnO) {
-                    status_str = "Your turn";
-                } else {
-                    status_str = "Opponent turn";
-                }
-            }
-        }
-    }
-
-    elements_text_box(canvas, 64, 16, 64, 16, AlignCenter, AlignCenter, status_str, false);
-    if(ttt_multi_game_get_state(model->game) == TttMultiGameStateFinished) {
-        elements_multiline_text_aligned(
-            canvas, 100, 32, AlignCenter, AlignTop, "Press OK\nto restart");
-    }
-}
-
-static void ttt_multi_game_view_process_left(TttMultiGameView* view);
-static void ttt_multi_game_view_process_right(TttMultiGameView* view);
-static void ttt_multi_game_view_process_up(TttMultiGameView* view);
-static void ttt_multi_game_view_process_down(TttMultiGameView* view);
-static void ttt_multi_game_view_process_ok(TttMultiGameView* view);
-
-static bool ttt_multi_game_view_input_callback(InputEvent* event, void* context) {
-    furi_assert(context);
-
-    TttMultiGameView* game_view = context;
-    bool consumed = false;
-
-    if(event->type == InputTypeShort) {
-        switch(event->key) {
-        case InputKeyLeft:
-            ttt_multi_game_view_process_left(game_view);
-            consumed = true;
-            break;
-        case InputKeyRight:
-            ttt_multi_game_view_process_right(game_view);
-            consumed = true;
-            break;
-        case InputKeyUp:
-            ttt_multi_game_view_process_up(game_view);
-            consumed = true;
-            break;
-        case InputKeyDown:
-            ttt_multi_game_view_process_down(game_view);
-            consumed = true;
-            break;
-        case InputKeyOk:
-            ttt_multi_game_view_process_ok(game_view);
-            consumed = true;
-            break;
-        default:
-            break;
-        }
-    }
-
-    return consumed;
-}
-
-void ttt_multi_game_view_model_reset(TttMultiGameViewModel* model) {
-    furi_assert(model);
-    furi_assert(model->game);
-
-    model->position_x = 1;
-    model->position_y = 1;
-    ttt_multi_game_reset(model->game);
-}
-
-TttMultiGameView* ttt_multi_game_view_alloc() {
-    TttMultiGameView* game_view = malloc(sizeof(TttMultiGameView));
-    game_view->view = view_alloc();
-    view_set_context(game_view->view, game_view);
-    view_allocate_model(game_view->view, ViewModelTypeLocking, sizeof(TttMultiGameViewModel));
-    view_set_draw_callback(game_view->view, (ViewDrawCallback)ttt_multi_game_view_draw_callback);
-    view_set_input_callback(game_view->view, ttt_multi_game_view_input_callback);
-
-    with_view_model(
-        game_view->view,
-        TttMultiGameViewModel * model,
-        {
-            model->game = ttt_multi_game_alloc();
-            model->last_move = ttt_multi_game_move_alloc();
-            ttt_multi_game_view_model_reset(model);
-        },
-        true);
-
-    return game_view;
-}
-
-void ttt_multi_game_view_free(TttMultiGameView* game_view) {
-    furi_assert(game_view);
-
-    with_view_model(
-        game_view->view,
-        TttMultiGameViewModel * model,
-        {
-            ttt_multi_game_free(model->game);
-            ttt_multi_game_move_free(model->last_move);
-        },
-        true);
-
-    view_free(game_view->view);
-    free(game_view);
-}
-
-View* ttt_multi_game_get_view(TttMultiGameView* game_view) {
-    furi_assert(game_view);
-
-    return game_view->view;
-}
-
-void ttt_multi_game_view_process_up(TttMultiGameView* game_view) {
-    furi_assert(game_view);
-
-    with_view_model(
-        game_view->view,
-        TttMultiGameViewModel * model,
-        {
-            if(model->position_y > 0) {
-                model->position_y--;
-            }
-        },
-        true);
-}
-
-void ttt_multi_game_view_process_down(TttMultiGameView* game_view) {
-    furi_assert(game_view);
-
-    with_view_model(
-        game_view->view,
-        TttMultiGameViewModel * model,
-        {
-            if(model->position_y < 2) {
-                model->position_y++;
-            }
-        },
-        true);
-}
-
-void ttt_multi_game_view_process_left(TttMultiGameView* game_view) {
-    furi_assert(game_view);
-
-    with_view_model(
-        game_view->view,
-        TttMultiGameViewModel * model,
-        {
-            if(model->position_x > 0) {
-                model->position_x--;
-            }
-        },
-        true);
-}
-
-void ttt_multi_game_view_process_right(TttMultiGameView* game_view) {
-    furi_assert(game_view);
-
-    with_view_model(
-        game_view->view,
-        TttMultiGameViewModel * model,
-        {
-            if(model->position_x < 2) {
-                model->position_x++;
-            }
-        },
-        true);
-}
-
-void ttt_multi_game_view_process_ok(TttMultiGameView* game_view) {
-    furi_assert(game_view);
-    TttMultiGameViewCallback callback = NULL;
-    void* context = NULL;
-
-    with_view_model(
-        game_view->view,
-        TttMultiGameViewModel * model,
-        {
-            if(ttt_multi_game_get_state(model->game) == TttMultiGameStateFinished) {
-                ttt_multi_game_view_model_reset(model);
-            } else {
-                model->last_move->player = ttt_multi_game_current_player(model->game);
-                model->last_move->x = model->position_x;
-                model->last_move->y = model->position_y;
-
-                if(ttt_multi_game_is_move_valid(model->game, model->last_move)) {
-                    callback = model->callback;
-                    context = model->context;
-                }
-            }
-        },
-        true);
-
-    if(callback) {
-        callback(context, TttMultiCustomEventGameMove);
-    }
-}
-
-void ttt_multi_game_view_move(TttMultiGameView* game_view, TttMultiGameMove* move) {
-    furi_assert(game_view);
-    furi_assert(move);
-
-    TttMultiGameResult result;
-    TttMultiGameViewCallback callback = NULL;
-    void* context = NULL;
-
-    with_view_model(
-        game_view->view,
-        TttMultiGameViewModel * model,
-        {
-            ttt_multi_game_make_move(model->game, move);
-            result = ttt_multi_game_get_result(model->game);
-            if(result != TttMultiGameResultNone) {
-                callback = model->callback;
-                context = model->context;
-            }
-        },
-        true);
-
-    if(callback) {
-        callback(context, TttMultiCustomEventGameFinish);
-    }
-}
-
-void ttt_multi_game_view_set_callback(
-    TttMultiGameView* game_view,
-    TttMultiGameViewCallback callback,
-    void* context) {
-    furi_assert(game_view);
-
-    with_view_model(
-        game_view->view,
-        TttMultiGameViewModel * model,
-        {
-            model->callback = callback;
-            model->context = context;
-        },
-        true);
-}
-
-void ttt_multi_game_view_set_remote_play(TttMultiGameView* game_view, TttMultiGamePlayer player) {
-    furi_assert(game_view);
-
-    with_view_model(
-        game_view->view,
-        TttMultiGameViewModel * model,
-        {
-            model->local_player = player;
-            model->is_local = false;
-        },
-        true);
-}
-
-void ttt_multi_game_view_set_local_play(TttMultiGameView* game_view) {
-    furi_assert(game_view);
-
-    with_view_model(
-        game_view->view, TttMultiGameViewModel * model, { model->is_local = true; }, true);
-}
-
-void ttt_multi_game_view_get_last_move(TttMultiGameView* game_view, TttMultiGameMove* move) {
-    furi_assert(game_view);
-    furi_assert(move);
-
-    with_view_model(
-        game_view->view,
-        TttMultiGameViewModel * model,
-        {
-            if(model->last_move->player != TttMultiGamePlayerNone) {
-                ttt_multi_game_move_copy(move, model->last_move);
-            }
-        },
-        true);
-}
-
-TttMultiGameResult ttt_multi_game_view_get_result(TttMultiGameView* game_view) {
-    furi_assert(game_view);
-
-    TttMultiGameResult result = TttMultiGameResultNone;
-
-    with_view_model(
-        game_view->view,
-        TttMultiGameViewModel * model,
-        { result = ttt_multi_game_get_result(model->game); },
-        true);
-
-    return result;
-}
-
-void ttt_multi_game_view_reset(TttMultiGameView* game_view) {
-    furi_assert(game_view);
-
-    with_view_model(
-        game_view->view,
-        TttMultiGameViewModel * model,
-        { ttt_multi_game_view_model_reset(model); },
-        true);
-}

+ 0 - 32
apps_source_code/flipper-tictactoe-multi/views/ttt_multi_game_view.h

@@ -1,32 +0,0 @@
-#pragma once
-
-#include <gui/view.h>
-#include <gui/elements.h>
-#include "../ttt_multi_custom_event.h"
-#include "../helpers/ttt_multi_game.h"
-
-typedef void (*TttMultiGameViewCallback)(void* context, TttMultiCustomEvent event);
-typedef struct TttMultiGameView TttMultiGameView;
-
-TttMultiGameView* ttt_multi_game_view_alloc();
-
-void ttt_multi_game_view_free(TttMultiGameView* game_view);
-
-View* ttt_multi_game_get_view(TttMultiGameView* game_view);
-
-void ttt_multi_game_view_move(TttMultiGameView* game_view, TttMultiGameMove* move);
-
-void ttt_multi_game_view_set_callback(
-    TttMultiGameView* game_view,
-    TttMultiGameViewCallback callback,
-    void* context);
-
-void ttt_multi_game_view_set_remote_play(TttMultiGameView* game_view, TttMultiGamePlayer player);
-
-void ttt_multi_game_view_set_local_play(TttMultiGameView* game_view);
-
-void ttt_multi_game_view_get_last_move(TttMultiGameView* game_view, TttMultiGameMove* move);
-
-TttMultiGameResult ttt_multi_game_view_get_result(TttMultiGameView* game_view);
-
-void ttt_multi_game_view_reset(TttMultiGameView* game_view);