Le support aux utilisateurs et les demandes de création de comptes externes doivent être faites depuis les issues du projet GitLab HEFR (https://gitlab.forge.hefr.ch/forge-hefr/gitlab-hefr)

Commit a788898b authored by Arton Hoxha's avatar Arton Hoxha
Browse files

added more comments in headers and removed unused code and merge

parent e85b910b
Pipeline #15703 failed with stages
in 8 seconds
......@@ -20,7 +20,7 @@
*
* Abstract: Introduction to C language and modular programming
*
* Purpose: Gives the state and the direction the wheel is turning.
* Purpose: Used to display the end image
*
* Author: <Corentin Bompard & Arton Hoxha>
*
......@@ -29,6 +29,9 @@
#include "../lcd/lcd.h"
/**
* Image used when the game is done
*/
extern Image end_img;
#endif
......@@ -34,7 +34,7 @@ void game_init(struct game* game)
game->selected_char_index = 0;
game->correct_letters = 0;
game->selected_char = 'a';
game->selected_word = " ";
game->selected_word = " "; // init 9 chars word
game->selected_word_length = 0;
for (unsigned i = 0; i < WORD_LENGTH; i++) {
game->are_chars_in_word[i] = 0;
......@@ -42,14 +42,7 @@ void game_init(struct game* game)
msgq_post(game->render_msq, (void*)RENDER_MAIN_MENU);
}
void thread_game(void* param)
{
game* game = (struct game*)param;
while (true) {
handle_events((int)msgq_fetch(game->events_msq), game);
}
}
// custom str_length because C does not differenciante empty char with char
static int str_length(char* str)
{
int len = 0;
......@@ -75,7 +68,11 @@ static void check_word(game* game)
detected_error = NO_ERROR;
game->counter =
(game->selected_word_length - game->correct_letters + 1) *
<<<<<<< Updated upstream
TIME_FACTOR_DIFFICULTY;
=======
TIME_FACTOR; // timer for player to find a word
>>>>>>> Stashed changes
}
}
}
......@@ -112,22 +109,26 @@ void handle_events(game_events event, game* game)
}
if (event == GAME_WHEEL_RIGHT) {
if (game->inGame) {
// select next right char
game->selected_char_index =
(game->selected_char_index + 1) % ARRAY_SIZE(alphabet);
game->selected_char = alphabet[game->selected_char_index];
msgq_post(game->render_msq, (void*)RENDER_CHAR);
} else if (game->inSelection) {
// select next right char
game->selected_char_index =
(game->selected_char_index + 1) % ARRAY_SIZE(alphabet);
game->selected_char = alphabet[game->selected_char_index];
msgq_post(game->render_msq, (void*)RENDER_CHAR);
} else if (game->inMenu || game->inEndMenu) {
// select 'no'
msgq_post(game->menu_msq, (void*)MENU_RIGHT);
}
} else if (event == GAME_WHEEL_LEFT) {
if (game->inGame) {
// select next left char
game->selected_char_index = (game->selected_char_index - 1) < 0
? game->selected_char_index =
ARRAY_SIZE(alphabet) - 1
......@@ -136,6 +137,7 @@ void handle_events(game_events event, game* game)
msgq_post(game->render_msq, (void*)RENDER_CHAR);
} else if (game->inSelection) {
// select next left char
game->selected_char_index = (game->selected_char_index - 1) < 0
? game->selected_char_index =
ARRAY_SIZE(alphabet) - 1
......@@ -143,16 +145,19 @@ void handle_events(game_events event, game* game)
game->selected_char = alphabet[game->selected_char_index];
msgq_post(game->render_msq, (void*)RENDER_CHAR);
} else if (game->inMenu || game->inEndMenu) {
// select 'yes'
msgq_post(game->menu_msq, (void*)MENU_LEFT);
}
} else if (event == GAME_WHEEL_CLICK) {
if (game->inSelection) {
// validate selected char in selection
if (index != WORD_LENGTH - 1) {
game->selected_word[index++] = game->selected_char;
msgq_post(game->render_msq, (void*)RENDER_CHAR);
msgq_post(game->render_msq, (void*)RENDER_NEXT_CHAR);
} else {
// all chars are entered
game->inSelection = false;
game->inMenu = true;
game->selected_word[index++] = game->selected_char;
......@@ -164,12 +169,15 @@ void handle_events(game_events event, game* game)
msgq_post(game->menu_msq, (void*)MENU_RENDER);
}
} else if (game->inMainScreen) {
// go to selection screen
game->inMainScreen = false;
game->inSelection = true;
msgq_post(game->render_msq, (void*)RENDER_SELECTION);
} else if (game->inGame) {
// player 2 is playing and select char
check_word(game);
} else if (game->inMenu || game->inEndMenu) {
// menu click in selection word confirm or in end menu
msgq_post(game->menu_msq, (void*)MENU_CLICK);
}
} else if (event == GAME_START) {
......@@ -198,16 +206,19 @@ void handle_events(game_events event, game* game)
}
msgq_post(game->render_msq, (void*)RENDER_RESET);
} else if (event == GAME_BLINK_ON) {
// display char
if (!game->inMenu) {
msgq_post(game->render_msq, (void*)RENDER_CHAR);
}
} else if (event == GAME_BLINK_OFF) {
// remove char
if (!game->inMenu) {
msgq_post(game->render_msq, (void*)RENDER_REMOVE_CHAR);
}
} else if (event == GAME_BTN_CLICK) {
if (game->inSelection) {
// select word without entering 9 chars
game->inSelection = false;
game->inMenu = true;
game->selected_word_length = str_length(game->selected_word);
......@@ -219,3 +230,11 @@ void handle_events(game_events event, game* game)
}
}
}
void thread_game(void* param)
{
game* game = (struct game*)param;
while (true) {
handle_events((int)msgq_fetch(game->events_msq), game);
}
}
......@@ -30,6 +30,7 @@
#include "../kernel/msgq.h"
#include "stdint.h"
// game structure for our entire game
typedef struct game {
msgqid_t menu_msq;
msgqid_t render_msq;
......@@ -51,9 +52,7 @@ typedef struct game {
int are_chars_in_word[];
} game;
void thread_game(void* param);
void game_init();
// enumeration for all events in our game
typedef enum {
GAME_BTN_CLICK,
GAME_WHEEL_LEFT,
......@@ -67,16 +66,16 @@ typedef enum {
GAME_RESET_SELECTION
} game_events;
// enumeration for all events in menu
typedef enum {
MENU_RESET,
MENU_RIGHT,
MENU_LEFT,
MENU_CLICK,
MENU_RENDER,
MENU_RENDER_CHAR,
MENU_REMOVE_CHAR
} game_menu;
// enumeration for render in lcd screen
typedef enum {
RENDER_MAIN_MENU,
RENDER_GAME,
......@@ -87,11 +86,19 @@ typedef enum {
RENDER_WORD_CHAR,
RENDER_NEXT_CHAR,
RENDER_REMOVE_CHAR,
RENDER_MENU,
RENDER_NEXT_PART,
RENDER_END
} game_render;
void handle_events(game_events event, game* game);
/**
* Thread which receives game struct pointer and manage variables
* @param param: expect to receive game struct
*/
void thread_game(void* param);
/**
* init the game strutct
*/
void game_init();
#endif
......@@ -2,7 +2,36 @@
#ifndef HANGMAN_H
#define HANGMAN_H
/**
* Copyright 2020 University of Applied Sciences Western Switzerland / Fribourg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project: HEIA-FR / Embedded Systems 2 EP
*
* Abstract: Embedded Project in embedded systems course
*
* Purpose: Hangman parts
*
* Author: <Corentin Bompard & Arton Hoxha>
*
* Date: <15.05.2020>
*/
#include "../lcd/lcd.h"
/**
* Hangman table which holds each part of the hangman
*/
extern Image hangman[7];
#endif
......@@ -2,7 +2,36 @@
#ifndef MAIN_MENU_H
#define MAIN_MENU_H
/**
* Copyright 2020 University of Applied Sciences Western Switzerland / Fribourg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project: HEIA-FR / Embedded Systems 2 EP
*
* Abstract: Embedded Project in embedded systems course
*
* Purpose: Image for the welcome screen
*
* Author: <Corentin Bompard & Arton Hoxha>
*
* Date: <15.05.2020>
*/
#include "../lcd/lcd.h"
/**
* Image shown at the welcome screen
*/
extern Image main_menu;
#endif
......@@ -20,10 +20,7 @@
#define SW_GPIO AM335X_GPIO1
#define WHEEL_SW_GPIO AM335X_GPIO0
#define WHEEL_SW_PIN 2
#define LIGHT_BLUE 0x2ff
#define S1_PIN 15
#define S2_PIN 16
#define S3_PIN 17
#define BLINK_PERIOD 100
#define GAME_PERIOD 10
......@@ -33,7 +30,6 @@ enum dmtimer_timers timer_game = DMTIMER_3;
static void s1_handler(void* param)
{
game* game = (struct game*)param;
printf("game state: %d", game->inSelection);
if (game->inSelection && game->selected_word[0] &&
game->selected_word[0] != ' ') {
......@@ -96,7 +92,11 @@ void refresh_counter(void* param)
void init()
{
<<<<<<< Updated upstream
counter_init(); // init wheel and seg7 too
=======
counter_init(); // inits wheel and seg7 too
>>>>>>> Stashed changes
lcd_init();
intc_init();
interrupt_init();
......
......@@ -15,6 +15,8 @@
#define REPLAY_X 48
#define REPLAY_Y 20
#define SELECTED_WORD_X 45
#define CLEAR_LCD_POS_X 50
#define CLEAR_LCD_POS_Y 95
#define POS_0 0
// Menu entries
......@@ -39,12 +41,11 @@ unsigned current_choice = PLAY_OR_PLAY_AGAIN;
static void menu_display(game* game)
{
if (game->inMenu) {
lcd_draw_rect(
0,
50,
0,
95,
BLACK); // clear lcd display due to lag with lcd_clear() method
lcd_draw_rect(POS_0,
CLEAR_LCD_POS_X,
POS_0,
CLEAR_LCD_POS_Y,
BLACK); // clear lcd display
lcd_display_string(confirm, POS_0, POS_0, false);
lcd_display_string(game->selected_word, SELECTED_WORD_X, POS_0, false);
lcd_change_text_color(RED);
......
......@@ -19,15 +19,20 @@
* This module is based on the software library developped by Texas Instruments
* Incorporated - http://www.ti.com/ for its AM335x starter kit.
*
* Project: HEIA-FR / Embedded Systems 1 Laboratory 3
* Project: HEIA-FR / Embedded Systems 2 EP
*
* Abstract: Embedded Project in embedded systems course
*
* Purpose: This module implement the choice of the user in a LCD screen
* Purpose: Thread who manages menus for word selection and play again
*
* Author: Corentin Bompard & Lucas Bueche
* Date: 05.11.2019
* Author: <Corentin Bompard & Lucas Bueche>
* Date: <15.05.2020>
*/
/**
* Thread which uses game struct to manage menus for word selection and play
* again
*/
void thread_menu(void* param);
#endif /* MENU_H_ */
......@@ -43,8 +43,16 @@
#define CHAR_OFFSET 10
#define X_CLEAR_PIXELS_IMG 20
#define Y_CLEAR_PIXELS_IMG 24
#define WELCOMESTR_POS_Y 25
#define CLICKWHEELSTR_POS_X 85
#define CLICKWHEELSTR_POS_Y 5
#define PLAYER1STR_POS_Y 20
#define SELECTED_WORD_STR_POS_X 12
#define RENDER_TICK_X_OFFSET 2
#define RENDER_TICK_Y_OFFSET 10
#define RENDER_TICK_OFFSET 3
char* str = "Select word:";
char* select_word_str = "Select word:";
char* player1_str = "Player 1";
char* selected_word_str = "Your word:";
char* hangman_str = "Hangman";
......@@ -52,8 +60,9 @@ char* hangman_str = "Hangman";
static void render_main_menu()
{
lcd_draw_image(&main_menu, MENU_IMAGE_POS, MENU_IMAGE_POS);
lcd_display_string("Welcome!", POS_0, 25, false);
lcd_display_string("Click wheel ", 85, 5, false);
lcd_display_string("Welcome!", POS_0, WELCOMESTR_POS_Y, false);
lcd_display_string(
"Click wheel ", CLICKWHEELSTR_POS_X, CLICKWHEELSTR_POS_Y, false);
}
static void render_selection()
......@@ -66,14 +75,16 @@ static void render_selection()
POS_0,
SCREEN_WIDTH - 1,
BLACK);
lcd_display_string(player1_str, POS_0, 20, false);
lcd_display_string(str, 12, POS_0, false);
lcd_display_string(player1_str, POS_0, PLAYER1STR_POS_Y, false);
lcd_display_string(
selected_word_str, SELECTED_WORD_STR_POS_X, POS_0, false);
for (int i = 0; i < WORD_LENGTH; i++) {
lcd_draw_rect(SELECTION_TICK_X,
SELECTION_TICK_X + 2,
SELECTION_TICK_Y + 10 * i,
SELECTION_TICK_Y * 3 + 10 * i,
WHITE);
lcd_draw_rect(
SELECTION_TICK_X,
SELECTION_TICK_X + RENDER_TICK_X_OFFSET,
SELECTION_TICK_Y + RENDER_TICK_Y_OFFSET * i,
SELECTION_TICK_Y * RENDER_TICK_OFFSET + RENDER_TICK_Y_OFFSET * i,
WHITE);
}
}
......@@ -88,7 +99,7 @@ static void render_game(game* game)
lcd_draw_rect(SELECTION_TICK_X - SELECTION_TICK_X_OFFSET,
SELECTION_TICK_X - SELECTION_TICK_Y_OFFSET,
SELECTION_TICK_Y,
SELECTION_TICK_Y * 3,
SELECTION_TICK_Y * RENDER_TICK_OFFSET,
WHITE);
// draw word ticks
for (int i = 0; i < game->selected_word_length; i++) {
......@@ -118,7 +129,7 @@ void thread_render(void* param)
game* game = (struct game*)param;
uint32_t char_x = CHAR_X;
uint32_t char_y = CHAR_Y;
static int hangman_part_index = 1;
static int hangman_part_index = 1; // first part of the hangman
while (1) {
int msg = (int)msgq_fetch(game->render_msq);
if (msg == RENDER_MAIN_MENU) {
......@@ -141,13 +152,13 @@ void thread_render(void* param)
render_selection();
} else if (msg == RENDER_GAME) {
render_game(game);
char_x = CHAR_X;
char_x = CHAR_X; // set the selection char in screen
char_y = CHAR_Y;
} else if (msg == RENDER_END) {
lcd_draw_image(&end_img, POS_0, POS_0);
msgq_post(game->events_msq, (void*)GAME_END);
} else if (msg == RENDER_RESET) {
hangman_part_index = 1;
hangman_part_index = 1; // reset to first part
char_y = CHAR_Y;
render_selection();
} else if (msg == RENDER_WORD_CHAR) {
......
......@@ -16,18 +16,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project: HEIA-FR / Embedded Systems 2 Laboratory
* Project: HEIA-FR / Embedded Systems 2 EP
*
* Abstract: Introduction to C language and modular programming
* Abstract: Embedded Project in embedded systems course
*
* Purpose: Gives the state and the direction the wheel is turning.
* Purpose: Thread to render something in lcd screen
*
* Author: <Corentin Bompard & Arton Hoxha>
*
* Date: <01.10.2019>
* Date: <15.05.2020>
*/
#include "../game/game.h"
/**
* Thread which uses game struct to render in lcd
*/
void thread_render(void* param);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment