Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 01492e78 authored by BAROLLET Theo's avatar BAROLLET Theo
Browse files

prepare merge of make_level

parent 27cf493c
No related branches found
No related tags found
No related merge requests found
......@@ -70,6 +70,16 @@ void coord_in_dir_n(int y, int x, direction dir, int *cy, int *cx, int n) {
}
}
void move_entity(int fy, int fx, int ty, int tx) {
map * m = current_map();
int from = coord_idx(fy, fx);
int to = coord_idx(ty, tx);
m->entities[to] = m->entities[from];
m->entities[from] = NULL;
}
void coord_in_dir(int y, int x, direction dir, int *cy, int *cx) {
coord_in_dir_n(y, x, dir, cy, cx, 1);
......
......@@ -14,6 +14,11 @@ void turn_left(void);
*/
void coord_in_dir (int y, int x, direction dir, int *cy, int *cx);
/**
* Moves an entity from position (fx, fy) to position (tx, ty)
*/
void move_entity(int fy, int fx, int ty, int x);
/**
* Idem but when moving 'n' squares in direction 'dir'.
*/
......
......@@ -109,7 +109,6 @@ void player_in_dir_n(int *cy, int *cx, int n)
coord_in_dir_n (player_y, player_x, player_direction, cy, cx, n);
}
void forward (int player_direction)
{
int y, x;
......
......@@ -6,6 +6,5 @@
#include "map.h"
#include "input.h"
#include "action.h"
#include "shop.h"
#endif//AGDBENTURES_H
/* @AGDB
* level_name: MANDATORY
* engine_name: MANDATORY
* exec_name: MANDATORY
* engine_tags:
* engine_antitags:
*/
#include <stdlib.h>
int verify_level() {
if (TODO_COND) {
return EXIT_SUCCESS;
} else {
return EXIT_FAILURE;
}
}
int main() {
int a = 0;
return 0;
}
\ No newline at end of file
/* @AGDB
* level_name: Pet Follow
* engine_name: fullgame
* exec_name: pet_follow
* engine_tags:
* engine_antitags:
*/
#include <stdlib.h>
#include "agdbentures.h"
#define CIRCULAR_BUFFER_SIZE 20
#define FOLLOW_DISTANCE \
5 // The distance at which the pet will follow the character
typedef enum {
LEFT,
RIGHT,
UP,
DOWN,
} command;
typedef struct {
command internal[CIRCULAR_BUFFER_SIZE];
int read_index; // The next command to read
} circular_buffer;
void buffer_write(circular_buffer *buffer, command to_write) {
buffer->internal[buffer->read_index + FOLLOW_DISTANCE];
}
command buffer_read(circular_buffer *buffer) {
command command_read = buffer->internal[buffer->read_index];
buffer->read_index += 1;
if (buffer->read_index > CIRCULAR_BUFFER_SIZE) {
buffer->read_index = 0;
}
return command_read;
}
void init_buffer(circular_buffer *buffer) {
for (int i = 0; i < FOLLOW_DISTANCE; i++) {
//buffer->internal[i] = command.RIGHT;
}
buffer->read_index = 0;
}
int verify_level() {
if (1) {
return EXIT_SUCCESS;
} else {
return EXIT_FAILURE;
}
}
int main() {
command command = wait_command();
return 0;
}
\ No newline at end of file
File moved
File moved
/* @AGDB
* Level: local structure
* Bug idea: a local structure representing the character is passed without
* pointer in a function call. An armor & sword are "bought" in the "weapon
* store" (function), but "disappear" as the character leaves the shop (exit).
*
* Tags: #pointer, #local, #structure
*
* Engine requirements
* - player_x and player_y globals
* - reading basic maps
* - stack of maps (entering / leaving)
* - non-moving hardcoded monsters
* - hardcoded discussion with Shopkeeper
* - gold as global variable
* - basic buy system (buy highest possible)
* - verify level based on position at exit
*/
#include "agdbentures.h"
/*
* Buy an armor and weapon, and defeat the Troll on the brige.
*/
/* One screen is 30 characters wide. This is a 2-screen map */
const char *str_map =
"\
~~~~~ \n\
+-----+ ~~~~~ \n\
+--D--+ ~~~~~ \n\
~~~~~ \n\
T > \n\
@ $ $ $ $ $ $ ~~~~~ \n\
~~~~~ \n\
";
const char *str_shop =
"\
+---------+\n\
| ******* |\n\
| S |\n\
+---------+\n\
| |\n\
| @ |\n\
+----D----+\n\
";
typedef struct {
int weapon;
int armor;
} equipment;
void enter_shop (equipment eq)
/* BUGSOLUTION: equipment should be passed as a pointer to the structure
* void enter_shop (equipment *eq)
*/
{
load_map (str_shop);
forward();
talk();
/* buy a weapon */
/* SOLREMOVE */
eq.weapon = buy_weapon();
eq.armor = buy_armor();
/* SOLADD
* eq->weapon = buy_weapon();
* eq->armor = buy_armor();
*/
turn_right();
turn_right();
forward();
forward();
unload_map();
/* BUGIDEA: in a previous level, introduce the idea of stack of maps and
* forgetting to unload */
return;
}
int main(void)
{
equipment my_eq;
load_map (str_map);
my_eq.weapon = NO_WEAPON;
my_eq.armor = NO_ARMOR;
forward_n(18);
turn_left();
forward();
forward();
enter_shop(equipment);
forward();
turn_left();
forward_n(28);
fight();
forward_n(9);
verify_exit();
}
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
fight
up
up
up
up
buy
down
down
down
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
right
fight
right
right
right
right
right
right
right
right
#!/usr/bin/env python3
import curses
from easytracker import init_tracker, PauseReasonType
from easytracker.utils import variable_dict_to_struct
DEBUG=0
def debug():
while tracker.get_pause_reason().type != PauseReasonType.EXITED:
tracker.resume()
frame = tracker.get_current_frame(as_raw_python_objects=True)
variables = tracker.get_global_variables(as_raw_python_objects=True)
variables = variable_dict_to_struct(variables)
weapon, armor = get_equipment(frame)
gold = get_gold(variables)
map = get_map(variables)
p_x, p_y = get_player_pos(variables)
print(f"weapon {weapon} armor {armor} gold {gold}")
print(f"player {p_x} {p_y}")
print(map)
input()
def log(message):
if DEBUG:
print(message)
def main(stdscr):
curses.curs_set(False)
# Clear screen
stdscr.clear()
pad = curses.newpad(100, 100)
while tracker.get_pause_reason().type != PauseReasonType.EXITED:
tracker.resume()
frame = tracker.get_current_frame(as_raw_python_objects=True)
variables = tracker.get_global_variables(as_raw_python_objects=True)
variables = variable_dict_to_struct(variables)
weapon, armor = get_equipment(frame)
gold = get_gold(variables)
map = get_map(variables)
p_x, p_y = get_player_pos(variables)
#if map is not None:
# print_map(map)
#print(x, y)
# display map
y, x = 0, 0
for c in map:
if c == '\x00':
y+=1
x = 0
else:
pad.addch(y,x, str(c))
x += 1
# display player
if p_y > 0 and p_x > 0:
pad.addch(p_y, p_x, '@')
# display armor
pad.addstr(25,0, f"armor {armor}")
# display weapon
pad.addstr(26,0, f"weapon {weapon}")
# display gold
pad.addstr(27,0, f"gold {gold}")
# Displays a section of the pad in the middle of the screen.
# (0,0) : coordinate of upper-left corner of pad area to display.
# (5,5) : coordinate of upper-left corner of window area to be filled
# with pad content.
# (20, 75) : coordinate of lower-right corner of window area to be
# : filled with pad content.
pad.refresh( 0,0, 5,5, 40,75)
stdscr.getkey()
pad.clear()
def get_equipment(frame):
while frame is not None:
variables = variable_dict_to_struct(frame.variables)
try:
my_eq = variables.eq
except AttributeError:
try:
my_eq = variables.my_eq
except AttributeError:
frame = frame.parent
continue
# dereference if we have a pointer
if isinstance(my_eq, tuple):
my_eq = my_eq[0]
return (my_eq.weapon, my_eq.armor)
return (None, None)
def get_gold(glob_vars):
try:
return glob_vars.gold
except:
return None
def get_player_pos(glob_vars):
try:
player_x = glob_vars.player_x
player_y = glob_vars.player_y
except:
return (None, None)
return (player_x, player_y)
def get_map(glob_vars):
try:
maps_struct = glob_vars.mstack
shop_map = glob_vars.str_shop
main_map = glob_vars.str_map
except:
return None
lenght = maps_struct.length
log(f"lenght {lenght} {type(lenght)}")
log(f"{main_map}")
log(f"{shop_map}")
if lenght == 0:
return None
#map = maps_struct.maps[lenght-1]
if lenght == 1:
return main_map
if lenght == 2:
return shop_map
return None
def print_map(strm):
#return
for c in strm:
if c == '\x00':
print("")
else:
print(str(c), end="")
tracker = init_tracker("GDB")
tracker.send_direct_command("set inferior-tty /dev/pts/13")
tracker.load_program("local_struct")
tracker.start(in_file="in.txt")
# tracker.start("in.txt")
# tracker.start()
tracker.watch("player_x")
tracker.watch("player_y")
if DEBUG:
debug()
else:
curses.wrapper(main)
/* @AGDB
* level_name: Local_structure
* exec_name: local_struct
* engine_name: mediumgame
* engine_tags:
*
* Bug idea... a local structure representing the character is passed without
* pointer in a function call. An armor & sword are "bought" in the "weapon
* store" (function), but "disappear" as the character leaves the shop (exit).
*
* Tags: #pointer, #local, #structure
*
* Engine
* - player_x, player_y, direction are globals
* - reading basic maps
* - stack of maps (entering / leaving)
* - non-moving hardcoded monsters
* - hardcoded discussion with Shopkeeper
* - gold as global variable
* - basic buy system (buy highest possible)
* - verify level based on position at exit
*
* Checks
* - buys are done in the shop (i.e., in function enter_shop)
* · watch buy_weapon and buy_armor
* - equipment is not modify outside the shop
* · watch memory for equipment
* - exit position is not changed
* - verify_exit is called
* - troll is defeated in combat and there is no new path to the exit
* · difficult to check
*/
#include "agdbentures.h"
#include "shop.h"
/*************************************************************
* Level objectives:
* Buy armor and weapon, and defeat the Troll on the brige.
*************************************************************/
/**
* In this map, a lot of gold, a shop with a door D, and a troll T guarding the
* bridge leading to the exit.
* */
char str_map[] =
"\
~~~~~ \n\
+-----+ ~~~~~ \n\
+--D--+ ~~~~~ \n\
~~~~~ \n\
T > \n\
@ $$$$$$$$$$$$$ ~~~~~ \n\
~~~~~ \n\
";
/**
* The map for the shop. A door at the bottom, and a shopkeeper S behind its
* counter, and items of weaponry behind him/her.
*/
char str_shop[] =
"\
+---------+\n\
| [[[/))) |\n\
| S |\n\
+---------+\n\
| |\n\
| |\n\
+----D----+\n\
";
/**
* Function called when entering the shop to buy equipment. Parameter is the
* equipement to update when buying.
*/
#ifdef BUG
void enter_shop(equipment eq)
#else
void enter_shop(equipment* eq)
#endif
{
printf("You enter a shop.\n");
load_map(str_shop);
map* m = current_map();
player_x = m->door_x; /* place player above the door */
player_y = m->door_y - 1;
bool leave_shop = false;
while (!leave_shop) {
/* apply_command(); */
command cmd = wait_command();
switch (cmd) {
case CMD_NONE:
break;
case CMD_EOF:
leave_shop = true;
break;
case CMD_BUY:
/* buy a weapon */
#ifdef BUG
eq.weapon = buy_weapon();
eq.armor = buy_armor();
#else
eq->weapon = buy_weapon();
eq->armor = buy_armor();
#endif
break;
case CMD_FIGHT:
printf("You will regret this!\n");
char mon = 'S';
fight_monster(&mon, eq);
break;
default:
fprintf(stderr, "Cannot handle this command!\n");
}
if (player_x == m->door_x && player_y == m->door_y &&
player_direction == DIR_DOWN) {
/* leaving the shop */
leave_shop = true;
}
}
/* forward(); */
/* talk(); */
unload_map();
/* BUGIDEA: in a previous level, introduce the idea of stack of maps and
* forgetting to unload */
printf("You leave the shop.\n");
return;
}
int main(void) {
/* set_unbuffered_terminal(); */
/* We started the level naked, weaponry-wise */
equipment my_eq;
my_eq.weapon = NO_WEAPON;
my_eq.armor = NO_ARMOR;
/* Initialize the first map */
init_map_stack();
load_map(str_map);
map* m = current_map();
printf("Enter your commands (up, down, left, right...):\n");
while (true) {
/* apply_command(); */
command cmd = wait_command();
if (cmd == CMD_EOF) {
break;
} else if (cmd == CMD_FIGHT) {
/* now is time to fight! */
fight(my_eq);
} else if (player_x == m->door_x && player_y == m->door_y &&
player_direction == DIR_UP) {
/* entering the shop */
/* Now buy some armor + weapon so we can defeat the troll. */
#ifdef BUG
enter_shop(my_eq);
#else
enter_shop(&my_eq);
#endif
}
}
/* reset_terminal(); */
/* hopefully we are now at the exit */
/* forward_n(10); */
verify_exit();
}
#include "shop.h"
const int weapon_price[WEAPONS_N] = {0, 1, 2, 5};
const int armor_price[ARMORS_N] = {0, 2, 4, 8};
int buy_generic(const int price[], int num_prices)
{
int idx=num_prices-1;
while (idx > 0 && price[idx] > gold) { idx--; };
gold = gold - price[idx];
if (!idx) {
printf ("You do not have enough gold for that.\n");
} else {
printf ("You buy something for %d gold.\n",price[idx]);
printf ("You now have %d gold.\n",gold);
}
return idx;
}
weapon_type buy_weapon(void)
{
printf("You try to buy a weapon...\n");
int widx = buy_generic (weapon_price, WEAPONS_N);
return (weapon_type)widx;
}
armor_type buy_armor(void)
{
printf("You try to buy armor...\n");
int aidx = buy_generic (armor_price, ARMORS_N);
return (armor_type)aidx;
}
#ifndef SHOP_H
#define SHOP_H
#include "common.h"
/**
* Different types of weapons
*/
typedef enum {
NO_WEAPON,
DAGGER,
SHORT_SWORD,
LONG_SWORD,
WEAPONS_N
} weapon_type;
/**
* Different types of armor
*/
typedef enum {
NO_ARMOR,
LEATHER_JACKET,
CHAINMAIL,
FULLPLATE,
ARMORS_N
} armor_type;
/**
* Buy the most expensive weapon possible.
*/
weapon_type buy_weapon(void);
/**
* Buy the most expensive armor possible.
*/
armor_type buy_armor(void);
#endif//SHOP_H
......@@ -82,6 +82,11 @@ parser.add_argument(
args = parser.parse_args()
if args.teacher:
args.udefines.append("BUG")
else:
args.defines.append("BUG")
def create_dir(dir_path: str, clear=False):
"""Creates the given directory if it doesn't exist if clear is True, deletes the directory first"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment