![]() ![]() ![]() *You can find an example of the former being used in an InDesign like app in Design Patterns by the Gang of Four if you want further reference on how to set that up. I don't make games for a living so I'm sure there are even better ways to do it. When the pivot point is no longer valid (the snake no longer has any parts that cross the pivot) I'd remove it from the array. If I was implementing it I'd use an array of pivot points that would tell the snake how to turn pieces of the snake as it traverses the board. As the snake moves you can just increment over the array and change the points to take into account the direction of movement and how far to move. The snake object could have an array (or better yet an ArrayList) that stores the coordinates of the blocks that make up a snake. It wouldn't be unreasonable to let the snake draw itself on the board* or at least store it's display information for the board to handle. If it detects a collision on between the snake and itself, the game would end. If it the game board detects a collision between the snake and food, it would move the food sprite to the next position and invoke Eat() on the snake object in play. 13 Change the code We will use blocks of 32x32 pixels The game size will be 25. Probably a better idea would be to move user input elsewhere and have the game board communicate state changes to the various sprites (snake, food, wall etc) including collision detection. It looks like you're trying to put a lot of sprite interaction logic in your snake class. I'm getting the feeling your question is more general than simple array handling. GetWorld().addObject ( new Food(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(400)) * Write a description of class Snake here.Īctor a = getOneIntersectingObject(Food.class) The class Snake: import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) * Constructor for objects of class WorldofSnake.ĪddObject ( new Food(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(400)) The world: public class WorldofSnake extends World Print "You do not have anymore points game over.Got a new task in School to code the Snake Game from scratch and need to use a array to add a new Snake bodypart when the Snakehead eats food and at the beginning the Snake need to have 1 head and 2 bodyparts.and I have no idea how to do this.can someone out there help me on right direction.how to start? Here is my code so far: You just have to move validInput = False one space to the right. elif validInput = True:Įnough points to make that wager. One last thing, you have an indentation problem in your code. If you properly add in these lines of code you should now have a functional score counter. Now change this if statement if evaluateBet(userInput) = True: This is a wonderful way to see for loops and arrays in action. It also has made a resurgence through mobile gaming platforms (all the way back to flip phones, EEK). Put these print statements so the score can be printed out print "Wins: " + str(wins) Snake was a popular game in the 70's at arcades. Under this line in the main() function while programLoop = True: Right under your def main() define the wins and losses variables both equal to 0 def main(): You already have almost all of the code necessary to make a score counter, just a few things you need to add in here and there. Print "You may only choose to type from the options 'yes' or 'no' " If userInput = "yes" or userInput = "no": UserInput = raw_input("\nWould you like to play again?: Type 'yes' or 'no': ") Print "You do not have anymore points game over." Print "You may only choose to type from the options 'high' or 'low' " If userInput = "high" or userInput = "low": UserInput = raw_input("\nPlace a bet: Either type 'High' or 'Low': ") Print "Points remaining: " + str( points ) Print "Your wager must be greater than 0. Print "You don't have enough points to make that wager. Print "The random number is: " + str(randNum)Įlif choice = "low" and randNum points: Thanks and here is my code: import randomįor amtChar in range(0, len( userInput ) ): Total beginner in programing just began a few months ago :D I do know that the score counter should be part of my main function but I am just not sure how to add a score counter, hence I am here. If you guys can tell me how to add a score on my game or show me how I would really appreciate it. But I am wanting to add a score counter to my program - the score counter will keep track of how many times a user loses and wins. Hi my friends helped me program this game in python. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |