Litherz Posted January 3, 2015 Share Posted January 3, 2015 I want to create a top trumps game using pseudo code with variables, loops, If statements and inputs, how would I write it? Thanks Link to comment Share on other sites More sharing options...
0 Nick H. Supervisor Posted January 3, 2015 Supervisor Share Posted January 3, 2015 Pseudocode is just fake code. There is no definitive way of writing pseudocode, you just write it in a way that resembles code. For example, black jack: define Card 1 define Card 2 Draw 2 cards if (Card 1 + Card 2) > 21 {tell user "you're bust"} Else {display current total} That's overly simplistic, but it would allow a coder to see how I wanted the code to be written, and they could then code it in the code of their choice. simplezz 1 Share Link to comment Share on other sites More sharing options...
0 pqt Posted January 3, 2015 Share Posted January 3, 2015 Misunderstood the question - removed Link to comment Share on other sites More sharing options...
0 Litherz Posted January 3, 2015 Author Share Posted January 3, 2015 Pseudocode is just fake code. There is no definitive way of writing pseudocode, you just write it in a way that resembles code. For example, black jack: define Card 1 define Card 2 Draw 2 cards if (Card 1 + Card 2) > 21 {tell user "you're bust"} Else {display current total} That's overly simplistic, but it would allow a coder to see how I wanted the code to be written, and they could then code it in the code of their choice. Thanks for the example, if I have 3 red and 3 yellow cards, how would I define or write it as variable? Link to comment Share on other sites More sharing options...
0 Nick H. Supervisor Posted January 3, 2015 Supervisor Share Posted January 3, 2015 Thanks for the example, if I have 3 red and 3 yellow cards, how would I define or write it as variable?Just from that information, I would probably say: define rCard1 define rCard2 define rCard3 define yCard1 define yCard2 define yCard3But I don't know anything about the game Top Trumps, so there may be a better way of defining the cards. By doing the above, you would be able to have each red card and each yellow card with different values - whatever those values may be. Link to comment Share on other sites More sharing options...
0 Nagisan Posted January 3, 2015 Share Posted January 3, 2015 Just from that information, I would probably say: define rCard1 define rCard2 define rCard3 define yCard1 define yCard2 define yCard3 But I don't know anything about the game Top Trumps, so there may be a better way of defining the cards. By doing the above, you would be able to have each red card and each yellow card with different values - whatever those values may be. I would personally prefer an array for something like that: define rCard[3] define yCard[3] Would make it easier to programmatically manipulate it if needed (you could write a small loop to populate or clear the cards instead of having to type out rCard1, rCard2, rCard3 each time, for example). But that's just me, and it could easily be interpreted and programmed that way even if the pseudocode was written as you wrote. Link to comment Share on other sites More sharing options...
0 Nick H. Supervisor Posted January 3, 2015 Supervisor Share Posted January 3, 2015 I would personally prefer an array...Very true, and if it were me I would probably do it as an array as well. However, I don't know how far along in his studies Litherz is, and it may be that he hasn't covered arrays yet. But that's only my assumption based on the original question. Link to comment Share on other sites More sharing options...
0 Litherz Posted January 3, 2015 Author Share Posted January 3, 2015 Thanks to both of you for your help, I will give it a go tomorrow but is it possible if I can PM you the code when it's in progress/finished just to double check it's good? Link to comment Share on other sites More sharing options...
0 Andre S. Veteran Posted January 3, 2015 Veteran Share Posted January 3, 2015 Just post it here and you'll have many more eyes to check it Elliot B. 1 Share Link to comment Share on other sites More sharing options...
0 Nagisan Posted January 3, 2015 Share Posted January 3, 2015 Just post it here and you'll have many more eyes to check it Probably quicker response times too as a PM may not be answered as quickly as someone sees the post in this thread depending on time of day and what the people he's PMing may be doing. Not that I mind receiving PMs but in this case it will likely give better and quicker responses to just keep posting here. Link to comment Share on other sites More sharing options...
0 Litherz Posted January 7, 2015 Author Share Posted January 7, 2015 I have created a diagram to describe how the game works, it will have 7 cards, 3x red, 2x blue and 2x yellow (special card). The game works by if the player chosen category number is higher than other player, then the player wins all the played cards. I have started to write it but not sure if its correct or not and I don't know how I would declare the cards variables, BEGIN mix up the cards hand out all the cards player on the right starts player picks a category from the card player tell their chosen category number other players tell their same category number IF yellow card used THEN minus or plus the number on the yellow card ELSE player with the highest category number gets all the played cards IF any player with no cards left THEN ELSE player who won starts next LOOP END Link to comment Share on other sites More sharing options...
0 Nagisan Posted January 7, 2015 Share Posted January 7, 2015 Honestly that psuedocode looks good enough to get an idea of what is needed. Remember, psuedocode isn't about writing the program out, it's about giving enough detail that a programmer can write a program that does what you need the program to do. I would probably do something along the lines of "Define cards" -> "Ask how many players" -> "Distribute cards evenly among players", that to me would say you need to create an array or list that stores all the possible cards of the game (perhaps get fancy and use a database so you can actually modify the cards without having to recompile it) -> define a player class (which would store cards, score, etc), then you can create a list (or array, or whatever) for each player (in the player class) to store the cards that each individual player has. From there you basically have a list of all the cards in the game, a list of all the players, and each player class has a list of cards they have in their hand, their score, and whatever else you want to track for each player. Link to comment Share on other sites More sharing options...
0 Litherz Posted January 7, 2015 Author Share Posted January 7, 2015 Honestly that psuedocode looks good enough to get an idea of what is needed. Remember, psuedocode isn't about writing the program out, it's about giving enough detail that a programmer can write a program that does what you need the program to do. I would probably do something along the lines of "Define cards" -> "Ask how many players" -> "Distribute cards evenly among players", that to me would say you need to create an array or list that stores all the possible cards of the game (perhaps get fancy and use a database so you can actually modify the cards without having to recompile it) -> define a player class (which would store cards, score, etc), then you can create a list (or array, or whatever) for each player (in the player class) to store the cards that each individual player has. From there you basically have a list of all the cards in the game, a list of all the players, and each player class has a list of cards they have in their hand, their score, and whatever else you want to track for each player. Thanks for checking the code and the extra information tip, To define all the cards in the game along with the card category values, I use this method to define? define rCard1, height 30cm, width 50cm define rCard2, height 32cm, width 54cm define bCard1, height 40cm, width 30cm Also after a player won each round, how do I specific the loop to go back to 'player picks a category from the card' step and not from the beginning 'mix up the cards' Link to comment Share on other sites More sharing options...
0 Nagisan Posted January 7, 2015 Share Posted January 7, 2015 Thanks for checking the code and the extra information tip, To define all the cards in the game along with the card category values, I use this method to define? define rCard1, height 30cm, width 50cm define rCard2, height 32cm, width 54cm define bCard1, height 40cm, width 30cm Also after a player won each round, how do I specific the loop to go back to 'player picks a category from the card' step and not from the beginning 'mix up the cards' Using your example from above I would probably do something along the lines of: BEGIN mix up the cards hand out all the cards DEFINE winner = player to right WHILE winner is not "" winner picks a category from the card winner tells their chosen category number other players tell their same category number IF yellow card used THEN minus or plus the number on the yellow card ELSE player with the highest category number gets all the played cards IF any player with no cards left THEN winner == "" ELSE winner = player with highest category number WEND END Should be simple enough to follow, it empties out the "winner" variable if anyone runs out of cards, which ends the while loop (in case it's not clear, WEND just signifies where the loop ends). Link to comment Share on other sites More sharing options...
Question
Litherz
I want to create a top trumps game using pseudo code with variables, loops, If statements and inputs, how would I write it?
Thanks
Link to comment
Share on other sites
13 answers to this question
Recommended Posts