New answers tagged

3

Wow! What a project! I had tons of fun working on this! There are a lot of things to like about your code. Instead of going over the general improvements I made, I'm going to explain each part that I changed and why I changed it. Note: I did not touch the threading * and other hunger behavior because I am not confident enough with my ability to improve ...


0

Do something about the code formatting (intendation) in this question. The code reads really awful. Review of Piece Piece has an instance variable of the same type, which is stored through the copy constructor, but unused in the class. Many variables belong together x1, y1 etc.. Consider creating a class EuclidPoint which groups and x and y value. You can ...


0

Suggestions In addition to the suggestions provided by others, I observations on how to improve your code: Problems like these, where we both have some information that needs to be stored and have a bundle of functions closely related can be effectively made into a class. The problem is cyclic over the 3 options rock, paper, and scissors, which means we ...


2

I don't mind the other two answers but I felt like there was a better way to do this. Consider using a dictionary where the key will be the selection and the value will be what that selection beats. So the dict will be: choices = { 'paper': 'rock', # paper beats rock 'rock': 'scissors', # rock beats scissors 'scissors': 'paper', # scissors ...


3

First I suggest you to split your logic into several function, it will help you to see what is essential and what you could optimize / remove. import random print("Rock, Paper, Scissors") AVAILABLE_CHOICES = ['rock', 'paper', 'scissors'] def rps(): try: userInput = getUserInput() computerChoice = getComputerChoise() result = getResult() ...


1

Getting the computer choice Many things can be improved in the way the computer choice is computed: import random computerChoice = '' for x in range(1): num = random.randint(1,4) if num == 1: computerChoice = 'rock' elif num == 2: computerChoice = 'paper' elif num == 4: computerChoice = 'scissors' Here are different steps to make things ...


2

Good job separating concerns Your tetris game-board model, piece and UI code is nicely separated in classes, so each one has its own responibility. Well done! Don't use magic values, use Enum public Piece(int f) This switches on a magic value of f. Piece is a excellent candidate for Enum! public enum Piece { L, J, T, Z, I, ... } Enum works as class ...


5

Your two main issues have not been resolved. Separation of Concerns I still find it hard to split the UI and the program logic although I have created a static Screen class for that. Even though you have tried to offset UI operations to a dedicated class Screen, your code is still full of mixed concerns logic (presentation vs application vs test). ...


4

Your game has the same kind of flaw like a lot of the other games that have recently been here on Code Review: an unnecessary recursion in the main game flow: What do I mean by that? Let's look at your main function: def main(): # ... all of the actual game here ... if play_again(): main() else: print("Goodbye!") ...


2

Here are some things that may help you improve your code. Use consistent formatting The code as posted has inconsistent indentation which makes it hard to read and understand. Pick a style and apply it consistently. Use more whitespace Lines like this one: for(int i=0;i<5;i++){ are easier for most humans to read and understand with more whitespace ...


1

First of all: the code does not work, so this is not the appropiate place for your question (code review is to improve code which works). Having said that, I proceed to give you some help (next time, ask your question where appropiate). card1 and card2 are taking values which are not numbers (look at what face_value() has as an output; it only prints ...


2

This would be a great opportunity to explore es6 classes. create a Fighter class that contains the basic attributes and methods for a fighter/hero // for example: class Fighter { name = ''; life = 10; get isAlive() { this.life > 0; } constructor({ name = null}) { if (!name) { throw new Error('A hero needs a name!'); } ...


2

getChoice can be optimized as such. My code uses Character input as opposed to a string value. In the previous case, user can enter a String which is a costly operation and the previous code has an empty if block, which is not good coding practice. private int getChoice() { char x = '1'; try { x = sc.next().charAt(0); if(x < 48 ||...


2

the program does not cleanly compile. When compiling, always enable the warnings, then fix those warnings. ( for gcc, at a minimum use: -Wall -Wextra -Wconversion -pedantic -std=gnu11 ) Note: other compilers use different options to produce the same results The posted code results in: gcc -ggdb -Wall -Wextra -Wconversion -pedantic -std=gnu11 -c "...


3

I see a number of things that may help you improve your program. Use the required #includes The code uses std::vector and std::string which means that it should #include <vector> and <string>. It was not difficult to infer, but it helps reviewers if the code is complete. Use 0 instead of NULL for values that are not pointers The value 0 is a ...


2

I am not sure why you do not just use numpys ndarray and instead have invented your own version. I would however suggest you make it derive from numpys ndarray, which will save you a lot of work, and it allow you to do all kinds of nice things with it. I would also use __setitem__ instead of replace, so you can use the grid[x,y] = value, notation. There are ...


1

The right tool for the job Adventure games are data-driven programs. In the game, you will have objects which have descriptions. You will have places, which have descriptions, contents, and connections to other locations. You will have a player, who will have a description, an inventory (contents), and move from location to location. Inform 7 is an ...


2

I would move the story/writing out of the python script and into a text file. Even better, I would put it into some JSON compliant format. This isn't the only way to do this, but this is what I came up with just now: A given JSON object describes a single scene/event. Each possible event has a unique ID, and has a list of possible transitions (certain user ...


Top 50 recent answers are included