void player2_turn() { int dice = dice_data(2); int purchase; int fine; int get; player2_position = dice+player2_position; if (player2_position > 40) { player2_position = player2_position-40; } printf("Player[2] droped %d points\n",dice); if (space[player2_position].occupy_condition == 0) { purchase = buy_space(player2_position, 2); printf("Player[2] bought %s for %d dollars\n",space[player2_position].space_name, purchase); player[2]=player[2]-purchase; printf("Player[2] has %d dollars left\n\n",player[2]); } else if (space[player2_position].occupy_condition == 2) { printf("%s is already belongs to Player[2]\n\n",space[player2_position].space_name); } else if (space[player2_position].occupy_condition == 1) { fine = get_payment(player2_position); player[2] = player[2]-fine; player[1] = player[1]+fine; printf("FINE: %s is owned by Player[1], Player[2] is fined %d dollars\n",space[player2_position].space_name,fine); printf("Player[2] has %d dollars left\n\n",player[2]); } else if (space[player2_position].occupy_condition == -1) { if (player2_position == 30) { player2_position = 10; player[2] = player[2]-50; printf("Player[2] is sent to Jail and fined 50 dollars\n"); printf("Player[2] has %d dollars left\n\n",player[2]); } else{ get = get_payment(player2_position); player[2] = player[2]-get; printf("Player[2] get %d dollars from %s\n",-get,space[player2_position].space_name);// -get to get positive value printf("Player[2] has %d dollars left\n\n",player[2]); } } else printf("WARNING: %s ERROR\n\n",space[player2_position].space_name); }
/** * Apply/trigger a shop map. * @param shop_mat The shop map object. * @param op Object that triggered this. * @return Returns 1 if 'op' was destroyed, 0 otherwise. */ int apply_shop_mat(object *shop_mat, object *op) { int rv = 0; /* prevent loops */ SET_FLAG(op, FLAG_NO_APPLY); if (op->type != PLAYER) { if (QUERY_FLAG(op, FLAG_UNPAID)) { /* Somebody dropped an unpaid item, just move to an adjacent place. */ int i = find_free_spot(op->arch, NULL, op->map, op->x, op->y, 1, 9); if (i != -1) { rv = transfer_ob(op, op->x + freearr_x[i], op->y + freearr_y[i], 0, shop_mat, NULL); } } rv = teleport(shop_mat, SHOP_MAT, op); } /* Only used for players. */ else if (get_payment(op, op->inv)) { object *tmp; rv = teleport(shop_mat, SHOP_MAT, op); if (shop_mat->msg) { new_draw_info(NDI_UNIQUE, op, shop_mat->msg); } /* This check below is a bit simplistic - generally it should be correct, * but there is never a guarantee that the bottom space on the map is * actually the shop floor. */ else if (!rv && (tmp = GET_MAP_OB_LAYER(op->map, op->x, op->y, 0)) != NULL && tmp->type != SHOP_FLOOR) { new_draw_info(NDI_UNIQUE, op, "Thank you for visiting our shop."); } } /* If we get here, a player tried to leave a shop but was not able * to afford the items he has. We try to move the player so that * they are not on the mat anymore */ else { int i = find_free_spot(op->arch, NULL, op->map, op->x, op->y, 1, 9); if (i == -1) { LOG(llevBug, "BUG: Internal shop-mat problem (map:%s object:%s pos: %d,%d).\n", op->map->name, op->name, op->x, op->y); } else { remove_ob(op); check_walk_off(op, NULL, MOVE_APPLY_DEFAULT); op->x += freearr_x[i]; op->y += freearr_y[i]; rv = (insert_ob_in_map(op, op->map, shop_mat, 0) == NULL); } } CLEAR_FLAG(op, FLAG_NO_APPLY); return rv; }
/** * Descends containers looking for unpaid items, and pays for them. * @param pl Player buying the stuff. * @param op Object we are examining. If op has and inventory, we examine * that. Ii there are objects below op, we descend down. * @retval 0 Player still has unpaid items. * @retval 1 Player has paid for everything. */ int get_payment(object *pl, object *op) { char buf[MAX_BUF]; int ret = 1; if (op != NULL && op->inv) { ret = get_payment(pl, op->inv); } if (!ret) { return 0; } if (op != NULL && op->below) { ret = get_payment(pl, op->below); } if (!ret) { return 0; } if (op != NULL && QUERY_FLAG(op, FLAG_UNPAID)) { strncpy(buf, query_cost_string(op, pl, F_BUY), sizeof(buf)); if (!pay_for_item(op, pl)) { sint64 i = query_cost(op, pl, F_BUY) - query_money(pl); CLEAR_FLAG(op, FLAG_UNPAID); new_draw_info_format(NDI_UNIQUE, pl, "You lack %s to buy %s.", cost_string_from_value(i), query_name(op, NULL)); SET_FLAG(op, FLAG_UNPAID); return 0; } else { object *tmp, *c_cont = op->env; tag_t c = op->count; CLEAR_FLAG(op, FLAG_UNPAID); CLEAR_FLAG(op, FLAG_STARTEQUIP); if (pl->type == PLAYER) { new_draw_info_format(NDI_UNIQUE, pl, "You paid %s for %s.", buf, query_name(op, NULL)); } tmp = merge_ob(op, NULL); if (pl->type == PLAYER) { /* It was merged */ if (tmp) { esrv_del_item(CONTR(pl), c, c_cont); op = tmp; } esrv_send_item(pl, op); } } } return 1; }
void player1_turn() { int dice = dice_data(2); int purchase; int fine; int get; player1_position = dice+player1_position; //drop the dices /* when finish one loop, the counter back to zero */ if (player1_position > 40) { player1_position = player1_position-40; } printf("Player[1] droped %d points\n",dice); /* when occupy_condition = 0 buy the space the cost is it's original price */ if (space[player1_position].occupy_condition == 0) { purchase = buy_space(player1_position, 1); printf("Player[1] bought %s for %d dollars\n",space[player1_position].space_name, purchase); player[1]=player[1]-purchase; printf("Player[1] has %d dollars left\n\n",player[1]); } /* for player1 when the space's occupy_condation = 1 it means the space has been purchased, no fine and no get */ else if (space[player1_position].occupy_condition == 1) { printf("%s is already belongs to Player[1]\n\n",space[player1_position].space_name); } /* for player1 When the space's occupy_condition != 1, for example of 2 player1 - fine and player + fine */ else if (space[player1_position].occupy_condition == 2) { fine = get_payment(player1_position); player[1] = player[1]-fine; player[2] = player[2]+fine; printf("FINE: %s is owned by Player[2], Player[1] is fined %d dollars\n",space[player1_position].space_name,fine); printf("Player[1] has %d dollars left\n\n",player[1]); } /* When the space's occupy_condition == -1 the fine and get depends on space itself */ else if (space[player1_position].occupy_condition == -1) { if (player1_position == 30) { player1_position = 10; player[1] = player[1]-50; printf("Player[1] is sent to Jail and fined 50 dollars\n"); printf("Player[1] has %d dollars left\n\n",player[1]); } else{ get = get_payment(player1_position); player[1] = player[1]-get; printf("Player[1] get %d dollars from %s\n",-get,space[player1_position].space_name); // -get to get positive value printf("Player[1] has %d dollars left\n\n",player[1]); } } /* error */ else printf("WARNING: %s ERROR\n\n",space[player1_position].space_name); }